diff --git a/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php index 291cec9b..a71828ed 100644 --- a/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php @@ -482,7 +482,7 @@ protected function mapCurrency(string $currency): int * * @param array $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 { diff --git a/src/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapper.php index 7615b1a4..3966b0e1 100644 --- a/src/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapper.php @@ -413,8 +413,6 @@ 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']); @@ -422,23 +420,33 @@ private function mapSingleOrderHistoryTransaction(array $rawTx): array $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 { diff --git a/tests/Unit/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapperTest.php index a945d1b0..f66fced2 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapperTest.php @@ -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, @@ -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,