1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apoca\Sibs\Brands; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use GuzzleHttp\Client; |
7
|
|
|
use GuzzleHttp\Exception\ClientException; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class PaymentWithMBWay |
11
|
|
|
* |
12
|
|
|
* @package Apoca\Sibs\Brands |
13
|
|
|
*/ |
14
|
|
|
class PaymentWithMBWay extends Payment |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $accountId; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $endpoint; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
protected $clientConfig = []; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* PaymentWithMBWay constructor. |
33
|
|
|
* |
34
|
|
|
* @param float $amount |
35
|
|
|
* @param string $currency |
36
|
|
|
* @param string $brand |
37
|
|
|
* @param string $type |
38
|
|
|
* @param string $accountId |
39
|
|
|
* @param array $optionalParameters |
40
|
|
|
*/ |
41
|
|
|
public function __construct( |
42
|
|
|
float $amount, |
43
|
|
|
string $currency, |
44
|
|
|
string $brand, |
45
|
|
|
string $type, |
46
|
|
|
string $accountId, |
47
|
|
|
array $optionalParameters |
48
|
|
|
) { |
49
|
|
|
parent::__construct($amount, $currency, $brand, $type, $optionalParameters); |
50
|
|
|
$this->accountId = $accountId; |
51
|
|
|
$this->endpoint = config('sibs.host') . config('sibs.version') . '/'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Execute the payment |
56
|
|
|
* |
57
|
|
|
* @return object |
58
|
|
|
*/ |
59
|
|
|
public function pay() |
60
|
|
|
{ |
61
|
|
|
$data = (object)null; |
62
|
|
|
|
63
|
|
|
try { |
64
|
|
|
$client = new Client($this->clientConfig); |
65
|
|
|
|
66
|
|
|
$payload = [ |
67
|
|
|
'entityId' => config('sibs.authentication.entityId'), |
68
|
|
|
'amount' => number_format($this->amount, 2, '.', ''), |
69
|
|
|
'currency' => $this->currency, |
70
|
|
|
'paymentBrand' => $this->brand, |
71
|
|
|
'paymentType' => $this->type, |
72
|
|
|
'virtualAccount.accountId' => $this->accountId, |
73
|
|
|
]; |
74
|
|
|
if (config('sibs.mode') === 'test') { |
75
|
|
|
$payload = array_merge($payload, |
76
|
|
|
[ |
77
|
|
|
'customParameters[SIBS_ENV]' => 'QLY', |
78
|
|
|
'testMode' => 'EXTERNAL', |
79
|
|
|
]); |
80
|
|
|
} |
81
|
|
|
$response = $client->post($this->endpoint . 'payments', [ |
82
|
|
|
'headers' => [ |
83
|
|
|
'Authorization' => config('sibs.authentication.token'), |
84
|
|
|
], |
85
|
|
|
'form_params' => array_merge($payload, $this->getOptionalParameters()), |
86
|
|
|
]); |
87
|
|
|
|
88
|
|
|
$data->status = $response->getStatusCode(); |
89
|
|
|
$data->response = json_decode($response->getBody()->getContents(), false); |
90
|
|
|
|
91
|
|
|
return $data; |
92
|
|
|
} catch (ClientException $e) { |
93
|
|
|
$response = $e->getResponse(); |
94
|
|
|
|
95
|
|
|
$data->status = $response->getStatusCode(); |
96
|
|
|
$data->response = json_decode($response->getBody()->getContents(), false); |
97
|
|
|
|
98
|
|
|
return $data; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |