1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
-
-
- namespace MirfalahTech\Laravel\Payment\Gateway\RazerPay;
-
-
- use Illuminate\Http\Request;
- use Illuminate\Support\Arr;
- use Illuminate\Support\Facades\Response as Res;
- use MirfalahTech\Laravel\Payment\Contracts\PayableEntity;
- use MirfalahTech\Laravel\Payment\Contracts\PaymentGatewayDriver;
- use Symfony\Component\HttpFoundation\Response;
-
- class RazerPayDriver implements PaymentGatewayDriver
- {
- /**
- * @var string
- */
- protected $endpoint;
-
- /**
- * @var string
- */
- protected $merchant_id;
-
- /**
- * @var string
- */
- protected $secret_key;
- /**
- * @var string
- */
- protected $verify_key;
-
- public function __construct(string $endpoint, string $merchant_id, string $verify_key, string $secret_key)
- {
- $this->endpoint = rtrim($endpoint, '/');
- $this->merchant_id = $merchant_id;
- $this->secret_key = $secret_key;
- $this->verify_key = $verify_key;
- }
-
- public function createPaymentURL(PayableEntity $payable, array $options = []): string
- {
- $order_id = urlencode($payable->getBillId());
- $bill_name = urlencode($payable->getBillName());
- $bill_email = $payable->getBillEmail();
- $bill_mobile = $payable->getBillPhoneNumber();
- $detail = urlencode($payable->getBillDescription());
- $country = $payable->getBillCountry();
- $bill_desc = urlencode(preg_replace('/[^A-Z0-9,\-_]/i', '_', $detail));
- $amount = sprintf('%0.2f', $payable->getBillAmount());
- $currency = $payable->getBillCurrency();
- $verify_code = md5($amount . $this->merchant_id . $payable->getBillId() . $this->verify_key);
-
- $query = array_merge(
- compact(
- 'amount', 'order_id', 'bill_name', 'bill_email', 'bill_mobile',
- 'bill_desc', 'country', 'verify_code', 'currency'
- ),
- Arr::only($options, ['channel'])
- );
-
- return "$this->endpoint/MOLPay/pay/$this->merchant_id/?" .
- http_build_query($query);
- }
-
- public function verifyGatewayReturn(Request $request): bool
- {
- $tranID = $request->request->get('tranID');
- $order_id = $request->request->get('orderid');
- $status = $request->request->get('status');
- $domain = $request->request->get('domain');
- $amount = $request->request->get('amount');
- $currency = $request->request->get('currency');
- $appcode = $request->request->get('appcode');
- $pay_date = $request->request->get('paydate');
-
- $key0 = md5($tranID . $order_id . $status . $domain . $amount . $currency);
-
- $key1 = md5($pay_date . $domain . $key0 . $appcode . $this->secret_key);
-
- return $key1 == $request->request->get('skey');
- }
-
- public function verifyGatewayCallback(Request $request, Response &$response = null): bool
- {
- $response = $request->request->has('nbcb') ?
- Res::make('CBTOKEN:MPSTATOK') :
- Res::make('OK');
-
- return $this->verifyGatewayReturn($request);
- }
-
- public function getBillIdFromRequest(Request $request){
- return $request->query->get('orderid');
- }
- }
|