From bb6df2d616375f3469aaf3c5f792f4be09ed1881 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Wed, 29 May 2024 17:33:00 +0200 Subject: [PATCH 1/7] tests - added refund test to AkbankPos functional test --- tests/Functional/AkbankPosTest.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/Functional/AkbankPosTest.php b/tests/Functional/AkbankPosTest.php index 2fd8bbe7..0d53f7c8 100644 --- a/tests/Functional/AkbankPosTest.php +++ b/tests/Functional/AkbankPosTest.php @@ -231,6 +231,33 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThro return $lastResponse; } + /** + * @depends testNonSecurePostPaymentSuccess + */ + public function testRefundSuccess(array $lastResponse): array + { + $refundOrder = $this->createRefundOrder(\get_class($this->pos), $lastResponse); + + $eventIsThrown = false; + $this->eventDispatcher->addListener( + RequestDataPreparedEvent::class, + function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThrown): void { + $eventIsThrown = true; + $this->assertSame(PosInterface::TX_TYPE_REFUND, $requestDataPreparedEvent->getTxType()); + $this->assertCount(7, $requestDataPreparedEvent->getRequestData()); + }); + + $this->pos->refund($refundOrder); + + $response = $this->pos->getResponse(); + $this->assertTrue($this->pos->isSuccess(), $response['error_message'] ?? ''); + $this->assertIsArray($response); + $this->assertNotEmpty($response); + $this->assertTrue($eventIsThrown); + + return $lastResponse; + } + public function testNonSecurePaymentRecurringSuccess(): array { $order = $this->createPaymentOrder( @@ -403,6 +430,7 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThro $this->recurringPos->history($historyOrder); $response = $this->recurringPos->getResponse(); + $this->assertTrue($this->recurringPos->isSuccess()); $this->assertIsArray($response); $this->assertTrue($eventIsThrown); $this->assertNotEmpty($response['transactions']); From 23a045a48b27c8281a07565fe7ea22b50938dab1 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Wed, 29 May 2024 17:47:26 +0200 Subject: [PATCH 2/7] issue 218 add TX_TYPE_REFUND_PARTIAL --- .../AkbankPosRequestDataMapper.php | 19 ++-- .../EstPosRequestDataMapper.php | 19 ++-- .../GarantiPosRequestDataMapper.php | 19 ++-- .../InterPosRequestDataMapper.php | 17 ++-- .../KuveytPosRequestDataMapper.php | 17 ++-- .../PayFlexCPV4PosRequestDataMapper.php | 19 ++-- .../PayFlexV4PosRequestDataMapper.php | 17 ++-- .../PayForPosRequestDataMapper.php | 19 ++-- .../PosNetRequestDataMapper.php | 17 ++-- .../PosNetV1PosRequestDataMapper.php | 15 ++-- .../RequestDataMapperInterface.php | 5 +- .../ToslaPosRequestDataMapper.php | 13 +-- .../VakifKatilimPosRequestDataMapper.php | 2 +- .../KuveytPosResponseDataMapper.php | 3 + src/Gateways/AbstractGateway.php | 5 +- src/Gateways/AkbankPos.php | 19 ++-- src/Gateways/EstPos.php | 17 ++-- src/Gateways/GarantiPos.php | 17 ++-- src/Gateways/InterPos.php | 17 ++-- src/Gateways/KuveytPos.php | 27 +++--- src/Gateways/PayFlexCPV4Pos.php | 17 ++-- src/Gateways/PayFlexV4Pos.php | 17 ++-- src/Gateways/PayForPos.php | 17 ++-- src/Gateways/PosNet.php | 17 ++-- src/Gateways/PosNetV1Pos.php | 17 ++-- src/Gateways/ToslaPos.php | 28 +++--- src/Gateways/VakifKatilimPos.php | 38 ++++---- src/PosInterface.php | 3 + src/Serializer/KuveytPosSerializer.php | 1 + src/Serializer/PayFlexCPV4PosSerializer.php | 4 +- tests/Functional/EstV3PosTest.php | 2 +- tests/Functional/KuveytPosTest.php | 2 +- tests/Functional/ToslaPosTest.php | 2 +- .../AkbankPosRequestDataMapperTest.php | 6 +- .../EstPosRequestDataMapperTest.php | 81 +++++++++-------- .../GarantiPosRequestDataMapperTest.php | 61 +++++++++---- .../InterPosRequestDataMapperTest.php | 80 ++++++++++------- .../KuveytPosRequestDataMapperTest.php | 10 ++- .../PayFlexV4PosRequestDataMapperTest.php | 68 +++++++++----- .../PayForPosRequestDataMapperTest.php | 89 +++++++++++-------- .../PosNetRequestDataMapperTest.php | 14 +-- .../PosNetV1PosRequestDataMapperTest.php | 17 ++-- .../ToslaPosRequestDataMapperTest.php | 9 +- .../VakifKatilimPosRequestDataMapperTest.php | 10 ++- tests/Unit/Gateways/AkbankPosTest.php | 25 ++++-- tests/Unit/Gateways/EstPosTest.php | 2 +- tests/Unit/Gateways/GarantiPosTest.php | 2 +- tests/Unit/Gateways/InterPosTest.php | 2 +- tests/Unit/Gateways/KuveytPosTest.php | 5 ++ tests/Unit/Gateways/PayFlexCPV4PosTest.php | 2 +- tests/Unit/Gateways/PayFlexV4PosTest.php | 2 +- tests/Unit/Gateways/PayForTest.php | 2 +- tests/Unit/Gateways/PosNetTest.php | 2 +- tests/Unit/Gateways/PosNetV1PosTest.php | 2 +- tests/Unit/Gateways/ToslaPosTest.php | 11 ++- tests/Unit/Gateways/VakifKatilimTest.php | 27 ++++-- .../Serializer/KuveytPosSerializerTest.php | 6 ++ 57 files changed, 608 insertions(+), 395 deletions(-) diff --git a/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php index b070454d..02620c82 100644 --- a/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php @@ -29,23 +29,24 @@ class AkbankPosRequestDataMapper extends AbstractRequestDataMapper * {@inheritDoc} */ protected array $txTypeMappings = [ - PosInterface::TX_TYPE_PAY_AUTH => [ + PosInterface::TX_TYPE_PAY_AUTH => [ PosInterface::MODEL_NON_SECURE => '1000', PosInterface::MODEL_3D_SECURE => '3000', PosInterface::MODEL_3D_PAY => '3000', PosInterface::MODEL_3D_HOST => '3000', ], - PosInterface::TX_TYPE_PAY_PRE_AUTH => [ + PosInterface::TX_TYPE_PAY_PRE_AUTH => [ PosInterface::MODEL_NON_SECURE => '1004', PosInterface::MODEL_3D_SECURE => '3004', PosInterface::MODEL_3D_PAY => '3004', PosInterface::MODEL_3D_HOST => '3004', ], - PosInterface::TX_TYPE_PAY_POST_AUTH => '1005', - PosInterface::TX_TYPE_REFUND => '1002', - PosInterface::TX_TYPE_CANCEL => '1003', - PosInterface::TX_TYPE_ORDER_HISTORY => '1010', - PosInterface::TX_TYPE_HISTORY => '1009', + PosInterface::TX_TYPE_PAY_POST_AUTH => '1005', + PosInterface::TX_TYPE_REFUND => '1002', + PosInterface::TX_TYPE_REFUND_PARTIAL => '1002', + PosInterface::TX_TYPE_CANCEL => '1003', + PosInterface::TX_TYPE_ORDER_HISTORY => '1010', + PosInterface::TX_TYPE_HISTORY => '1009', ]; /** @@ -261,13 +262,13 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o * * {@inheritDoc} */ - public function createRefundRequestData(AbstractPosAccount $posAccount, array $order): array + public function createRefundRequestData(AbstractPosAccount $posAccount, array $order, string $refundTxType): array { $order = $this->prepareRefundOrder($order); $requestData = $this->getRequestAccountData($posAccount) + [ 'version' => self::API_VERSION, - 'txnCode' => $this->mapTxType(PosInterface::TX_TYPE_REFUND), + 'txnCode' => $this->mapTxType($refundTxType), 'requestDateTime' => $this->formatRequestDateTime($order['transaction_time']), 'randomNumber' => $this->crypt->generateRandomString(), 'transaction' => [ diff --git a/src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php index cdd53a23..8a01b4c5 100644 --- a/src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php @@ -31,13 +31,14 @@ class EstPosRequestDataMapper extends AbstractRequestDataMapper * {@inheritDoc} */ protected array $txTypeMappings = [ - PosInterface::TX_TYPE_PAY_AUTH => 'Auth', - PosInterface::TX_TYPE_PAY_PRE_AUTH => 'PreAuth', - PosInterface::TX_TYPE_PAY_POST_AUTH => 'PostAuth', - PosInterface::TX_TYPE_CANCEL => 'Void', - PosInterface::TX_TYPE_REFUND => 'Credit', - PosInterface::TX_TYPE_STATUS => 'ORDERSTATUS', - PosInterface::TX_TYPE_HISTORY => 'ORDERHISTORY', + PosInterface::TX_TYPE_PAY_AUTH => 'Auth', + PosInterface::TX_TYPE_PAY_PRE_AUTH => 'PreAuth', + PosInterface::TX_TYPE_PAY_POST_AUTH => 'PostAuth', + PosInterface::TX_TYPE_CANCEL => 'Void', + PosInterface::TX_TYPE_REFUND => 'Credit', + PosInterface::TX_TYPE_REFUND_PARTIAL => 'Credit', + PosInterface::TX_TYPE_STATUS => 'ORDERSTATUS', + PosInterface::TX_TYPE_HISTORY => 'ORDERHISTORY', ]; /** @@ -199,14 +200,14 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o * {@inheritDoc} * @return array{OrderId: string, Currency: string, Type: string, Total?: string, Name: string, Password: string, ClientId: string} */ - public function createRefundRequestData(AbstractPosAccount $posAccount, array $order): array + public function createRefundRequestData(AbstractPosAccount $posAccount, array $order, string $refundTxType): array { $order = $this->prepareRefundOrder($order); $requestData = [ 'OrderId' => (string) $order['id'], 'Currency' => $this->mapCurrency($order['currency']), - 'Type' => $this->mapTxType(PosInterface::TX_TYPE_REFUND), + 'Type' => $this->mapTxType($refundTxType), ]; if (isset($order['amount'])) { diff --git a/src/DataMapper/RequestDataMapper/GarantiPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/GarantiPosRequestDataMapper.php index 4d930394..d48c2865 100644 --- a/src/DataMapper/RequestDataMapper/GarantiPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/GarantiPosRequestDataMapper.php @@ -47,13 +47,14 @@ class GarantiPosRequestDataMapper extends AbstractRequestDataMapper * {@inheritDoc} */ protected array $txTypeMappings = [ - PosInterface::TX_TYPE_PAY_AUTH => 'sales', - PosInterface::TX_TYPE_PAY_PRE_AUTH => 'preauth', - PosInterface::TX_TYPE_PAY_POST_AUTH => 'postauth', - PosInterface::TX_TYPE_CANCEL => 'void', - PosInterface::TX_TYPE_REFUND => 'refund', - PosInterface::TX_TYPE_HISTORY => 'orderhistoryinq', - PosInterface::TX_TYPE_STATUS => 'orderinq', + PosInterface::TX_TYPE_PAY_AUTH => 'sales', + PosInterface::TX_TYPE_PAY_PRE_AUTH => 'preauth', + PosInterface::TX_TYPE_PAY_POST_AUTH => 'postauth', + PosInterface::TX_TYPE_CANCEL => 'void', + PosInterface::TX_TYPE_REFUND => 'refund', + PosInterface::TX_TYPE_REFUND_PARTIAL => 'refund', + PosInterface::TX_TYPE_HISTORY => 'orderhistoryinq', + PosInterface::TX_TYPE_STATUS => 'orderinq', ]; protected array $recurringOrderFrequencyMapping = [ @@ -254,7 +255,7 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o * * {@inheritDoc} */ - public function createRefundRequestData(AbstractPosAccount $posAccount, array $order): array + public function createRefundRequestData(AbstractPosAccount $posAccount, array $order, string $refundTxType): array { $order = $this->prepareRefundOrder($order); @@ -269,7 +270,7 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o 'OrderID' => $order['id'], ], 'Transaction' => [ - 'Type' => $this->mapTxType(PosInterface::TX_TYPE_REFUND), + 'Type' => $this->mapTxType($refundTxType), 'InstallmentCnt' => $this->mapInstallment($order['installment']), 'Amount' => $this->formatAmount($order['amount']), //sabit olarak amount 100 gonderilecek, 'CurrencyCode' => $this->mapCurrency($order['currency']), diff --git a/src/DataMapper/RequestDataMapper/InterPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/InterPosRequestDataMapper.php index b64e9c7b..fa7219ba 100644 --- a/src/DataMapper/RequestDataMapper/InterPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/InterPosRequestDataMapper.php @@ -42,12 +42,13 @@ class InterPosRequestDataMapper extends AbstractRequestDataMapper * {@inheritdoc} */ protected array $txTypeMappings = [ - PosInterface::TX_TYPE_PAY_AUTH => 'Auth', - PosInterface::TX_TYPE_PAY_PRE_AUTH => 'PreAuth', - PosInterface::TX_TYPE_PAY_POST_AUTH => 'PostAuth', - PosInterface::TX_TYPE_CANCEL => 'Void', - PosInterface::TX_TYPE_REFUND => 'Refund', - PosInterface::TX_TYPE_STATUS => 'StatusHistory', + PosInterface::TX_TYPE_PAY_AUTH => 'Auth', + PosInterface::TX_TYPE_PAY_PRE_AUTH => 'PreAuth', + PosInterface::TX_TYPE_PAY_POST_AUTH => 'PostAuth', + PosInterface::TX_TYPE_CANCEL => 'Void', + PosInterface::TX_TYPE_REFUND => 'Refund', + PosInterface::TX_TYPE_REFUND_PARTIAL => 'Refund', + PosInterface::TX_TYPE_STATUS => 'StatusHistory', ]; /** @@ -170,7 +171,7 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o * {@inheritDoc} * @return array{OrderId: null, orgOrderId: string, PurchAmount: string, TxnType: string, SecureType: string, Lang: string, MOTO: string, UserCode: string, UserPass: string, ShopCode: string} */ - public function createRefundRequestData(AbstractPosAccount $posAccount, array $order): array + public function createRefundRequestData(AbstractPosAccount $posAccount, array $order, string $refundTxType): array { $order = $this->prepareRefundOrder($order); @@ -178,7 +179,7 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o 'OrderId' => null, 'orgOrderId' => (string) $order['id'], 'PurchAmount' => (string) $order['amount'], - 'TxnType' => $this->mapTxType(PosInterface::TX_TYPE_REFUND), + 'TxnType' => $this->mapTxType($refundTxType), 'SecureType' => $this->secureTypeMappings[PosInterface::MODEL_NON_SECURE], 'Lang' => $this->getLang($posAccount, $order), 'MOTO' => self::MOTO, diff --git a/src/DataMapper/RequestDataMapper/KuveytPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/KuveytPosRequestDataMapper.php index 739dd145..12ba644e 100644 --- a/src/DataMapper/RequestDataMapper/KuveytPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/KuveytPosRequestDataMapper.php @@ -40,10 +40,11 @@ class KuveytPosRequestDataMapper extends AbstractRequestDataMapper * {@inheritDoc} */ protected array $txTypeMappings = [ - PosInterface::TX_TYPE_PAY_AUTH => 'Sale', - PosInterface::TX_TYPE_CANCEL => 'SaleReversal', - PosInterface::TX_TYPE_STATUS => 'GetMerchantOrderDetail', - PosInterface::TX_TYPE_REFUND => 'Drawback', // Also there is a "PartialDrawback" + PosInterface::TX_TYPE_PAY_AUTH => 'Sale', + PosInterface::TX_TYPE_CANCEL => 'SaleReversal', + PosInterface::TX_TYPE_STATUS => 'GetMerchantOrderDetail', + PosInterface::TX_TYPE_REFUND => 'Drawback', + PosInterface::TX_TYPE_REFUND_PARTIAL => 'PartialDrawback', ]; /** @@ -309,13 +310,10 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o * @param KuveytPosAccount $posAccount * {@inheritDoc} */ - public function createRefundRequestData(AbstractPosAccount $posAccount, array $order): array + public function createRefundRequestData(AbstractPosAccount $posAccount, array $order, string $refundTxType): array { $order = $this->prepareRefundOrder($order); - $isPartialRefund = isset($order['order_amount']) && $order['order_amount'] > $order['amount']; - $txType = $isPartialRefund ? 'PartialDrawback' : $this->mapTxType(PosInterface::TX_TYPE_REFUND); - $result = [ 'IsFromExternalNetwork' => true, 'BusinessKey' => 0, @@ -337,7 +335,7 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o 'SubMerchantId' => 0, 'CardType' => $this->cardTypeMapping[CreditCardInterface::CARD_TYPE_VISA], //Default gönderilebilir. 'BatchID' => 0, - 'TransactionType' => $txType, + 'TransactionType' => $this->mapTxType($refundTxType), 'InstallmentCount' => 0, 'Amount' => $this->formatAmount($order['amount']), 'DisplayAmount' => 0, @@ -466,7 +464,6 @@ protected function prepareRefundOrder(array $order): array 'auth_code' => $order['auth_code'], 'transaction_id' => $order['transaction_id'], 'amount' => $order['amount'], - 'order_amount' => $order['order_amount'] ?? null, 'currency' => $order['currency'] ?? PosInterface::CURRENCY_TRY, ]); } diff --git a/src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php index ec53fee0..0ca2d167 100644 --- a/src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php @@ -24,13 +24,14 @@ class PayFlexCPV4PosRequestDataMapper extends AbstractRequestDataMapper * {@inheritDoc} */ protected array $txTypeMappings = [ - PosInterface::TX_TYPE_PAY_AUTH => 'Sale', - PosInterface::TX_TYPE_PAY_PRE_AUTH => 'Auth', - PosInterface::TX_TYPE_PAY_POST_AUTH => 'Capture', - PosInterface::TX_TYPE_CANCEL => 'Cancel', - PosInterface::TX_TYPE_REFUND => 'Refund', - PosInterface::TX_TYPE_HISTORY => 'TxnHistory', - PosInterface::TX_TYPE_STATUS => 'OrderInquiry', + PosInterface::TX_TYPE_PAY_AUTH => 'Sale', + PosInterface::TX_TYPE_PAY_PRE_AUTH => 'Auth', + PosInterface::TX_TYPE_PAY_POST_AUTH => 'Capture', + PosInterface::TX_TYPE_CANCEL => 'Cancel', + PosInterface::TX_TYPE_REFUND => 'Refund', + PosInterface::TX_TYPE_REFUND_PARTIAL => 'Refund', + PosInterface::TX_TYPE_HISTORY => 'TxnHistory', + PosInterface::TX_TYPE_STATUS => 'OrderInquiry', ]; /** @@ -241,12 +242,12 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o * @return array{MerchantId: string, Password: string, TransactionType: string, ReferenceTransactionId: string, * ClientIp: string, CurrencyAmount: string} */ - public function createRefundRequestData(AbstractPosAccount $posAccount, array $order): array + public function createRefundRequestData(AbstractPosAccount $posAccount, array $order, string $refundTxType): array { $order = $this->prepareRefundOrder($order); return $this->getRequestAccountData($posAccount) + [ - 'TransactionType' => $this->mapTxType(PosInterface::TX_TYPE_REFUND), + 'TransactionType' => $this->mapTxType($refundTxType), 'ReferenceTransactionId' => (string) $order['transaction_id'], 'ClientIp' => (string) $order['ip'], 'CurrencyAmount' => $this->formatAmount($order['amount']), diff --git a/src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php index 4c019ee2..c2637081 100644 --- a/src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php @@ -28,12 +28,13 @@ class PayFlexV4PosRequestDataMapper extends AbstractRequestDataMapper * {@inheritDoc} */ protected array $txTypeMappings = [ - PosInterface::TX_TYPE_PAY_AUTH => 'Sale', - PosInterface::TX_TYPE_PAY_PRE_AUTH => 'Auth', - PosInterface::TX_TYPE_PAY_POST_AUTH => 'Capture', - PosInterface::TX_TYPE_CANCEL => 'Cancel', - PosInterface::TX_TYPE_REFUND => 'Refund', - PosInterface::TX_TYPE_STATUS => 'status', + PosInterface::TX_TYPE_PAY_AUTH => 'Sale', + PosInterface::TX_TYPE_PAY_PRE_AUTH => 'Auth', + PosInterface::TX_TYPE_PAY_POST_AUTH => 'Capture', + PosInterface::TX_TYPE_CANCEL => 'Cancel', + PosInterface::TX_TYPE_REFUND => 'Refund', + PosInterface::TX_TYPE_REFUND_PARTIAL => 'Refund', + PosInterface::TX_TYPE_STATUS => 'status', ]; /** @@ -233,14 +234,14 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o * @return array{MerchantId: string, Password: string, TransactionType: string, ReferenceTransactionId: string, * ClientIp: string, CurrencyAmount: string} */ - public function createRefundRequestData(AbstractPosAccount $posAccount, array $order): array + public function createRefundRequestData(AbstractPosAccount $posAccount, array $order, string $refundTxType): array { $order = $this->prepareRefundOrder($order); return [ 'MerchantId' => $posAccount->getClientId(), 'Password' => $posAccount->getPassword(), - 'TransactionType' => $this->mapTxType(PosInterface::TX_TYPE_REFUND), + 'TransactionType' => $this->mapTxType($refundTxType), 'ReferenceTransactionId' => (string) $order['transaction_id'], 'ClientIp' => (string) $order['ip'], 'CurrencyAmount' => $this->formatAmount($order['amount']), diff --git a/src/DataMapper/RequestDataMapper/PayForPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PayForPosRequestDataMapper.php index 8d60dbcd..7a03c07d 100644 --- a/src/DataMapper/RequestDataMapper/PayForPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/PayForPosRequestDataMapper.php @@ -43,13 +43,14 @@ class PayForPosRequestDataMapper extends AbstractRequestDataMapper * {@inheritDoc} */ protected array $txTypeMappings = [ - PosInterface::TX_TYPE_PAY_AUTH => 'Auth', - PosInterface::TX_TYPE_PAY_PRE_AUTH => 'PreAuth', - PosInterface::TX_TYPE_PAY_POST_AUTH => 'PostAuth', - PosInterface::TX_TYPE_CANCEL => 'Void', - PosInterface::TX_TYPE_REFUND => 'Refund', - PosInterface::TX_TYPE_HISTORY => 'TxnHistory', - PosInterface::TX_TYPE_STATUS => 'OrderInquiry', + PosInterface::TX_TYPE_PAY_AUTH => 'Auth', + PosInterface::TX_TYPE_PAY_PRE_AUTH => 'PreAuth', + PosInterface::TX_TYPE_PAY_POST_AUTH => 'PostAuth', + PosInterface::TX_TYPE_CANCEL => 'Void', + PosInterface::TX_TYPE_REFUND => 'Refund', + PosInterface::TX_TYPE_REFUND_PARTIAL => 'Refund', + PosInterface::TX_TYPE_HISTORY => 'TxnHistory', + PosInterface::TX_TYPE_STATUS => 'OrderInquiry', ]; /** @@ -155,7 +156,7 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o * {@inheritDoc} * @return array{MbrId: string, SecureType: string, Lang: string, OrgOrderId: string, TxnType: string, PurchAmount: string, Currency: string, MerchantId: string, UserCode: string, UserPass: string} */ - public function createRefundRequestData(AbstractPosAccount $posAccount, array $order): array + public function createRefundRequestData(AbstractPosAccount $posAccount, array $order, string $refundTxType): array { $order = $this->prepareRefundOrder($order); @@ -164,7 +165,7 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o 'SecureType' => $this->secureTypeMappings[PosInterface::MODEL_NON_SECURE], 'Lang' => $this->getLang($posAccount, $order), 'OrgOrderId' => (string) $order['id'], - 'TxnType' => $this->mapTxType(PosInterface::TX_TYPE_REFUND), + 'TxnType' => $this->mapTxType($refundTxType), 'PurchAmount' => (string) $order['amount'], 'Currency' => $this->mapCurrency($order['currency']), ]; diff --git a/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php index 8a94bf64..d2d5a711 100644 --- a/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php @@ -46,12 +46,13 @@ class PosNetRequestDataMapper extends AbstractRequestDataMapper * {@inheritDoc} */ protected array $txTypeMappings = [ - PosInterface::TX_TYPE_PAY_AUTH => 'Sale', - PosInterface::TX_TYPE_PAY_PRE_AUTH => 'Auth', - PosInterface::TX_TYPE_PAY_POST_AUTH => 'Capt', - PosInterface::TX_TYPE_CANCEL => 'reverse', - PosInterface::TX_TYPE_REFUND => 'return', - PosInterface::TX_TYPE_STATUS => 'agreement', + PosInterface::TX_TYPE_PAY_AUTH => 'Sale', + PosInterface::TX_TYPE_PAY_PRE_AUTH => 'Auth', + PosInterface::TX_TYPE_PAY_POST_AUTH => 'Capt', + PosInterface::TX_TYPE_CANCEL => 'reverse', + PosInterface::TX_TYPE_REFUND => 'return', + PosInterface::TX_TYPE_REFUND_PARTIAL => 'return', + PosInterface::TX_TYPE_STATUS => 'agreement', ]; /** @@ -201,11 +202,11 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o * * {@inheritDoc} */ - public function createRefundRequestData(AbstractPosAccount $posAccount, array $order): array + public function createRefundRequestData(AbstractPosAccount $posAccount, array $order, string $refundTxType): array { $order = $this->prepareRefundOrder($order); - $txType = $this->mapTxType(PosInterface::TX_TYPE_REFUND); + $txType = $this->mapTxType($refundTxType); $requestData = [ 'mid' => $posAccount->getClientId(), 'tid' => $posAccount->getTerminalId(), diff --git a/src/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapper.php index 3c98209e..2e912cb2 100644 --- a/src/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapper.php @@ -51,12 +51,13 @@ class PosNetV1PosRequestDataMapper extends AbstractRequestDataMapper * {@inheritDoc} */ protected array $txTypeMappings = [ - PosInterface::TX_TYPE_PAY_AUTH => 'Sale', - PosInterface::TX_TYPE_PAY_PRE_AUTH => 'Auth', - PosInterface::TX_TYPE_PAY_POST_AUTH => 'Capture', - PosInterface::TX_TYPE_CANCEL => 'Reverse', - PosInterface::TX_TYPE_REFUND => 'Return', - PosInterface::TX_TYPE_STATUS => 'TransactionInquiry', + PosInterface::TX_TYPE_PAY_AUTH => 'Sale', + PosInterface::TX_TYPE_PAY_PRE_AUTH => 'Auth', + PosInterface::TX_TYPE_PAY_POST_AUTH => 'Capture', + PosInterface::TX_TYPE_CANCEL => 'Reverse', + PosInterface::TX_TYPE_REFUND => 'Return', + PosInterface::TX_TYPE_REFUND_PARTIAL => 'Return', + PosInterface::TX_TYPE_STATUS => 'TransactionInquiry', ]; /** @@ -281,7 +282,7 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o * * {@inheritDoc} */ - public function createRefundRequestData(AbstractPosAccount $posAccount, array $order): array + public function createRefundRequestData(AbstractPosAccount $posAccount, array $order, string $refundTxType): array { $order = $this->prepareRefundOrder($order); diff --git a/src/DataMapper/RequestDataMapper/RequestDataMapperInterface.php b/src/DataMapper/RequestDataMapper/RequestDataMapperInterface.php index bdf3919c..9fe2a730 100644 --- a/src/DataMapper/RequestDataMapper/RequestDataMapperInterface.php +++ b/src/DataMapper/RequestDataMapper/RequestDataMapperInterface.php @@ -135,14 +135,17 @@ public function createStatusRequestData(AbstractPosAccount $posAccount, array $o public function createCancelRequestData(AbstractPosAccount $posAccount, array $order): array; /** + * @phpstan-param PosInterface::TX_TYPE_REFUND* $refundTxType + * * @param AbstractPosAccount $posAccount * @param array $order + * @param string $refundTxType * * @return array * * @throws UnsupportedTransactionTypeException */ - public function createRefundRequestData(AbstractPosAccount $posAccount, array $order): array; + public function createRefundRequestData(AbstractPosAccount $posAccount, array $order, string $refundTxType): array; /** * @param AbstractPosAccount $posAccount diff --git a/src/DataMapper/RequestDataMapper/ToslaPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/ToslaPosRequestDataMapper.php index 234f61d1..3e50d328 100644 --- a/src/DataMapper/RequestDataMapper/ToslaPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/ToslaPosRequestDataMapper.php @@ -23,11 +23,12 @@ class ToslaPosRequestDataMapper extends AbstractRequestDataMapper * {@inheritDoc} */ protected array $txTypeMappings = [ - PosInterface::TX_TYPE_PAY_AUTH => '1', - PosInterface::TX_TYPE_PAY_PRE_AUTH => '2', - PosInterface::TX_TYPE_PAY_POST_AUTH => '3', - PosInterface::TX_TYPE_CANCEL => '4', - PosInterface::TX_TYPE_REFUND => '5', + PosInterface::TX_TYPE_PAY_AUTH => '1', + PosInterface::TX_TYPE_PAY_PRE_AUTH => '2', + PosInterface::TX_TYPE_PAY_POST_AUTH => '3', + PosInterface::TX_TYPE_CANCEL => '4', + PosInterface::TX_TYPE_REFUND => '5', + PosInterface::TX_TYPE_REFUND_PARTIAL => '5', ]; /** @@ -146,7 +147,7 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o /** * {@inheritDoc} */ - public function createRefundRequestData(AbstractPosAccount $posAccount, array $order): array + public function createRefundRequestData(AbstractPosAccount $posAccount, array $order, string $refundTxType): array { $order = $this->prepareRefundOrder($order); diff --git a/src/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapper.php index 606025f5..d5c5f567 100644 --- a/src/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapper.php @@ -229,7 +229,7 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o * @param KuveytPosAccount $posAccount * {@inheritDoc} */ - public function createRefundRequestData(AbstractPosAccount $posAccount, array $order): array + public function createRefundRequestData(AbstractPosAccount $posAccount, array $order, string $refundTxType): array { $order = $this->prepareRefundOrder($order); diff --git a/src/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapper.php index 60460e0d..ef4c5723 100644 --- a/src/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapper.php @@ -196,6 +196,9 @@ public function mapStatusResponse(array $rawResponseData): array return $defaultResponse; } + /** + * @inheritDoc + */ public function mapRefundResponse(array $rawResponseData): array { $rawResponseData = $this->emptyStringsToNull($rawResponseData); diff --git a/src/Gateways/AbstractGateway.php b/src/Gateways/AbstractGateway.php index 03ccd7f8..3d4fc245 100644 --- a/src/Gateways/AbstractGateway.php +++ b/src/Gateways/AbstractGateway.php @@ -311,7 +311,10 @@ public function makeRegularPostPayment(array $order): PosInterface public function refund(array $order): PosInterface { $txType = PosInterface::TX_TYPE_REFUND; - $requestData = $this->requestDataMapper->createRefundRequestData($this->account, $order); + if (isset($order['order_amount']) && $order['amount'] < $order['order_amount']) { + $txType = PosInterface::TX_TYPE_REFUND_PARTIAL; + } + $requestData = $this->requestDataMapper->createRefundRequestData($this->account, $order, $txType); $event = new RequestDataPreparedEvent( $requestData, diff --git a/src/Gateways/AkbankPos.php b/src/Gateways/AkbankPos.php index d374bc7f..54d2b752 100644 --- a/src/Gateways/AkbankPos.php +++ b/src/Gateways/AkbankPos.php @@ -27,19 +27,20 @@ class AkbankPos extends AbstractGateway /** @inheritdoc */ protected static array $supportedTransactions = [ - PosInterface::TX_TYPE_PAY_AUTH => [ + PosInterface::TX_TYPE_PAY_AUTH => [ PosInterface::MODEL_3D_SECURE, PosInterface::MODEL_3D_PAY, PosInterface::MODEL_3D_HOST, PosInterface::MODEL_NON_SECURE, ], - PosInterface::TX_TYPE_PAY_PRE_AUTH => true, - PosInterface::TX_TYPE_PAY_POST_AUTH => true, - PosInterface::TX_TYPE_STATUS => false, - PosInterface::TX_TYPE_CANCEL => true, - PosInterface::TX_TYPE_REFUND => true, - PosInterface::TX_TYPE_ORDER_HISTORY => true, - PosInterface::TX_TYPE_HISTORY => true, + PosInterface::TX_TYPE_PAY_PRE_AUTH => true, + PosInterface::TX_TYPE_PAY_POST_AUTH => true, + PosInterface::TX_TYPE_STATUS => false, + PosInterface::TX_TYPE_CANCEL => true, + PosInterface::TX_TYPE_REFUND => true, + PosInterface::TX_TYPE_REFUND_PARTIAL => true, + PosInterface::TX_TYPE_ORDER_HISTORY => true, + PosInterface::TX_TYPE_HISTORY => true, ]; /** @@ -196,7 +197,7 @@ protected function send($contents, string $txType, string $paymentModel, string $response = $this->client->post($url, [ 'headers' => [ 'Content-Type' => 'application/json', - 'auth-hash' => $hash, + 'auth-hash' => $hash, ], 'body' => $contents, ]); diff --git a/src/Gateways/EstPos.php b/src/Gateways/EstPos.php index 8f0b84c6..9fc39856 100644 --- a/src/Gateways/EstPos.php +++ b/src/Gateways/EstPos.php @@ -30,20 +30,21 @@ class EstPos extends AbstractGateway /** @inheritdoc */ protected static array $supportedTransactions = [ - PosInterface::TX_TYPE_PAY_AUTH => [ + PosInterface::TX_TYPE_PAY_AUTH => [ PosInterface::MODEL_3D_SECURE, PosInterface::MODEL_3D_PAY, PosInterface::MODEL_3D_HOST, PosInterface::MODEL_3D_PAY_HOSTING, PosInterface::MODEL_NON_SECURE, ], - PosInterface::TX_TYPE_PAY_PRE_AUTH => true, - PosInterface::TX_TYPE_PAY_POST_AUTH => true, - PosInterface::TX_TYPE_STATUS => true, - PosInterface::TX_TYPE_CANCEL => true, - PosInterface::TX_TYPE_REFUND => true, - PosInterface::TX_TYPE_ORDER_HISTORY => true, - PosInterface::TX_TYPE_HISTORY => false, + PosInterface::TX_TYPE_PAY_PRE_AUTH => true, + PosInterface::TX_TYPE_PAY_POST_AUTH => true, + PosInterface::TX_TYPE_STATUS => true, + PosInterface::TX_TYPE_CANCEL => true, + PosInterface::TX_TYPE_REFUND => true, + PosInterface::TX_TYPE_REFUND_PARTIAL => true, + PosInterface::TX_TYPE_ORDER_HISTORY => true, + PosInterface::TX_TYPE_HISTORY => false, ]; diff --git a/src/Gateways/GarantiPos.php b/src/Gateways/GarantiPos.php index 550ba002..24d5df15 100644 --- a/src/Gateways/GarantiPos.php +++ b/src/Gateways/GarantiPos.php @@ -37,18 +37,19 @@ class GarantiPos extends AbstractGateway /** @inheritdoc */ protected static array $supportedTransactions = [ - PosInterface::TX_TYPE_PAY_AUTH => [ + PosInterface::TX_TYPE_PAY_AUTH => [ PosInterface::MODEL_3D_SECURE, PosInterface::MODEL_3D_PAY, PosInterface::MODEL_NON_SECURE, ], - PosInterface::TX_TYPE_PAY_PRE_AUTH => true, - PosInterface::TX_TYPE_PAY_POST_AUTH => true, - PosInterface::TX_TYPE_STATUS => true, - PosInterface::TX_TYPE_CANCEL => true, - PosInterface::TX_TYPE_REFUND => true, - PosInterface::TX_TYPE_ORDER_HISTORY => true, - PosInterface::TX_TYPE_HISTORY => false, + PosInterface::TX_TYPE_PAY_PRE_AUTH => true, + PosInterface::TX_TYPE_PAY_POST_AUTH => true, + PosInterface::TX_TYPE_STATUS => true, + PosInterface::TX_TYPE_CANCEL => true, + PosInterface::TX_TYPE_REFUND => true, + PosInterface::TX_TYPE_REFUND_PARTIAL => true, + PosInterface::TX_TYPE_ORDER_HISTORY => true, + PosInterface::TX_TYPE_HISTORY => false, ]; diff --git a/src/Gateways/InterPos.php b/src/Gateways/InterPos.php index b121a76f..b2b450d9 100644 --- a/src/Gateways/InterPos.php +++ b/src/Gateways/InterPos.php @@ -39,19 +39,20 @@ class InterPos extends AbstractGateway /** @inheritdoc */ protected static array $supportedTransactions = [ - PosInterface::TX_TYPE_PAY_AUTH => [ + PosInterface::TX_TYPE_PAY_AUTH => [ PosInterface::MODEL_3D_SECURE, PosInterface::MODEL_3D_PAY, PosInterface::MODEL_3D_HOST, PosInterface::MODEL_NON_SECURE, ], - PosInterface::TX_TYPE_PAY_PRE_AUTH => true, - PosInterface::TX_TYPE_PAY_POST_AUTH => true, - PosInterface::TX_TYPE_STATUS => true, - PosInterface::TX_TYPE_CANCEL => true, - PosInterface::TX_TYPE_REFUND => true, - PosInterface::TX_TYPE_HISTORY => false, - PosInterface::TX_TYPE_ORDER_HISTORY => false, + PosInterface::TX_TYPE_PAY_PRE_AUTH => true, + PosInterface::TX_TYPE_PAY_POST_AUTH => true, + PosInterface::TX_TYPE_STATUS => true, + PosInterface::TX_TYPE_CANCEL => true, + PosInterface::TX_TYPE_REFUND => true, + PosInterface::TX_TYPE_REFUND_PARTIAL => true, + PosInterface::TX_TYPE_HISTORY => false, + PosInterface::TX_TYPE_ORDER_HISTORY => false, ]; /** @return InterPosAccount */ diff --git a/src/Gateways/KuveytPos.php b/src/Gateways/KuveytPos.php index 344f8d6f..fcab2e4a 100644 --- a/src/Gateways/KuveytPos.php +++ b/src/Gateways/KuveytPos.php @@ -43,17 +43,18 @@ class KuveytPos extends AbstractGateway /** @inheritdoc */ protected static array $supportedTransactions = [ - PosInterface::TX_TYPE_PAY_AUTH => [ + PosInterface::TX_TYPE_PAY_AUTH => [ PosInterface::MODEL_NON_SECURE, PosInterface::MODEL_3D_SECURE, ], - PosInterface::TX_TYPE_PAY_PRE_AUTH => false, - PosInterface::TX_TYPE_PAY_POST_AUTH => false, - PosInterface::TX_TYPE_STATUS => true, - PosInterface::TX_TYPE_CANCEL => true, - PosInterface::TX_TYPE_REFUND => true, - PosInterface::TX_TYPE_HISTORY => false, - PosInterface::TX_TYPE_ORDER_HISTORY => false, + PosInterface::TX_TYPE_PAY_PRE_AUTH => false, + PosInterface::TX_TYPE_PAY_POST_AUTH => false, + PosInterface::TX_TYPE_STATUS => true, + PosInterface::TX_TYPE_CANCEL => true, + PosInterface::TX_TYPE_REFUND => true, + PosInterface::TX_TYPE_REFUND_PARTIAL => true, + PosInterface::TX_TYPE_HISTORY => false, + PosInterface::TX_TYPE_ORDER_HISTORY => false, ]; /** @return KuveytPosAccount */ @@ -73,6 +74,7 @@ public function getApiURL(string $txType = null, string $paymentModel = null, ?s $txType, [ PosInterface::TX_TYPE_REFUND, + PosInterface::TX_TYPE_REFUND_PARTIAL, PosInterface::TX_TYPE_STATUS, PosInterface::TX_TYPE_CANCEL, ], @@ -211,7 +213,12 @@ public function make3DPayment(Request $request, array $order, string $txType, Cr */ protected function send($contents, string $txType, string $paymentModel, string $url): array { - if (\in_array($txType, [PosInterface::TX_TYPE_REFUND, PosInterface::TX_TYPE_STATUS, PosInterface::TX_TYPE_CANCEL], true)) { + if (\in_array($txType, [ + PosInterface::TX_TYPE_REFUND, + PosInterface::TX_TYPE_REFUND_PARTIAL, + PosInterface::TX_TYPE_STATUS, + PosInterface::TX_TYPE_CANCEL, + ], true)) { if (!\is_array($contents)) { throw new InvalidArgumentException(\sprintf('Invalid data type provided for %s transaction!', $txType)); } @@ -233,7 +240,7 @@ protected function send($contents, string $txType, string $paymentModel, string } /** - * @phpstan-param PosInterface::TX_TYPE_STATUS|PosInterface::TX_TYPE_REFUND|PosInterface::TX_TYPE_CANCEL $txType + * @phpstan-param PosInterface::TX_TYPE_STATUS|PosInterface::TX_TYPE_REFUND|PosInterface::TX_TYPE_REFUND_PARTIAL|PosInterface::TX_TYPE_CANCEL $txType * * @param array $contents * @param string $txType diff --git a/src/Gateways/PayFlexCPV4Pos.php b/src/Gateways/PayFlexCPV4Pos.php index 9915391a..fe9bab34 100644 --- a/src/Gateways/PayFlexCPV4Pos.php +++ b/src/Gateways/PayFlexCPV4Pos.php @@ -39,18 +39,19 @@ class PayFlexCPV4Pos extends AbstractGateway /** @inheritdoc */ protected static array $supportedTransactions = [ - PosInterface::TX_TYPE_PAY_AUTH => [ + PosInterface::TX_TYPE_PAY_AUTH => [ PosInterface::MODEL_3D_PAY, PosInterface::MODEL_3D_HOST, PosInterface::MODEL_NON_SECURE, ], - PosInterface::TX_TYPE_PAY_PRE_AUTH => true, - PosInterface::TX_TYPE_PAY_POST_AUTH => true, - PosInterface::TX_TYPE_STATUS => false, - PosInterface::TX_TYPE_CANCEL => true, - PosInterface::TX_TYPE_REFUND => true, - PosInterface::TX_TYPE_HISTORY => false, - PosInterface::TX_TYPE_ORDER_HISTORY => false, + PosInterface::TX_TYPE_PAY_PRE_AUTH => true, + PosInterface::TX_TYPE_PAY_POST_AUTH => true, + PosInterface::TX_TYPE_STATUS => false, + PosInterface::TX_TYPE_CANCEL => true, + PosInterface::TX_TYPE_REFUND => true, + PosInterface::TX_TYPE_REFUND_PARTIAL => true, + PosInterface::TX_TYPE_HISTORY => false, + PosInterface::TX_TYPE_ORDER_HISTORY => false, ]; /** @return PayFlexAccount */ diff --git a/src/Gateways/PayFlexV4Pos.php b/src/Gateways/PayFlexV4Pos.php index 93d38102..13af344f 100644 --- a/src/Gateways/PayFlexV4Pos.php +++ b/src/Gateways/PayFlexV4Pos.php @@ -41,17 +41,18 @@ class PayFlexV4Pos extends AbstractGateway /** @inheritdoc */ protected static array $supportedTransactions = [ - PosInterface::TX_TYPE_PAY_AUTH => [ + PosInterface::TX_TYPE_PAY_AUTH => [ PosInterface::MODEL_3D_SECURE, PosInterface::MODEL_NON_SECURE, ], - PosInterface::TX_TYPE_PAY_PRE_AUTH => true, - PosInterface::TX_TYPE_PAY_POST_AUTH => true, - PosInterface::TX_TYPE_STATUS => true, - PosInterface::TX_TYPE_CANCEL => true, - PosInterface::TX_TYPE_REFUND => true, - PosInterface::TX_TYPE_HISTORY => false, - PosInterface::TX_TYPE_ORDER_HISTORY => false, + PosInterface::TX_TYPE_PAY_PRE_AUTH => true, + PosInterface::TX_TYPE_PAY_POST_AUTH => true, + PosInterface::TX_TYPE_STATUS => true, + PosInterface::TX_TYPE_CANCEL => true, + PosInterface::TX_TYPE_REFUND => true, + PosInterface::TX_TYPE_REFUND_PARTIAL => true, + PosInterface::TX_TYPE_HISTORY => false, + PosInterface::TX_TYPE_ORDER_HISTORY => false, ]; /** @return PayFlexAccount */ diff --git a/src/Gateways/PayForPos.php b/src/Gateways/PayForPos.php index bc9d2958..4b0a2a05 100644 --- a/src/Gateways/PayForPos.php +++ b/src/Gateways/PayForPos.php @@ -36,19 +36,20 @@ class PayForPos extends AbstractGateway /** @inheritdoc */ protected static array $supportedTransactions = [ - PosInterface::TX_TYPE_PAY_AUTH => [ + PosInterface::TX_TYPE_PAY_AUTH => [ PosInterface::MODEL_3D_SECURE, PosInterface::MODEL_3D_PAY, PosInterface::MODEL_3D_HOST, PosInterface::MODEL_NON_SECURE, ], - PosInterface::TX_TYPE_PAY_PRE_AUTH => true, - PosInterface::TX_TYPE_PAY_POST_AUTH => true, - PosInterface::TX_TYPE_STATUS => true, - PosInterface::TX_TYPE_CANCEL => true, - PosInterface::TX_TYPE_REFUND => true, - PosInterface::TX_TYPE_HISTORY => true, - PosInterface::TX_TYPE_ORDER_HISTORY => true, + PosInterface::TX_TYPE_PAY_PRE_AUTH => true, + PosInterface::TX_TYPE_PAY_POST_AUTH => true, + PosInterface::TX_TYPE_STATUS => true, + PosInterface::TX_TYPE_CANCEL => true, + PosInterface::TX_TYPE_REFUND => true, + PosInterface::TX_TYPE_REFUND_PARTIAL => true, + PosInterface::TX_TYPE_HISTORY => true, + PosInterface::TX_TYPE_ORDER_HISTORY => true, ]; /** @return PayForAccount */ diff --git a/src/Gateways/PosNet.php b/src/Gateways/PosNet.php index 7a7f2806..bf7317a6 100644 --- a/src/Gateways/PosNet.php +++ b/src/Gateways/PosNet.php @@ -41,17 +41,18 @@ class PosNet extends AbstractGateway /** @inheritdoc */ protected static array $supportedTransactions = [ - PosInterface::TX_TYPE_PAY_AUTH => [ + PosInterface::TX_TYPE_PAY_AUTH => [ PosInterface::MODEL_3D_SECURE, PosInterface::MODEL_NON_SECURE, ], - PosInterface::TX_TYPE_PAY_PRE_AUTH => true, - PosInterface::TX_TYPE_PAY_POST_AUTH => true, - PosInterface::TX_TYPE_STATUS => true, - PosInterface::TX_TYPE_CANCEL => true, - PosInterface::TX_TYPE_REFUND => true, - PosInterface::TX_TYPE_HISTORY => false, - PosInterface::TX_TYPE_ORDER_HISTORY => false, + PosInterface::TX_TYPE_PAY_PRE_AUTH => true, + PosInterface::TX_TYPE_PAY_POST_AUTH => true, + PosInterface::TX_TYPE_STATUS => true, + PosInterface::TX_TYPE_CANCEL => true, + PosInterface::TX_TYPE_REFUND => true, + PosInterface::TX_TYPE_REFUND_PARTIAL => true, + PosInterface::TX_TYPE_HISTORY => false, + PosInterface::TX_TYPE_ORDER_HISTORY => false, ]; /** diff --git a/src/Gateways/PosNetV1Pos.php b/src/Gateways/PosNetV1Pos.php index 759f24e1..adf17d20 100644 --- a/src/Gateways/PosNetV1Pos.php +++ b/src/Gateways/PosNetV1Pos.php @@ -36,17 +36,18 @@ class PosNetV1Pos extends AbstractGateway /** @inheritdoc */ protected static array $supportedTransactions = [ - PosInterface::TX_TYPE_PAY_AUTH => [ + PosInterface::TX_TYPE_PAY_AUTH => [ PosInterface::MODEL_3D_SECURE, PosInterface::MODEL_NON_SECURE, ], - PosInterface::TX_TYPE_PAY_PRE_AUTH => true, - PosInterface::TX_TYPE_PAY_POST_AUTH => true, - PosInterface::TX_TYPE_STATUS => true, - PosInterface::TX_TYPE_CANCEL => true, - PosInterface::TX_TYPE_REFUND => true, - PosInterface::TX_TYPE_HISTORY => false, - PosInterface::TX_TYPE_ORDER_HISTORY => false, + PosInterface::TX_TYPE_PAY_PRE_AUTH => true, + PosInterface::TX_TYPE_PAY_POST_AUTH => true, + PosInterface::TX_TYPE_STATUS => true, + PosInterface::TX_TYPE_CANCEL => true, + PosInterface::TX_TYPE_REFUND => true, + PosInterface::TX_TYPE_REFUND_PARTIAL => true, + PosInterface::TX_TYPE_HISTORY => false, + PosInterface::TX_TYPE_ORDER_HISTORY => false, ]; /** @return PosNetAccount */ diff --git a/src/Gateways/ToslaPos.php b/src/Gateways/ToslaPos.php index 20770418..7cb51ce1 100644 --- a/src/Gateways/ToslaPos.php +++ b/src/Gateways/ToslaPos.php @@ -49,12 +49,13 @@ class ToslaPos extends AbstractGateway PosInterface::MODEL_3D_HOST, ], - PosInterface::TX_TYPE_HISTORY => false, - PosInterface::TX_TYPE_ORDER_HISTORY => true, - PosInterface::TX_TYPE_PAY_POST_AUTH => true, - PosInterface::TX_TYPE_CANCEL => true, - PosInterface::TX_TYPE_REFUND => true, - PosInterface::TX_TYPE_STATUS => true, + PosInterface::TX_TYPE_HISTORY => false, + PosInterface::TX_TYPE_ORDER_HISTORY => true, + PosInterface::TX_TYPE_PAY_POST_AUTH => true, + PosInterface::TX_TYPE_CANCEL => true, + PosInterface::TX_TYPE_REFUND => true, + PosInterface::TX_TYPE_REFUND_PARTIAL => true, + PosInterface::TX_TYPE_STATUS => true, ]; @@ -260,20 +261,21 @@ private function registerPayment(array $order, string $paymentModel, string $txT private function getRequestURIByTransactionType(string $txType, string $paymentModel): string { $arr = [ - PosInterface::TX_TYPE_PAY_AUTH => [ + PosInterface::TX_TYPE_PAY_AUTH => [ PosInterface::MODEL_NON_SECURE => 'Payment', PosInterface::MODEL_3D_PAY => 'threeDPayment', PosInterface::MODEL_3D_HOST => 'threeDPayment', ], - PosInterface::TX_TYPE_PAY_PRE_AUTH => [ + PosInterface::TX_TYPE_PAY_PRE_AUTH => [ PosInterface::MODEL_3D_PAY => 'threeDPreAuth', PosInterface::MODEL_3D_HOST => 'threeDPreAuth', ], - PosInterface::TX_TYPE_PAY_POST_AUTH => 'postAuth', - PosInterface::TX_TYPE_CANCEL => 'void', - PosInterface::TX_TYPE_REFUND => 'refund', - PosInterface::TX_TYPE_STATUS => 'inquiry', - PosInterface::TX_TYPE_ORDER_HISTORY => 'history', + PosInterface::TX_TYPE_PAY_POST_AUTH => 'postAuth', + PosInterface::TX_TYPE_CANCEL => 'void', + PosInterface::TX_TYPE_REFUND => 'refund', + PosInterface::TX_TYPE_REFUND_PARTIAL => 'refund', + PosInterface::TX_TYPE_STATUS => 'inquiry', + PosInterface::TX_TYPE_ORDER_HISTORY => 'history', ]; if (!isset($arr[$txType])) { diff --git a/src/Gateways/VakifKatilimPos.php b/src/Gateways/VakifKatilimPos.php index 16c67595..2ffa8b59 100644 --- a/src/Gateways/VakifKatilimPos.php +++ b/src/Gateways/VakifKatilimPos.php @@ -39,20 +39,21 @@ class VakifKatilimPos extends AbstractGateway /** @inheritdoc */ protected static array $supportedTransactions = [ - PosInterface::TX_TYPE_PAY_AUTH => [ + PosInterface::TX_TYPE_PAY_AUTH => [ PosInterface::MODEL_NON_SECURE, PosInterface::MODEL_3D_SECURE, PosInterface::MODEL_3D_HOST, ], - PosInterface::TX_TYPE_PAY_PRE_AUTH => [ + PosInterface::TX_TYPE_PAY_PRE_AUTH => [ PosInterface::MODEL_NON_SECURE, ], - PosInterface::TX_TYPE_PAY_POST_AUTH => true, - PosInterface::TX_TYPE_STATUS => true, - PosInterface::TX_TYPE_CANCEL => true, - PosInterface::TX_TYPE_REFUND => true, - PosInterface::TX_TYPE_HISTORY => true, - PosInterface::TX_TYPE_ORDER_HISTORY => true, + PosInterface::TX_TYPE_PAY_POST_AUTH => true, + PosInterface::TX_TYPE_STATUS => true, + PosInterface::TX_TYPE_CANCEL => true, + PosInterface::TX_TYPE_REFUND => true, + PosInterface::TX_TYPE_REFUND_PARTIAL => true, + PosInterface::TX_TYPE_HISTORY => true, + PosInterface::TX_TYPE_ORDER_HISTORY => true, ]; /** @return KuveytPosAccount */ @@ -244,29 +245,34 @@ private function getRequestURIByTransactionType(string $txType, string $paymentM $orderTxType ??= PosInterface::TX_TYPE_PAY_AUTH; $arr = [ - PosInterface::TX_TYPE_PAY_AUTH => [ + PosInterface::TX_TYPE_PAY_AUTH => [ PosInterface::MODEL_NON_SECURE => 'Non3DPayGate', PosInterface::MODEL_3D_SECURE => 'ThreeDModelProvisionGate', ], - PosInterface::TX_TYPE_PAY_PRE_AUTH => [ + PosInterface::TX_TYPE_PAY_PRE_AUTH => [ PosInterface::MODEL_NON_SECURE => 'PreAuthorizaten', ], - PosInterface::TX_TYPE_PAY_POST_AUTH => 'PreAuthorizatenClose', - PosInterface::TX_TYPE_CANCEL => [ + PosInterface::TX_TYPE_PAY_POST_AUTH => 'PreAuthorizatenClose', + PosInterface::TX_TYPE_CANCEL => [ PosInterface::MODEL_NON_SECURE => [ PosInterface::TX_TYPE_PAY_AUTH => 'SaleReversal', PosInterface::TX_TYPE_PAY_PRE_AUTH => 'PreAuthorizationReversal', ], ], - PosInterface::TX_TYPE_REFUND => [ + PosInterface::TX_TYPE_REFUND => [ PosInterface::MODEL_NON_SECURE => [ PosInterface::TX_TYPE_PAY_AUTH => 'DrawBack', PosInterface::TX_TYPE_PAY_PRE_AUTH => 'PreAuthorizationDrawBack', ], ], - PosInterface::TX_TYPE_STATUS => 'SelectOrderByMerchantOrderId', - PosInterface::TX_TYPE_ORDER_HISTORY => 'SelectOrder', - PosInterface::TX_TYPE_HISTORY => 'SelectOrder', + PosInterface::TX_TYPE_REFUND_PARTIAL => [ + PosInterface::MODEL_NON_SECURE => [ + PosInterface::TX_TYPE_PAY_AUTH => 'PartialDrawBack', + ], + ], + PosInterface::TX_TYPE_STATUS => 'SelectOrderByMerchantOrderId', + PosInterface::TX_TYPE_ORDER_HISTORY => 'SelectOrder', + PosInterface::TX_TYPE_HISTORY => 'SelectOrder', ]; if (\is_string($arr[$txType])) { diff --git a/src/PosInterface.php b/src/PosInterface.php index 6b149835..0a486a81 100644 --- a/src/PosInterface.php +++ b/src/PosInterface.php @@ -39,6 +39,9 @@ interface PosInterface /** @var string */ public const TX_TYPE_REFUND = 'refund'; + /** @var string */ + public const TX_TYPE_REFUND_PARTIAL = 'refund_partial'; + /** @var string */ public const TX_TYPE_STATUS = 'status'; diff --git a/src/Serializer/KuveytPosSerializer.php b/src/Serializer/KuveytPosSerializer.php index 365e41f3..a1a9f9c1 100644 --- a/src/Serializer/KuveytPosSerializer.php +++ b/src/Serializer/KuveytPosSerializer.php @@ -23,6 +23,7 @@ class KuveytPosSerializer implements SerializerInterface /** @var string[] */ private array $nonPaymentTransactions = [ PosInterface::TX_TYPE_REFUND, + PosInterface::TX_TYPE_REFUND_PARTIAL, PosInterface::TX_TYPE_STATUS, PosInterface::TX_TYPE_CANCEL, ]; diff --git a/src/Serializer/PayFlexCPV4PosSerializer.php b/src/Serializer/PayFlexCPV4PosSerializer.php index 6c61f97c..6822ea75 100644 --- a/src/Serializer/PayFlexCPV4PosSerializer.php +++ b/src/Serializer/PayFlexCPV4PosSerializer.php @@ -48,7 +48,9 @@ public function encode(array $data, string $txType) ); } - if (PosInterface::TX_TYPE_REFUND === $txType || PosInterface::TX_TYPE_CANCEL === $txType) { + if (PosInterface::TX_TYPE_REFUND === $txType + || PosInterface::TX_TYPE_REFUND_PARTIAL === $txType + || PosInterface::TX_TYPE_CANCEL === $txType) { return $this->serializer->encode($data, XmlEncoder::FORMAT); } diff --git a/tests/Functional/EstV3PosTest.php b/tests/Functional/EstV3PosTest.php index f50edc19..da15f1d0 100644 --- a/tests/Functional/EstV3PosTest.php +++ b/tests/Functional/EstV3PosTest.php @@ -230,7 +230,7 @@ public function testRefundSuccess(array $lastResponse): array RequestDataPreparedEvent::class, function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThrown): void { $eventIsThrown = true; - $this->assertSame(PosInterface::TX_TYPE_REFUND, $requestDataPreparedEvent->getTxType()); + $this->assertSame(PosInterface::TX_TYPE_REFUND_PARTIAL, $requestDataPreparedEvent->getTxType()); $this->assertCount(7, $requestDataPreparedEvent->getRequestData()); }); diff --git a/tests/Functional/KuveytPosTest.php b/tests/Functional/KuveytPosTest.php index 95274b51..5d4fcf40 100644 --- a/tests/Functional/KuveytPosTest.php +++ b/tests/Functional/KuveytPosTest.php @@ -287,7 +287,7 @@ public function testPartialRefundSuccess(array $lastResponse): array RequestDataPreparedEvent::class, function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThrown): void { $eventIsThrown = true; - $this->assertSame(PosInterface::TX_TYPE_REFUND, $requestDataPreparedEvent->getTxType()); + $this->assertSame(PosInterface::TX_TYPE_REFUND_PARTIAL, $requestDataPreparedEvent->getTxType()); $this->assertCount(14, $requestDataPreparedEvent->getRequestData()); }); diff --git a/tests/Functional/ToslaPosTest.php b/tests/Functional/ToslaPosTest.php index 5c9f1bad..cd146842 100644 --- a/tests/Functional/ToslaPosTest.php +++ b/tests/Functional/ToslaPosTest.php @@ -211,7 +211,7 @@ public function testPartialRefundSuccess(): array RequestDataPreparedEvent::class, function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThrown): void { $eventIsThrown = true; - $this->assertSame(PosInterface::TX_TYPE_REFUND, $requestDataPreparedEvent->getTxType()); + $this->assertSame(PosInterface::TX_TYPE_REFUND_PARTIAL, $requestDataPreparedEvent->getTxType()); $this->assertCount(7, $requestDataPreparedEvent->getRequestData()); }); diff --git a/tests/Unit/DataMapper/RequestDataMapper/AkbankPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/AkbankPosRequestDataMapperTest.php index 5df8d1d2..565386b8 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/AkbankPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/AkbankPosRequestDataMapperTest.php @@ -368,13 +368,13 @@ public function testCreateCancelRequestData(array $order, array $expectedData): /** * @dataProvider refundRequestDataProvider */ - public function testCreateRefundRequestData(array $order, array $expectedData): void + public function testCreateRefundRequestData(array $order, string $txType, array $expectedData): void { $this->crypt->expects(self::once()) ->method('generateRandomString') ->willReturn($expectedData['randomNumber']); - $actualData = $this->requestDataMapper->createRefundRequestData($this->account, $order); + $actualData = $this->requestDataMapper->createRefundRequestData($this->account, $order, $txType); $this->assertSame(23, \strlen($actualData['requestDateTime'])); unset($actualData['requestDateTime']); @@ -552,6 +552,7 @@ public static function refundRequestDataProvider(): array 'amount' => 1.02, 'currency' => PosInterface::CURRENCY_TRY, ], + 'txType' => PosInterface::TX_TYPE_REFUND, 'expected' => [ 'terminal' => [ 'merchantSafeId' => '2023090417500272654BD9A49CF07574', @@ -576,6 +577,7 @@ public static function refundRequestDataProvider(): array 'currency' => PosInterface::CURRENCY_TRY, 'recurringOrderInstallmentNumber' => 2, ], + 'txType' => PosInterface::TX_TYPE_REFUND, 'expected' => [ 'terminal' => [ 'merchantSafeId' => '2023090417500272654BD9A49CF07574', diff --git a/tests/Unit/DataMapper/RequestDataMapper/EstPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/EstPosRequestDataMapperTest.php index 5a3cf5b2..b3694e12 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/EstPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/EstPosRequestDataMapperTest.php @@ -272,20 +272,15 @@ public function testCreateRecurringStatusRequestData(): void } /** - * @return void + * @dataProvider refundRequestDataProvider */ - public function testCreateRefundRequestData(): void + public function testCreateRefundRequestData(array $order, string $txType, array $expectedData): void { - $order = [ - 'id' => '2020110828BC', - 'amount' => 50, - 'currency' => PosInterface::CURRENCY_TRY, - ]; + $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order, $txType); - $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order); - - $expectedData = $this->getSampleRefundXMLData($this->account, $order); - $this->assertEquals($expectedData, $actual); + \ksort($actual); + \ksort($expectedData); + $this->assertSame($expectedData, $actual); } @@ -545,6 +540,46 @@ public static function orderHistoryRequestDataProvider(): array ]; } + public static function refundRequestDataProvider(): array + { + return [ + 'full_refund' => [ + 'order' => [ + 'id' => 'order-123', + 'currency' => PosInterface::CURRENCY_TRY, + 'amount' => 5, + ], + 'txType' => PosInterface::TX_TYPE_REFUND, + 'expected' => [ + 'ClientId' => '700655000200', + 'Currency' => '949', + 'Name' => 'ISBANKAPI', + 'OrderId' => 'order-123', + 'Password' => 'ISBANK07', + 'Total' => '5', + 'Type' => 'Credit', + ], + ], + 'partial_refund' => [ + 'order' => [ + 'id' => 'order-123', + 'currency' => PosInterface::CURRENCY_TRY, + 'amount' => 5, + ], + 'txType' => PosInterface::TX_TYPE_REFUND_PARTIAL, + 'expected' => [ + 'ClientId' => '700655000200', + 'Currency' => '949', + 'Name' => 'ISBANKAPI', + 'OrderId' => 'order-123', + 'Password' => 'ISBANK07', + 'Total' => '5', + 'Type' => 'Credit', + ], + ], + ]; + } + /** * @param AbstractPosAccount $posAccount * @param array $order @@ -645,28 +680,4 @@ private function getSampleRecurringStatusRequestData(AbstractPosAccount $posAcco ], ]; } - - /** - * @param AbstractPosAccount $posAccount - * @param array $order - * - * @return array - */ - private function getSampleRefundXMLData(AbstractPosAccount $posAccount, array $order): array - { - $data = [ - 'Name' => $posAccount->getUsername(), - 'Password' => $posAccount->getPassword(), - 'ClientId' => $posAccount->getClientId(), - 'OrderId' => $order['id'], - 'Currency' => 949, - 'Type' => 'Credit', - ]; - - if ($order['amount']) { - $data['Total'] = $order['amount']; - } - - return $data; - } } diff --git a/tests/Unit/DataMapper/RequestDataMapper/GarantiPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/GarantiPosRequestDataMapperTest.php index 21cae2a2..eace3103 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/GarantiPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/GarantiPosRequestDataMapperTest.php @@ -281,11 +281,13 @@ public function testCreateStatusRequestData(): void /** * @dataProvider refundOrderDataProvider */ - public function testCreateRefundRequestData(GarantiPosAccount $garantiPosAccount, array $order, array $expectedData): void + public function testCreateRefundRequestData(array $order, string $txType, array $expectedData): void { - $actual = $this->requestDataMapper->createRefundRequestData($garantiPosAccount, $order); + $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order, $txType); - $this->assertEquals($expectedData, $actual); + \ksort($actual); + \ksort($expectedData); + $this->assertSame($expectedData, $actual); } /** @@ -435,7 +437,7 @@ private function getSampleStatusRequestData(AbstractPosAccount $posAccount, arra public static function refundOrderDataProvider(): \Generator { - $order = [ + $order = [ 'id' => '2020110828BC', 'ip' => '127.15.15.1', 'currency' => PosInterface::CURRENCY_TRY, @@ -443,20 +445,41 @@ public static function refundOrderDataProvider(): \Generator 'ref_ret_num' => '831803579226', 'installment' => 0, ]; - $account = AccountFactory::createGarantiPosAccount( - 'garanti', - '7000679', - 'PROVAUT', - '123qweASD/', - '30691298', - PosInterface::MODEL_3D_SECURE, - '12345678', - 'PROVRFN', - '123qweASD/' - ); + + yield [ + 'order' => $order, + 'tx_type' => PosInterface::TX_TYPE_REFUND, + 'expectedData' => [ + 'Mode' => 'TEST', + 'Version' => '512', + 'Terminal' => [ + 'ProvUserID' => 'PROVRFN', + 'UserID' => 'PROVRFN', + 'HashData' => 'CF49751B3B793B9E1946A08815451989D0231D68A5B495C6EABA9C400442F2E6B7DF97446CE2D3562780767E634A6ECBAA1DF69F6DF7F447884A71BDE38D12AA', + 'ID' => '30691298', + 'MerchantID' => '7000679', + ], + 'Customer' => [ + 'IPAddress' => '127.15.15.1', + ], + 'Order' => [ + 'OrderID' => '2020110828BC', + ], + 'Transaction' => [ + 'Type' => 'refund', + 'InstallmentCnt' => '', + 'Amount' => 12310, + 'CurrencyCode' => '949', + 'CardholderPresentCode' => '0', + 'MotoInd' => 'N', + 'OriginalRetrefNum' => '831803579226', + ], + ], + ]; + yield [ - 'account' => $account, 'order' => $order, + 'tx_type' => PosInterface::TX_TYPE_REFUND_PARTIAL, 'expectedData' => [ 'Mode' => 'TEST', 'Version' => '512', @@ -476,7 +499,7 @@ public static function refundOrderDataProvider(): \Generator 'Transaction' => [ 'Type' => 'refund', 'InstallmentCnt' => '', - 'Amount' => '12310', + 'Amount' => 12310, 'CurrencyCode' => '949', 'CardholderPresentCode' => '0', 'MotoInd' => 'N', @@ -491,8 +514,8 @@ public static function orderHistoryRequestDataProvider(): array return [ [ 'order' => [ - 'id' => 'order222', - 'ip' => '156.155.154.153', + 'id' => 'order222', + 'ip' => '156.155.154.153', 'installment' => 0, ], 'expected' => [ diff --git a/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php index 03b77856..e26d72a2 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php @@ -254,19 +254,15 @@ public function testCreateStatusRequestData(): void } /** - * @return void + * @dataProvider refundOrderDataProvider */ - public function testCreateRefundRequestData(): void + public function testCreateRefundRequestData(array $order, string $txType, array $expectedData): void { - $order = [ - 'id' => '2020110828BC', - 'amount' => 50, - ]; - - $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order); + $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order, $txType); - $expectedData = $this->getSampleRefundXMLData($order, $this->account); - $this->assertEquals($expectedData, $actual); + \ksort($actual); + \ksort($expectedData); + $this->assertSame($expectedData, $actual); } /** @@ -390,28 +386,6 @@ private function getSampleStatusRequestData(array $order, InterPosAccount $inter ]; } - /** - * @param array $order - * @param InterPosAccount $interPosAccount - * - * @return array - */ - private function getSampleRefundXMLData(array $order, InterPosAccount $interPosAccount): array - { - return [ - 'UserCode' => $interPosAccount->getUsername(), - 'UserPass' => $interPosAccount->getPassword(), - 'ShopCode' => $interPosAccount->getClientId(), - 'OrderId' => null, - 'orgOrderId' => $order['id'], - 'PurchAmount' => $order['amount'], - 'TxnType' => 'Refund', - 'SecureType' => 'NonSecure', - 'Lang' => $interPosAccount->getLang(), - 'MOTO' => '0', - ]; - } - public static function threeDFormDataProvider(): array { $order = [ @@ -507,4 +481,46 @@ public static function threeDFormDataProvider(): array ], ]; } + + public static function refundOrderDataProvider(): \Generator + { + $order = [ + 'id' => '2020110828BC', + 'amount' => 123.1, + ]; + + yield [ + 'order' => $order, + 'tx_type' => PosInterface::TX_TYPE_REFUND, + 'expectedData' => [ + 'Lang' => 'tr', + 'MOTO' => '0', + 'OrderId' => null, + 'PurchAmount' => '123.1', + 'SecureType' => 'NonSecure', + 'ShopCode' => '3123', + 'TxnType' => 'Refund', + 'UserCode' => 'InterTestApi', + 'UserPass' => '3', + 'orgOrderId' => '2020110828BC', + ], + ]; + + yield [ + 'order' => $order, + 'tx_type' => PosInterface::TX_TYPE_REFUND_PARTIAL, + 'expectedData' => [ + 'Lang' => 'tr', + 'MOTO' => '0', + 'OrderId' => null, + 'PurchAmount' => '123.1', + 'SecureType' => 'NonSecure', + 'ShopCode' => '3123', + 'TxnType' => 'Refund', + 'UserCode' => 'InterTestApi', + 'UserPass' => '3', + 'orgOrderId' => '2020110828BC', + ], + ]; + } } diff --git a/tests/Unit/DataMapper/RequestDataMapper/KuveytPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/KuveytPosRequestDataMapperTest.php index bfe66992..d5e7da15 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/KuveytPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/KuveytPosRequestDataMapperTest.php @@ -184,13 +184,13 @@ public function testCreateCancelRequestData(array $order, array $expected): void /** * @dataProvider createRefundRequestDataProvider */ - public function testCreateRefundRequestData(array $order, array $expected): void + public function testCreateRefundRequestData(array $order, string $txType, array $expected): void { $this->crypt->expects(self::once()) ->method('createHash') ->willReturn('request-hash'); - $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order); + $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order, $txType); foreach ($actual as &$item) { if (is_array($item)) { @@ -384,7 +384,7 @@ public static function createCancelRequestDataProvider(): iterable public static function createRefundRequestDataProvider(): Generator { yield [ - 'full_order' => [ + 'full_refund' => [ 'id' => '2023070849CD', 'remote_order_id' => '114293600', 'ref_ret_num' => '318923298433', @@ -393,7 +393,8 @@ public static function createRefundRequestDataProvider(): Generator 'amount' => 1.01, 'currency' => PosInterface::CURRENCY_TRY, ], - 'expected' => [ + 'tx_type' => PosInterface::TX_TYPE_REFUND, + 'expected' => [ 'IsFromExternalNetwork' => true, 'BusinessKey' => 0, 'ResourceId' => 0, @@ -445,6 +446,7 @@ public static function createRefundRequestDataProvider(): Generator 'order_amount' => 10.01, 'currency' => PosInterface::CURRENCY_TRY, ], + 'tx_type' => PosInterface::TX_TYPE_REFUND_PARTIAL, 'expected' => [ 'IsFromExternalNetwork' => true, 'BusinessKey' => 0, diff --git a/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php index d42623f8..a24f0afa 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php @@ -213,16 +213,16 @@ public function testCreateCancelRequestData(): void $this->assertEquals($expectedValue, $actualData); } - public function testCreateRefundRequestData(): void + /** + * @dataProvider refundRequestDataProvider + */ + public function testCreateRefundRequestData(array $order, string $txType, array $expectedData): void { - $order = $this->order; - $order['transaction_id'] = '7022b92e-3aa1-44fb-86d4-33658c700c80'; - $order['amount'] = 1000; + $actualData = $this->requestDataMapper->createRefundRequestData($this->account, $order, $txType); - $expectedValue = $this->getSampleRefundRequestData(); - $actualData = $this->requestDataMapper->createRefundRequestData($this->account, $order); - - $this->assertEquals($expectedValue, $actualData); + \ksort($actualData); + \ksort($expectedData); + $this->assertSame($expectedData, $actualData); } /** @@ -235,7 +235,7 @@ public function testCreate3DFormData(): void $this->dispatcher->expects(self::never()) ->method('dispatch'); - $actualData = $this->requestDataMapper->create3DFormData( + $actualData = $this->requestDataMapper->create3DFormData( null, null, null, @@ -451,6 +451,44 @@ public static function three3DEnrollmentRequestDataDataProvider(): \Generator ]; } + public static function refundRequestDataProvider(): array + { + return [ + 'full_refund' => [ + 'order' => [ + 'transaction_id' => '7022b92e-3aa1-44fb-86d4-33658c700c80', + 'amount' => 5, + 'ip' => '127.0.0.1', + ], + 'txType' => PosInterface::TX_TYPE_REFUND, + 'expected' => [ + 'ClientIp' => '127.0.0.1', + 'CurrencyAmount' => '5.00', + 'MerchantId' => '000000000111111', + 'Password' => '3XTgER89as', + 'ReferenceTransactionId' => '7022b92e-3aa1-44fb-86d4-33658c700c80', + 'TransactionType' => 'Refund', + ], + ], + 'partial_refund' => [ + 'order' => [ + 'transaction_id' => '7022b92e-3aa1-44fb-86d4-33658c700c80', + 'amount' => 5, + 'ip' => '127.0.0.1', + ], + 'txType' => PosInterface::TX_TYPE_REFUND_PARTIAL, + 'expected' => [ + 'ClientIp' => '127.0.0.1', + 'CurrencyAmount' => '5.00', + 'MerchantId' => '000000000111111', + 'Password' => '3XTgER89as', + 'ReferenceTransactionId' => '7022b92e-3aa1-44fb-86d4-33658c700c80', + 'TransactionType' => 'Refund', + ], + ], + ]; + } + /** * @param PayFlexAccount $posAccount * @param array $order @@ -497,18 +535,6 @@ private function getSampleNonSecurePaymentPostRequestData(AbstractPosAccount $po ]; } - private function getSampleRefundRequestData(): array - { - return [ - 'MerchantId' => '000000000111111', - 'Password' => '3XTgER89as', - 'TransactionType' => 'Refund', - 'ReferenceTransactionId' => '7022b92e-3aa1-44fb-86d4-33658c700c80', - 'ClientIp' => '127.0.0.1', - 'CurrencyAmount' => '1000.00', - ]; - } - /** * @return array */ diff --git a/tests/Unit/DataMapper/RequestDataMapper/PayForPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PayForPosRequestDataMapperTest.php index e33f8398..c7c32c05 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/PayForPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/PayForPosRequestDataMapperTest.php @@ -264,20 +264,15 @@ public function testCreateStatusRequestData(): void } /** - * @return void + * @dataProvider refundRequestDataProvider */ - public function testCreateRefundRequestData(): void + public function testCreateRefundRequestData(array $order, string $txType, array $expectedData): void { - $order = [ - 'id' => '2020110828BC', - 'currency' => PosInterface::CURRENCY_TRY, - 'amount' => 10.1, - ]; - - $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order); + $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order, $txType); - $expectedData = $this->getSampleRefundXMLData($this->account, $order); - $this->assertEquals($expectedData, $actual); + \ksort($expectedData); + \ksort($actual); + $this->assertSame($expectedData, $actual); } /** @@ -390,34 +385,12 @@ private function getSampleStatusRequestData(AbstractPosAccount $posAccount, arra ]; } - /** - * @param AbstractPosAccount $posAccount - * @param array $order - * - * @return array - */ - private function getSampleRefundXMLData(AbstractPosAccount $posAccount, array $order): array - { - return [ - 'MbrId' => '5', - 'MerchantId' => $posAccount->getClientId(), - 'UserCode' => $posAccount->getUsername(), - 'UserPass' => $posAccount->getPassword(), - 'OrgOrderId' => $order['id'], - 'SecureType' => 'NonSecure', - 'Lang' => 'tr', - 'TxnType' => 'Refund', - 'PurchAmount' => $order['amount'], - 'Currency' => 949, - ]; - } - public static function orderHistoryRequestDataProvider(): array { return [ [ 'order' => [ - 'id' => '2020110828BC', + 'id' => '2020110828BC', ], 'expected' => [ 'MerchantId' => '085300000009704', @@ -437,7 +410,7 @@ public static function historyRequestDataProvider(): array { return [ [ - 'data' => [ + 'data' => [ 'transaction_date' => new \DateTime('2022-05-18'), ], 'expected' => [ @@ -554,4 +527,50 @@ public static function threeDFormDataProvider(): array ], ]; } + + public static function refundRequestDataProvider(): array + { + return [ + 'full_refund' => [ + 'order' => [ + 'id' => '7022b92e-3aa1-44fb-86d4-33658c700c80', + 'currency' => PosInterface::CURRENCY_TRY, + 'amount' => 5, + ], + 'txType' => PosInterface::TX_TYPE_REFUND, + 'expected' => [ + 'Currency' => '949', + 'Lang' => 'tr', + 'MbrId' => '5', + 'MerchantId' => '085300000009704', + 'OrgOrderId' => '7022b92e-3aa1-44fb-86d4-33658c700c80', + 'PurchAmount' => '5', + 'SecureType' => 'NonSecure', + 'TxnType' => 'Refund', + 'UserCode' => 'QNB_API_KULLANICI_3DPAY', + 'UserPass' => 'UcBN0', + ], + ], + 'partial_refund' => [ + 'order' => [ + 'id' => '7022b92e-3aa1-44fb-86d4-33658c700c80', + 'currency' => PosInterface::CURRENCY_TRY, + 'amount' => 5, + ], + 'txType' => PosInterface::TX_TYPE_REFUND_PARTIAL, + 'expected' => [ + 'Currency' => '949', + 'Lang' => 'tr', + 'MbrId' => '5', + 'MerchantId' => '085300000009704', + 'OrgOrderId' => '7022b92e-3aa1-44fb-86d4-33658c700c80', + 'PurchAmount' => '5', + 'SecureType' => 'NonSecure', + 'TxnType' => 'Refund', + 'UserCode' => 'QNB_API_KULLANICI_3DPAY', + 'UserPass' => 'UcBN0', + ], + ], + ]; + } } diff --git a/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php index abb2457e..6c23fa7d 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php @@ -259,13 +259,15 @@ public function testCreateStatusRequestData(array $order, array $expectedData): } /** - * @dataProvider refundDataProvider + * @dataProvider refundRequestDataProvider */ - public function testCreateRefundRequestData(array $order, array $expectedData): void + public function testCreateRefundRequestData(array $order, string $txType, array $expectedData): void { - $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order); + $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order, $txType); - $this->assertEquals($expectedData, $actual); + \ksort($actual); + \ksort($expectedData); + $this->assertSame($expectedData, $actual); } public static function threeDFormDataDataProvider(): array @@ -450,7 +452,7 @@ public static function statusRequestDataProvider(): array ]; } - public static function refundDataProvider(): array + public static function refundRequestDataProvider(): array { return [ 'with_order_id' => [ @@ -460,6 +462,7 @@ public static function refundDataProvider(): array 'amount' => 50, 'currency' => PosInterface::CURRENCY_TRY, ], + 'tx_type' => PosInterface::TX_TYPE_REFUND, 'expected' => [ 'mid' => '6706598320', 'tid' => '67005551', @@ -478,6 +481,7 @@ public static function refundDataProvider(): array 'amount' => 50, 'currency' => PosInterface::CURRENCY_TRY, ], + 'tx_type' => PosInterface::TX_TYPE_REFUND, 'expected' => [ 'mid' => '6706598320', 'tid' => '67005551', diff --git a/tests/Unit/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapperTest.php index e1031aaa..c88de79c 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapperTest.php @@ -163,7 +163,7 @@ public function testCreateNonSecurePostAuthPaymentRequestData(array $order, arra */ public function testCreateNonSecurePaymentRequestData(array $order, array $expectedData): void { - $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($this->account,$order, PosInterface::TX_TYPE_PAY_AUTH, $this->card); + $actual = $this->requestDataMapper->createNonSecurePaymentRequestData($this->account, $order, PosInterface::TX_TYPE_PAY_AUTH, $this->card); $this->assertEquals($expectedData, $actual); } @@ -216,10 +216,13 @@ public function testCreateStatusRequestData(array $order, array $expected): void /** * @dataProvider createRefundRequestDataDataProvider */ - public function testCreateRefundRequestData(array $order, array $expected): void + public function testCreateRefundRequestData(array $order, string $txType, array $expected): void { - $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order); - $this->assertEquals($expected, $actual); + $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order, $txType); + + ksort($actual); + ksort($expected); + $this->assertSame($expected, $actual); } @@ -281,7 +284,7 @@ public static function threeDFormDataTestProvider(): iterable public static function nonSecurePaymentRequestDataDataProvider(): iterable { yield [ - 'order' => [ + 'order' => [ 'id' => '123', 'amount' => 10.0, 'installment' => 0, @@ -449,6 +452,7 @@ public static function createRefundRequestDataDataProvider(): iterable 'payment_model' => PosInterface::MODEL_3D_SECURE, 'transaction_type' => PosInterface::TX_TYPE_PAY_AUTH, ], + 'tx_type' => PosInterface::TX_TYPE_REFUND, 'expected' => [ 'ApiType' => 'JSON', 'ApiVersion' => 'V100', @@ -473,6 +477,7 @@ public static function createRefundRequestDataDataProvider(): iterable 'payment_model' => PosInterface::MODEL_3D_SECURE, 'transaction_type' => PosInterface::TX_TYPE_PAY_AUTH, ], + 'tx_type' => PosInterface::TX_TYPE_REFUND, 'expected' => [ 'ApiType' => 'JSON', 'ApiVersion' => 'V100', @@ -497,6 +502,7 @@ public static function createRefundRequestDataDataProvider(): iterable 'payment_model' => PosInterface::MODEL_3D_SECURE, 'transaction_type' => PosInterface::TX_TYPE_PAY_AUTH, ], + 'tx_type' => PosInterface::TX_TYPE_REFUND, 'expected' => [ 'ApiType' => 'JSON', 'ApiVersion' => 'V100', @@ -521,6 +527,7 @@ public static function createRefundRequestDataDataProvider(): iterable 'amount' => 112, 'transaction_type' => PosInterface::TX_TYPE_PAY_PRE_AUTH, ], + 'tx_type' => PosInterface::TX_TYPE_REFUND, 'expected' => [ 'ApiType' => 'JSON', 'ApiVersion' => 'V100', diff --git a/tests/Unit/DataMapper/RequestDataMapper/ToslaPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/ToslaPosRequestDataMapperTest.php index ae1b2beb..bf04cad4 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/ToslaPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/ToslaPosRequestDataMapperTest.php @@ -234,7 +234,7 @@ public function testCreateStatusRequestData(array $order, array $expected): void /** * @dataProvider refundRequestDataProvider */ - public function testCreateRefundRequestData(array $order, array $expected): void + public function testCreateRefundRequestData(array $order, string $txType, array $expected): void { $this->crypt->expects(self::once()) ->method('generateRandomString') @@ -243,9 +243,11 @@ public function testCreateRefundRequestData(array $order, array $expected): void ->method('createHash') ->willReturn($expected['hash']); - $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order); + $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order, $txType); - $this->assertEquals($expected, $actual); + ksort($actual); + ksort($expected); + $this->assertSame($expected, $actual); } public static function statusRequestDataProvider(): array @@ -297,6 +299,7 @@ public static function refundRequestDataProvider(): array 'amount' => 1.02, 'time_span' => '20231209215355', ], + 'tx_type' => PosInterface::TX_TYPE_REFUND, 'expected' => [ 'clientId' => '1000000494', 'apiUser' => 'POS_ENT_Test_001', diff --git a/tests/Unit/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapperTest.php index b1a63bdd..2a307581 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapperTest.php @@ -204,10 +204,13 @@ public function testCreateCancelRequestData(array $order, array $expected): void /** * @dataProvider createRefundRequestDataProvider */ - public function testCreateRefundRequestData(array $order, array $expected): void + public function testCreateRefundRequestData(array $order, string $txType, array $expected): void { - $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order); - $this->assertEquals($expected, $actual); + $actual = $this->requestDataMapper->createRefundRequestData($this->account, $order, $txType); + + \ksort($actual); + \ksort($expected); + $this->assertSame($expected, $actual); } /** @@ -321,6 +324,7 @@ public static function createRefundRequestDataProvider(): Generator 'remote_order_id' => '114293600', 'amount' => 1.01, ], + 'tx_type' => PosInterface::TX_TYPE_REFUND, 'expected' => [ 'MerchantId' => '1', 'CustomerId' => '11111', diff --git a/tests/Unit/Gateways/AkbankPosTest.php b/tests/Unit/Gateways/AkbankPosTest.php index c454e32c..179c2b39 100644 --- a/tests/Unit/Gateways/AkbankPosTest.php +++ b/tests/Unit/Gateways/AkbankPosTest.php @@ -600,15 +600,14 @@ public function testCancelRequest(array $order, string $apiUrl): void /** * @dataProvider refundRequestDataProvider */ - public function testRefundRequest(array $order, string $apiUrl): void + public function testRefundRequest(array $order, string $txType, string $apiUrl): void { $account = $this->pos->getAccount(); - $txType = PosInterface::TX_TYPE_REFUND; $requestData = ['createRefundRequestData']; $this->requestMapperMock->expects(self::once()) ->method('createRefundRequestData') - ->with($account, $order) + ->with($account, $order, $txType) ->willReturn($requestData); $this->configureClientResponse( @@ -648,6 +647,11 @@ public static function getApiUrlDataProvider(): array 'paymentModel' => PosInterface::MODEL_NON_SECURE, 'expected' => 'https://apipre.akbank.com/api/v1/payment/virtualpos/transaction/process', ], + [ + 'txType' => PosInterface::TX_TYPE_REFUND_PARTIAL, + 'paymentModel' => PosInterface::MODEL_NON_SECURE, + 'expected' => 'https://apipre.akbank.com/api/v1/payment/virtualpos/transaction/process', + ], [ 'txType' => PosInterface::TX_TYPE_HISTORY, 'paymentModel' => PosInterface::MODEL_NON_SECURE, @@ -702,10 +706,21 @@ public static function cancelRequestDataProvider(): array public static function refundRequestDataProvider(): array { return [ - [ + 'full_refund' => [ 'order' => [ - 'id' => '2020110828BC', + 'id' => '2020110828BC', + 'amount' => 5, + ], + 'tx_type' => PosInterface::TX_TYPE_REFUND, + 'api_url' => 'https://apipre.akbank.com/api/v1/payment/virtualpos/transaction/process', + ], + 'partial_refund' => [ + 'order' => [ + 'id' => '2020110828BC', + 'amount' => 5, + 'order_amount' => 10, ], + 'tx_type' => PosInterface::TX_TYPE_REFUND_PARTIAL, 'api_url' => 'https://apipre.akbank.com/api/v1/payment/virtualpos/transaction/process', ], ]; diff --git a/tests/Unit/Gateways/EstPosTest.php b/tests/Unit/Gateways/EstPosTest.php index 3a70de9a..d032f8dc 100644 --- a/tests/Unit/Gateways/EstPosTest.php +++ b/tests/Unit/Gateways/EstPosTest.php @@ -365,7 +365,7 @@ public function testRefund(array $bankResponse, array $expectedData, bool $isSuc $this->requestMapperMock->expects(self::once()) ->method('createRefundRequestData') - ->with($account, $order) + ->with($account, $order, $txType) ->willReturn($requestData); $this->configureClientResponse( diff --git a/tests/Unit/Gateways/GarantiPosTest.php b/tests/Unit/Gateways/GarantiPosTest.php index c29803fa..159bb71d 100644 --- a/tests/Unit/Gateways/GarantiPosTest.php +++ b/tests/Unit/Gateways/GarantiPosTest.php @@ -426,7 +426,7 @@ public function testRefundRequest(array $order, string $apiUrl): void $this->requestMapperMock->expects(self::once()) ->method('createRefundRequestData') - ->with($account, $order) + ->with($account, $order, $txType) ->willReturn($requestData); $decodedResponse = ['decodedData']; diff --git a/tests/Unit/Gateways/InterPosTest.php b/tests/Unit/Gateways/InterPosTest.php index e8d17011..4cac171b 100644 --- a/tests/Unit/Gateways/InterPosTest.php +++ b/tests/Unit/Gateways/InterPosTest.php @@ -454,7 +454,7 @@ public function testRefundRequest(array $order, string $apiUrl): void $this->requestMapperMock->expects(self::once()) ->method('createRefundRequestData') - ->with($account, $order) + ->with($account, $order, $txType) ->willReturn($requestData); $decodedResponse = ['decodedData']; diff --git a/tests/Unit/Gateways/KuveytPosTest.php b/tests/Unit/Gateways/KuveytPosTest.php index 103aff46..0d433790 100644 --- a/tests/Unit/Gateways/KuveytPosTest.php +++ b/tests/Unit/Gateways/KuveytPosTest.php @@ -487,6 +487,11 @@ public static function getApiUrlDataProvider(): array 'paymentModel' => PosInterface::MODEL_NON_SECURE, 'expected' => 'https://boatest.kuveytturk.com.tr/BOA.Integration.WCFService/BOA.Integration.VirtualPos/VirtualPosService.svc?wsdl', ], + [ + 'txType' => PosInterface::TX_TYPE_REFUND_PARTIAL, + 'paymentModel' => PosInterface::MODEL_NON_SECURE, + 'expected' => 'https://boatest.kuveytturk.com.tr/BOA.Integration.WCFService/BOA.Integration.VirtualPos/VirtualPosService.svc?wsdl', + ], [ 'txType' => PosInterface::TX_TYPE_CANCEL, 'paymentModel' => PosInterface::MODEL_NON_SECURE, diff --git a/tests/Unit/Gateways/PayFlexCPV4PosTest.php b/tests/Unit/Gateways/PayFlexCPV4PosTest.php index b98b7e3b..f4939630 100644 --- a/tests/Unit/Gateways/PayFlexCPV4PosTest.php +++ b/tests/Unit/Gateways/PayFlexCPV4PosTest.php @@ -444,7 +444,7 @@ public function testRefundRequest(array $order, string $apiUrl): void $this->requestMapperMock->expects(self::once()) ->method('createRefundRequestData') - ->with($account, $order) + ->with($account, $order, $txType) ->willReturn($requestData); $decodedResponse = ['decodedData']; diff --git a/tests/Unit/Gateways/PayFlexV4PosTest.php b/tests/Unit/Gateways/PayFlexV4PosTest.php index cb0cef3f..232ef759 100644 --- a/tests/Unit/Gateways/PayFlexV4PosTest.php +++ b/tests/Unit/Gateways/PayFlexV4PosTest.php @@ -461,7 +461,7 @@ public function testRefundRequest(array $order, string $apiUrl): void $this->requestMapperMock->expects(self::once()) ->method('createRefundRequestData') - ->with($account, $order) + ->with($account, $order, $txType) ->willReturn($requestData); $decodedResponse = ['decodedData']; diff --git a/tests/Unit/Gateways/PayForTest.php b/tests/Unit/Gateways/PayForTest.php index 50ec1c45..04f71d13 100644 --- a/tests/Unit/Gateways/PayForTest.php +++ b/tests/Unit/Gateways/PayForTest.php @@ -459,7 +459,7 @@ public function testRefundRequest(array $order, string $apiUrl): void $this->requestMapperMock->expects(self::once()) ->method('createRefundRequestData') - ->with($account, $order) + ->with($account, $order, $txType) ->willReturn($requestData); $decodedResponse = ['decodedData']; diff --git a/tests/Unit/Gateways/PosNetTest.php b/tests/Unit/Gateways/PosNetTest.php index ea16862e..8989393b 100644 --- a/tests/Unit/Gateways/PosNetTest.php +++ b/tests/Unit/Gateways/PosNetTest.php @@ -502,7 +502,7 @@ public function testRefundRequest(array $order, string $apiUrl): void $this->requestMapperMock->expects(self::once()) ->method('createRefundRequestData') - ->with($account, $order) + ->with($account, $order, $txType) ->willReturn($requestData); $decodedResponse = ['decodedData']; diff --git a/tests/Unit/Gateways/PosNetV1PosTest.php b/tests/Unit/Gateways/PosNetV1PosTest.php index 53bab61a..f656c860 100644 --- a/tests/Unit/Gateways/PosNetV1PosTest.php +++ b/tests/Unit/Gateways/PosNetV1PosTest.php @@ -440,7 +440,7 @@ public function testRefundRequest(array $order, string $apiUrl): void $this->requestMapperMock->expects(self::once()) ->method('createRefundRequestData') - ->with($account, $order) + ->with($account, $order, $txType) ->willReturn($requestData); $decodedResponse = ['decodedData']; diff --git a/tests/Unit/Gateways/ToslaPosTest.php b/tests/Unit/Gateways/ToslaPosTest.php index 9bd8a0ec..90cf1a80 100644 --- a/tests/Unit/Gateways/ToslaPosTest.php +++ b/tests/Unit/Gateways/ToslaPosTest.php @@ -383,6 +383,7 @@ public function testCancel( */ public function testRefund( array $order, + string $txType, array $requestData, string $encodedRequest, string $responseContent, @@ -393,7 +394,7 @@ public function testRefund( { $this->requestMapperMock->expects(self::once()) ->method('createRefundRequestData') - ->with($this->pos->getAccount(), $order) + ->with($this->pos->getAccount(), $order, $txType) ->willReturn($requestData); $this->responseMapperMock->expects(self::once()) @@ -499,6 +500,7 @@ public static function refundDataProvider(): iterable { yield [ 'order' => ToslaPosRequestDataMapperTest::refundRequestDataProvider()[0]['order'], + 'txType' => PosInterface::TX_TYPE_REFUND, 'requestData' => ToslaPosRequestDataMapperTest::refundRequestDataProvider()[0]['expected'], 'encodedRequestData' => \json_encode(ToslaPosRequestDataMapperTest::refundRequestDataProvider()[0]['expected'], JSON_THROW_ON_ERROR), 'responseData' => \json_encode(ToslaPosResponseDataMapperTest::refundDataProvider()['success1']['responseData'], JSON_THROW_ON_ERROR), @@ -721,7 +723,7 @@ public function testRefundRequest(array $order, string $apiUrl): void $this->requestMapperMock->expects(self::once()) ->method('createRefundRequestData') - ->with($account, $order) + ->with($account, $order, $txType) ->willReturn($requestData); $decodedResponse = ['decodedData']; @@ -793,6 +795,11 @@ public static function getApiUrlDataProvider(): array 'paymentModel' => PosInterface::MODEL_NON_SECURE, 'expected' => 'https://ent.akodepos.com/api/Payment/refund', ], + [ + 'txType' => PosInterface::TX_TYPE_REFUND_PARTIAL, + 'paymentModel' => PosInterface::MODEL_NON_SECURE, + 'expected' => 'https://ent.akodepos.com/api/Payment/refund', + ], [ 'txType' => PosInterface::TX_TYPE_ORDER_HISTORY, 'paymentModel' => PosInterface::MODEL_NON_SECURE, diff --git a/tests/Unit/Gateways/VakifKatilimTest.php b/tests/Unit/Gateways/VakifKatilimTest.php index 46c0120b..979d0b4f 100644 --- a/tests/Unit/Gateways/VakifKatilimTest.php +++ b/tests/Unit/Gateways/VakifKatilimTest.php @@ -489,15 +489,14 @@ public function testCancelRequest(array $order, string $apiUrl): void /** * @dataProvider refundRequestDataProvider */ - public function testRefundRequest(array $order, string $apiUrl): void + public function testRefundRequest(array $order, string $txType, string $apiUrl): void { $account = $this->pos->getAccount(); - $txType = PosInterface::TX_TYPE_REFUND; $requestData = ['createRefundRequestData']; $this->requestMapperMock->expects(self::once()) ->method('createRefundRequestData') - ->with($account, $order) + ->with($account, $order, $txType) ->willReturn($requestData); $decodedResponse = ['decodedData']; @@ -659,6 +658,12 @@ public static function getApiUrlDataProvider(): array 'paymentModel' => PosInterface::MODEL_NON_SECURE, 'expected' => 'https://boa.vakifkatilim.com.tr/VirtualPOS.Gateway/Home/DrawBack', ], + [ + 'txType' => PosInterface::TX_TYPE_REFUND_PARTIAL, + 'orderTxType' => PosInterface::TX_TYPE_PAY_AUTH, + 'paymentModel' => PosInterface::MODEL_NON_SECURE, + 'expected' => 'https://boa.vakifkatilim.com.tr/VirtualPOS.Gateway/Home/PartialDrawBack', + ], [ 'txType' => PosInterface::TX_TYPE_CANCEL, 'orderTxType' => PosInterface::TX_TYPE_PAY_PRE_AUTH, @@ -752,20 +757,32 @@ public static function cancelRequestDataProvider(): array public static function refundRequestDataProvider(): array { return [ - 'pay_order' => [ + 'pay_order' => [ 'order' => [ 'id' => '2020110828BC', 'transaction_type' => PosInterface::TX_TYPE_PAY_AUTH, ], + 'txType' => PosInterface::TX_TYPE_REFUND, 'api_url' => 'https://boa.vakifkatilim.com.tr/VirtualPOS.Gateway/Home/DrawBack', ], - 'pay_auth_order' => [ + 'pay_auth_order' => [ 'order' => [ 'id' => '2020110828BC', 'transaction_type' => PosInterface::TX_TYPE_PAY_PRE_AUTH, ], + 'txType' => PosInterface::TX_TYPE_REFUND, 'api_url' => 'https://boa.vakifkatilim.com.tr/VirtualPOS.Gateway/Home/PreAuthorizationDrawBack', ], + 'pay_order_partial_refund' => [ + 'order' => [ + 'id' => '2020110828BC', + 'order_amount' => 10, + 'amount' => 5, + 'transaction_type' => PosInterface::TX_TYPE_PAY_AUTH, + ], + 'txType' => PosInterface::TX_TYPE_REFUND_PARTIAL, + 'api_url' => 'https://boa.vakifkatilim.com.tr/VirtualPOS.Gateway/Home/PartialDrawBack', + ], ]; } diff --git a/tests/Unit/Serializer/KuveytPosSerializerTest.php b/tests/Unit/Serializer/KuveytPosSerializerTest.php index 28e2288c..f429b5eb 100644 --- a/tests/Unit/Serializer/KuveytPosSerializerTest.php +++ b/tests/Unit/Serializer/KuveytPosSerializerTest.php @@ -105,6 +105,12 @@ public static function encodeDataProvider(): Generator 'expected' => $refundTests[0]['expected'], ]; + yield 'test_partial_refund' => [ + 'input' => $refundTests[0]['expected'], + 'txType' => PosInterface::TX_TYPE_REFUND_PARTIAL, + 'expected' => $refundTests[0]['expected'], + ]; + yield 'test_cancel' => [ 'input' => ['abc' => 1], 'txType' => PosInterface::TX_TYPE_CANCEL, From eaf0d5e05ac44aa2445067b9d690943466b084a0 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Wed, 29 May 2024 17:54:23 +0200 Subject: [PATCH 3/7] VakifKatilimPosRequestDataMapper remove unnecessary $txTypeMappings --- .../VakifKatilimPosRequestDataMapper.php | 7 ------- .../VakifKatilimPosRequestDataMapperTest.php | 19 ------------------- 2 files changed, 26 deletions(-) diff --git a/src/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapper.php index d5c5f567..466b193c 100644 --- a/src/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapper.php @@ -34,13 +34,6 @@ class VakifKatilimPosRequestDataMapper extends AbstractRequestDataMapper PosInterface::MODEL_NON_SECURE => '5', ]; - /** - * {@inheritDoc} - */ - protected array $txTypeMappings = [ - PosInterface::TX_TYPE_PAY_AUTH => '1', - ]; - /** * Currency mapping * diff --git a/tests/Unit/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapperTest.php index 2a307581..12838e71 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapperTest.php @@ -9,7 +9,6 @@ use Mews\Pos\DataMapper\RequestDataMapper\VakifKatilimPosRequestDataMapper; use Mews\Pos\Entity\Account\KuveytPosAccount; use Mews\Pos\Entity\Card\CreditCardInterface; -use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\Factory\AccountFactory; use Mews\Pos\Factory\CreditCardFactory; use Mews\Pos\Factory\CryptFactory; @@ -60,24 +59,6 @@ protected function setUp(): void $this->requestDataMapper = new VakifKatilimPosRequestDataMapper($this->dispatcher, $crypt); } - /** - * @testWith ["pay", "1"] - */ - public function testMapTxType(string $txType, string $expected): void - { - $actual = $this->requestDataMapper->mapTxType($txType); - $this->assertSame($expected, $actual); - } - - /** - * @testWith ["Sale"] - */ - public function testMapTxTypeException(string $txType): void - { - $this->expectException(UnsupportedTransactionTypeException::class); - $this->requestDataMapper->mapTxType($txType); - } - /** * @return void */ From ea3e4b9eef974b332832111a65bda40a0c945473 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Thu, 6 Jun 2024 11:09:26 +0200 Subject: [PATCH 4/7] improve code examples --- docs/CANCEL-EXAMPLE.md | 12 +++++-- docs/HISTORY-EXAMPLE.md | 12 +++++-- docs/NON-SECURE-PAYMENT-EXAMPLE.md | 28 ++++++++++------- docs/ORDER-HISTORY-EXAMPLE.md | 5 +-- docs/PRE-AUTH-POST-EXAMPLE.md | 7 +++-- docs/REFUND-EXAMPLE.md | 13 ++++++-- docs/STATUS-EXAMPLE.md | 12 +++++-- docs/THREED-PAYMENT-EXAMPLE.md | 31 +++++++++---------- ...URE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md | 7 +++-- examples/_common-codes/3d/form.php | 11 +++---- examples/_templates/_credit_card_form.php | 2 +- 11 files changed, 85 insertions(+), 55 deletions(-) diff --git a/docs/CANCEL-EXAMPLE.md b/docs/CANCEL-EXAMPLE.md index fbf764c2..bbc44b71 100644 --- a/docs/CANCEL-EXAMPLE.md +++ b/docs/CANCEL-EXAMPLE.md @@ -12,7 +12,8 @@ require './vendor/autoload.php'; // API kullanıcı bilgileri // AccountFactory'de kullanılacak method Gateway'e göre değişir!!! -// /examples altındaki örnek kodlara bakınız. +// /examples altındaki _config.php dosyalara bakınız +// (örn: /examples/akbankpos/3d/_config.php) $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i 'yourClientID', @@ -30,7 +31,7 @@ try { $pos = \Mews\Pos\Factory\PosFactory::createPosGateway($account, $config, $eventDispatcher); - // GarantiPos ve KuveytPos'u test ortamda test edebilmek için zorunlu. + // GarantiPos'u test ortamda test edebilmek için zorunlu. $pos->setTestMode(true); } catch (\Mews\Pos\Exceptions\BankNotFoundException | \Mews\Pos\Exceptions\BankClassNullException $e) { var_dump($e)); @@ -116,7 +117,12 @@ $lastResponse = $session->get('last_response'); $ip = '127.0.0.1'; $order = createCancelOrder(get_class($pos), $lastResponse, $ip); -$pos->cancel($order); +try { + $pos->cancel($order); +} catch (\Error $e) { + var_dump($e); + exit; +} $response = $pos->getResponse(); var_dump($response); ``` diff --git a/docs/HISTORY-EXAMPLE.md b/docs/HISTORY-EXAMPLE.md index a3e5434f..0180695a 100644 --- a/docs/HISTORY-EXAMPLE.md +++ b/docs/HISTORY-EXAMPLE.md @@ -12,7 +12,8 @@ require './vendor/autoload.php'; // API kullanıcı bilgileri // AccountFactory'de kullanılacak method Gateway'e göre değişir!!! -// /examples altındaki örnek kodlara bakınız. +// /examples altındaki _config.php dosyalara bakınız +// (örn: /examples/akbankpos/3d/_config.php) $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i 'yourClientID', @@ -30,7 +31,7 @@ try { $pos = \Mews\Pos\Factory\PosFactory::createPosGateway($account, $config, $eventDispatcher); - // GarantiPos ve KuveytPos'u test ortamda test edebilmek için zorunlu. + // GarantiPos'u test ortamda test edebilmek için zorunlu. $pos->setTestMode(true); } catch (\Mews\Pos\Exceptions\BankNotFoundException | \Mews\Pos\Exceptions\BankClassNullException $e) { var_dump($e)); @@ -77,7 +78,12 @@ function createHistoryOrder(string $gatewayClass, array $extraData): array $order = createHistoryOrder(get_class($pos), []); -$pos->history($order); +try { + $pos->history($order); +} catch (\Error $e) { + var_dump($e); + exit; +} $response = $pos->getResponse(); var_dump($response); ``` diff --git a/docs/NON-SECURE-PAYMENT-EXAMPLE.md b/docs/NON-SECURE-PAYMENT-EXAMPLE.md index 42941560..806ed7d0 100644 --- a/docs/NON-SECURE-PAYMENT-EXAMPLE.md +++ b/docs/NON-SECURE-PAYMENT-EXAMPLE.md @@ -15,7 +15,8 @@ $transactionType = \Mews\Pos\PosInterface::TX_TYPE_PAY_AUTH; // API kullanıcı bilgileri // AccountFactory'de kullanılacak method Gateway'e göre değişir!!! -// /examples altındaki örnek kodlara bakınız. +// /examples altındaki _config.php dosyalara bakınız +// (örn: /examples/akbankpos/3d/_config.php) $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i 'yourClientID', @@ -33,7 +34,7 @@ try { $pos = \Mews\Pos\Factory\PosFactory::createPosGateway($account, $config, $eventDispatcher); - // GarantiPos ve KuveytPos'u test ortamda test edebilmek için zorunlu. + // GarantiPos'u test ortamda test edebilmek için zorunlu. $pos->setTestMode(true); } catch (\Mews\Pos\Exceptions\BankNotFoundException | \Mews\Pos\Exceptions\BankClassNullException $e) { var_dump($e)); @@ -50,7 +51,7 @@ require 'config.php'; // Sipariş bilgileri $order = [ - 'id' => 'BENZERSIZ-SIPERIS-ID', + 'id' => 'BENZERSIZ-SIPARIS-ID', 'amount' => 1.01, 'currency' => \Mews\Pos\PosInterface::CURRENCY_TRY, //optional. default: TRY 'installment' => 0, //0 ya da 1'den büyük değer, optional. default: 0 @@ -80,20 +81,25 @@ $card = \Mews\Pos\Factory\CreditCardFactory::createForGateway( } // Ödeme tamamlanıyor -$pos->payment( - $paymentModel, - $order, - $transactionType, - $card -); +try { + $pos->payment( + $paymentModel, + $order, + $transactionType, + $card + ); +} catch (\Error $e) { + var_dump($e); + exit; +} -// Ödeme başarılı mı? -$pos->isSuccess(); // Sonuç çıktısı $response = $pos->getResponse(); + var_dump($response); // response içeriği için /examples/template/_payment_response.php dosyaya bakınız. +// Ödeme başarılı mı? if ($pos->isSuccess()) { // NOT: Ödeme durum sorgulama, iptal ve iade işlemleri yapacaksanız $response değerini saklayınız. } diff --git a/docs/ORDER-HISTORY-EXAMPLE.md b/docs/ORDER-HISTORY-EXAMPLE.md index cb4230d9..a9dcbf72 100644 --- a/docs/ORDER-HISTORY-EXAMPLE.md +++ b/docs/ORDER-HISTORY-EXAMPLE.md @@ -12,7 +12,8 @@ require './vendor/autoload.php'; // API kullanıcı bilgileri // AccountFactory'de kullanılacak method Gateway'e göre değişir!!! -// /examples altındaki örnek kodlara bakınız. +// /examples altındaki _config.php dosyalara bakınız +// (örn: /examples/akbankpos/3d/_config.php) $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i 'yourClientID', @@ -30,7 +31,7 @@ try { $pos = \Mews\Pos\Factory\PosFactory::createPosGateway($account, $config, $eventDispatcher); - // GarantiPos ve KuveytPos'u test ortamda test edebilmek için zorunlu. + // GarantiPos'u test ortamda test edebilmek için zorunlu. $pos->setTestMode(true); } catch (\Mews\Pos\Exceptions\BankNotFoundException | \Mews\Pos\Exceptions\BankClassNullException $e) { var_dump($e)); diff --git a/docs/PRE-AUTH-POST-EXAMPLE.md b/docs/PRE-AUTH-POST-EXAMPLE.md index 6750159d..9603fde1 100644 --- a/docs/PRE-AUTH-POST-EXAMPLE.md +++ b/docs/PRE-AUTH-POST-EXAMPLE.md @@ -23,7 +23,8 @@ $transactionType = \Mews\Pos\PosInterface::TX_TYPE_PAY_PRE_AUTH; // API kullanıcı bilgileri // AccountFactory'de kullanılacak method Gateway'e göre değişir!!! -// /examples altındaki örnek kodlara bakınız. +// /examples altındaki _config.php dosyalara bakınız +// (örn: /examples/akbankpos/3d/_config.php) $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i 'yourClientID', @@ -41,7 +42,7 @@ try { $pos = \Mews\Pos\Factory\PosFactory::createPosGateway($account, $config, $eventDispatcher); - // GarantiPos ve KuveytPos'u test ortamda test edebilmek için zorunlu. + // GarantiPos'u test ortamda test edebilmek için zorunlu. $pos->setTestMode(true); } catch (\Mews\Pos\Exceptions\BankNotFoundException | \Mews\Pos\Exceptions\BankClassNullException $e) { var_dump($e)); @@ -61,7 +62,7 @@ require 'config.php'; // Sipariş bilgileri $order = [ - 'id' => 'BENZERSIZ-SIPERIS-ID', + 'id' => 'BENZERSIZ-SIPARIS-ID', 'amount' => 1.01, 'currency' => \Mews\Pos\PosInterface::CURRENCY_TRY, //optional. default: TRY 'installment' => 0, //0 ya da 1'den büyük değer, optional. default: 0 diff --git a/docs/REFUND-EXAMPLE.md b/docs/REFUND-EXAMPLE.md index c88190c8..eee6f86f 100644 --- a/docs/REFUND-EXAMPLE.md +++ b/docs/REFUND-EXAMPLE.md @@ -12,7 +12,8 @@ require './vendor/autoload.php'; // API kullanıcı bilgileri // AccountFactory'de kullanılacak method Gateway'e göre değişir!!! -// /examples altındaki örnek kodlara bakınız. +// /examples altındaki _config.php dosyalara bakınız +// (örn: /examples/akbankpos/3d/_config.php) $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i 'yourClientID', @@ -30,7 +31,7 @@ try { $pos = \Mews\Pos\Factory\PosFactory::createPosGateway($account, $config, $eventDispatcher); - // GarantiPos ve KuveytPos'u test ortamda test edebilmek için zorunlu. + // GarantiPos'u test ortamda test edebilmek için zorunlu. $pos->setTestMode(true); } catch (\Mews\Pos\Exceptions\BankNotFoundException | \Mews\Pos\Exceptions\BankClassNullException $e) { var_dump($e)); @@ -102,7 +103,13 @@ $refundAmount = $lastResponse['amount'] - 2; $ip = '127.0.0.1'; $order = createRefundOrder(get_class($pos), $lastResponse, $ip, $refundAmount); -$pos->refund($order); +try { + $pos->refund($order); +} catch (\Error $e) { + var_dump($e); + exit; +} + $response = $pos->getResponse(); var_dump($response); ``` diff --git a/docs/STATUS-EXAMPLE.md b/docs/STATUS-EXAMPLE.md index 1dbdc183..0284ae57 100644 --- a/docs/STATUS-EXAMPLE.md +++ b/docs/STATUS-EXAMPLE.md @@ -12,7 +12,8 @@ require './vendor/autoload.php'; // API kullanıcı bilgileri // AccountFactory'de kullanılacak method Gateway'e göre değişir!!! -// /examples altındaki örnek kodlara bakınız. +// /examples altındaki _config.php dosyalara bakınız +// (örn: /examples/akbankpos/3d/_config.php) $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i 'yourClientID', @@ -30,7 +31,7 @@ try { $pos = \Mews\Pos\Factory\PosFactory::createPosGateway($account, $config, $eventDispatcher); - // GarantiPos ve KuveytPos'u test ortamda test edebilmek için zorunlu. + // GarantiPos'u test ortamda test edebilmek için zorunlu. $pos->setTestMode(true); } catch (\Mews\Pos\Exceptions\BankNotFoundException | \Mews\Pos\Exceptions\BankClassNullException $e) { var_dump($e)); @@ -79,7 +80,12 @@ $lastResponse = $session->get('last_response'); $ip = '127.0.0.1'; $order = createStatusOrder(get_class($pos), $lastResponse, $ip); -$pos->status($order); +try { + $pos->status($order); +} catch (\Error $e) { + var_dump($e); + exit; +} $response = $pos->getResponse(); var_dump($response); ``` diff --git a/docs/THREED-PAYMENT-EXAMPLE.md b/docs/THREED-PAYMENT-EXAMPLE.md index dbb19610..bae95382 100644 --- a/docs/THREED-PAYMENT-EXAMPLE.md +++ b/docs/THREED-PAYMENT-EXAMPLE.md @@ -31,7 +31,8 @@ $transactionType = \Mews\Pos\PosInterface::TX_TYPE_PAY_AUTH; // API kullanıcı bilgileri // AccountFactory'de kullanılacak method Gateway'e göre değişir!!! -// /examples altındaki örnek kodlara bakınız. +// /examples altındaki _config.php dosyalara bakınız +// (örn: /examples/akbankpos/3d/_config.php) $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i 'yourClientID', @@ -49,7 +50,7 @@ try { $pos = \Mews\Pos\Factory\PosFactory::createPosGateway($account, $config, $eventDispatcher); - // GarantiPos ve KuveytPos'u test ortamda test edebilmek için zorunlu. + // GarantiPos'u test ortamda test edebilmek için zorunlu. $pos->setTestMode(true); } catch (\Mews\Pos\Exceptions\BankNotFoundException | \Mews\Pos\Exceptions\BankClassNullException $e) { var_dump($e); @@ -66,7 +67,7 @@ require 'config.php'; // Sipariş bilgileri $order = [ - 'id' => 'BENZERSIZ-SIPERIS-ID', + 'id' => 'BENZERSIZ-SIPARIS-ID', 'amount' => 1.01, 'currency' => \Mews\Pos\PosInterface::CURRENCY_TRY, //optional. default: TRY 'installment' => 0, //0 ya da 1'den büyük değer, optional. default: 0 @@ -210,6 +211,9 @@ try { $requestDataPreparedEvent->setRequestData($requestData); }); +// ============================================================================================ +// OZEL DURUMLAR ICIN KODLAR END +// ============================================================================================ $formData = $pos->get3DFormData( $order, $paymentModel, @@ -220,9 +224,6 @@ try { var_dump($e); exit; } -// ============================================================================================ -// OZEL DURUMLAR ICIN KODLAR END -// ============================================================================================ ``` ```html @@ -237,13 +238,11 @@ try { ``` **response.php (gateway'den döndükten sonra çalışacak kod)** @@ -300,20 +299,18 @@ try { $card ); - // Ödeme başarılı mı? - $pos->isSuccess(); - // Sonuç çıktısı $response = $pos->getResponse(); var_dump($response); // response içeriği için /examples/template/_payment_response.php dosyaya bakınız. + // Ödeme başarılı mı? if ($pos->isSuccess()) { // NOT: Ödeme durum sorgulama, iptal ve iade işlemleri yapacaksanız $response değerini saklayınız. } } catch (\Mews\Pos\Exceptions\HashMismatchException $e) { // Bankadan gelen verilerin bankaya ait olmadığında bu exception oluşur. - // Banka API bilgileriniz hatalı ise de oluşur. + // veya Banka API bilgileriniz hatalı ise de oluşur. } catch (\Error $e) { var_dump($e); exit; diff --git a/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md b/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md index 30d541cb..08e971e3 100644 --- a/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md +++ b/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md @@ -29,7 +29,8 @@ $paymentModel = \Mews\Pos\PosInterface::MODEL_3D_SECURE; $transactionType = \Mews\Pos\PosInterface::TX_TYPE_PAY_AUTH; // AccountFactory'de kullanılacak method Gateway'e göre değişir!!! -// /examples altındaki örnek kodlara bakınız. +// /examples altındaki _config.php dosyalara bakınız +// (örn: /examples/akbankpos/3d/_config.php) $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i 'yourClientID', @@ -47,7 +48,7 @@ try { $pos = \Mews\Pos\Factory\PosFactory::createPosGateway($account, $config, $eventDispatcher); - // GarantiPos ve KuveytPos'u test ortamda test edebilmek için zorunlu. + // GarantiPos'u test ortamda test edebilmek için zorunlu. $pos->setTestMode(true); } catch (\Mews\Pos\Exceptions\BankNotFoundException | \Mews\Pos\Exceptions\BankClassNullException $e) { var_dump($e)); @@ -92,7 +93,7 @@ require 'config.php'; // Sipariş bilgileri $order = [ - 'id' => 'BENZERSIZ-SIPERIS-ID', + 'id' => 'BENZERSIZ-SIPARIS-ID', 'amount' => 1.01, 'currency' => \Mews\Pos\PosInterface::CURRENCY_TRY, //optional. default: TRY 'installment' => 0, //0 ya da 1'den büyük değer, optional. default: 0 diff --git a/examples/_common-codes/3d/form.php b/examples/_common-codes/3d/form.php index fe85ea77..5537dfce 100644 --- a/examples/_common-codes/3d/form.php +++ b/examples/_common-codes/3d/form.php @@ -233,12 +233,11 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent): void { --> diff --git a/examples/_templates/_credit_card_form.php b/examples/_templates/_credit_card_form.php index 05f7e871..dd665485 100644 --- a/examples/_templates/_credit_card_form.php +++ b/examples/_templates/_credit_card_form.php @@ -64,7 +64,7 @@
From 507aabfff66e98f69fbd7f8750f33681535fa5a4 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Thu, 6 Jun 2024 13:57:06 +0200 Subject: [PATCH 5/7] examples - fix json parse error when paying in modal box --- docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md | 4 ++-- examples/_common-codes/3d/form.php | 2 +- examples/_templates/_payment_secure_response.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md b/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md index 08e971e3..16981e55 100644 --- a/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md +++ b/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md @@ -175,7 +175,7 @@ $renderedForm = ob_get_clean(); */ let displayResponse = function (event) { let alertBox = $('#result-alert'); - let data = JSON.parse(event.data); + let data = JSON.parse(atob(event.data)); $('#result-response').append(JSON.stringify(data, null, '\t')); if (data.status === 'approved') { alertBox.append('payment successful'); @@ -277,7 +277,7 @@ try { if (window.parent) { // response.php iframe'de calisti // odeme sonucunu ana window'a yani form.php'e gonderiyoruz. - window.parent.postMessage(``); + window.parent.postMessage(``); } ``` diff --git a/examples/_common-codes/3d/form.php b/examples/_common-codes/3d/form.php index 5537dfce..c6444374 100644 --- a/examples/_common-codes/3d/form.php +++ b/examples/_common-codes/3d/form.php @@ -268,7 +268,7 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent): void { */ let displayResponse = function (event) { let alertBox = $('#result-alert'); - let data = JSON.parse(event.data); + let data = JSON.parse(atob(event.data)); $('#result-response').append(JSON.stringify(data, null, '\t')); if (data.status === 'approved') { alertBox.append('payment successful'); diff --git a/examples/_templates/_payment_secure_response.php b/examples/_templates/_payment_secure_response.php index a5b65807..8a61886b 100644 --- a/examples/_templates/_payment_secure_response.php +++ b/examples/_templates/_payment_secure_response.php @@ -106,11 +106,11 @@ if (window.opener && window.opener !== window) { // you are in a popup // send result data to parent window - window.opener.parent.postMessage(``); + window.opener.parent.postMessage(``); } else if (window.parent) { // you are in iframe // send result data to parent window - window.parent.postMessage(``); + window.parent.postMessage(``); } From fb4b775e3a7541ba894d3fc1888639fdbc8fd6c2 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Thu, 6 Jun 2024 17:58:16 +0200 Subject: [PATCH 6/7] examples - upgrade to bootstrap 5 and remove jquery --- ...URE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md | 45 +++-- examples/_common-codes/3d/form.php | 66 +++--- examples/_common-codes/3d/index.php | 4 +- examples/_common-codes/regular/cancel.php | 6 +- examples/_common-codes/regular/history.php | 3 +- .../_common-codes/regular/order_history.php | 3 +- examples/_common-codes/regular/refund.php | 3 +- examples/_common-codes/regular/status.php | 4 +- examples/_main_config.php | 4 + examples/_templates/_credit_card_form.php | 55 ++--- examples/_templates/_header.php | 191 +++++++++++------- .../_templates/_render_payment_response.php | 2 +- 12 files changed, 236 insertions(+), 150 deletions(-) diff --git a/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md b/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md index 16981e55..32ff2cb5 100644 --- a/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md +++ b/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md @@ -167,24 +167,28 @@ $renderedForm = ob_get_clean(); @@ -204,7 +208,8 @@ $renderedForm = ob_get_clean(); window.addEventListener('message', function (event) { messageReceived = true; displayResponse(event); - $('#iframe-modal').modal('hide'); + let myModal = bootstrap.Modal.getInstance(document.getElementById('iframe-modal')); + myModal.hide(); }); /** @@ -212,20 +217,24 @@ $renderedForm = ob_get_clean(); * modal box içinde yeni iframe oluşturuyoruz ve iframe içine $renderedForm verisini basıyoruz. */ let iframe = document.createElement('iframe'); - document.getElementById("iframe-modal-dialog").appendChild(iframe); - $(iframe).height('500px'); - $(iframe).width('410px'); + document.getElementById("iframe-modal-body").appendChild(iframe); + iframe.style.height = '500px'; + iframe.style.width = '410px'; iframe.contentWindow.document.open(); iframe.contentWindow.document.write(``); iframe.contentWindow.document.close(); - $('#iframe-modal').modal('show'); + let modalElement = document.getElementById('iframe-modal'); + let myModal = new bootstrap.Modal(modalElement, { + keyboard: false + }) + myModal.show(); - $('#iframe-modal').on('hidden.bs.modal', function () { + modalElement.addEventListener('hidden.bs.modal', function () { if (!messageReceived) { - let alertBox = $('#result-alert'); - alertBox.addClass('alert-danger'); - alertBox.append('modal box kapatildi'); - alertBox.show(); + let alertBox = document.getElementById('result-alert'); + alertBox.classList.add('alert-danger'); + alertBox.appendChild(document.createTextNode('modal box kapatildi')); + alertBox.style.display = 'block'; } }); diff --git a/examples/_common-codes/3d/form.php b/examples/_common-codes/3d/form.php index c6444374..fecadd2b 100644 --- a/examples/_common-codes/3d/form.php +++ b/examples/_common-codes/3d/form.php @@ -260,24 +260,28 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent): void { @@ -287,9 +291,14 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent): void {