Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

RazerPayDriver.php 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace MirfalahTech\Laravel\Payment\Gateway\RazerPay;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Arr;
  5. use Illuminate\Support\Facades\Response as Res;
  6. use MirfalahTech\Laravel\Payment\Contracts\PayableEntity;
  7. use MirfalahTech\Laravel\Payment\Contracts\PaymentGatewayDriver;
  8. use Symfony\Component\HttpFoundation\Response;
  9. class RazerPayDriver implements PaymentGatewayDriver
  10. {
  11. /**
  12. * @var string
  13. */
  14. protected $endpoint;
  15. /**
  16. * @var string
  17. */
  18. protected $merchant_id;
  19. /**
  20. * @var string
  21. */
  22. protected $secret_key;
  23. /**
  24. * @var string
  25. */
  26. protected $verify_key;
  27. public function __construct(string $endpoint, string $merchant_id, string $verify_key, string $secret_key)
  28. {
  29. $this->endpoint = rtrim($endpoint, '/');
  30. $this->merchant_id = $merchant_id;
  31. $this->secret_key = $secret_key;
  32. $this->verify_key = $verify_key;
  33. }
  34. public function createPaymentURL(PayableEntity $payable, array $options = []): string
  35. {
  36. $order_id = urlencode($payable->getBillId());
  37. $bill_name = urlencode($payable->getBillName());
  38. $bill_email = $payable->getBillEmail();
  39. $bill_mobile = $payable->getBillPhoneNumber();
  40. $detail = urlencode($payable->getBillDescription());
  41. $country = $payable->getBillCountry();
  42. $bill_desc = urlencode(preg_replace('/[^A-Z0-9,\-_]/i', '_', $detail));
  43. $amount = sprintf('%0.2f', $payable->getBillAmount());
  44. $currency = $payable->getBillCurrency();
  45. $verify_code = md5($amount . $this->merchant_id . $payable->getBillId() . $this->verify_key);
  46. $query = array_merge(
  47. compact(
  48. 'amount', 'order_id', 'bill_name', 'bill_email', 'bill_mobile',
  49. 'bill_desc', 'country', 'verify_code', 'currency'
  50. ),
  51. Arr::only($options, ['channel'])
  52. );
  53. return "$this->endpoint/MOLPay/pay/$this->merchant_id/?" .
  54. http_build_query($query);
  55. }
  56. public function verifyGatewayReturn(Request $request): bool
  57. {
  58. $tranID = $request->request->get('tranID');
  59. $order_id = $request->request->get('orderid');
  60. $status = $request->request->get('status');
  61. $domain = $request->request->get('domain');
  62. $amount = $request->request->get('amount');
  63. $currency = $request->request->get('currency');
  64. $appcode = $request->request->get('appcode');
  65. $pay_date = $request->request->get('paydate');
  66. $key0 = md5($tranID . $order_id . $status . $domain . $amount . $currency);
  67. $key1 = md5($pay_date . $domain . $key0 . $appcode . $this->secret_key);
  68. return $key1 == $request->request->get('skey');
  69. }
  70. public function verifyGatewayCallback(Request $request, Response &$response = null): bool
  71. {
  72. $response = $request->request->has('nbcb') ?
  73. Res::make('CBTOKEN:MPSTATOK') :
  74. Res::make('OK');
  75. return $this->verifyGatewayReturn($request);
  76. }
  77. public function getBillIdFromRequest(Request $request){
  78. return $request->query->get('orderid');
  79. }
  80. }