-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWollito.php
115 lines (96 loc) · 3.22 KB
/
Wollito.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
namespace wollito\Wollito;
class Wollito
{
private $accepted_currencies = ["USD", "GBP", "EUR"];
private $api_key = "";
private $api_secret = "";
private $currency = "GBP";
private $descriptor = "";
private $site_url = "";
private $url = "https://paymentgateway.wollito.com/";
public function __construct($api_key = "",$site_url = "", $currency = "GBP")
{
$this->set_keys($api_key, $api_key);
$this->set_currency($currency);
$this->set_site_url($site_url);
}
public function set_keys($api_key, $api_secret)
{
$this->api_key = $api_key;
$this->api_secret = $api_secret;
}
public function set_currency($currency){
if($this->validate_currency($currency)){
$this->currency = $currency;
}
}
public function set_descriptor($descriptor)
{
$this->descriptor = $descriptor;
}
public function set_site_url($url)
{
$this->site_url = $url;
}
public function create_charge_link($amount, $order_id, $return_url)
{
$this->check_keys();
$currency = $this->currency;
$email = "a@gmail.com";
$site = $this->site_url;
$product = $order_id;
$publishable_key = $this->api_key;
$private_key = $this->api_secret;
$type = "PHP";
$d = base64_encode($currency . "***" . $amount . "***" . $order_id . "***" . $email . "***" . $site . "***" . $product. "***" . $publishable_key. "***" . $private_key. "***" .$type);
if(strpos($return_url, "http") === false){
$this->return_error("Invalid return url");
}
return "https://paymentgateway.wollito.com/3d.php?d=".$d."&redirect=".$return_url;
}
public function check_token($token){
$res = file_get_contents("https://paymentgateway.wollito.com/token_check.php?token=".$token);
if($res == "success"){
return "success";
}else if($res == "pending"){
return "pending";
}
return "failed";
}
private function check_keys(){
if($this->api_key && $this->api_secret){
return true;
}else{
$this->return_error("Public and Secret key cannot be null.");
}
}
private function validate_currency($currency){
foreach ($this->accepted_currencies as $accept){
if(strtoupper($currency) == $accept){
return true;
}
}
$this->return_error("Currency not accepted. Please choose one of the following; GBP, USD, EUR.");
}
public function validate_webhook_call($secret){
if(isset($secret['secret'])){
if($this->api_secret == $secret['secret']){
return true;
}
}
$this->return_error("Could not be authenticated");
}
private function return_error($message){
throw new Exception($message);
}
private function url(){
if(isset($_SERVER['HTTPS'])){
$protocol = ($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http";
}
else{
$protocol = 'http';
}
return $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
}
}