Skip to content

Commit

Permalink
Merge pull request #57 from farayaz/56-fix-keepa-gateway-bugs
Browse files Browse the repository at this point in the history
fix keepa gateway bugs
  • Loading branch information
mehrdadx10 authored Jul 8, 2024
2 parents d49b4df + d0a4371 commit eb1009d
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/Gateways/Keepa.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ final class Keepa extends GatewayAbstract
protected $statuses = [
'amount-mismatch' => 'مغایرت مبلغ پرداختی',
'token-mismatch' => 'عدم تطبیق توکن بازگشتی',
'verify-status-false' => 'تایید اولیه نا موفق',
'confirm-status-false' => 'تایید ثانویه نا موفق',
];

protected $requirements = ['token'];
Expand All @@ -25,7 +27,7 @@ public function request(
string $mobile,
string $callbackUrl
): array {
$url = $this->url . '/request_payment_token';
$url = $this->url . 'request_payment_token';
$params = [
'Amount' => $amount,
'CallBack_Url' => $callbackUrl,
Expand All @@ -50,41 +52,40 @@ public function verify(
): array {
$default = [
'payment_token' => null,
'state' => null,
'msg' => null,
'reciept_number' => null,
];
$params = array_merge($default, $params);
if (! in_array($params['state'], [100, 101, 102, 103])) {
throw new LarapayException($this->translateStatus($params['state']));
}

if ($params['payment_token'] != $token) {
throw new LarapayException($this->translateStatus('token-mismatch'));
}

$url = $this->url . 'verify_transaction';
$data = [
'payment_token' => $token,
'reciept_number' => $params['reciept_number'],
];

$url = $this->url . 'verify_transaction';
$result = $this->_request($url, $data);
if ($amount != $result['Content']['CreditAmount']) {
if ($result['Content']['Status'] != true) {
throw new LarapayException($this->translateStatus('verify-status-false'));
}
if ($amount != $result['Content']['Amount']) {
throw new LarapayException($this->translateStatus('amount-mismatch'));
}

$url = $this->url . 'confirm_transaction';
$data = [
'payment_token' => $token,
'reciept_number' => $params['reciept_number'],
];
$result = $this->_request($url, $data);
if ($result['Content']['Status'] != true) {
throw new LarapayException($this->translateStatus('confirm-status-false'));
}

return [
'fee' => 0,
'card' => null,
'result' => $result['Status'],
'reference_id' => $result['track_id'],
'tracking_code' => $result['CallingID'],
'reference_id' => $result['ConfirmTransactionNumber'],
'tracking_code' => $params['reciept_number'],
];
}

Expand Down

0 comments on commit eb1009d

Please sign in to comment.