diff --git a/src/Abstracts/PaymentMethod.php b/src/Abstracts/PaymentMethod.php index 8c178da..bcf2a65 100644 --- a/src/Abstracts/PaymentMethod.php +++ b/src/Abstracts/PaymentMethod.php @@ -252,11 +252,12 @@ public function createSignature(array $input, string $type = 'request'): string * * @param array $data * @param bool $is_json + * @param string $url * * @return mixed|string * @throws \Exception */ - public function callApi(array $data, bool $is_json = true) + public function callApi(array $data, bool $is_json = true, string $url = null) { $content_type = $is_json ? 'json' : 'form_params'; $payload = [ @@ -276,7 +277,10 @@ public function callApi(array $data, bool $is_json = true) ]); try { - $response = $client->post($this->gateway_url . '/FortAPI/paymentApi', $payload); + $url = $url ?? $this->gateway_url . '/FortAPI/paymentApi'; + + $response = $client->post($url, $payload); + } catch (ClientException $exception) { throw new IncompletePayment($exception->getMessage(), $exception->getCode()); } diff --git a/src/MerchantPage/MerchantPage.php b/src/MerchantPage/MerchantPage.php index d65ec2f..453dee3 100644 --- a/src/MerchantPage/MerchantPage.php +++ b/src/MerchantPage/MerchantPage.php @@ -98,4 +98,34 @@ public function prepareTokenizationData(array $params): array return $params; } + + /** + * check the transaction status + * + * @param array $params + * + * @return array + * @throws \Exception + */ + public function checkTransactionStatus(array $params): array + { + $params = array_merge([ + 'query_command' => 'CHECK_STATUS', + 'access_code' => $this->access_code, + 'merchant_identifier' => $this->merchant_identifier, + 'language' => $this->language, + ], $params); + + // if signature is not already set + if (!$signature = Arr::get($params, 'signature')) { + + // create the signature + $signature = $this->createSignature($params); + + // add signature in the params + $params['signature'] = $signature; + } + + return $this->callApi($params, true, 'https://sbpaymentservices.payfort.com/FortAPI/paymentApi'); + } }