You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SenangPayDriver.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace MirfalahTech\Laravel\Payment\Gateway\SenangPay;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\Response as Res;
  5. use MirfalahTech\Laravel\Payment\Contracts\PayableEntity;
  6. use MirfalahTech\Laravel\Payment\Contracts\PaymentGatewayDriver;
  7. use Symfony\Component\HttpFoundation\Response;
  8. class SenangPayDriver implements PaymentGatewayDriver
  9. {
  10. /**
  11. * @var string
  12. */
  13. protected $endpoint;
  14. /**
  15. * @var string
  16. */
  17. protected $merchant_id;
  18. /**
  19. * @var string
  20. */
  21. protected $secret_key;
  22. public function __construct(string $endpoint, string $merchant_id, string $secret_key){
  23. $this->endpoint = rtrim($endpoint, '/');
  24. $this->merchant_id = $merchant_id;
  25. $this->secret_key = $secret_key;
  26. }
  27. public function createPaymentURL(PayableEntity $payable, array $options = []): string
  28. {
  29. $detail = $payable->getBillDescription();
  30. $amount = $payable->getBillAmount();
  31. $order_id = $payable->getBillId();
  32. $detail = preg_replace('/[^A-Z0-9,\-_]/i', '_', $detail);
  33. $amount = sprintf('%0.2f', $amount);
  34. $hash = md5($this->secret_key.$detail.$amount.$order_id);
  35. return "$this->endpoint/payment/$this->merchant_id?'".
  36. http_build_query(compact('detail', 'order_id', 'amount', 'hash'));
  37. }
  38. public function verifyGatewayReturn(Request $request): bool
  39. {
  40. return true;
  41. }
  42. public function verifyGatewayCallback(Request $request, Response &$response = null): bool
  43. {
  44. $response = Res::make('OK');
  45. return true;
  46. }
  47. }