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 { $hash = $request->query->get('hash'); return $hash == $this->computeHash($request->request->all()); } public function verifyGatewayCallback(Request $request, Response &$response = null): bool { $response = Res::make('OK'); $hash = $request->request->get('hash'); return $hash == $this->computeHash($request->request->all()); } public function getBillIdFromRequest(Request $request): ?string{ return $request->get('order_id'); } public function getBillStatus(Request $request): ?int { return $request->request->get('status') == 1 ? Payment::SUCCESS : Payment::PENDING; } public function computeHash($payload){ $payload['hash'] = '[HASH]'; return md5($this->secret_key.'?'.http_build_query($payload)); } }