Skip to content

Commit

Permalink
add transaction verification method
Browse files Browse the repository at this point in the history
- PaymentMethod.php update the callApi method to accept url
- MerchantPage.php add new method checkTransactionStatus
  • Loading branch information
moeen-basra committed Jan 6, 2020
1 parent a7ae04e commit 7fc9df2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Abstracts/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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());
}
Expand Down
30 changes: 30 additions & 0 deletions src/MerchantPage/MerchantPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit 7fc9df2

Please sign in to comment.