From f7ee2bde9d9af48dc2219e3167fbb49304eba6fd Mon Sep 17 00:00:00 2001 From: mustapayev Date: Tue, 18 Feb 2025 15:34:16 +0100 Subject: [PATCH] fix issue #249 - AkbankPos invalid amount pattern --- examples/_common-codes/regular/history.php | 4 +-- examples/akbankpos/_payment_config.php | 4 +-- .../AkbankPosRequestDataMapper.php | 12 ++++++- tests/Functional/AkbankPosTest.php | 7 ++-- .../AkbankPosRequestDataMapperTest.php | 36 +++++++++---------- 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/examples/_common-codes/regular/history.php b/examples/_common-codes/regular/history.php index 5a7a75eb..dad48b95 100644 --- a/examples/_common-codes/regular/history.php +++ b/examples/_common-codes/regular/history.php @@ -49,8 +49,8 @@ function createHistoryOrder(string $gatewayClass, array $extraData, string $ip): 'end_date' => $txTime, ]; // ya da batch number ile (batch number odeme isleminden alinan response'da bulunur): -// $order = [ -// 'batch_num' => 24, +// return [ +// 'batch_num' => 396, // ]; } diff --git a/examples/akbankpos/_payment_config.php b/examples/akbankpos/_payment_config.php index 1cd4dab3..ee621f63 100644 --- a/examples/akbankpos/_payment_config.php +++ b/examples/akbankpos/_payment_config.php @@ -8,10 +8,10 @@ $testCards = [ 'visa1' => [ // OTP 123456 - 'number' => '5218076007402834', + 'number' => '4355093000315232', 'year' => '40', 'month' => '11', - 'cvv' => '820', + 'cvv' => '471', 'name' => 'John Doe', ], ]; diff --git a/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php index c667f462..ba034c00 100644 --- a/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php @@ -373,7 +373,7 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s 'terminalSafeId' => $posAccount->getTerminalId(), 'orderId' => (string) $order['id'], 'lang' => $this->getLang($posAccount, $order), - 'amount' => (string) $order['amount'], + 'amount' => $this->formatAmount($order['amount']), 'currencyCode' => (string) $this->mapCurrency((string) $order['currency']), 'installCount' => (string) $this->mapInstallment((int) $order['installment']), 'okUrl' => (string) $order['success_url'], @@ -515,6 +515,16 @@ protected function prepareCancelOrder(array $order): array ]); } + /** + * @param float $amount + * + * @return string + */ + protected function formatAmount(float $amount): string + { + return \number_format($amount, 2, '.', ''); + } + /** * @inheritDoc * diff --git a/tests/Functional/AkbankPosTest.php b/tests/Functional/AkbankPosTest.php index 07ec0851..a3452d1e 100644 --- a/tests/Functional/AkbankPosTest.php +++ b/tests/Functional/AkbankPosTest.php @@ -55,10 +55,10 @@ protected function setUp(): void $this->card = CreditCardFactory::createForGateway( $this->pos, - '5218076007402834', + '4355093000315232', '40', '11', - '820', + '471', ); } @@ -323,8 +323,9 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThro $this->recurringPos->cancel($statusOrder); - $this->assertTrue($this->recurringPos->isSuccess()); $response = $this->recurringPos->getResponse(); + $this->assertTrue($this->recurringPos->isSuccess(), $response['error_message'] ?? null); + $this->assertIsArray($response); $this->assertNotEmpty($response); $this->assertTrue($eventIsThrown); diff --git a/tests/Unit/DataMapper/RequestDataMapper/AkbankPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/AkbankPosRequestDataMapperTest.php index 6763f971..6d00a29d 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/AkbankPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/AkbankPosRequestDataMapperTest.php @@ -182,7 +182,7 @@ public function testGet3DFormDataSubMerchant(): void 'terminalSafeId' => '2023090417500284633D137A249DBBEB', 'orderId' => '2020110828BC', 'lang' => 'TR', - 'amount' => '1.1', + 'amount' => '1.10', 'currencyCode' => '949', 'installCount' => '1', 'okUrl' => 'http:://localhost/success', @@ -270,7 +270,7 @@ public function testCreate3DPaymentSubMerchantRequestData(): void 'orderId' => '2020110828BC', ], 'transaction' => [ - 'amount' => 1.1, + 'amount' => '1.10', 'currencyCode' => 949, 'motoInd' => 0, 'installCount' => 1, @@ -679,7 +679,7 @@ public static function refundRequestDataProvider(): array 'orderId' => '2020110828BC', ], 'transaction' => [ - 'amount' => 1.02, + 'amount' => '1.02', 'currencyCode' => 949, ], ], @@ -702,7 +702,7 @@ public static function refundRequestDataProvider(): array 'orderTrackId' => '2020110828BC', ], 'transaction' => [ - 'amount' => 1.02, + 'amount' => '1.02', 'currencyCode' => 949, ], 'version' => '1.00', @@ -744,7 +744,7 @@ public static function nonSecurePaymentRequestDataProvider(): array 'orderId' => '2020110828BC', ], 'transaction' => [ - 'amount' => 1.1, + 'amount' => '1.10', 'currencyCode' => 949, 'motoInd' => 0, 'installCount' => 1, @@ -780,7 +780,7 @@ public static function nonSecurePaymentRequestDataProvider(): array 'orderId' => '2020110828BC', ], 'transaction' => [ - 'amount' => 1.1, + 'amount' => '1.10', 'currencyCode' => 949, 'motoInd' => 0, 'installCount' => 2, @@ -816,7 +816,7 @@ public static function nonSecurePaymentRequestDataProvider(): array 'orderId' => '2020110828BC', ], 'transaction' => [ - 'amount' => 1.1, + 'amount' => '1.10', 'currencyCode' => 949, 'motoInd' => 0, 'installCount' => 1, @@ -856,7 +856,7 @@ public static function nonSecurePaymentRequestDataProvider(): array 'orderTrackId' => '2020110828BC', ], 'transaction' => [ - 'amount' => 1.1, + 'amount' => '1.10', 'currencyCode' => 949, 'motoInd' => 1, 'installCount' => 1, @@ -896,7 +896,7 @@ public static function nonSecurePaymentPostRequestDataProvider(): array 'orderId' => '2020110828BC', ], 'transaction' => [ - 'amount' => 1.1, + 'amount' => '1.10', 'currencyCode' => 949, ], 'customer' => [ @@ -953,7 +953,7 @@ public static function threeDFormDataProvider(): array '3d_host_form_data' => [ 'order' => [ 'id' => '2020110828BC', - 'amount' => 1.10, + 'amount' => 10, 'ip' => '127.0.0.1', 'installment' => 0, 'currency' => PosInterface::CURRENCY_TRY, @@ -974,7 +974,7 @@ public static function threeDFormDataProvider(): array 'terminalSafeId' => '2023090417500284633D137A249DBBEB', 'orderId' => '2020110828BC', 'lang' => 'TR', - 'amount' => '1.1', + 'amount' => '10.00', 'currencyCode' => '949', 'installCount' => '1', 'okUrl' => 'http:://localhost/success', @@ -987,7 +987,7 @@ public static function threeDFormDataProvider(): array '3d_pay_form_data' => [ 'order' => [ 'id' => '2020110828BC', - 'amount' => 1.10, + 'amount' => 1.1, 'ip' => '127.0.0.1', 'installment' => 0, 'currency' => PosInterface::CURRENCY_TRY, @@ -1008,7 +1008,7 @@ public static function threeDFormDataProvider(): array 'terminalSafeId' => '2023090417500284633D137A249DBBEB', 'orderId' => '2020110828BC', 'lang' => 'TR', - 'amount' => '1.1', + 'amount' => '1.10', 'currencyCode' => '949', 'installCount' => '1', 'okUrl' => 'http:://localhost/success', @@ -1024,7 +1024,7 @@ public static function threeDFormDataProvider(): array '3d_form_data' => [ 'order' => [ 'id' => '2020110828BC', - 'amount' => 1.10, + 'amount' => 1.1, 'ip' => '127.0.0.1', 'installment' => 0, 'currency' => PosInterface::CURRENCY_TRY, @@ -1045,7 +1045,7 @@ public static function threeDFormDataProvider(): array 'terminalSafeId' => '2023090417500284633D137A249DBBEB', 'orderId' => '2020110828BC', 'lang' => 'TR', - 'amount' => '1.1', + 'amount' => '1.10', 'currencyCode' => '949', 'installCount' => '1', 'okUrl' => 'http:://localhost/success', @@ -1061,7 +1061,7 @@ public static function threeDFormDataProvider(): array '3d_pre_pay_form_data' => [ 'order' => [ 'id' => '2020110828BC', - 'amount' => 1.10, + 'amount' => 1000, 'ip' => '127.0.0.1', 'installment' => 0, 'currency' => PosInterface::CURRENCY_TRY, @@ -1082,7 +1082,7 @@ public static function threeDFormDataProvider(): array 'terminalSafeId' => '2023090417500284633D137A249DBBEB', 'orderId' => '2020110828BC', 'lang' => 'TR', - 'amount' => '1.1', + 'amount' => '1000.00', 'currencyCode' => '949', 'installCount' => '1', 'okUrl' => 'http:://localhost/success', @@ -1121,7 +1121,7 @@ public static function create3DPaymentRequestDataDataProvider(): \Generator 'orderId' => '2020110828BC', ], 'transaction' => [ - 'amount' => 100.25, + 'amount' => '100.25', 'currencyCode' => 949, 'motoInd' => 0, 'installCount' => 1,