|
@@ -4,6 +4,7 @@
|
4
|
4
|
namespace MirfalahTech\Laravel\Payment\Gateway\SenangPay;
|
5
|
5
|
|
6
|
6
|
|
|
7
|
+use Illuminate\Contracts\Config\Repository;
|
7
|
8
|
use Illuminate\Http\Request;
|
8
|
9
|
use Illuminate\Support\Facades\Response as Res;
|
9
|
10
|
use MirfalahTech\Laravel\Payment\Contracts\PayableEntity;
|
|
@@ -36,26 +37,19 @@ class SenangPayDriver implements PaymentGatewayDriver
|
36
|
37
|
*/
|
37
|
38
|
protected $keyMap;
|
38
|
39
|
|
39
|
|
- public function __construct(string $endpoint, string $merchant_id, string $secret_key, array $keyMap)
|
|
40
|
+ public function __construct(Repository $config, array $options)
|
40
|
41
|
{
|
41
|
|
- $this->endpoint = rtrim($endpoint, '/');
|
42
|
|
- $this->merchant_id = $merchant_id;
|
43
|
|
- $this->secret_key = $secret_key;
|
44
|
|
- $this->keyMap = $keyMap;
|
|
42
|
+ $finalConfig = array_merge($config->get('payment.gateway'), $options);
|
|
43
|
+ $this->endpoint = rtrim($finalConfig['endpoint'], '/');
|
|
44
|
+ $this->merchant_id = $finalConfig['merchant_id'];
|
|
45
|
+ $this->secret_key = $finalConfig['secret_key'];
|
|
46
|
+ $this->keyMap = $finalConfig['key_map'];
|
45
|
47
|
}
|
46
|
48
|
|
47
|
49
|
public function createPaymentURL(PayableEntity $payable, array $options = []): string
|
48
|
50
|
{
|
49
|
|
- $detail = $payable->getBillDescription();
|
50
|
|
- $amount = $payable->getBillAmount();
|
51
|
|
- $order_id = $payable->getBillId();
|
52
|
|
-
|
53
|
|
- $detail = preg_replace('/[^A-Z0-9,\-_]/i', '_', $detail);
|
54
|
|
- $amount = sprintf('%0.2f', $amount);
|
55
|
|
- $hash = md5($this->secret_key . $detail . $amount . $order_id);
|
56
|
|
-
|
57
|
51
|
return "$this->endpoint/payment/$this->merchant_id?" .
|
58
|
|
- http_build_query(compact('detail', 'order_id', 'amount', 'hash'));
|
|
52
|
+ http_build_query($this->preparePaymentParam($payable, $options));
|
59
|
53
|
}
|
60
|
54
|
|
61
|
55
|
public function verifyGatewayReturn(Request $request): bool
|
|
@@ -93,4 +87,29 @@ class SenangPayDriver implements PaymentGatewayDriver
|
93
|
87
|
$query = preg_replace('/(^|&)'.$key.'[^&]*($|&)/','$1hash=[HASH]$2', $query);
|
94
|
88
|
return md5($this->secret_key . '?' . $query);
|
95
|
89
|
}
|
|
90
|
+
|
|
91
|
+ public function isPostMethodSupported(): bool
|
|
92
|
+ {
|
|
93
|
+ return true;
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ public function createPostMethodPayment(PayableEntity $payable, array $options = []): Response
|
|
97
|
+ {
|
|
98
|
+ $params = $this->preparePaymentParam($payable, $options);
|
|
99
|
+ ob_start();
|
|
100
|
+ include __DIR__.'../res/view/response.php';
|
|
101
|
+ return new Response(ob_get_clean());
|
|
102
|
+ }
|
|
103
|
+
|
|
104
|
+ protected function preparePaymentParam(PayableEntity $payable, array $options = []): array{
|
|
105
|
+ $detail = $payable->getBillDescription();
|
|
106
|
+ $amount = $payable->getBillAmount();
|
|
107
|
+ $order_id = $payable->getBillId();
|
|
108
|
+
|
|
109
|
+ $detail = preg_replace('/[^A-Z0-9,\-_]/i', '_', $detail);
|
|
110
|
+ $amount = sprintf('%0.2f', $amount);
|
|
111
|
+ $hash = md5($this->secret_key . $detail . $amount . $order_id);
|
|
112
|
+
|
|
113
|
+ return compact('detail', 'order_id', 'amount', 'hash');
|
|
114
|
+ }
|
96
|
115
|
}
|