123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
-
-
- namespace MirfalahTech\Laravel\Payment\Gateway\SenangPay;
-
-
- use Illuminate\Http\Request;
- 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 SenangPayDriver implements PaymentGatewayDriver
- {
- /**
- * @var string
- */
- protected $endpoint;
-
- /**
- * @var string
- */
- protected $merchant_id;
-
- /**
- * @var string
- */
- protected $secret_key;
-
- public function __construct(string $endpoint, string $merchant_id, string $secret_key){
- $this->endpoint = rtrim($endpoint, '/');
- $this->merchant_id = $merchant_id;
- $this->secret_key = $secret_key;
- }
-
- public function createPaymentURL(PayableEntity $payable, array $options = []): string
- {
- $detail = $payable->getBillDescription();
- $amount = $payable->getBillAmount();
- $order_id = $payable->getBillId();
-
- $detail = preg_replace('/[^A-Z0-9,\-_]/i', '_', $detail);
- $amount = sprintf('%0.2f', $amount);
- $hash = md5($this->secret_key.$detail.$amount.$order_id);
-
- return "$this->endpoint/payment/$this->merchant_id?'".
- http_build_query(compact('detail', 'order_id', 'amount', 'hash'));
- }
-
- public function verifyGatewayReturn(Request $request): bool
- {
- return true;
- }
-
- public function verifyGatewayCallback(Request $request, Response &$response = null): bool
- {
- $response = Res::make('OK');
- return true;
- }
- }
|