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'); } }