1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kalkulus\Thetellara; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Config; |
|
|
|
|
6
|
|
|
use Illuminate\Support\Str; |
|
|
|
|
7
|
|
|
|
8
|
|
|
class Thetellara |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Your environment mode |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
protected $tellerEnv; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Your environment mode initialze url |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $tellerInitializeUrl; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Your environment mode payment response url |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $tellerPaymentResponseUrl; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Issued Merchant ID from Theteller Dashboard |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $merchantID; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Merchant redirect url |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $redirectUrl; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Issued API username from Theteller Dashboard |
42
|
|
|
* @var mixed |
43
|
|
|
*/ |
44
|
|
|
protected $apiUsername; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Issued API key from Theteller Dashboard |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $apiKey; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Based 64 value with is formed from apiKey and apiUsername |
54
|
|
|
* @var string |
55
|
|
|
*/ |
56
|
|
|
protected $baseValue; |
57
|
|
|
|
58
|
|
|
public function __construct() |
59
|
|
|
{ |
60
|
|
|
$this->setEnvMode(); |
61
|
|
|
$this->setMerchantId(); |
62
|
|
|
$this->setRedirectUrl(); |
63
|
|
|
$this->setApiUsername(); |
64
|
|
|
$this->setApiKey(); |
65
|
|
|
$this->setBaseValue(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get Environment Mode from config file |
70
|
|
|
*/ |
71
|
|
|
public function setEnvMode() |
72
|
|
|
{ |
73
|
|
|
$this->tellerEnv = Config::get('theteller.tellerEnv'); |
74
|
|
|
|
75
|
|
|
if ($this->tellerEnv == 'test') { |
76
|
|
|
$this->tellerInitializeUrl = "https://test.theteller.net/checkout/initiate"; |
77
|
|
|
$this->tellerPaymentResponseUrl = "https://test.theteller.net/v1.1/users/transactions/"; |
78
|
|
|
} else { |
79
|
|
|
$this->tellerInitializeUrl = "https://checkout.theteller.net/initiate"; |
80
|
|
|
$this->tellerPaymentResponseUrl = "https://prod.theteller.net/v1.1/users/transactions/"; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get Merchant ID from config file |
86
|
|
|
*/ |
87
|
|
|
public function setMerchantId() |
88
|
|
|
{ |
89
|
|
|
$this->merchantID = Config::get('theteller.merchantId'); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Get Client Redirect URL from config file |
94
|
|
|
*/ |
95
|
|
|
public function setRedirectUrl() |
96
|
|
|
{ |
97
|
|
|
$this->redirectUrl = Config::get('theteller.redirectUrl'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get API Username from config file |
102
|
|
|
*/ |
103
|
|
|
public function setApiUsername() |
104
|
|
|
{ |
105
|
|
|
$this->apiUsername = Config::get('theteller.apiUsername'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Get API Key from config file |
110
|
|
|
*/ |
111
|
|
|
public function setApiKey() |
112
|
|
|
{ |
113
|
|
|
$this->apiKey = Config::get('theteller.apiKey'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Get API Key from config file |
118
|
|
|
*/ |
119
|
|
|
public function setBaseValue() |
120
|
|
|
{ |
121
|
|
|
$this->baseValue = $this->apiUsername.':'.$this->apiKey; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param string $transactionId |
126
|
|
|
* @param string $email |
127
|
|
|
* @param string $desc |
128
|
|
|
* @param float $amount |
129
|
|
|
*/ |
130
|
|
|
public function initialize($transactionId, $email, $amount, $desc = null) |
131
|
|
|
{ |
132
|
|
|
$payload = json_encode( |
133
|
|
|
[ |
134
|
|
|
"merchant_id" => $this->merchantID, |
135
|
|
|
"transaction_id" => $transactionId, |
136
|
|
|
"desc" => $desc ?? "Payswitch Payment Request", |
137
|
|
|
"amount" => Str::of(str_pad($amount, 12, '0', STR_PAD_LEFT)), |
138
|
|
|
"redirect_url" => $this->redirectUrl, |
139
|
|
|
"email" => $email |
140
|
|
|
] |
141
|
|
|
); |
142
|
|
|
|
143
|
|
|
$curl = curl_init(); |
144
|
|
|
|
145
|
|
|
curl_setopt_array($curl, array( |
146
|
|
|
CURLOPT_URL => $this->tellerInitializeUrl, |
147
|
|
|
CURLOPT_RETURNTRANSFER => true, |
148
|
|
|
CURLOPT_ENCODING => "", |
149
|
|
|
CURLOPT_MAXREDIRS => 10, |
150
|
|
|
CURLOPT_TIMEOUT => 30, |
151
|
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
152
|
|
|
CURLOPT_CUSTOMREQUEST => "POST", |
153
|
|
|
CURLOPT_POSTFIELDS => $payload, |
154
|
|
|
CURLOPT_HTTPHEADER => array( |
155
|
|
|
"Authorization: Basic ".base64_encode($this->baseValue)."", |
156
|
|
|
"Cache-Control: no-cache", |
157
|
|
|
"Content-Type: application/json" |
158
|
|
|
), |
159
|
|
|
)); |
160
|
|
|
|
161
|
|
|
$response = curl_exec($curl); |
162
|
|
|
$err = curl_error($curl); |
163
|
|
|
|
164
|
|
|
|
165
|
|
|
curl_close($curl); |
166
|
|
|
|
167
|
|
|
if ($err) { |
168
|
|
|
echo "cURL Error #:" . $err; |
169
|
|
|
} else { |
170
|
|
|
return json_decode($response); |
|
|
|
|
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public function getPaymentDetails() |
175
|
|
|
{ |
176
|
|
|
$transactionId = request()->query('transaction_id'); |
|
|
|
|
177
|
|
|
|
178
|
|
|
$curl = curl_init(); |
179
|
|
|
|
180
|
|
|
curl_setopt_array($curl, array( |
181
|
|
|
CURLOPT_URL => $this->tellerPaymentResponseUrl.$transactionId."/status", |
182
|
|
|
CURLOPT_RETURNTRANSFER => true, |
183
|
|
|
CURLOPT_ENCODING => "", |
184
|
|
|
CURLOPT_MAXREDIRS => 10, |
185
|
|
|
CURLOPT_TIMEOUT => 30, |
186
|
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
187
|
|
|
CURLOPT_CUSTOMREQUEST => "GET", |
188
|
|
|
CURLOPT_HTTPHEADER => array( |
189
|
|
|
"Cache-Control: no-cache", |
190
|
|
|
"Merchant-Id: ".$this->merchantID, |
191
|
|
|
), |
192
|
|
|
)); |
193
|
|
|
|
194
|
|
|
$response = curl_exec($curl); |
195
|
|
|
$err = curl_error($curl); |
196
|
|
|
|
197
|
|
|
curl_close($curl); |
198
|
|
|
|
199
|
|
|
if ($err) { |
200
|
|
|
echo "cURL Error #:" . $err; |
201
|
|
|
} else { |
202
|
|
|
dd(json_decode($response)); |
|
|
|
|
203
|
|
|
return json_decode($response); |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
} |
207
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths