Skip to content

Commit

Permalink
vakifkatilim - improve order_status response mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
mustapayev committed Oct 12, 2024
1 parent 239338c commit 05b2817
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class KuveytPosResponseDataMapper extends AbstractResponseDataMapper
/**
* Order Status Codes
*
* @var array<int, string>
* @var array<int, PosInterface::PAYMENT_STATUS_*>
*/
protected array $orderStatusMappings = [
1 => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ class VakifKatilimPosResponseDataMapper extends AbstractResponseDataMapper
'51' => 'reject',
];

/**
* Order Status Codes
*
* @var array<int, PosInterface::PAYMENT_STATUS_*>
*/
protected array $orderStatusMappings = [
1 => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED,
4 => PosInterface::PAYMENT_STATUS_FULLY_REFUNDED,
5 => PosInterface::PAYMENT_STATUS_PARTIALLY_REFUNDED,
6 => PosInterface::PAYMENT_STATUS_CANCELED,
];

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -491,20 +503,16 @@ private function mapSingleOrderHistoryTransaction(array $rawTx): array
$defaultResponse['installment_count'] = $this->mapInstallment($rawTx['InstallmentCount']);
$defaultResponse['masked_number'] = $rawTx['CardNumber'];
$defaultResponse['first_amount'] = (float) $rawTx['FirstAmount'];
$defaultResponse['order_status'] = $rawTx['LastOrderStatusDescription'];

/**
* OrderStatus
* 1 => Satis
* 6 => Iptal
*/
if ('1' === $rawTx['OrderStatus']) {
$defaultResponse['order_status'] = $this->orderStatusMappings[$rawTx['LastOrderStatus']] ?? $rawTx['LastOrderStatusDescription'];
$initialOrderStatus = $this->orderStatusMappings[$rawTx['OrderStatus']] ?? null;

if (PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED === $initialOrderStatus) {
$defaultResponse['capture_amount'] = isset($rawTx['TranAmount']) ? (float) $rawTx['TranAmount'] : 0;
$defaultResponse['capture'] = $defaultResponse['first_amount'] === $defaultResponse['capture_amount'];
if ($defaultResponse['capture']) {
$defaultResponse['capture_time'] = $defaultResponse['transaction_time'];
}
} elseif ('6' === $rawTx['OrderStatus']) {
} elseif (PosInterface::PAYMENT_STATUS_CANCELED === $initialOrderStatus) {
$defaultResponse['cancel_time'] = $defaultResponse['transaction_time'];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ public static function statusTestDataProvider(): iterable
'installment_count' => 0,
'masked_number' => '5353********7017',
'order_id' => '1995434716',
'order_status' => null,
'order_status' => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED,
'payment_model' => null,
'proc_return_code' => '00',
'ref_ret_num' => '035909014127',
Expand Down Expand Up @@ -797,7 +797,7 @@ public static function statusTestDataProvider(): iterable
'installment_count' => 0,
'masked_number' => '5188********2666',
'order_id' => '20240701CF44',
'order_status' => 'Iptal',
'order_status' => PosInterface::PAYMENT_STATUS_CANCELED,
'payment_model' => '3d',
'proc_return_code' => '00',
'ref_ret_num' => '418315149569',
Expand Down Expand Up @@ -1283,7 +1283,7 @@ public static function historyTestDataProvider(): array
'capture_time' => null,
'error_message' => null,
'ref_ret_num' => '036008014143',
'order_status' => 'Satis',
'order_status' => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED,
'transaction_type' => null,
'first_amount' => 2.7,
'capture_amount' => 0,
Expand Down Expand Up @@ -1494,7 +1494,7 @@ public static function orderHistoryTestDataProvider(): array
'first_amount' => 10.01,
'installment_count' => 2,
'masked_number' => '5351********9885',
'order_status' => 'Iptal',
'order_status' => PosInterface::PAYMENT_STATUS_CANCELED,
'payment_model' => '3d',
'proc_return_code' => '00',
'ref_ret_num' => '418315158962',
Expand All @@ -1515,7 +1515,7 @@ public static function orderHistoryTestDataProvider(): array
'first_amount' => 10.01,
'installment_count' => 2,
'masked_number' => '5351********9885',
'order_status' => 'Iptal',
'order_status' => PosInterface::PAYMENT_STATUS_CANCELED,
'payment_model' => '3d',
'proc_return_code' => '00',
'ref_ret_num' => '418315158962',
Expand Down

0 comments on commit 05b2817

Please sign in to comment.