Skip to content

Commit

Permalink
issue #191 akbankpos - update orderHistory mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
nuryagdym committed Apr 26, 2024
1 parent 5f807f2 commit 707869a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ protected function mapCurrency(string $currency): int
*
* @param array<string, mixed> $data
*
* @return array{batch_num: int}|array{start_date: DateTimeInterface, end_date: DateTimeInterface}
* @return array{batch_num?: int, start_date?: DateTimeInterface, end_date?: DateTimeInterface}
*/
protected function prepareHistoryOrder(array $data): array
{
Expand Down
38 changes: 23 additions & 15 deletions src/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,32 +413,40 @@ private function mapSingleOrderHistoryTransaction(array $rawTx): array
}

$transaction['status_detail'] = $this->getStatusDetail($transaction['proc_return_code']);
$transaction['ref_ret_num'] = $rawTx['rrn'];
$transaction['masked_number'] = $rawTx['maskedCardNumber'];
$transaction['currency'] = $this->mapCurrency($rawTx['currencyCode']);
$transaction['installment_count'] = $this->mapInstallment($rawTx['installCount']);
$transaction['transaction_type'] = $this->mapTxType($rawTx['txnCode']);
$transaction['first_amount'] = null === $rawTx['amount'] ? null : $this->formatAmount($rawTx['amount']);
$transaction['transaction_time'] = new \DateTimeImmutable($rawTx['txnDateTime']);

if (self::TX_APPROVED === $transaction['status']) {
$transaction['masked_number'] = $rawTx['maskedCardNumber'];
$transaction['ref_ret_num'] = $rawTx['rrn'];
// batchNumber is not provided when payment is canceled
$transaction['batch_num'] = $rawTx['batchNumber'] ?? null;
$transaction['order_status'] = $this->mapOrderStatus($rawTx['txnStatus'], $rawTx['preAuthStatus'] ?? null);
$transaction['auth_code'] = $rawTx['authCode'];
if (PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED === $transaction['order_status'] && \in_array(
$transaction['transaction_type'],
[
PosInterface::TX_TYPE_PAY_AUTH,
PosInterface::TX_TYPE_PAY_POST_AUTH,
],
true,
)
) {
$transaction['capture_amount'] = null === $rawTx['amount'] ? null : $this->formatAmount($rawTx['amount']);
$transaction['capture'] = $transaction['first_amount'] === $transaction['capture_amount'];
if ($transaction['capture']) {
$transaction['capture_time'] = new \DateTimeImmutable($rawTx['txnDateTime']);
if (PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED === $transaction['order_status']) {
if (\in_array(
$transaction['transaction_type'],
[
PosInterface::TX_TYPE_PAY_AUTH,
PosInterface::TX_TYPE_PAY_POST_AUTH,
],
true,
)
) {
$transaction['capture_amount'] = null === $rawTx['amount'] ? null : $this->formatAmount($rawTx['amount']);
$transaction['capture'] = $transaction['first_amount'] === $transaction['capture_amount'];
if ($transaction['capture']) {
$transaction['capture_time'] = new \DateTimeImmutable($rawTx['txnDateTime']);
}
} elseif (PosInterface::TX_TYPE_PAY_PRE_AUTH === $transaction['transaction_type']) {
$transaction['capture_amount'] = null === $rawTx['preAuthCloseAmount'] ? null : $this->formatAmount($rawTx['preAuthCloseAmount']);
$transaction['capture'] = $transaction['first_amount'] === $transaction['capture_amount'];
if ($transaction['capture']) {
$transaction['capture_time'] = new \DateTimeImmutable($rawTx['preAuthCloseDate']);
}
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1935,17 +1935,17 @@ public static function orderHistoryDataProvider(): array
'proc_return_code' => 'VPS-0000',
'transaction_id' => null,
'transaction_time' => new \DateTimeImmutable('2024-04-15T20:17:19.205'),
'capture_time' => null,
'capture_time' => new \DateTimeImmutable('2024-04-15T20:17:20.158'),
'error_message' => null,
'ref_ret_num' => '410724359538',
'masked_number' => '521807******2834',
'order_status' => 'PAYMENT_COMPLETED',
'transaction_type' => 'pre',
'capture_amount' => null,
'capture_amount' => 30.0,
'status' => 'approved',
'error_code' => null,
'status_detail' => 'approved',
'capture' => null,
'capture' => true,
'currency' => 'TRY',
'first_amount' => 30.0,
'installment_count' => 3,
Expand Down Expand Up @@ -2142,8 +2142,8 @@ public static function orderHistoryDataProvider(): array
'transaction_time' => new \DateTimeImmutable('2024-04-14T15:24:43.133'),
'capture_time' => null,
'error_message' => null,
'ref_ret_num' => '410624359235',
'masked_number' => '435509******5232',
'ref_ret_num' => null,
'masked_number' => null,
'order_status' => null,
'transaction_type' => 'pay',
'capture_amount' => null,
Expand Down

0 comments on commit 707869a

Please sign in to comment.