From 97e29fbcf32637273ff249a1f25d846f71bedad0 Mon Sep 17 00:00:00 2001 From: Ibrahim Gunduz Date: Tue, 17 Apr 2018 16:19:01 +0000 Subject: [PATCH] Request builders and response processors extracted from payment implementations --- src/Builder/AbstractBuilderFactory.php | 25 ++ src/Builder/AbstractRequestBuilder.php | 22 + src/Builder/Gvp/BaseRequestBuilder.php | 123 +++++ src/Builder/Gvp/CancelRequestBuilder.php | 58 +++ .../Gvp/PostAuthorizationRequestBuilder.php | 59 +++ .../Gvp/PreAuthorizationRequestBuilder.php | 63 +++ src/Builder/Gvp/RefundRequestBuilder.php | 59 +++ src/Builder/Gvp/SaleRequestBuilder.php | 64 +++ src/Builder/GvpBuilderFactory.php | 70 +++ src/Builder/NestPay/BaseRequestBuilder.php | 51 +++ src/Builder/NestPay/CancelRequestBuilder.php | 31 ++ .../PostAuthorizationRequestBuilder.php | 21 + .../PreAuthorizationRequestBuilder.php | 34 ++ src/Builder/NestPay/RefundRequestBuilder.php | 31 ++ src/Builder/NestPay/SaleRequestBuilder.php | 38 ++ src/Builder/NestPayBuilderFactory.php | 70 +++ src/Builder/Posnet/BaseRequestBuilder.php | 72 +++ src/Builder/Posnet/CancelRequestBuilder.php | 36 ++ .../PostAuthorizationRequestBuilder.php | 34 ++ .../Posnet/PreAuthorizationRequestBuilder.php | 37 ++ src/Builder/Posnet/RefundRequestBuilder.php | 28 ++ src/Builder/Posnet/SaleRequestBuilder.php | 37 ++ src/Builder/PosnetBuilderFactory.php | 76 ++++ src/Configuration/Posnet.php | 46 ++ .../{Decimal.php => DecimalFormatter.php} | 2 +- ...ExpireDate.php => ExpireDateFormatter.php} | 2 +- ...hp => IsoNumericCurrencyCodeFormatter.php} | 2 +- .../{Money.php => MoneyFormatter.php} | 2 +- ...php => MultiDigitInstallmentFormatter.php} | 3 +- ...ExpireDate.php => ExpireDateFormatter.php} | 2 +- .../CustomCurrencyCodeFormatter.php} | 4 +- ...ExpireDate.php => ExpireDateFormatter.php} | 2 +- .../{OrderId.php => OrderIdFormatter.php} | 2 +- ...hp => SingleDigitInstallmentFormatter.php} | 2 +- src/Pos/AbstractPos.php | 153 +------ src/Pos/Gvp.php | 422 +----------------- src/Pos/NestPay.php | 243 +--------- src/Pos/Posnet.php | 260 +---------- src/Processor/AbstractProcessorFactory.php | 25 ++ src/Processor/AbstractResponseProcessor.php | 23 + src/Processor/Gvp/BaseResponseProcessor.php | 75 ++++ src/Processor/Gvp/CancelResponseProcessor.php | 10 + .../PostAuthorizationResponseProcessor.php | 10 + .../Gvp/PreAuthorizationResponseProcessor.php | 10 + src/Processor/Gvp/RefundResponseProcessor.php | 10 + src/Processor/Gvp/SaleResponseProcessor.php | 10 + src/Processor/GvpProcessorFactory.php | 35 ++ .../NestPay/BaseResponseProcessor.php | 77 ++++ .../NestPay/CancelResponseProcessor.php | 10 + .../PostAuthorizationResponseProcessor.php | 10 + .../PreAuthorizationResponseProcessor.php | 10 + .../NestPay/RefundResponseProcessor.php | 10 + .../NestPay/SaleResponseProcessor.php | 10 + src/Processor/NestPayProcessorFactory.php | 35 ++ .../Posnet/BaseResponseProcessor.php | 73 +++ .../Posnet/CancelResponseProcessor.php | 10 + .../PostAuthorizationResponseProcessor.php | 10 + .../PreAuthorizationResponseProcessor.php | 10 + .../Posnet/RefundResponseProcessor.php | 10 + .../Posnet/SaleResponseProcessor.php | 10 + src/Processor/PosnetProcessorFactory.php | 35 ++ src/TransactionType.php | 13 + .../Builder/Gvp/CancelRequestBuilderTest.php | 73 +++ .../PostAuthorizationRequestBuilderTest.php | 63 +++ .../PreAuthorizationRequestBuilderTest.php | 68 +++ .../Builder/Gvp/RefundRequestBuilderTest.php | 63 +++ tests/Builder/Gvp/SaleRequestBuilderTest.php | 81 ++++ tests/Builder/GvpBuilderFactoryTest.php | 39 ++ .../NestPay/CancelRequestBuilderTest.php | 71 +++ .../PostAuthorizationRequestBuilderTest.php | 60 +++ .../PreAuthorizationRequestBuilderTest.php | 66 +++ .../NestPay/RefundRequestBuilderTest.php | 73 +++ .../NestPay/SaleRequestBuilderTest.php | 78 ++++ tests/Builder/NestPayBuilderFactoryTest.php | 41 ++ .../Posnet/CancelRequestBuilderTest.php | 58 +++ .../PostAuthorizationRequestBuilderTest.php | 76 ++++ .../PreAuthorizationRequestBuilderTest.php | 80 ++++ .../Posnet/RefundRequestBuilderTest.php | 61 +++ .../Builder/Posnet/SaleRequestBuilderTest.php | 80 ++++ tests/Builder/PosnetBuilderFactoryTest.php | 46 ++ ...cimalTest.php => DecimalFormatterTest.php} | 10 +- tests/Formatter/Gvp/ExpireDateTest.php | 4 +- ...> IsoNumericCurrencyCodeFormatterTest.php} | 14 +- .../{MoneyTest.php => MoneyFormatterTest.php} | 10 +- ...=> MultiDigitInstallmentFormatterTest.php} | 6 +- tests/Formatter/NestPay/ExpireDateTest.php | 4 +- .../CustomCurrencyCodeFormatterTest.php} | 14 +- ...teTest.php => ExpireDateFormatterTest.php} | 6 +- ...derIdTest.php => OrderIdFormatterTest.php} | 8 +- ...> SingleDigitInstallmentFormatterTest.php} | 6 +- tests/Processor/GvpProcessorFactoryTest.php | 39 ++ .../Processor/NestPayProcessorFactoryTest.php | 39 ++ .../Processor/PosnetProcessorFactoryTest.php | 39 ++ .../request/gvp/cancel_request_with_order.xml | 29 ++ .../gvp/cancel_request_with_transaction.xml | 29 ++ .../request/gvp/postauthorization_request.xml | 29 ++ .../request/gvp/preauthorization_request.xml | 34 ++ tests/samples/request/gvp/refund_request.xml | 29 ++ .../samples/request/gvp/sale_request_eur.xml | 35 ++ .../gvp/sale_request_eur_with_installment.xml | 35 ++ .../nestpay/cancel_request_with_order.xml | 9 + .../cancel_request_with_transaction.xml | 9 + .../nestpay/postauthorization_request.xml | 9 + .../nestpay/preauthorization_request.xml | 14 + .../request/nestpay/refund_request_full.xml | 9 + .../nestpay/refund_request_partial.xml | 11 + .../request/nestpay/sale_request_eur.xml | 14 + .../sale_request_eur_with_installment.xml | 15 + .../samples/request/posnet/cancel_request.xml | 12 + .../posnet/post_authorization_request_eur.xml | 12 + ...orization_request_eur_with_installment.xml | 13 + .../posnet/pre_authorization_request_eur.xml | 15 + ...orization_request_eur_with_installment.xml | 16 + .../samples/request/posnet/refund_request.xml | 12 + .../request/posnet/sale_request_eur.xml | 15 + .../sale_request_eur_with_installment.xml | 16 + 116 files changed, 3549 insertions(+), 1075 deletions(-) create mode 100644 src/Builder/AbstractBuilderFactory.php create mode 100644 src/Builder/AbstractRequestBuilder.php create mode 100644 src/Builder/Gvp/BaseRequestBuilder.php create mode 100644 src/Builder/Gvp/CancelRequestBuilder.php create mode 100644 src/Builder/Gvp/PostAuthorizationRequestBuilder.php create mode 100644 src/Builder/Gvp/PreAuthorizationRequestBuilder.php create mode 100644 src/Builder/Gvp/RefundRequestBuilder.php create mode 100644 src/Builder/Gvp/SaleRequestBuilder.php create mode 100644 src/Builder/GvpBuilderFactory.php create mode 100644 src/Builder/NestPay/BaseRequestBuilder.php create mode 100644 src/Builder/NestPay/CancelRequestBuilder.php create mode 100644 src/Builder/NestPay/PostAuthorizationRequestBuilder.php create mode 100644 src/Builder/NestPay/PreAuthorizationRequestBuilder.php create mode 100644 src/Builder/NestPay/RefundRequestBuilder.php create mode 100644 src/Builder/NestPay/SaleRequestBuilder.php create mode 100644 src/Builder/NestPayBuilderFactory.php create mode 100644 src/Builder/Posnet/BaseRequestBuilder.php create mode 100644 src/Builder/Posnet/CancelRequestBuilder.php create mode 100644 src/Builder/Posnet/PostAuthorizationRequestBuilder.php create mode 100644 src/Builder/Posnet/PreAuthorizationRequestBuilder.php create mode 100644 src/Builder/Posnet/RefundRequestBuilder.php create mode 100644 src/Builder/Posnet/SaleRequestBuilder.php create mode 100644 src/Builder/PosnetBuilderFactory.php rename src/Formatter/{Decimal.php => DecimalFormatter.php} (85%) rename src/Formatter/Gvp/{ExpireDate.php => ExpireDateFormatter.php} (78%) rename src/Formatter/{IsoNumericCurrencyCode.php => IsoNumericCurrencyCodeFormatter.php} (89%) rename src/Formatter/{Money.php => MoneyFormatter.php} (85%) rename src/Formatter/{MultiDigitInstallment.php => MultiDigitInstallmentFormatter.php} (73%) rename src/Formatter/NestPay/{ExpireDate.php => ExpireDateFormatter.php} (78%) rename src/Formatter/{PosnetCurrencyCode.php => Posnet/CustomCurrencyCodeFormatter.php} (89%) rename src/Formatter/Posnet/{ExpireDate.php => ExpireDateFormatter.php} (78%) rename src/Formatter/Posnet/{OrderId.php => OrderIdFormatter.php} (89%) rename src/Formatter/{SingleDigitInstallment.php => SingleDigitInstallmentFormatter.php} (70%) create mode 100644 src/Processor/AbstractProcessorFactory.php create mode 100644 src/Processor/AbstractResponseProcessor.php create mode 100644 src/Processor/Gvp/BaseResponseProcessor.php create mode 100644 src/Processor/Gvp/CancelResponseProcessor.php create mode 100644 src/Processor/Gvp/PostAuthorizationResponseProcessor.php create mode 100644 src/Processor/Gvp/PreAuthorizationResponseProcessor.php create mode 100644 src/Processor/Gvp/RefundResponseProcessor.php create mode 100644 src/Processor/Gvp/SaleResponseProcessor.php create mode 100644 src/Processor/GvpProcessorFactory.php create mode 100644 src/Processor/NestPay/BaseResponseProcessor.php create mode 100644 src/Processor/NestPay/CancelResponseProcessor.php create mode 100644 src/Processor/NestPay/PostAuthorizationResponseProcessor.php create mode 100644 src/Processor/NestPay/PreAuthorizationResponseProcessor.php create mode 100644 src/Processor/NestPay/RefundResponseProcessor.php create mode 100644 src/Processor/NestPay/SaleResponseProcessor.php create mode 100644 src/Processor/NestPayProcessorFactory.php create mode 100644 src/Processor/Posnet/BaseResponseProcessor.php create mode 100644 src/Processor/Posnet/CancelResponseProcessor.php create mode 100644 src/Processor/Posnet/PostAuthorizationResponseProcessor.php create mode 100644 src/Processor/Posnet/PreAuthorizationResponseProcessor.php create mode 100644 src/Processor/Posnet/RefundResponseProcessor.php create mode 100644 src/Processor/Posnet/SaleResponseProcessor.php create mode 100644 src/Processor/PosnetProcessorFactory.php create mode 100644 src/TransactionType.php create mode 100644 tests/Builder/Gvp/CancelRequestBuilderTest.php create mode 100644 tests/Builder/Gvp/PostAuthorizationRequestBuilderTest.php create mode 100644 tests/Builder/Gvp/PreAuthorizationRequestBuilderTest.php create mode 100644 tests/Builder/Gvp/RefundRequestBuilderTest.php create mode 100644 tests/Builder/Gvp/SaleRequestBuilderTest.php create mode 100644 tests/Builder/GvpBuilderFactoryTest.php create mode 100644 tests/Builder/NestPay/CancelRequestBuilderTest.php create mode 100644 tests/Builder/NestPay/PostAuthorizationRequestBuilderTest.php create mode 100644 tests/Builder/NestPay/PreAuthorizationRequestBuilderTest.php create mode 100644 tests/Builder/NestPay/RefundRequestBuilderTest.php create mode 100644 tests/Builder/NestPay/SaleRequestBuilderTest.php create mode 100644 tests/Builder/NestPayBuilderFactoryTest.php create mode 100644 tests/Builder/Posnet/CancelRequestBuilderTest.php create mode 100644 tests/Builder/Posnet/PostAuthorizationRequestBuilderTest.php create mode 100644 tests/Builder/Posnet/PreAuthorizationRequestBuilderTest.php create mode 100644 tests/Builder/Posnet/RefundRequestBuilderTest.php create mode 100644 tests/Builder/Posnet/SaleRequestBuilderTest.php create mode 100644 tests/Builder/PosnetBuilderFactoryTest.php rename tests/Formatter/{DecimalTest.php => DecimalFormatterTest.php} (74%) rename tests/Formatter/{IsoNumericCurrencyCodeTest.php => IsoNumericCurrencyCodeFormatterTest.php} (60%) rename tests/Formatter/{MoneyTest.php => MoneyFormatterTest.php} (74%) rename tests/Formatter/{MultiDigitInstallmentTest.php => MultiDigitInstallmentFormatterTest.php} (75%) rename tests/Formatter/{PosnetCurrencyCodeTest.php => Posnet/CustomCurrencyCodeFormatterTest.php} (61%) rename tests/Formatter/Posnet/{ExpireDateTest.php => ExpireDateFormatterTest.php} (56%) rename tests/Formatter/Posnet/{OrderIdTest.php => OrderIdFormatterTest.php} (79%) rename tests/Formatter/{SingleDigitInstallmentTest.php => SingleDigitInstallmentFormatterTest.php} (75%) create mode 100644 tests/Processor/GvpProcessorFactoryTest.php create mode 100644 tests/Processor/NestPayProcessorFactoryTest.php create mode 100644 tests/Processor/PosnetProcessorFactoryTest.php create mode 100644 tests/samples/request/gvp/cancel_request_with_order.xml create mode 100644 tests/samples/request/gvp/cancel_request_with_transaction.xml create mode 100644 tests/samples/request/gvp/postauthorization_request.xml create mode 100644 tests/samples/request/gvp/preauthorization_request.xml create mode 100644 tests/samples/request/gvp/refund_request.xml create mode 100644 tests/samples/request/gvp/sale_request_eur.xml create mode 100644 tests/samples/request/gvp/sale_request_eur_with_installment.xml create mode 100644 tests/samples/request/nestpay/cancel_request_with_order.xml create mode 100644 tests/samples/request/nestpay/cancel_request_with_transaction.xml create mode 100644 tests/samples/request/nestpay/postauthorization_request.xml create mode 100644 tests/samples/request/nestpay/preauthorization_request.xml create mode 100644 tests/samples/request/nestpay/refund_request_full.xml create mode 100644 tests/samples/request/nestpay/refund_request_partial.xml create mode 100644 tests/samples/request/nestpay/sale_request_eur.xml create mode 100644 tests/samples/request/nestpay/sale_request_eur_with_installment.xml create mode 100644 tests/samples/request/posnet/cancel_request.xml create mode 100644 tests/samples/request/posnet/post_authorization_request_eur.xml create mode 100644 tests/samples/request/posnet/post_authorization_request_eur_with_installment.xml create mode 100644 tests/samples/request/posnet/pre_authorization_request_eur.xml create mode 100644 tests/samples/request/posnet/pre_authorization_request_eur_with_installment.xml create mode 100644 tests/samples/request/posnet/refund_request.xml create mode 100644 tests/samples/request/posnet/sale_request_eur.xml create mode 100644 tests/samples/request/posnet/sale_request_eur_with_installment.xml diff --git a/src/Builder/AbstractBuilderFactory.php b/src/Builder/AbstractBuilderFactory.php new file mode 100644 index 0000000..1a997a2 --- /dev/null +++ b/src/Builder/AbstractBuilderFactory.php @@ -0,0 +1,25 @@ +configuration = $configuration; + } + + /** + * @param $transactionType + * @return AbstractRequestBuilder + */ + abstract protected function createBuilder($transactionType); +} diff --git a/src/Builder/AbstractRequestBuilder.php b/src/Builder/AbstractRequestBuilder.php new file mode 100644 index 0000000..d10fdf4 --- /dev/null +++ b/src/Builder/AbstractRequestBuilder.php @@ -0,0 +1,22 @@ +configuration = $configuration; + } + + abstract public function build(Request $request); +} diff --git a/src/Builder/Gvp/BaseRequestBuilder.php b/src/Builder/Gvp/BaseRequestBuilder.php new file mode 100644 index 0000000..f5a0030 --- /dev/null +++ b/src/Builder/Gvp/BaseRequestBuilder.php @@ -0,0 +1,123 @@ +currencyCodeFormatter = $currencyCodeFormatter; + $this->amountFormatter = $amountFormatter; + $this->installmentFormatter = $installmentFormatter; + $this->expireDateFormatter = $expireDateFormatter; + } + + protected function buildBaseRequest(Request $request) + { + /** @var GvpConfiguration $configuration */ + $configuration = $this->configuration; + return [ + 'Version' => self::API_VERSION, + 'Mode' => $configuration->getMode(), + 'Terminal' => $this->buildTerminal($request), + 'Order' => $this->buildOrder($request), + 'Customer' => $this->buildCustomer(), + 'Transaction' => $this->buildTransaction($request) + ]; + } + + abstract protected function buildTransaction(Request $request); + abstract protected function getCredentialPair(); + abstract protected function buildHash(Request $request, $password); + + protected function buildCustomer() + { + return [ + 'IPAddress' => '127.0.0.1', + 'EmailAddress' => 'dummy@dummy.net' + ]; + } + + protected function generateSecurityHash($password) + { + /** @var GvpConfiguration $configuration */ + $configuration = $this->configuration; + + $tidPrefix = str_repeat('0', 9 - strlen($configuration->getTerminalId())); + $terminalId = sprintf('%s%s', $tidPrefix, $configuration->getTerminalId()); + return strtoupper(SHA1(sprintf('%s%s', $password, $terminalId))); + } + + protected function buildTerminal(Request $request) + { + /** @var GvpConfiguration $configuration */ + $configuration = $this->configuration; + + list($username, $password) = $this->getCredentialPair(); + + $hash = $this->buildHash($request, $password); + + return array( + 'ProvUserID' => $username, + 'HashData' => $hash, + 'UserID' => $username, + 'ID' => $configuration->getTerminalId(), + 'MerchantID' => $configuration->getMerchantId() + ); + } + + protected function buildCard(Request $request) + { + $expireMonth = $this->expireDateFormatter->format( + [ + $request->getExpireMonth(), + $request->getExpireYear() + ] + ); + + return array( + 'Number' => $request->getCardNumber(), + 'ExpireDate' => $expireMonth, + 'CVV2' => $request->getSecurityCode() + ); + } + + protected function buildOrder(Request $request) + { + return [ + 'OrderID' => $request->getOrderId(), + 'GroupID' => null, + 'Description' => null + ]; + } +} diff --git a/src/Builder/Gvp/CancelRequestBuilder.php b/src/Builder/Gvp/CancelRequestBuilder.php new file mode 100644 index 0000000..519eabd --- /dev/null +++ b/src/Builder/Gvp/CancelRequestBuilder.php @@ -0,0 +1,58 @@ +buildBaseRequest($request); + $serializer = new Serializer(Serializer::XML); + return $serializer->serialize($data, ['root_name' => self::ENVELOPE_NAME]); + } + + protected function buildTransaction(Request $request) + { + return [ + 'Type' => self::TRANSACTION_TYPE, + 'Amount' => 1, + 'CurrencyCode' => null, + + #TODO: Will be changed after 3D integration + 'CardholderPresentCode' => self::CARD_HOLDER_PRESENT_CODE_NON_3D, + + 'MotoInd' => 'N', + 'OriginalRetrefNum' => $request->getTransactionId() + ]; + } + + protected function getCredentialPair() + { + /** @var Gvp $configuration */ + $configuration = $this->configuration; + return [$configuration->getRefundUsername(), $configuration->getRefundPassword()]; + } + + protected function buildHash(Request $request, $password) + { + /** @var Gvp $configuration */ + $configuration = $this->configuration; + return strtoupper( + sha1( + sprintf( + '%s%s%s%s', + $request->getOrderId(), + $configuration->getTerminalId(), + 1, + $this->generateSecurityHash($password) + ) + ) + ); + } +} diff --git a/src/Builder/Gvp/PostAuthorizationRequestBuilder.php b/src/Builder/Gvp/PostAuthorizationRequestBuilder.php new file mode 100644 index 0000000..1a813dd --- /dev/null +++ b/src/Builder/Gvp/PostAuthorizationRequestBuilder.php @@ -0,0 +1,59 @@ +buildBaseRequest($request); + + $serializer = new Serializer(Serializer::XML); + return $serializer->serialize($data, ['root_name' => self::ENVELOPE_NAME]); + } + + protected function buildTransaction(Request $request) + { + return [ + 'Type' => self::TRANSACTION_TYPE, + 'Amount' => $this->amountFormatter->format($request->getAmount()), + 'CurrencyCode' => $this->currencyCodeFormatter->format($request->getCurrency()), + + #TODO: Will be changed after 3D integration + 'CardholderPresentCode' => self::CARD_HOLDER_PRESENT_CODE_NON_3D, + + 'MotoInd' => 'N', + 'OriginalRetrefNum' => $request->getTransactionId(), + ]; + } + + protected function getCredentialPair() + { + /** @var Gvp $configuration */ + $configuration = $this->configuration; + return [$configuration->getAuthorizationUsername(), $configuration->getAuthorizationPassword()]; + } + + protected function buildHash(Request $request, $password) + { + /** @var Gvp $configuration */ + $configuration = $this->configuration; + return strtoupper( + sha1( + sprintf( + '%s%s%s%s', + $request->getOrderId(), + $configuration->getTerminalId(), + $this->amountFormatter->format($request->getAmount()), + $this->generateSecurityHash($password) + ) + ) + ); + } +} diff --git a/src/Builder/Gvp/PreAuthorizationRequestBuilder.php b/src/Builder/Gvp/PreAuthorizationRequestBuilder.php new file mode 100644 index 0000000..2dde493 --- /dev/null +++ b/src/Builder/Gvp/PreAuthorizationRequestBuilder.php @@ -0,0 +1,63 @@ +buildBaseRequest($request), + ['Card' => $this->buildCard($request)] + ); + + $serializer = new Serializer(Serializer::XML); + return $serializer->serialize($data, ['root_name' => self::ENVELOPE_NAME]); + } + + protected function buildTransaction(Request $request) + { + return [ + 'Type' => self::TRANSACTION_TYPE, + 'Amount' => $this->amountFormatter->format($request->getAmount()), + 'CurrencyCode' => $this->currencyCodeFormatter->format($request->getCurrency()), + + #TODO: Will be changed after 3D integration + 'CardholderPresentCode' => self::CARD_HOLDER_PRESENT_CODE_NON_3D, + + 'MotoInd' => 'N', + 'OriginalRetrefNum' => null, + ]; + } + + protected function getCredentialPair() + { + /** @var Gvp $configuration */ + $configuration = $this->configuration; + return [$configuration->getAuthorizationUsername(), $configuration->getAuthorizationPassword()]; + } + + protected function buildHash(Request $request, $password) + { + /** @var Gvp $configuration */ + $configuration = $this->configuration; + return strtoupper( + sha1( + sprintf( + '%s%s%s%s%s', + $request->getOrderId(), + $configuration->getTerminalId(), + $request->getCardNumber(), + $this->amountFormatter->format($request->getAmount()), + $this->generateSecurityHash($password) + ) + ) + ); + } +} diff --git a/src/Builder/Gvp/RefundRequestBuilder.php b/src/Builder/Gvp/RefundRequestBuilder.php new file mode 100644 index 0000000..17a3a4e --- /dev/null +++ b/src/Builder/Gvp/RefundRequestBuilder.php @@ -0,0 +1,59 @@ +buildBaseRequest($request); + + $serializer = new Serializer(Serializer::XML); + return $serializer->serialize($data, ['root_name' => self::ENVELOPE_NAME]); + } + + protected function buildTransaction(Request $request) + { + return [ + 'Type' => self::TRANSACTION_TYPE, + 'Amount' => $this->amountFormatter->format($request->getAmount()), + 'CurrencyCode' => $this->currencyCodeFormatter->format($request->getCurrency()), + + #TODO: Will be changed after 3D integration + 'CardholderPresentCode' => self::CARD_HOLDER_PRESENT_CODE_NON_3D, + + 'MotoInd' => 'N', + 'OriginalRetrefNum' => null, + ]; + } + + protected function getCredentialPair() + { + /** @var Gvp $configuration */ + $configuration = $this->configuration; + return [$configuration->getRefundUsername(), $configuration->getRefundPassword()]; + } + + protected function buildHash(Request $request, $password) + { + /** @var Gvp $configuration */ + $configuration = $this->configuration; + return strtoupper( + sha1( + sprintf( + '%s%s%s%s', + $request->getOrderId(), + $configuration->getTerminalId(), + $this->amountFormatter->format($request->getAmount()), + $this->generateSecurityHash($password) + ) + ) + ); + } +} diff --git a/src/Builder/Gvp/SaleRequestBuilder.php b/src/Builder/Gvp/SaleRequestBuilder.php new file mode 100644 index 0000000..4f6c916 --- /dev/null +++ b/src/Builder/Gvp/SaleRequestBuilder.php @@ -0,0 +1,64 @@ +buildBaseRequest($request), + ['Card' => $this->buildCard($request)] + ); + + $serializer = new Serializer(Serializer::XML); + return $serializer->serialize($data, ['root_name' => self::ENVELOPE_NAME]); + } + + protected function buildTransaction(Request $request) + { + return [ + 'Type' => self::TRANSACTION_TYPE, + 'InstallmentCnt' => $this->installmentFormatter->format($request->getInstallment()), + 'Amount' => $this->amountFormatter->format($request->getAmount()), + 'CurrencyCode' => $this->currencyCodeFormatter->format($request->getCurrency()), + + #TODO: Will be changed after 3D integration + 'CardholderPresentCode' => self::CARD_HOLDER_PRESENT_CODE_NON_3D, + + 'MotoInd' => 'N', + 'OriginalRetrefNum' => null, + ]; + } + + protected function getCredentialPair() + { + /** @var Gvp $configuration */ + $configuration = $this->configuration; + return [$configuration->getAuthorizationUsername(), $configuration->getAuthorizationPassword()]; + } + + protected function buildHash(Request $request, $password) + { + /** @var Gvp $configuration */ + $configuration = $this->configuration; + return strtoupper( + sha1( + sprintf( + '%s%s%s%s%s', + $request->getOrderId(), + $configuration->getTerminalId(), + $request->getCardNumber(), + $this->amountFormatter->format($request->getAmount()), + $this->generateSecurityHash($password) + ) + ) + ); + } +} diff --git a/src/Builder/GvpBuilderFactory.php b/src/Builder/GvpBuilderFactory.php new file mode 100644 index 0000000..f341d9d --- /dev/null +++ b/src/Builder/GvpBuilderFactory.php @@ -0,0 +1,70 @@ +configuration, + new IsoNumericCurrencyCodeFormatter(), + new MoneyFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + case TransactionType::CANCEL: + return new CancelRequestBuilder( + $this->configuration, + new IsoNumericCurrencyCodeFormatter(), + new MoneyFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + case TransactionType::REFUND: + return new RefundRequestBuilder( + $this->configuration, + new IsoNumericCurrencyCodeFormatter(), + new MoneyFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + case TransactionType::PRE_AUTHORIZATION: + return new PreAuthorizationRequestBuilder( + $this->configuration, + new IsoNumericCurrencyCodeFormatter(), + new MoneyFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + case TransactionType::POST_AUTHORIZATION: + return new PostAuthorizationRequestBuilder( + $this->configuration, + new IsoNumericCurrencyCodeFormatter(), + new MoneyFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + default: + throw new NotImplementedError('Not implemented transaction type: ' . $transactionType); + } + } +} diff --git a/src/Builder/NestPay/BaseRequestBuilder.php b/src/Builder/NestPay/BaseRequestBuilder.php new file mode 100644 index 0000000..6d1a21a --- /dev/null +++ b/src/Builder/NestPay/BaseRequestBuilder.php @@ -0,0 +1,51 @@ +amountFormatter = $amountFormatter; + $this->currencyCodeFormatter = $currencyCodeFormatter; + $this->installmentFormatter = $installmentFormatter; + $this->expireDateFormatter = $expireDateFormatter; + } + + protected function buildBaseRequest($type) + { + /** @var \Paranoia\Configuration\NestPay $config */ + $config = $this->configuration; + return [ + 'Mode' => $config->getMode(), + 'ClientId' => $config->getClientId(), + 'Name' => $config->getUsername(), + 'Password' => $config->getPassword(), + 'Type' => $type, + ]; + } +} diff --git a/src/Builder/NestPay/CancelRequestBuilder.php b/src/Builder/NestPay/CancelRequestBuilder.php new file mode 100644 index 0000000..89068ab --- /dev/null +++ b/src/Builder/NestPay/CancelRequestBuilder.php @@ -0,0 +1,31 @@ +buildBaseRequest(self::TRANSACTION_TYPE); + + if ($request->getOrderId() && !$request->getTransactionId()) { + $data = array_merge($data, [ + 'OrderId' => $request->getOrderId() + ]); + } + + if ($request->getTransactionId()) { + $data = array_merge($data, [ + 'TransId' => $request->getTransactionId() + ]); + } + + $serializer = new Serializer(Serializer::XML); + return $serializer->serialize($data, ['root_name' => self::ENVELOPE_NAME]); + } +} diff --git a/src/Builder/NestPay/PostAuthorizationRequestBuilder.php b/src/Builder/NestPay/PostAuthorizationRequestBuilder.php new file mode 100644 index 0000000..cfb2285 --- /dev/null +++ b/src/Builder/NestPay/PostAuthorizationRequestBuilder.php @@ -0,0 +1,21 @@ +buildBaseRequest(self::TRANSACTION_TYPE), [ + 'OrderId' => $request->getOrderId() + ]); + + $serializer = new Serializer(Serializer::XML); + return $serializer->serialize($data, ['root_name' => self::ENVELOPE_NAME]); + } +} diff --git a/src/Builder/NestPay/PreAuthorizationRequestBuilder.php b/src/Builder/NestPay/PreAuthorizationRequestBuilder.php new file mode 100644 index 0000000..c4317c0 --- /dev/null +++ b/src/Builder/NestPay/PreAuthorizationRequestBuilder.php @@ -0,0 +1,34 @@ +buildBaseRequest(self::TRANSACTION_TYPE), + [ + 'OrderId' => $request->getOrderId(), + 'Total' => $this->amountFormatter->format($request->getAmount()), + 'Currency' => $this->currencyCodeFormatter->format($request->getCurrency()), + 'Number' => $request->getCardNumber(), + 'Cvv2Val' => $request->getSecurityCode(), + 'Expires' => $this->expireDateFormatter->format( + [ + $request->getExpireMonth(), + $request->getExpireYear() + ] + ), + ] + ); + + $serializer = new Serializer(Serializer::XML); + return $serializer->serialize($data, ['root_name' => self::ENVELOPE_NAME]); + } +} diff --git a/src/Builder/NestPay/RefundRequestBuilder.php b/src/Builder/NestPay/RefundRequestBuilder.php new file mode 100644 index 0000000..b4fddb9 --- /dev/null +++ b/src/Builder/NestPay/RefundRequestBuilder.php @@ -0,0 +1,31 @@ +buildBaseRequest(self::TRANSACTION_TYPE), + [ + 'OrderId' => $request->getOrderId(), + ] + ); + + if ($request->getAmount()) { + $data = array_merge($data, [ + 'Total' => $this->amountFormatter->format($request->getAmount()), + 'Currency' => $this->currencyCodeFormatter->format($request->getCurrency()), + ]); + } + + $serializer = new Serializer(Serializer::XML); + return $serializer->serialize($data, ['root_name' => self::ENVELOPE_NAME]); + } +} diff --git a/src/Builder/NestPay/SaleRequestBuilder.php b/src/Builder/NestPay/SaleRequestBuilder.php new file mode 100644 index 0000000..45bc625 --- /dev/null +++ b/src/Builder/NestPay/SaleRequestBuilder.php @@ -0,0 +1,38 @@ +buildBaseRequest(self::TRANSACTION_TYPE), + [ + 'OrderId' => $request->getOrderId(), + 'Total' => $this->amountFormatter->format($request->getAmount()), + 'Currency' => $this->currencyCodeFormatter->format($request->getCurrency()), + 'Number' => $request->getCardNumber(), + 'Cvv2Val' => $request->getSecurityCode(), + 'Expires' => $this->expireDateFormatter->format( + [ + $request->getExpireMonth(), + $request->getExpireYear() + ] + ), + ] + ); + + if ($request->getInstallment()) { + $data['Taksit'] = $this->installmentFormatter->format($request->getInstallment()); + } + + $serializer = new Serializer(Serializer::XML); + return $serializer->serialize($data, ['root_name' => self::ENVELOPE_NAME]); + } +} diff --git a/src/Builder/NestPayBuilderFactory.php b/src/Builder/NestPayBuilderFactory.php new file mode 100644 index 0000000..91aebae --- /dev/null +++ b/src/Builder/NestPayBuilderFactory.php @@ -0,0 +1,70 @@ +configuration, + new IsoNumericCurrencyCodeFormatter(), + new DecimalFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + case TransactionType::CANCEL: + return new CancelRequestBuilder( + $this->configuration, + new IsoNumericCurrencyCodeFormatter(), + new DecimalFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + case TransactionType::REFUND: + return new RefundRequestBuilder( + $this->configuration, + new IsoNumericCurrencyCodeFormatter(), + new DecimalFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + case TransactionType::PRE_AUTHORIZATION: + return new PreAuthorizationRequestBuilder( + $this->configuration, + new IsoNumericCurrencyCodeFormatter(), + new DecimalFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + case TransactionType::POST_AUTHORIZATION: + return new PostAuthorizationRequestBuilder( + $this->configuration, + new IsoNumericCurrencyCodeFormatter(), + new DecimalFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + default: + throw new NotImplementedError('Not implemented transaction type: ' . $transactionType); + } + } +} diff --git a/src/Builder/Posnet/BaseRequestBuilder.php b/src/Builder/Posnet/BaseRequestBuilder.php new file mode 100644 index 0000000..fba0370 --- /dev/null +++ b/src/Builder/Posnet/BaseRequestBuilder.php @@ -0,0 +1,72 @@ +currencyCodeFormatter = $currencyCodeFormatter; + $this->amountFormatter = $amountFormatter; + $this->installmentFormatter = $installmentFormatter; + $this->expireDateFormatter = $expireDateFormatter; + $this->orderIdFormatter = $orderIdFormatter; + } + + protected function buildBaseRequest(Request $request) + { + /** @var Posnet $configuration */ + $configuration = $this->configuration; + return [ + 'mid' => $configuration->getMerchantId(), + 'tid' => $configuration->getTerminalId(), + 'username' => $configuration->getUsername(), + 'password' => $configuration->getPassword() + ]; + } + + protected function buildCard(Request $request) + { + return [ + 'ccno' => $request->getCardNumber(), + 'cvc' => $request->getSecurityCode(), + 'expDate' => $this->expireDateFormatter->format( + [ + $request->getExpireMonth(), + $request->getExpireYear() + ] + ) + ]; + } +} diff --git a/src/Builder/Posnet/CancelRequestBuilder.php b/src/Builder/Posnet/CancelRequestBuilder.php new file mode 100644 index 0000000..0eafaf1 --- /dev/null +++ b/src/Builder/Posnet/CancelRequestBuilder.php @@ -0,0 +1,36 @@ +buildBaseRequest($request), + [ + self::TRANSACTION_TYPE => [ + 'transaction' => self::TEMPORARY_DEFAULT_TRANSACTION_TYPE, + 'hostLogKey' => $request->getTransactionId(), + //authCode just needed when VFT transaction performed + // For the other transaction types we can keep it as '000000' + 'authCode' => '000000' + ] + ] + ); + + $serializer = new Serializer(Serializer::XML); + return $serializer->serialize($data, ['root_name' => self::ENVELOPE_NAME]); + } +} diff --git a/src/Builder/Posnet/PostAuthorizationRequestBuilder.php b/src/Builder/Posnet/PostAuthorizationRequestBuilder.php new file mode 100644 index 0000000..2d41226 --- /dev/null +++ b/src/Builder/Posnet/PostAuthorizationRequestBuilder.php @@ -0,0 +1,34 @@ +buildBaseRequest($request), + [ + self::TRANSACTION_TYPE => [ + 'amount' => $this->amountFormatter->format($request->getAmount()), + 'currencyCode' => $this->currencyCodeFormatter->format($request->getCurrency()), + 'hostLogKey' => $request->getTransactionId() + ] + ] + ); + + if ($request->getInstallment()) { + $data[self::TRANSACTION_TYPE]['installment'] = $this->installmentFormatter->format( + $request->getInstallment() + ); + } + + $serializer = new Serializer(Serializer::XML); + return $serializer->serialize($data, ['root_name' => self::ENVELOPE_NAME]); + } +} diff --git a/src/Builder/Posnet/PreAuthorizationRequestBuilder.php b/src/Builder/Posnet/PreAuthorizationRequestBuilder.php new file mode 100644 index 0000000..9550b85 --- /dev/null +++ b/src/Builder/Posnet/PreAuthorizationRequestBuilder.php @@ -0,0 +1,37 @@ +buildBaseRequest($request), + [ + self::TRANSACTION_TYPE => array_merge( + [ + 'amount' => $this->amountFormatter->format($request->getAmount()), + 'currencyCode' => $this->currencyCodeFormatter->format($request->getCurrency()), + 'orderID' => $this->orderIdFormatter->format($request->getOrderId()) + ], + $this->buildCard($request) + ) + ] + ); + + if ($request->getInstallment()) { + $data[self::TRANSACTION_TYPE]['installment'] = $this->installmentFormatter->format( + $request->getInstallment() + ); + } + + $serializer = new Serializer(Serializer::XML); + return $serializer->serialize($data, ['root_name' => self::ENVELOPE_NAME]); + } +} diff --git a/src/Builder/Posnet/RefundRequestBuilder.php b/src/Builder/Posnet/RefundRequestBuilder.php new file mode 100644 index 0000000..9a1e0b6 --- /dev/null +++ b/src/Builder/Posnet/RefundRequestBuilder.php @@ -0,0 +1,28 @@ +buildBaseRequest($request), + [ + self::TRANSACTION_TYPE => [ + 'amount' => $this->amountFormatter->format($request->getAmount()), + 'currencyCode' => $this->currencyCodeFormatter->format($request->getCurrency()), + 'hostLogKey' => $request->getTransactionId() + ] + ] + ); + + $serializer = new Serializer(Serializer::XML); + return $serializer->serialize($data, ['root_name' => self::ENVELOPE_NAME]); + } +} diff --git a/src/Builder/Posnet/SaleRequestBuilder.php b/src/Builder/Posnet/SaleRequestBuilder.php new file mode 100644 index 0000000..dde4cd1 --- /dev/null +++ b/src/Builder/Posnet/SaleRequestBuilder.php @@ -0,0 +1,37 @@ +buildBaseRequest($request), + [ + self::TRANSACTION_TYPE => array_merge( + [ + 'amount' => $this->amountFormatter->format($request->getAmount()), + 'currencyCode' => $this->currencyCodeFormatter->format($request->getCurrency()), + 'orderID' => $this->orderIdFormatter->format($request->getOrderId()) + ], + $this->buildCard($request) + ) + ] + ); + + if ($request->getInstallment()) { + $data[self::TRANSACTION_TYPE]['installment'] = $this->installmentFormatter->format( + $request->getInstallment() + ); + } + + $serializer = new Serializer(Serializer::XML); + return $serializer->serialize($data, ['root_name' => self::ENVELOPE_NAME]); + } +} diff --git a/src/Builder/PosnetBuilderFactory.php b/src/Builder/PosnetBuilderFactory.php new file mode 100644 index 0000000..907d4d4 --- /dev/null +++ b/src/Builder/PosnetBuilderFactory.php @@ -0,0 +1,76 @@ +configuration, + new CustomCurrencyCodeFormatter(), + new MoneyFormatter(), + new MultiDigitInstallmentFormatter(), + new ExpireDateFormatter(), + new OrderIdFormatter() + ); + case TransactionType::CANCEL: + return new CancelRequestBuilder( + $this->configuration, + new CustomCurrencyCodeFormatter(), + new MoneyFormatter(), + new MultiDigitInstallmentFormatter(), + new ExpireDateFormatter(), + new OrderIdFormatter() + ); + case TransactionType::REFUND: + return new RefundRequestBuilder( + $this->configuration, + new CustomCurrencyCodeFormatter(), + new MoneyFormatter(), + new MultiDigitInstallmentFormatter(), + new ExpireDateFormatter(), + new OrderIdFormatter() + ); + case TransactionType::PRE_AUTHORIZATION: + return new PreAuthorizationRequestBuilder( + $this->configuration, + new CustomCurrencyCodeFormatter(), + new MoneyFormatter(), + new MultiDigitInstallmentFormatter(), + new ExpireDateFormatter(), + new OrderIdFormatter() + ); + case TransactionType::POST_AUTHORIZATION: + return new PostAuthorizationRequestBuilder( + $this->configuration, + new CustomCurrencyCodeFormatter(), + new MoneyFormatter(), + new MultiDigitInstallmentFormatter(), + new ExpireDateFormatter(), + new OrderIdFormatter() + ); + default: + throw new NotImplementedError('Not implemented transaction type: ' . $transactionType); + } + } +} diff --git a/src/Configuration/Posnet.php b/src/Configuration/Posnet.php index b0d3b92..204927b 100644 --- a/src/Configuration/Posnet.php +++ b/src/Configuration/Posnet.php @@ -13,6 +13,16 @@ class Posnet extends AbstractConfiguration */ private $terminalId; + /** + * @var string + */ + private $username; + + /** + * @var string + */ + private $password; + /** * @param int $merchantId * @@ -50,4 +60,40 @@ public function getTerminalId() { return $this->terminalId; } + + /** + * @return string + */ + public function getUsername() + { + return $this->username; + } + + /** + * @param string $username + * @return Posnet + */ + public function setUsername($username) + { + $this->username = $username; + return $this; + } + + /** + * @return string + */ + public function getPassword() + { + return $this->password; + } + + /** + * @param string $password + * @return Posnet + */ + public function setPassword($password) + { + $this->password = $password; + return $this; + } } diff --git a/src/Formatter/Decimal.php b/src/Formatter/DecimalFormatter.php similarity index 85% rename from src/Formatter/Decimal.php rename to src/Formatter/DecimalFormatter.php index 42d9638..335c082 100644 --- a/src/Formatter/Decimal.php +++ b/src/Formatter/DecimalFormatter.php @@ -3,7 +3,7 @@ use Paranoia\Exception\InvalidArgumentException; -class Decimal implements FormatterInterface +class DecimalFormatter implements FormatterInterface { public function format($input) { diff --git a/src/Formatter/Gvp/ExpireDate.php b/src/Formatter/Gvp/ExpireDateFormatter.php similarity index 78% rename from src/Formatter/Gvp/ExpireDate.php rename to src/Formatter/Gvp/ExpireDateFormatter.php index 1d53706..9ce00c9 100644 --- a/src/Formatter/Gvp/ExpireDate.php +++ b/src/Formatter/Gvp/ExpireDateFormatter.php @@ -3,7 +3,7 @@ use Paranoia\Formatter\FormatterInterface; -class ExpireDate implements FormatterInterface +class ExpireDateFormatter implements FormatterInterface { public function format($input) { diff --git a/src/Formatter/IsoNumericCurrencyCode.php b/src/Formatter/IsoNumericCurrencyCodeFormatter.php similarity index 89% rename from src/Formatter/IsoNumericCurrencyCode.php rename to src/Formatter/IsoNumericCurrencyCodeFormatter.php index 20fb731..5bc71d9 100644 --- a/src/Formatter/IsoNumericCurrencyCode.php +++ b/src/Formatter/IsoNumericCurrencyCodeFormatter.php @@ -4,7 +4,7 @@ use Paranoia\Currency; use Paranoia\Exception\InvalidArgumentException; -class IsoNumericCurrencyCode implements FormatterInterface +class IsoNumericCurrencyCodeFormatter implements FormatterInterface { const CODE_TRY = 949; const CODE_USD = 840; diff --git a/src/Formatter/Money.php b/src/Formatter/MoneyFormatter.php similarity index 85% rename from src/Formatter/Money.php rename to src/Formatter/MoneyFormatter.php index ae67755..0ddd229 100644 --- a/src/Formatter/Money.php +++ b/src/Formatter/MoneyFormatter.php @@ -3,7 +3,7 @@ use Paranoia\Exception\InvalidArgumentException; -class Money implements FormatterInterface +class MoneyFormatter implements FormatterInterface { public function format($input) { diff --git a/src/Formatter/MultiDigitInstallment.php b/src/Formatter/MultiDigitInstallmentFormatter.php similarity index 73% rename from src/Formatter/MultiDigitInstallment.php rename to src/Formatter/MultiDigitInstallmentFormatter.php index 504bcf5..f9fe77b 100644 --- a/src/Formatter/MultiDigitInstallment.php +++ b/src/Formatter/MultiDigitInstallmentFormatter.php @@ -1,9 +1,8 @@ configuration = $configuration; } - /** - * @param \Paranoia\Configuration\AbstractConfiguration $configuration - */ - public function setConfiguration($configuration) - { - $this->configuration = $configuration; - } - - /** - * @return EventDispatcher - */ - protected function getDispatcher() - { - if (!$this->dispatcher) { - $this->dispatcher = new EventDispatcher(); - } - return $this->dispatcher; - } - - /** - * build request data for preauthorization transaction. - * - * @param \Paranoia\Request $request - * - * @return mixed - */ - abstract protected function buildPreAuthorizationRequest(Request $request); - - /** - * build request data for postauthorization transaction. - * - * @param \Paranoia\Request $request - * - * @return mixed - */ - abstract protected function buildPostAuthorizationRequest(Request $request); - - /** - * build request data for sale transaction. - * - * @param \Paranoia\Request $request - * - * @return mixed - */ - abstract protected function buildSaleRequest(Request $request); - - /** - * build request data for refund transaction. - * - * @param \Paranoia\Request $request - * - * @return mixed - */ - abstract protected function buildRefundRequest(Request $request); - - /** - * build request data for cancel transaction. - * - * @param \Paranoia\Request $request - * - * @return mixed - */ - abstract protected function buildCancelRequest(Request $request); - /** * build complete raw data for the specified request. * * @param \Paranoia\Request $request - * @param string $requestBuilder + * @param string $transactionType * * @return mixed */ - abstract protected function buildRequest(Request $request, $requestBuilder); + abstract protected function buildRequest(Request $request, $transactionType); /** * parses response from returned provider. @@ -157,22 +68,6 @@ protected function sendRequest($url, $data, $options = null) } } - /** - * returns transaction code by expected provider. - * - * @param string $transactionType - * - * @throws \Paranoia\Exception\InvalidArgumentException - * @return string - */ - protected function getProviderTransactionType($transactionType) - { - if (!array_key_exists($transactionType, $this->transactionMap)) { - throw new InvalidArgumentException('Transaction type is unknown: ' . $transactionType); - } - return $this->transactionMap[$transactionType]; - } - /** * @param \Paranoia\Request $request * @@ -180,9 +75,9 @@ protected function getProviderTransactionType($transactionType) */ public function preAuthorization(Request $request) { - $rawRequest = $this->buildRequest($request, 'buildPreauthorizationRequest'); + $rawRequest = $this->buildRequest($request, TransactionType::PRE_AUTHORIZATION); $rawResponse = $this->sendRequest($this->configuration->getApiUrl(), $rawRequest); - $response = $this->parseResponse($rawResponse, self::TRANSACTION_TYPE_PREAUTHORIZATION); + $response = $this->parseResponse($rawResponse, TransactionType::PRE_AUTHORIZATION); return $response; } @@ -193,9 +88,9 @@ public function preAuthorization(Request $request) */ public function postAuthorization(Request $request) { - $rawRequest = $this->buildRequest($request, 'buildPostAuthorizationRequest'); + $rawRequest = $this->buildRequest($request, TransactionType::POST_AUTHORIZATION); $rawResponse = $this->sendRequest($this->configuration->getApiUrl(), $rawRequest); - $response = $this->parseResponse($rawResponse, self::TRANSACTION_TYPE_POSTAUTHORIZATION); + $response = $this->parseResponse($rawResponse, TransactionType::POST_AUTHORIZATION); return $response; } @@ -206,9 +101,9 @@ public function postAuthorization(Request $request) */ public function sale(Request $request) { - $rawRequest = $this->buildRequest($request, 'buildSaleRequest'); + $rawRequest = $this->buildRequest($request, TransactionType::SALE); $rawResponse = $this->sendRequest($this->configuration->getApiUrl(), $rawRequest); - $response = $this->parseResponse($rawResponse, self::TRANSACTION_TYPE_SALE); + $response = $this->parseResponse($rawResponse, TransactionType::SALE); return $response; } @@ -219,9 +114,9 @@ public function sale(Request $request) */ public function refund(Request $request) { - $rawRequest = $this->buildRequest($request, 'buildRefundRequest'); + $rawRequest = $this->buildRequest($request, TransactionType::REFUND); $rawResponse = $this->sendRequest($this->configuration->getApiUrl(), $rawRequest); - $response = $this->parseResponse($rawResponse, self::TRANSACTION_TYPE_REFUND); + $response = $this->parseResponse($rawResponse, TransactionType::REFUND); return $response; } @@ -232,9 +127,9 @@ public function refund(Request $request) */ public function cancel(Request $request) { - $rawRequest = $this->buildRequest($request, 'buildCancelRequest'); + $rawRequest = $this->buildRequest($request, TransactionType::CANCEL); $rawResponse = $this->sendRequest($this->configuration->getApiUrl(), $rawRequest); - $response = $this->parseResponse($rawResponse, self::TRANSACTION_TYPE_CANCEL); + $response = $this->parseResponse($rawResponse, TransactionType::CANCEL); return $response; } @@ -245,9 +140,9 @@ public function cancel(Request $request) */ public function pointQuery(Request $request) { - $rawRequest = $this->buildRequest($request, 'buildPointQueryRequest'); + $rawRequest = $this->buildRequest($request, TransactionType::POINT_INQUIRY); $rawResponse = $this->sendRequest($this->configuration->getApiUrl(), $rawRequest); - $response = $this->parseResponse($rawResponse, self::TRANSACTION_TYPE_POINT_QUERY); + $response = $this->parseResponse($rawResponse, TransactionType::POINT_INQUIRY); return $response; } @@ -258,21 +153,9 @@ public function pointQuery(Request $request) */ public function pointUsage(Request $request) { - $rawRequest = $this->buildRequest($request, 'buildPointUsageRequest'); + $rawRequest = $this->buildRequest($request, TransactionType::POINT_USAGE); $rawResponse = $this->sendRequest($this->configuration->getApiUrl(), $rawRequest); - $response = $this->parseResponse($rawResponse, self::TRANSACTION_TYPE_POINT_USAGE); + $response = $this->parseResponse($rawResponse, TransactionType::POINT_USAGE); return $response; } - - /** - * mask some critical information in transaction request. - * - * @param string $rawRequest - * - * @return string - */ - protected function maskRequest($rawRequest) - { - return $rawRequest; - } } diff --git a/src/Pos/Gvp.php b/src/Pos/Gvp.php index def6e2b..e23358d 100644 --- a/src/Pos/Gvp.php +++ b/src/Pos/Gvp.php @@ -1,395 +1,34 @@ 'preauth', - self::TRANSACTION_TYPE_POSTAUTHORIZATION => 'postauth', - self::TRANSACTION_TYPE_SALE => 'sales', - self::TRANSACTION_TYPE_CANCEL => 'void', - self::TRANSACTION_TYPE_REFUND => 'refund', - self::TRANSACTION_TYPE_POINT_QUERY => 'pointinquiry', - self::TRANSACTION_TYPE_POINT_USAGE => 'pointusage', - ); + /** @var GvpProcessorFactory */ + private $processorFactory; public function __construct(AbstractConfiguration $configuration) { parent::__construct($configuration); - $this->currencyFormatter = new IsoNumericCurrencyCode(); - $this->amountFormatter = new Money(); - $this->installmentFormatter = new SingleDigitInstallment(); - $this->expireDateFormatter = new ExpireDate(); - $this->orderIdFormatter = new NopeFormatter(); - } - - /** - * builds request base with common arguments. - * - * @param Request $request - * @param string $transactionType - * - * @return array - */ - private function buildBaseRequest(Request $request, $transactionType) - { - $terminal = $this->buildTerminal($request, $transactionType); - $customer = $this->buildCustomer(); - $order = $this->buildOrder($request); - $transaction = $this->buildTransaction($request, $transactionType); - return array( - 'Version' => '0.01', - 'Mode' => $this->configuration->getMode(), - 'Terminal' => $terminal, - 'Order' => $order, - 'Customer' => $customer, - 'Transaction' => $transaction - ); - } - - /** - * builds terminal section of request. - * - * @param Request $request - * * @param string $transactionType - * - * @return array - */ - private function buildTerminal(Request $request, $transactionType) - { - list($username, $password) = $this->getApiCredentialsByRequest($transactionType); - $hash = $this->getTransactionHash($request, $password, $transactionType); - return array( - 'ProvUserID' => $username, - 'HashData' => $hash, - 'UserID' => $username, - 'ID' => $this->configuration->getTerminalId(), - 'MerchantID' => $this->configuration->getMerchantId() - ); - } - - /** - * builds customer section of request. - * - * @return array - */ - private function buildCustomer() - { - /** - * we don't want to share customer information - * to bank. - */ - return array( - 'IPAddress' => '127.0.0.1', - 'EmailAddress' => 'dummy@dummy.net' - ); - } - - /** - * builds card section of request. - * - * @param Request $request - * - * @return array - */ - private function buildCard(Request $request) - { - $expireMonth = $this->expireDateFormatter->format([$request->getExpireMonth(), $request->getExpireYear()]); - - return array( - 'Number' => $request->getCardNumber(), - 'ExpireDate' => $expireMonth, - 'CVV2' => $request->getSecurityCode() - ); - } - - /** - * builds order section of request. - * - * @param Request $request - * - * @return array - */ - private function buildOrder(Request $request) - { - return array( - 'OrderID' => $this->orderIdFormatter->format($request->getOrderId()), - 'GroupID' => null, - 'Description' => null - ); - } - - /** - * builds terminal section of request. - * - * @param Request $request - * @param string $transactionType - * @param integer $cardHolderPresentCode - * @param string $originalRetrefNum - * - * @return array - */ - private function buildTransaction( - Request $request, - $transactionType, - $cardHolderPresentCode = 0, - $originalRetrefNum = null - ) { - $installment = $this->installmentFormatter->format($request->getInstallment()); - $amount = $this->isAmountRequired($transactionType) ? - $this->amountFormatter->format($request->getAmount()) : '1'; - $currency = ($request->getCurrency()) ? $this->currencyFormatter->format($request->getCurrency()) : null; - $type = $this->getProviderTransactionType($transactionType); - return array( - 'Type' => $type, - 'InstallmentCnt' => $installment, - 'Amount' => $amount, - 'CurrencyCode' => $currency, - 'CardholderPresentCode' => $cardHolderPresentCode, - 'MotoInd' => 'N', - 'OriginalRetrefNum' => $originalRetrefNum - ); - } - - /** - * returns boolean true, when amount field is required - * for request transaction type. - * - * @param string $transactionType - * - * @return boolean - */ - private function isAmountRequired($transactionType) - { - return in_array( - $transactionType, - array( - self::TRANSACTION_TYPE_SALE, - self::TRANSACTION_TYPE_PREAUTHORIZATION, - self::TRANSACTION_TYPE_POSTAUTHORIZATION, - ) - ); - } - - /** - * returns boolean true, when card number field is required - * for request transaction type. - * - * @param string $transactionType - * - * @return boolean - */ - private function isCardNumberRequired($transactionType) - { - return in_array( - $transactionType, - array( - self::TRANSACTION_TYPE_SALE, - self::TRANSACTION_TYPE_PREAUTHORIZATION, - ) - ); - } - - /** - * returns api credentials by transaction type of request. - * - * @param string $transactionType - * - * @return array - */ - private function getApiCredentialsByRequest($transactionType) - { - $isAuth = in_array( - $transactionType, - array( - self::TRANSACTION_TYPE_SALE, - self::TRANSACTION_TYPE_PREAUTHORIZATION, - self::TRANSACTION_TYPE_POSTAUTHORIZATION, - ) - ); - if ($isAuth) { - return array( - $this->configuration->getAuthorizationUsername(), - $this->configuration->getAuthorizationPassword() - ); - } else { - return array( - $this->configuration->getRefundUsername(), - $this->configuration->getRefundPassword() - ); - } - } - - /** - * returns security hash for using in transaction hash. - * - * @param string $password - * - * @return string - */ - private function getSecurityHash($password) - { - $tidPrefix = str_repeat('0', 9 - strlen($this->configuration->getTerminalId())); - $terminalId = sprintf('%s%s', $tidPrefix, $this->configuration->getTerminalId()); - return strtoupper(SHA1(sprintf('%s%s', $password, $terminalId))); - } - - /** - * returns transaction hash for using in transaction request. - * - * @param Request $request - * @param string $password - * @param string $transactionType - * - * @return string - */ - private function getTransactionHash(Request $request, $password, $transactionType) - { - $orderId = $this->orderIdFormatter->format($request->getOrderId()); - $terminalId = $this->configuration->getTerminalId(); - $cardNumber = $this->isCardNumberRequired($transactionType) ? $request->getCardNumber() : ''; - $amount = $this->isAmountRequired($transactionType) ? - $this->amountFormatter->format($request->getAmount()) : '1'; - $securityData = $this->getSecurityHash($password); - return strtoupper( - sha1( - sprintf( - '%s%s%s%s%s', - $orderId, - $terminalId, - $cardNumber, - $amount, - $securityData - ) - ) - ); + $this->builderFactory = new GvpBuilderFactory($this->configuration); + $this->processorFactory = new GvpProcessorFactory($this->configuration); } /** * {@inheritdoc} * @see \Paranoia\Pos\AbstractPos::buildRequest() */ - protected function buildRequest(Request $request, $requestBuilder) - { - $rawRequest = call_user_func(array( $this, $requestBuilder ), $request); - $serializer = new Serializer(Serializer::XML); - $xml = $serializer->serialize( - $rawRequest, - array( 'root_name' => 'GVPSRequest' ) - ); - return array( 'data' => $xml ); - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::buildPreauthorizationRequest() - */ - protected function buildPreAuthorizationRequest(Request $request) - { - $requestData = array( 'Card' => $this->buildCard($request) ); - return array_merge($requestData, $this->buildBaseRequest($request, self::TRANSACTION_TYPE_PREAUTHORIZATION)); - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::buildPostAuthorizationRequest() - */ - protected function buildPostAuthorizationRequest(Request $request) - { - $requestData = $this->buildBaseRequest($request, self::TRANSACTION_TYPE_POSTAUTHORIZATION); - return $requestData; - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::buildSaleRequest() - */ - protected function buildSaleRequest(Request $request) - { - $requestData = array( 'Card' => $this->buildCard($request) ); - return array_merge($requestData, $this->buildBaseRequest($request, self::TRANSACTION_TYPE_SALE)); - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::buildRefundRequest() - */ - protected function buildRefundRequest(Request $request) - { - return $this->buildBaseRequest($request, self::TRANSACTION_TYPE_REFUND); - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::buildCancelRequest() - */ - protected function buildCancelRequest(Request $request) - { - $requestData = $this->buildBaseRequest($request, self::TRANSACTION_TYPE_CANCEL); - $transactionId = ($request->getTransactionId()) ? $request->getTransactionId() : null; - $transaction = $this->buildTransaction($request, 0, $transactionId); - $requestData['Transaction'] = $transaction; - return $requestData; - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::parseResponse() - */ - protected function buildPointQueryRequest(Request $request) - { - throw new NotImplementedError(); - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::buildPointUsageRequest() - */ - protected function buildPointUsageRequest(Request $request) + protected function buildRequest(Request $request, $transactionType) { - throw new NotImplementedError(); + $rawRequest = $this->builderFactory->createBuilder($transactionType)->build($request); + return array( 'data' => $rawRequest); } /** @@ -398,43 +37,6 @@ protected function buildPointUsageRequest(Request $request) */ protected function parseResponse($rawResponse, $transactionType) { - $response = new PaymentResponse(); - try { - /** - * @var object $xml - */ - $xml = new \SimpleXmlElement($rawResponse); - } catch (\Exception $e) { - $exception = new BadResponseException('Provider returned unexpected response: ' . $rawResponse); - $eventArg = new TransactionEvent(null, null, $transactionType, $exception); - $this->getDispatcher()->dispatch(self::EVENT_ON_EXCEPTION, $eventArg); - throw $exception; - } - $response->setIsSuccess('00' == (string)$xml->Transaction->Response->Code); - $response->setResponseCode((string)$xml->Transaction->ReasonCode); - if (!$response->isSuccess()) { - $errorMessages = array(); - if (property_exists($xml->Transaction->Response, 'ErrorMsg')) { - $errorMessages[] = sprintf( - 'Error Message: %s', - (string)$xml->Transaction->Response->ErrorMsg - ); - } - if (property_exists($xml->Transaction->Response, 'SysErrMsg')) { - $errorMessages[] = sprintf( - 'System Error Message: %s', - (string)$xml->Transaction->Response->SysErrMsg - ); - } - $errorMessage = implode(' ', $errorMessages); - $response->setResponseMessage($errorMessage); - } else { - $response->setResponseMessage('Success'); - $response->setOrderId((string)$xml->Order->OrderID); - $response->setTransactionId((string)$xml->Transaction->RetrefNum); - } - $event = $response->isSuccess() ? self::EVENT_ON_TRANSACTION_SUCCESSFUL : self::EVENT_ON_TRANSACTION_FAILED; - $this->getDispatcher()->dispatch($event, new TransactionEvent(null, $response, $transactionType)); - return $response; + return $this->processorFactory->createProcessor($transactionType)->process($rawResponse); } } diff --git a/src/Pos/NestPay.php b/src/Pos/NestPay.php index e6923f2..d0913a5 100644 --- a/src/Pos/NestPay.php +++ b/src/Pos/NestPay.php @@ -1,213 +1,36 @@ currencyFormatter = new IsoNumericCurrencyCode(); - $this->amountFormatter = new Decimal(); - $this->installmentFormatter = new SingleDigitInstallment(); - $this->expireDateFormatter = new ExpireDate(); - $this->orderIdFormatter = new NopeFormatter(); + $this->builderFactory = new NestPayBuilderFactory($this->configuration); + $this->processorFactory = new NestPayProcessorFactory($this->configuration); } - /** - * @var array - */ - protected $transactionMap = array( - self::TRANSACTION_TYPE_PREAUTHORIZATION => 'PreAuth', - self::TRANSACTION_TYPE_POSTAUTHORIZATION => 'PostAuth', - self::TRANSACTION_TYPE_SALE => 'Auth', - self::TRANSACTION_TYPE_CANCEL => 'Void', - self::TRANSACTION_TYPE_REFUND => 'Credit', - self::TRANSACTION_TYPE_POINT_QUERY => '', - self::TRANSACTION_TYPE_POINT_USAGE => '', - ); - - /** - * builds request base with common arguments. - * - * @return array - */ - private function buildBaseRequest() - { - return array( - 'Name' => $this->configuration->getUsername(), - 'Password' => $this->configuration->getPassword(), - 'ClientId' => $this->configuration->getClientId(), - 'Mode' => $this->configuration->getMode() - ); - } /** * {@inheritdoc} * @see \Paranoia\Pos\AbstractPos::buildRequest() */ - protected function buildRequest(Request $request, $requestBuilder) - { - $rawRequest = call_user_func(array( $this, $requestBuilder ), $request); - $serializer = new Serializer(Serializer::XML); - $xml = $serializer->serialize( - array_merge($rawRequest, $this->buildBaseRequest()), - array( 'root_name' => 'CC5Request' ) - ); - return array( 'DATA' => $xml ); - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::buildPreauthorizationRequest() - */ - protected function buildPreAuthorizationRequest(Request $request) - { - $amount = $this->amountFormatter->format($request->getAmount()); - $installment = $this->installmentFormatter->format($request->getInstallment()); - $currency = $this->currencyFormatter->format($request->getCurrency()); - $expireMonth = $this->expireDateFormatter->format([$request->getExpireMonth(), $request->getExpireYear()]); - $type = $this->getProviderTransactionType(self::TRANSACTION_TYPE_PREAUTHORIZATION); - $requestData = array( - 'Type' => $type, - 'Total' => $amount, - 'Currency' => $currency, - 'Taksit' => $installment, - 'Number' => $request->getCardNumber(), - 'Cvv2Val' => $request->getSecurityCode(), - 'Expires' => $expireMonth, - 'OrderId' => $this->orderIdFormatter->format($request->getOrderId()), - ); - return $requestData; - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::buildPostAuthorizationRequest() - */ - protected function buildPostAuthorizationRequest(Request $request) - { - $type = $this->getProviderTransactionType(self::TRANSACTION_TYPE_POSTAUTHORIZATION); - $requestData = array( - 'Type' => $type, - 'OrderId' => $this->orderIdFormatter->format($request->getOrderId()), - ); - return $requestData; - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::buildSaleRequest() - */ - protected function buildSaleRequest(Request $request) - { - $amount = $this->amountFormatter->format($request->getAmount()); - $installment = $this->installmentFormatter->format($request->getInstallment()); - $currency = $this->currencyFormatter->format($request->getCurrency()); - $expireMonth = $this->expireDateFormatter->format([$request->getExpireMonth(), $request->getExpireYear()]); - $type = $this->getProviderTransactionType(self::TRANSACTION_TYPE_SALE); - $requestData = array( - 'Type' => $type, - 'Total' => $amount, - 'Currency' => $currency, - 'Taksit' => $installment, - 'Number' => $request->getCardNumber(), - 'Cvv2Val' => $request->getSecurityCode(), - 'Expires' => $expireMonth, - 'OrderId' => $this->orderIdFormatter->format($request->getOrderId()), - ); - return $requestData; - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::buildRefundRequest() - */ - protected function buildRefundRequest(Request $request) - { - $amount = $this->amountFormatter->format($request->getAmount()); - $currency = $this->currencyFormatter->format($request->getCurrency()); - $type = $this->getProviderTransactionType(self::TRANSACTION_TYPE_REFUND); - $requestData = array( - 'Type' => $type, - 'Total' => $amount, - 'Currency' => $currency, - 'OrderId' => $this->orderIdFormatter->format($request->getOrderId()), - ); - return $requestData; - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::buildCancelRequest() - */ - protected function buildCancelRequest(Request $request) - { - $type = $this->getProviderTransactionType(self::TRANSACTION_TYPE_CANCEL); - $requestData = array( - 'Type' => $type, - 'OrderId' => $this->orderIdFormatter->format($request->getOrderId()), - ); - if ($request->getTransactionId()) { - $requestData['TransId'] = $request->getTransactionId(); - } - return $requestData; - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::parseResponse() - */ - protected function buildPointQueryRequest(Request $request) - { - throw new NotImplementedError(); - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::buildPointUsageRequest() - */ - protected function buildPointUsageRequest(Request $request) + protected function buildRequest(Request $request, $transactionType) { - throw new NotImplementedError(); + $rawRequest = $this->builderFactory->createBuilder($transactionType)->build($request); + return array( 'DATA' => $rawRequest); } /** @@ -216,46 +39,6 @@ protected function buildPointUsageRequest(Request $request) */ protected function parseResponse($rawResponse, $transactionType) { - $response = new PaymentResponse(); - try { - /** - * @var object $xml - */ - $xml = new \SimpleXmlElement($rawResponse); - } catch (\Exception $e) { - $exception = new BadResponseException('Provider returned unexpected response: ' . $rawResponse); - $eventArg = new TransactionEvent(null, null, $transactionType, $exception); - $this->getDispatcher()->dispatch(self::EVENT_ON_EXCEPTION, $eventArg); - throw $exception; - } - $response->setIsSuccess((string)$xml->Response == 'Approved'); - $response->setResponseCode((string)$xml->ProcReturnCode); - if (!$response->isSuccess()) { - $errorMessages = array(); - if (property_exists($xml, 'Error')) { - $errorMessages[] = sprintf('Error: %s', (string)$xml->Error); - } - if (property_exists($xml, 'ErrMsg')) { - $errorMessages[] = sprintf( - 'Error Message: %s ', - (string)$xml->ErrMsg - ); - } - if (property_exists($xml, 'Extra') && property_exists($xml->Extra, 'HOSTMSG')) { - $errorMessages[] = sprintf( - 'Host Message: %s', - (string)$xml->Extra->HOSTMSG - ); - } - $errorMessage = implode(' ', $errorMessages); - $response->setResponseMessage($errorMessage); - } else { - $response->setResponseMessage('Success'); - $response->setOrderId((string)$xml->OrderId); - $response->setTransactionId((string)$xml->TransId); - } - $event = $response->isSuccess() ? self::EVENT_ON_TRANSACTION_SUCCESSFUL : self::EVENT_ON_TRANSACTION_FAILED; - $this->getDispatcher()->dispatch($event, new TransactionEvent(null, $response, $transactionType)); - return $response; + return $this->processorFactory->createProcessor($transactionType)->process($rawResponse); } } diff --git a/src/Pos/Posnet.php b/src/Pos/Posnet.php index ea9e034..43187cf 100644 --- a/src/Pos/Posnet.php +++ b/src/Pos/Posnet.php @@ -1,232 +1,34 @@ 'auth', - self::TRANSACTION_TYPE_POSTAUTHORIZATION => 'capt', - self::TRANSACTION_TYPE_SALE => 'sale', - self::TRANSACTION_TYPE_CANCEL => 'reverse', - self::TRANSACTION_TYPE_REFUND => 'return', - self::TRANSACTION_TYPE_POINT_QUERY => 'pointinquiry', - self::TRANSACTION_TYPE_POINT_USAGE => 'pointusage', - ); + /** @var PosnetProcessorFactory */ + private $processorFactory; public function __construct(AbstractConfiguration $configuration) { parent::__construct($configuration); - $this->currencyFormatter = new PosnetCurrencyCode(); - $this->amountFormatter = new Money(); - $this->installmentFormatter = new MultiDigitInstallment(); - $this->expireDateFormatter = new ExpireDate(); - $this->orderIdFormatter = new OrderId(); - } - - - /** - * builds request base with common arguments. - * - * @return array - */ - private function buildBaseRequest() - { - return array( - 'mid' => $this->configuration->getMerchantId(), - 'tid' => $this->configuration->getTerminalId() - ); + $this->builderFactory = new PosnetBuilderFactory($this->configuration); + $this->processorFactory = new PosnetProcessorFactory($this->configuration); } /** * {@inheritdoc} * @see \Paranoia\Pos\AbstractPos::buildRequest() */ - protected function buildRequest(Request $request, $requestBuilder) - { - $rawRequest = call_user_func(array( $this, $requestBuilder ), $request); - $serializer = new Serializer(Serializer::XML); - $xml = $serializer->serialize( - array_merge($this->buildBaseRequest(), $rawRequest), - array( 'root_name' => 'posnetRequest' ) - ); - return array( 'xmldata' => $xml ); - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::buildPreauthorizationRequest() - */ - protected function buildPreauthorizationRequest(Request $request) - { - $amount = $this->amountFormatter->format($request->getAmount()); - $installment = $this->installmentFormatter->format($request->getInstallment()); - $currency = $this->currencyFormatter->format($request->getCurrency()); - $expireMonth = $this->expireDateFormatter->format([$request->getExpireMonth(), $request->getExpireYear()]); - $type = $this->getProviderTransactionType(self::TRANSACTION_TYPE_PREAUTHORIZATION); - $requestData = array( - $type => array( - 'ccno' => $request->getCardNumber(), - 'expDate' => $expireMonth, - 'cvc' => $request->getSecurityCode(), - 'amount' => $amount, - 'currencyCode' => $currency, - 'orderID' => $this->orderIdFormatter->format($request->getOrderId()), - 'installment' => $installment, - #TODO: this fields will be used, when point and some bank benefit usage is implemented. - // 'extraPoint' => "000000", - // 'multiplePoint' => "000000" - ) - ); - return $requestData; - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::buildPostAuthorizationRequest() - */ - protected function buildPostAuthorizationRequest(Request $request) - { - $amount = $this->amountFormatter->format($request->getAmount()); - $installment = $this->installmentFormatter->format($request->getInstallment()); - $currency = $this->currencyFormatter->format($request->getCurrency()); - $type = $this->getProviderTransactionType(self::TRANSACTION_TYPE_POSTAUTHORIZATION); - $requestData = array( - $type => array( - 'hostLogKey' => $request->getTransactionId(), - 'authCode' => $request->getAuthCode(), - 'amount' => $amount, - 'currencyCode' => $currency, - 'installment' => $installment, - #TODO: this fields will be used, when point and some bank benefit usage is implemented. - // 'extraPoint' => "000000", - // 'multiplePoint' => "000000" - ) - ); - return $requestData; - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::buildSaleRequest() - */ - protected function buildSaleRequest(Request $request) - { - $amount = $this->amountFormatter->format($request->getAmount()); - $installment = $this->installmentFormatter->format($request->getInstallment()); - $currency = $this->currencyFormatter->format($request->getCurrency()); - $expireMonth = $this->expireDateFormatter->format([$request->getExpireMonth(), $request->getExpireYear()]); - $type = $this->getProviderTransactionType(self::TRANSACTION_TYPE_SALE); - $requestData = array( - $type => array( - 'ccno' => $request->getCardNumber(), - 'expDate' => $expireMonth, - 'cvc' => $request->getSecurityCode(), - 'amount' => $amount, - 'currencyCode' => $currency, - 'orderID' => $this->orderIdFormatter->format($request->getOrderId()), - 'installment' => $installment, - #TODO: this fields will be used, when point and some bank benefit usage is implemented. - // 'extraPoint' => "000000", - // 'multiplePoint' => "000000" - ) - ); - return $requestData; - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::buildRefundRequest() - */ - protected function buildRefundRequest(Request $request) - { - $amount = $this->amountFormatter->format($request->getAmount()); - $currency = $this->currencyFormatter->format($request->getCurrency()); - $type = $this->getProviderTransactionType(self::TRANSACTION_TYPE_REFUND); - $requestData = array( - $type => array( - 'hostLogKey' => $request->getTransactionId(), - 'amount' => $amount, - 'currencyCode' => $currency - ) - ); - return $requestData; - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::buildCancelRequest() - */ - protected function buildCancelRequest(Request $request) - { - $type = $this->getProviderTransactionType(self::TRANSACTION_TYPE_CANCEL); - $requestData = array( - $type => array( - 'transaction' => "sale", - 'hostLogKey' => $request->getTransactionId(), - 'authCode' => $request->getAuthCode() - ) - ); - return $requestData; - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::parseResponse() - */ - protected function buildPointQueryRequest(Request $request) - { - throw new NotImplementedError(); - } - - /** - * {@inheritdoc} - * @see \Paranoia\Pos\AbstractPos::buildPointUsageRequest() - */ - protected function buildPointUsageRequest(Request $request) + protected function buildRequest(Request $request, $transactionType) { - throw new NotImplementedError(); + $rawRequest = $this->builderFactory->createBuilder($transactionType)->build($request); + return array( 'xmldata' => $rawRequest); } /** @@ -235,43 +37,7 @@ protected function buildPointUsageRequest(Request $request) */ protected function parseResponse($rawResponse, $transactionType) { - $response = new PaymentResponse(); - try { - /** - * @var object $xml - */ - $xml = new \SimpleXmlElement($rawResponse); - } catch (\Exception $e) { - $exception = new BadResponseException('Provider returned unexpected response: ' . $rawResponse); - $eventArg = new TransactionEvent(null, null, $transactionType, $exception); - $this->getDispatcher()->dispatch(self::EVENT_ON_EXCEPTION, $eventArg); - throw $exception; - } - $response->setIsSuccess((int)$xml->approved > 0); - if (!$response->isSuccess()) { - $response->setResponseCode((string)$xml->respCode); - $errorMessages = array(); - if (property_exists($xml, 'respCode')) { - $errorMessages[] = sprintf('Error: %s', (string)$xml->respCode); - } - if (property_exists($xml, 'respText')) { - $errorMessages[] = sprintf('Error Message: %s ', (string)$xml->respText); - } - $errorMessage = implode(' ', $errorMessages); - $response->setResponseMessage($errorMessage); - } else { - $response->setResponseCode("0000"); - $response->setResponseMessage('Success'); - if (property_exists($xml, 'orderId')) { - $response->setOrderId((string)$xml->orderId); - } - $response->setTransactionId((string)$xml->hostlogkey); - if (property_exists($xml, 'authCode')) { - $response->setOrderId((string)$xml->authCode); - } - } - $event = $response->isSuccess() ? self::EVENT_ON_TRANSACTION_SUCCESSFUL : self::EVENT_ON_TRANSACTION_FAILED; - $this->getDispatcher()->dispatch($event, new TransactionEvent(null, $response, $transactionType)); - return $response; + $rawRequest = $this->builderFactory->createBuilder($transactionType)->build($request); + return array( 'DATA' => $rawRequest); } } diff --git a/src/Processor/AbstractProcessorFactory.php b/src/Processor/AbstractProcessorFactory.php new file mode 100644 index 0000000..1537e34 --- /dev/null +++ b/src/Processor/AbstractProcessorFactory.php @@ -0,0 +1,25 @@ +configuration = $configuration; + } + + /** + * @param string $transactionType + * @return AbstractResponseProcessor + */ + abstract public function createProcessor($transactionType); +} diff --git a/src/Processor/AbstractResponseProcessor.php b/src/Processor/AbstractResponseProcessor.php new file mode 100644 index 0000000..26216dc --- /dev/null +++ b/src/Processor/AbstractResponseProcessor.php @@ -0,0 +1,23 @@ +configuration = $configuration; + } + + abstract protected function validateResponse($transformedResponse); + + abstract public function process($rawResponse); +} diff --git a/src/Processor/Gvp/BaseResponseProcessor.php b/src/Processor/Gvp/BaseResponseProcessor.php new file mode 100644 index 0000000..c1989db --- /dev/null +++ b/src/Processor/Gvp/BaseResponseProcessor.php @@ -0,0 +1,75 @@ +Transaction->Response, 'ErrorMsg')) { + $errorMessages[] = sprintf( + 'Error Message: %s', + (string)$xml->Transaction->Response->ErrorMsg + ); + } + if (property_exists($xml->Transaction->Response, 'SysErrMsg')) { + $errorMessages[] = sprintf( + 'System Error Message: %s', + (string)$xml->Transaction->Response->SysErrMsg + ); + } + $errorMessage = implode(' ', $errorMessages); + $response->setResponseMessage($errorMessage); + } + + /** + * @param \SimpleXMLElement $xml + * @param PaymentResponse $response + */ + private function prepareTransactionDetails(\SimpleXMLElement $xml, PaymentResponse $response) + { + $response->setOrderId((string)$xml->Order->OrderID); + $response->setTransactionId((string)$xml->Transaction->RetrefNum); + } + + /** + * @param $rawResponse + * @return PaymentResponse + * @throws BadResponseException + */ + protected function processCommonResponse($rawResponse) + { + $response = new PaymentResponse(); + try { + /** @var \SimpleXMLElement $xml */ + $xml = new \SimpleXmlElement($rawResponse); + } catch (\Exception $e) { + $exception = new BadResponseException('Provider returned unexpected response: ' . $rawResponse); + throw $exception; + } + $this->validateResponse($xml); + $response->setIsSuccess('00' == (string)$xml->Transaction->Response->Code); + $response->setResponseCode((string)$xml->Transaction->ReasonCode); + if (!$response->isSuccess()) { + $this->prepareErrorDetails($xml, $response); + } else { + $this->prepareTransactionDetails($xml, $response); + } + + return $response; + } + + protected function validateResponse($transformedResponse) + { + //TODO: response validation should implemented. + return true; + } +} diff --git a/src/Processor/Gvp/CancelResponseProcessor.php b/src/Processor/Gvp/CancelResponseProcessor.php new file mode 100644 index 0000000..8b87a1e --- /dev/null +++ b/src/Processor/Gvp/CancelResponseProcessor.php @@ -0,0 +1,10 @@ +processCommonResponse($rawResponse); + } +} diff --git a/src/Processor/Gvp/PostAuthorizationResponseProcessor.php b/src/Processor/Gvp/PostAuthorizationResponseProcessor.php new file mode 100644 index 0000000..9b65a63 --- /dev/null +++ b/src/Processor/Gvp/PostAuthorizationResponseProcessor.php @@ -0,0 +1,10 @@ +processCommonResponse($rawResponse); + } +} diff --git a/src/Processor/Gvp/PreAuthorizationResponseProcessor.php b/src/Processor/Gvp/PreAuthorizationResponseProcessor.php new file mode 100644 index 0000000..4f337ef --- /dev/null +++ b/src/Processor/Gvp/PreAuthorizationResponseProcessor.php @@ -0,0 +1,10 @@ +processCommonResponse($rawResponse); + } +} diff --git a/src/Processor/Gvp/RefundResponseProcessor.php b/src/Processor/Gvp/RefundResponseProcessor.php new file mode 100644 index 0000000..335ecc5 --- /dev/null +++ b/src/Processor/Gvp/RefundResponseProcessor.php @@ -0,0 +1,10 @@ +processCommonResponse($rawResponse); + } +} diff --git a/src/Processor/Gvp/SaleResponseProcessor.php b/src/Processor/Gvp/SaleResponseProcessor.php new file mode 100644 index 0000000..b71b051 --- /dev/null +++ b/src/Processor/Gvp/SaleResponseProcessor.php @@ -0,0 +1,10 @@ +processCommonResponse($rawResponse); + } +} diff --git a/src/Processor/GvpProcessorFactory.php b/src/Processor/GvpProcessorFactory.php new file mode 100644 index 0000000..70a3582 --- /dev/null +++ b/src/Processor/GvpProcessorFactory.php @@ -0,0 +1,35 @@ +configuration); + case TransactionType::REFUND: + return new RefundResponseProcessor($this->configuration); + case TransactionType::CANCEL: + return new CancelResponseProcessor($this->configuration); + case TransactionType::PRE_AUTHORIZATION: + return new PreAuthorizationResponseProcessor($this->configuration); + case TransactionType::POST_AUTHORIZATION: + return new PostAuthorizationResponseProcessor($this->configuration); + default: + throw new InvalidArgumentException('Bad transaction type: ' . $transactionType); + } + } +} diff --git a/src/Processor/NestPay/BaseResponseProcessor.php b/src/Processor/NestPay/BaseResponseProcessor.php new file mode 100644 index 0000000..917ba33 --- /dev/null +++ b/src/Processor/NestPay/BaseResponseProcessor.php @@ -0,0 +1,77 @@ +Error); + } + if (property_exists($xml, 'ErrMsg')) { + $errorMessages[] = sprintf( + 'Error Message: %s ', + (string)$xml->ErrMsg + ); + } + if (property_exists($xml, 'Extra') && property_exists($xml->Extra, 'HOSTMSG')) { + $errorMessages[] = sprintf( + 'Host Message: %s', + (string)$xml->Extra->HOSTMSG + ); + } + $errorMessage = implode(' ', $errorMessages); + $response->setResponseMessage($errorMessage); + } + + /** + * @param \SimpleXMLElement $xml + * @param PaymentResponse $response + */ + private function prepareTransactionDetails(\SimpleXMLElement $xml, PaymentResponse $response) + { + $response->setOrderId((string)$xml->OrderId); + $response->setTransactionId((string)$xml->TransId); + } + + /** + * @param $rawResponse + * @return PaymentResponse + * @throws BadResponseException + */ + protected function processCommonResponse($rawResponse) + { + try { + /** @var \SimpleXMLElement $xml */ + $xml = new \SimpleXmlElement($rawResponse); + } catch (\Exception $e) { + $exception = new BadResponseException('Provider returned unexpected response: ' . $rawResponse); + throw $exception; + } + $this->validateResponse($xml); + $response = new PaymentResponse(); + $response->setIsSuccess((string)$xml->Response == 'Approved'); + $response->setResponseCode((string)$xml->ProcReturnCode); + if (!$response->isSuccess()) { + $this->prepareErrorDetails($xml, $response); + } else { + $this->prepareTransactionDetails($xml, $response); + } + return $response; + } + + protected function validateResponse($transformedResponse) + { + //TODO: response validation should implemented. + return true; + } +} diff --git a/src/Processor/NestPay/CancelResponseProcessor.php b/src/Processor/NestPay/CancelResponseProcessor.php new file mode 100644 index 0000000..7d9fed9 --- /dev/null +++ b/src/Processor/NestPay/CancelResponseProcessor.php @@ -0,0 +1,10 @@ +processCommonResponse($rawResponse); + } +} diff --git a/src/Processor/NestPay/PostAuthorizationResponseProcessor.php b/src/Processor/NestPay/PostAuthorizationResponseProcessor.php new file mode 100644 index 0000000..77d22fe --- /dev/null +++ b/src/Processor/NestPay/PostAuthorizationResponseProcessor.php @@ -0,0 +1,10 @@ +processCommonResponse($rawResponse); + } +} diff --git a/src/Processor/NestPay/PreAuthorizationResponseProcessor.php b/src/Processor/NestPay/PreAuthorizationResponseProcessor.php new file mode 100644 index 0000000..de9802b --- /dev/null +++ b/src/Processor/NestPay/PreAuthorizationResponseProcessor.php @@ -0,0 +1,10 @@ +processCommonResponse($rawResponse); + } +} diff --git a/src/Processor/NestPay/RefundResponseProcessor.php b/src/Processor/NestPay/RefundResponseProcessor.php new file mode 100644 index 0000000..736503d --- /dev/null +++ b/src/Processor/NestPay/RefundResponseProcessor.php @@ -0,0 +1,10 @@ +processCommonResponse($rawResponse); + } +} diff --git a/src/Processor/NestPay/SaleResponseProcessor.php b/src/Processor/NestPay/SaleResponseProcessor.php new file mode 100644 index 0000000..082ed39 --- /dev/null +++ b/src/Processor/NestPay/SaleResponseProcessor.php @@ -0,0 +1,10 @@ +processCommonResponse($rawResponse); + } +} diff --git a/src/Processor/NestPayProcessorFactory.php b/src/Processor/NestPayProcessorFactory.php new file mode 100644 index 0000000..30df613 --- /dev/null +++ b/src/Processor/NestPayProcessorFactory.php @@ -0,0 +1,35 @@ +configuration); + case TransactionType::REFUND: + return new RefundResponseProcessor($this->configuration); + case TransactionType::CANCEL: + return new CancelResponseProcessor($this->configuration); + case TransactionType::PRE_AUTHORIZATION: + return new PreAuthorizationResponseProcessor($this->configuration); + case TransactionType::POST_AUTHORIZATION: + return new PostAuthorizationResponseProcessor($this->configuration); + default: + throw new InvalidArgumentException('Bad transaction type: ' . $transactionType); + } + } +} diff --git a/src/Processor/Posnet/BaseResponseProcessor.php b/src/Processor/Posnet/BaseResponseProcessor.php new file mode 100644 index 0000000..9bea6c0 --- /dev/null +++ b/src/Processor/Posnet/BaseResponseProcessor.php @@ -0,0 +1,73 @@ +setResponseCode((string)$xml->respCode); + $errorMessages = array(); + if (property_exists($xml, 'respCode')) { + $errorMessages[] = sprintf('Error: %s', (string)$xml->respCode); + } + if (property_exists($xml, 'respText')) { + $errorMessages[] = sprintf('Error Message: %s ', (string)$xml->respText); + } + $errorMessage = implode(' ', $errorMessages); + $response->setResponseMessage($errorMessage); + } + + /** + * @param \SimpleXMLElement $xml + * @param PaymentResponse $response + */ + private function prepareTransactionDetails(\SimpleXMLElement $xml, PaymentResponse $response) + { + if (property_exists($xml, 'orderId')) { + $response->setOrderId((string)$xml->orderId); + } + $response->setTransactionId((string)$xml->hostlogkey); + if (property_exists($xml, 'authCode')) { + $response->setOrderId((string)$xml->authCode); + } + } + + /** + * @param $rawResponse + * @return PaymentResponse + * @throws BadResponseException + */ + protected function processCommonResponse($rawResponse) + { + try { + /** @var \SimpleXMLElement $xml */ + $xml = new \SimpleXmlElement($rawResponse); + } catch (\Exception $e) { + $exception = new BadResponseException('Provider returned unexpected response: ' . $rawResponse); + throw $exception; + } + $this->validateResponse($xml); + $response = new PaymentResponse(); + $response->setIsSuccess((int)$xml->approved > 0); + if (!$response->isSuccess()) { + $this->prepareErrorDetails($xml, $response); + } else { + $this->prepareTransactionDetails($xml, $response); + } + return $response; + } + + protected function validateResponse($transformedResponse) + { + //TODO: response validation should implemented. + return true; + } +} diff --git a/src/Processor/Posnet/CancelResponseProcessor.php b/src/Processor/Posnet/CancelResponseProcessor.php new file mode 100644 index 0000000..13999a4 --- /dev/null +++ b/src/Processor/Posnet/CancelResponseProcessor.php @@ -0,0 +1,10 @@ +processCommonResponse($rawResponse); + } +} diff --git a/src/Processor/Posnet/PostAuthorizationResponseProcessor.php b/src/Processor/Posnet/PostAuthorizationResponseProcessor.php new file mode 100644 index 0000000..c032b13 --- /dev/null +++ b/src/Processor/Posnet/PostAuthorizationResponseProcessor.php @@ -0,0 +1,10 @@ +processCommonResponse($rawResponse); + } +} diff --git a/src/Processor/Posnet/PreAuthorizationResponseProcessor.php b/src/Processor/Posnet/PreAuthorizationResponseProcessor.php new file mode 100644 index 0000000..1a00627 --- /dev/null +++ b/src/Processor/Posnet/PreAuthorizationResponseProcessor.php @@ -0,0 +1,10 @@ +processCommonResponse($rawResponse); + } +} diff --git a/src/Processor/Posnet/RefundResponseProcessor.php b/src/Processor/Posnet/RefundResponseProcessor.php new file mode 100644 index 0000000..d5eaa9a --- /dev/null +++ b/src/Processor/Posnet/RefundResponseProcessor.php @@ -0,0 +1,10 @@ +processCommonResponse($rawResponse); + } +} diff --git a/src/Processor/Posnet/SaleResponseProcessor.php b/src/Processor/Posnet/SaleResponseProcessor.php new file mode 100644 index 0000000..9c2e653 --- /dev/null +++ b/src/Processor/Posnet/SaleResponseProcessor.php @@ -0,0 +1,10 @@ +processCommonResponse($rawResponse); + } +} diff --git a/src/Processor/PosnetProcessorFactory.php b/src/Processor/PosnetProcessorFactory.php new file mode 100644 index 0000000..830b2b5 --- /dev/null +++ b/src/Processor/PosnetProcessorFactory.php @@ -0,0 +1,35 @@ +configuration); + case TransactionType::REFUND: + return new RefundResponseProcessor($this->configuration); + case TransactionType::CANCEL: + return new CancelResponseProcessor($this->configuration); + case TransactionType::PRE_AUTHORIZATION: + return new PreAuthorizationResponseProcessor($this->configuration); + case TransactionType::POST_AUTHORIZATION: + return new PostAuthorizationResponseProcessor($this->configuration); + default: + throw new InvalidArgumentException('Bad transaction type: ' . $transactionType); + } + } +} diff --git a/src/TransactionType.php b/src/TransactionType.php new file mode 100644 index 0000000..5001ccf --- /dev/null +++ b/src/TransactionType.php @@ -0,0 +1,13 @@ +setupRequest(); + $builder = $this->setupBuilder(); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/gvp/cancel_request_with_order.xml', + $rawRequest + ); + } + + public function test_cancel_transaction() + { + $request = $this->setupRequest(true); + $builder = $this->setupBuilder(); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/gvp/cancel_request_with_transaction.xml', + $rawRequest + ); + } + + protected function setupConfiguration() + { + $configuration = new GvpConfiguration(); + $configuration->setTerminalId('123456') + ->setMode('TEST') + ->setAuthorizationUsername('PROVAUT') + ->setAuthorizationPassword('PROVAUT') + ->setRefundUsername('PROVRFN') + ->setRefundPassword('PROVRFN'); + return $configuration; + } + + /** + * @param bool $isTransaction + * @return Request + */ + protected function setupRequest($isTransaction=false) + { + $request = new Request(); + $request->setOrderId('123456'); + if ($isTransaction) { + $request->setTransactionId('123456'); + } + return $request; + } + + protected function setupBuilder() + { + return new CancelRequestBuilder( + $this->setupConfiguration(), + new IsoNumericCurrencyCodeFormatter(), + new MoneyFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + } +} \ No newline at end of file diff --git a/tests/Builder/Gvp/PostAuthorizationRequestBuilderTest.php b/tests/Builder/Gvp/PostAuthorizationRequestBuilderTest.php new file mode 100644 index 0000000..ca71570 --- /dev/null +++ b/tests/Builder/Gvp/PostAuthorizationRequestBuilderTest.php @@ -0,0 +1,63 @@ +setupBuilder(); + $request = $this->setupRequest(); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/gvp/postauthorization_request.xml', + $rawRequest + ); + } + + protected function setupConfiguration() + { + $configuration = new GvpConfiguration(); + $configuration->setTerminalId('123456') + ->setMode('TEST') + ->setAuthorizationUsername('PROVAUT') + ->setAuthorizationPassword('PROVAUT') + ->setRefundUsername('PROVRFN') + ->setRefundPassword('PROVRFN'); + return $configuration; + } + + /** + * @param bool $isPartial + * @return Request + */ + protected function setupRequest($isPartial=false) + { + $request = new Request(); + $request->setOrderId('123456') + ->setTransactionId('123456') + ->setAmount(25.4) + ->setCurrency(Currency::CODE_EUR); + return $request; + } + + protected function setupBuilder() + { + return new PostAuthorizationRequestBuilder( + $this->setupConfiguration(), + new IsoNumericCurrencyCodeFormatter(), + new MoneyFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + } +} \ No newline at end of file diff --git a/tests/Builder/Gvp/PreAuthorizationRequestBuilderTest.php b/tests/Builder/Gvp/PreAuthorizationRequestBuilderTest.php new file mode 100644 index 0000000..a9583e7 --- /dev/null +++ b/tests/Builder/Gvp/PreAuthorizationRequestBuilderTest.php @@ -0,0 +1,68 @@ +setupBuilder(); + + $request = $this->setupRequest(); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/gvp/preauthorization_request.xml', + $rawRequest + ); + } + + protected function setupConfiguration() + { + $configuration = new GvpConfiguration(); + $configuration->setTerminalId('123456') + ->setMode('TEST') + ->setAuthorizationUsername('PROVAUT') + ->setAuthorizationPassword('PROVAUT') + ->setRefundUsername('PROVRFN') + ->setRefundPassword('PROVRFN'); + + return $configuration; + } + + /** + * @return Request + */ + protected function setupRequest() + { + $request = new Request(); + $request->setOrderId('123456') + ->setAmount(25.4) + ->setCurrency(Currency::CODE_EUR) + ->setCardNumber('1501501501501500') + ->setSecurityCode('000') + ->setExpireMonth(1) + ->setExpireYear(2020); + return $request; + } + + protected function setupBuilder() + { + return new PreAuthorizationRequestBuilder( + $this->setupConfiguration(), + new IsoNumericCurrencyCodeFormatter(), + new MoneyFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + } +} \ No newline at end of file diff --git a/tests/Builder/Gvp/RefundRequestBuilderTest.php b/tests/Builder/Gvp/RefundRequestBuilderTest.php new file mode 100644 index 0000000..b22501b --- /dev/null +++ b/tests/Builder/Gvp/RefundRequestBuilderTest.php @@ -0,0 +1,63 @@ +setupBuilder(); + $request = $this->setupRequest(); + + $rawRequest = $builder->build($request); + + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/gvp/refund_request.xml', + $rawRequest + ); + } + + protected function setupConfiguration() + { + $configuration = new GvpConfiguration(); + $configuration->setTerminalId('123456') + ->setMode('TEST') + ->setAuthorizationUsername('PROVAUT') + ->setAuthorizationPassword('PROVAUT') + ->setRefundUsername('PROVRFN') + ->setRefundPassword('PROVRFN'); + return $configuration; + } + + /** + * @return Request + */ + protected function setupRequest() + { + $request = new Request(); + $request->setOrderId('123456') + ->setAmount(25.4) + ->setCurrency(Currency::CODE_EUR); + return $request; + } + + protected function setupBuilder() + { + return new RefundRequestBuilder( + $this->setupConfiguration(), + new IsoNumericCurrencyCodeFormatter(), + new MoneyFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + } +} \ No newline at end of file diff --git a/tests/Builder/Gvp/SaleRequestBuilderTest.php b/tests/Builder/Gvp/SaleRequestBuilderTest.php new file mode 100644 index 0000000..1e85d47 --- /dev/null +++ b/tests/Builder/Gvp/SaleRequestBuilderTest.php @@ -0,0 +1,81 @@ +setupBuilder(); + $request = $this->setupRequest(); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/gvp/sale_request_eur.xml', + $rawRequest + ); + } + + public function test_sales_with_multi_installment() + { + $builder = $this->setupBuilder(); + $request = $this->setupRequest(true); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/gvp/sale_request_eur_with_installment.xml', + $rawRequest + ); + } + + protected function setupConfiguration() + { + $configuration = new GvpConfiguration(); + $configuration->setTerminalId('123456') + ->setMode('TEST') + ->setAuthorizationUsername('PROVAUT') + ->setAuthorizationPassword('PROVAUT') + ->setRefundUsername('PROVRFN') + ->setRefundPassword('PROVRFN'); + + return $configuration; + } + + /** + * @param bool $setInstallment + * @return Request + */ + protected function setupRequest($setInstallment=false) + { + $request = new Request(); + $request->setOrderId('123456') + ->setAmount(25.4) + ->setCurrency(Currency::CODE_EUR) + ->setCardNumber('1501501501501500') + ->setSecurityCode('000') + ->setExpireMonth(1) + ->setExpireYear(2020); + if($setInstallment) { + $request->setInstallment(3); + } + return $request; + } + + protected function setupBuilder() + { + return new SaleRequestBuilder( + $this->setupConfiguration(), + new IsoNumericCurrencyCodeFormatter(), + new MoneyFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + } +} \ No newline at end of file diff --git a/tests/Builder/GvpBuilderFactoryTest.php b/tests/Builder/GvpBuilderFactoryTest.php new file mode 100644 index 0000000..10e6be1 --- /dev/null +++ b/tests/Builder/GvpBuilderFactoryTest.php @@ -0,0 +1,39 @@ +getMockBuilder(GvpConfiguration::class)->getMock(); + $factory = new GvpBuilderFactory($configuration); + $this->assertInstanceOf(SaleRequestBuilder::class, $factory->createBuilder(TransactionType::SALE)); + $this->assertInstanceOf(RefundRequestBuilder::class, $factory->createBuilder(TransactionType::REFUND)); + $this->assertInstanceOf(CancelRequestBuilder::class, $factory->createBuilder(TransactionType::CANCEL)); + $this->assertInstanceOf(PreAuthorizationRequestBuilder::class, $factory->createBuilder(TransactionType::PRE_AUTHORIZATION)); + $this->assertInstanceOf(PostAuthorizationRequestBuilder::class, $factory->createBuilder(TransactionType::POST_AUTHORIZATION)); + } + + public function test_invalid_transaction_type() + { + $this->expectException(NotImplementedError::class); + + /** @var GvpConfiguration $configuration */ + $configuration = $this->getMockBuilder(GvpConfiguration::class)->getMock(); + + $factory = new GvpBuilderFactory($configuration); + $factory->createBuilder('Dummy'); + } +} diff --git a/tests/Builder/NestPay/CancelRequestBuilderTest.php b/tests/Builder/NestPay/CancelRequestBuilderTest.php new file mode 100644 index 0000000..a60a21e --- /dev/null +++ b/tests/Builder/NestPay/CancelRequestBuilderTest.php @@ -0,0 +1,71 @@ +setupBuilder(); + $request = $this->setupRequest(); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/nestpay/cancel_request_with_order.xml', + $rawRequest + ); + } + + public function test_cancel_transaction() + { + $builder = $this->setupBuilder(); + $request = $this->setupRequest(true); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/nestpay/cancel_request_with_transaction.xml', + $rawRequest + ); + } + + protected function setupConfiguration() + { + $configuration = new NestPayConfiguration(); + $configuration->setClientId('123456') + ->setMode('TEST') + ->setUsername('TEST') + ->setPassword('TEST'); + return $configuration; + } + + /** + * @param bool $isTransaction + * @return Request + */ + protected function setupRequest($isTransaction=false) + { + $request = new Request(); + $request->setOrderId('123456'); + if ($isTransaction) { + $request->setTransactionId('123456'); + } + return $request; + } + + protected function setupBuilder() + { + return new CancelRequestBuilder( + $this->setupConfiguration(), + new IsoNumericCurrencyCodeFormatter(), + new DecimalFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + } +} \ No newline at end of file diff --git a/tests/Builder/NestPay/PostAuthorizationRequestBuilderTest.php b/tests/Builder/NestPay/PostAuthorizationRequestBuilderTest.php new file mode 100644 index 0000000..b7028b3 --- /dev/null +++ b/tests/Builder/NestPay/PostAuthorizationRequestBuilderTest.php @@ -0,0 +1,60 @@ +setupBuilder(); + $request = $this->setupRequest(); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/nestpay/postauthorization_request.xml', + $rawRequest + ); + } + + protected function setupConfiguration() + { + $configuration = new NestPayConfiguration(); + $configuration->setClientId('123456') + ->setMode('TEST') + ->setUsername('TEST') + ->setPassword('TEST'); + return $configuration; + } + + /** + * @param bool $isTransaction + * @return Request + */ + protected function setupRequest($isTransaction=false) + { + $request = new Request(); + $request->setOrderId('123456'); + if ($isTransaction) { + $request->setTransactionId('123456'); + } + return $request; + } + + protected function setupBuilder() + { + return new PostAuthorizationRequestBuilder( + $this->setupConfiguration(), + new IsoNumericCurrencyCodeFormatter(), + new DecimalFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + } +} diff --git a/tests/Builder/NestPay/PreAuthorizationRequestBuilderTest.php b/tests/Builder/NestPay/PreAuthorizationRequestBuilderTest.php new file mode 100644 index 0000000..67d4c7f --- /dev/null +++ b/tests/Builder/NestPay/PreAuthorizationRequestBuilderTest.php @@ -0,0 +1,66 @@ +setupBuilder(); + + $request = $this->setupRequest(); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/nestpay/preauthorization_request.xml', + $rawRequest + ); + } + + protected function setupConfiguration() + { + $configuration = new NestPayConfiguration(); + $configuration->setClientId('123456') + ->setMode('TEST') + ->setUsername('TEST') + ->setPassword('TEST'); + return $configuration; + } + + /** + * @param bool $setInstallment + * @return Request + */ + protected function setupRequest() + { + $request = new Request(); + $request->setOrderId('123456') + ->setAmount(25.4) + ->setCurrency(Currency::CODE_EUR) + ->setCardNumber('1501501501501500') + ->setSecurityCode('000') + ->setExpireMonth(1) + ->setExpireYear(2020); + + return $request; + } + + protected function setupBuilder() + { + return new PreAuthorizationRequestBuilder( + $this->setupConfiguration(), + new IsoNumericCurrencyCodeFormatter(), + new DecimalFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + } +} diff --git a/tests/Builder/NestPay/RefundRequestBuilderTest.php b/tests/Builder/NestPay/RefundRequestBuilderTest.php new file mode 100644 index 0000000..a99a4e2 --- /dev/null +++ b/tests/Builder/NestPay/RefundRequestBuilderTest.php @@ -0,0 +1,73 @@ +setupBuilder(); + $request = $this->setupRequest(); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/nestpay/refund_request_full.xml', + $rawRequest + ); + } + + public function test_partial_refund() + { + $builder = $this->setupBuilder(); + $request = $this->setupRequest(true); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/nestpay/refund_request_partial.xml', + $rawRequest + ); + } + + protected function setupConfiguration() + { + $configuration = new NestPayConfiguration(); + $configuration->setClientId('123456') + ->setMode('TEST') + ->setUsername('TEST') + ->setPassword('TEST'); + return $configuration; + } + + /** + * @param bool $isPartial + * @return Request + */ + protected function setupRequest($isPartial=false) + { + $request = new Request(); + $request->setOrderId('123456'); + if($isPartial) { + $request->setAmount(25.4) + ->setCurrency(Currency::CODE_EUR); + } + return $request; + } + + protected function setupBuilder() + { + return new RefundRequestBuilder( + $this->setupConfiguration(), + new IsoNumericCurrencyCodeFormatter(), + new DecimalFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + } +} \ No newline at end of file diff --git a/tests/Builder/NestPay/SaleRequestBuilderTest.php b/tests/Builder/NestPay/SaleRequestBuilderTest.php new file mode 100644 index 0000000..fb7b349 --- /dev/null +++ b/tests/Builder/NestPay/SaleRequestBuilderTest.php @@ -0,0 +1,78 @@ +setupBuilder(); + $request = $this->setupRequest(); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/nestpay/sale_request_eur.xml', + $rawRequest + ); + } + + public function test_sales_with_multi_installment() + { + $builder = $this->setupBuilder(); + $request = $this->setupRequest(true); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/nestpay/sale_request_eur_with_installment.xml', + $rawRequest + ); + } + + protected function setupConfiguration() + { + $configuration = new NestPayConfiguration(); + $configuration->setClientId('123456') + ->setMode('TEST') + ->setUsername('TEST') + ->setPassword('TEST'); + return $configuration; + } + + /** + * @param bool $setInstallment + * @return Request + */ + protected function setupRequest($setInstallment=false) + { + $request = new Request(); + $request->setOrderId('123456') + ->setAmount(25.4) + ->setCurrency(Currency::CODE_EUR) + ->setCardNumber('1501501501501500') + ->setSecurityCode('000') + ->setExpireMonth(1) + ->setExpireYear(2020); + if($setInstallment) { + $request->setInstallment(3); + } + return $request; + } + + protected function setupBuilder() + { + return new SaleRequestBuilder( + $this->setupConfiguration(), + new IsoNumericCurrencyCodeFormatter(), + new DecimalFormatter(), + new SingleDigitInstallmentFormatter(), + new ExpireDateFormatter() + ); + } +} \ No newline at end of file diff --git a/tests/Builder/NestPayBuilderFactoryTest.php b/tests/Builder/NestPayBuilderFactoryTest.php new file mode 100644 index 0000000..4720ace --- /dev/null +++ b/tests/Builder/NestPayBuilderFactoryTest.php @@ -0,0 +1,41 @@ +getMockBuilder(NestPayConfiguration::class)->getMock(); + + $factory = new NestPayBuilderFactory($configuration); + $this->assertInstanceOf(SaleRequestBuilder::class, $factory->createBuilder(TransactionType::SALE)); + $this->assertInstanceOf(RefundRequestBuilder::class, $factory->createBuilder(TransactionType::REFUND)); + $this->assertInstanceOf(CancelRequestBuilder::class, $factory->createBuilder(TransactionType::CANCEL)); + $this->assertInstanceOf(PreAuthorizationRequestBuilder::class, $factory->createBuilder(TransactionType::PRE_AUTHORIZATION)); + $this->assertInstanceOf(PostAuthorizationRequestBuilder::class, $factory->createBuilder(TransactionType::POST_AUTHORIZATION)); + } + + public function test_invalid_transaction_type() + { + $this->expectException(NotImplementedError::class); + + /** @var NestPayConfiguration $configuration */ + $configuration = $this->getMockBuilder(NestPayConfiguration::class)->getMock(); + + $factory = new NestPayBuilderFactory($configuration); + $factory->createBuilder('Dummy'); + } +} diff --git a/tests/Builder/Posnet/CancelRequestBuilderTest.php b/tests/Builder/Posnet/CancelRequestBuilderTest.php new file mode 100644 index 0000000..dc24473 --- /dev/null +++ b/tests/Builder/Posnet/CancelRequestBuilderTest.php @@ -0,0 +1,58 @@ +setupBuilder(); + $request = $this->setupRequest(); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/posnet/cancel_request.xml', + $rawRequest + ); + } + + protected function setupConfiguration() + { + $configuration = new PosnetConfiguration(); + $configuration->setMerchantId('213456') + ->setTerminalId('654321') + ->setUsername('TEST') + ->setPassword('TEST'); + return $configuration; + } + + /** + * @return Request + */ + protected function setupRequest() + { + $request = new Request(); + $request->setTransactionId('12345678901'); + return $request; + } + + protected function setupBuilder() + { + return new CancelRequestBuilder( + $this->setupConfiguration(), + new CustomCurrencyCodeFormatter(), + new MoneyFormatter(), + new MultiDigitInstallmentFormatter(), + new ExpireDateFormatter(), + new OrderIdFormatter() + ); + } +} \ No newline at end of file diff --git a/tests/Builder/Posnet/PostAuthorizationRequestBuilderTest.php b/tests/Builder/Posnet/PostAuthorizationRequestBuilderTest.php new file mode 100644 index 0000000..1c2fe2f --- /dev/null +++ b/tests/Builder/Posnet/PostAuthorizationRequestBuilderTest.php @@ -0,0 +1,76 @@ +setupBuilder(); + $request = $this->setupRequest(); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/posnet/post_authorization_request_eur.xml', + $rawRequest + ); + } + + public function test_sales_with_multi_installment() + { + $builder = $this->setupBuilder(); + $request = $this->setupRequest(true); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/posnet/post_authorization_request_eur_with_installment.xml', + $rawRequest + ); + } + + protected function setupConfiguration() + { + $configuration = new PosnetConfiguration(); + $configuration->setMerchantId('213456') + ->setTerminalId('654321') + ->setUsername('TEST') + ->setPassword('TEST'); + return $configuration; + } + + /** + * @param bool $setInstallment + * @return Request + */ + protected function setupRequest($setInstallment=false) + { + $request = new Request(); + $request->setTransactionId('12345678901') + ->setAmount(25.4) + ->setCurrency(Currency::CODE_EUR); + if($setInstallment) { + $request->setInstallment(3); + } + return $request; + } + + protected function setupBuilder() + { + return new PostAuthorizationRequestBuilder( + $this->setupConfiguration(), + new CustomCurrencyCodeFormatter(), + new MoneyFormatter(), + new MultiDigitInstallmentFormatter(), + new ExpireDateFormatter(), + new OrderIdFormatter() + ); + } +} \ No newline at end of file diff --git a/tests/Builder/Posnet/PreAuthorizationRequestBuilderTest.php b/tests/Builder/Posnet/PreAuthorizationRequestBuilderTest.php new file mode 100644 index 0000000..c0036de --- /dev/null +++ b/tests/Builder/Posnet/PreAuthorizationRequestBuilderTest.php @@ -0,0 +1,80 @@ +setupBuilder(); + $request = $this->setupRequest(); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/posnet/pre_authorization_request_eur.xml', + $rawRequest + ); + } + + public function test_sales_with_multi_installment() + { + $builder = $this->setupBuilder(); + $request = $this->setupRequest(true); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/posnet/pre_authorization_request_eur_with_installment.xml', + $rawRequest + ); + } + + protected function setupConfiguration() + { + $configuration = new PosnetConfiguration(); + $configuration->setMerchantId('213456') + ->setTerminalId('654321') + ->setUsername('TEST') + ->setPassword('TEST'); + return $configuration; + } + + /** + * @param bool $setInstallment + * @return Request + */ + protected function setupRequest($setInstallment=false) + { + $request = new Request(); + $request->setOrderId('123456') + ->setAmount(25.4) + ->setCurrency(Currency::CODE_EUR) + ->setCardNumber('1501501501501500') + ->setSecurityCode('000') + ->setExpireMonth(1) + ->setExpireYear(2020); + if($setInstallment) { + $request->setInstallment(3); + } + return $request; + } + + protected function setupBuilder() + { + return new PreAuthorizationRequestBuilder( + $this->setupConfiguration(), + new CustomCurrencyCodeFormatter(), + new MoneyFormatter(), + new MultiDigitInstallmentFormatter(), + new ExpireDateFormatter(), + new OrderIdFormatter() + ); + } +} \ No newline at end of file diff --git a/tests/Builder/Posnet/RefundRequestBuilderTest.php b/tests/Builder/Posnet/RefundRequestBuilderTest.php new file mode 100644 index 0000000..e76375c --- /dev/null +++ b/tests/Builder/Posnet/RefundRequestBuilderTest.php @@ -0,0 +1,61 @@ +setupBuilder(); + $request = $this->setupRequest(); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/posnet/refund_request.xml', + $rawRequest + ); + } + + protected function setupConfiguration() + { + $configuration = new PosnetConfiguration(); + $configuration->setMerchantId('213456') + ->setTerminalId('654321') + ->setUsername('TEST') + ->setPassword('TEST'); + return $configuration; + } + + /** + * @return Request + */ + protected function setupRequest() + { + $request = new Request(); + $request->setTransactionId('12345678901') + ->setAmount(25.4) + ->setCurrency(Currency::CODE_EUR); + return $request; + } + + protected function setupBuilder() + { + return new RefundRequestBuilder( + $this->setupConfiguration(), + new CustomCurrencyCodeFormatter(), + new MoneyFormatter(), + new MultiDigitInstallmentFormatter(), + new ExpireDateFormatter(), + new OrderIdFormatter() + ); + } +} \ No newline at end of file diff --git a/tests/Builder/Posnet/SaleRequestBuilderTest.php b/tests/Builder/Posnet/SaleRequestBuilderTest.php new file mode 100644 index 0000000..02089f6 --- /dev/null +++ b/tests/Builder/Posnet/SaleRequestBuilderTest.php @@ -0,0 +1,80 @@ +setupBuilder(); + $request = $this->setupRequest(); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/posnet/sale_request_eur.xml', + $rawRequest + ); + } + + public function test_sales_with_multi_installment() + { + $builder = $this->setupBuilder(); + $request = $this->setupRequest(true); + $rawRequest = $builder->build($request); + $this->assertXmlStringEqualsXmlFile( + __DIR__ . '/../../samples/request/posnet/sale_request_eur_with_installment.xml', + $rawRequest + ); + } + + protected function setupConfiguration() + { + $configuration = new PosnetConfiguration(); + $configuration->setMerchantId('213456') + ->setTerminalId('654321') + ->setUsername('TEST') + ->setPassword('TEST'); + return $configuration; + } + + /** + * @param bool $setInstallment + * @return Request + */ + protected function setupRequest($setInstallment=false) + { + $request = new Request(); + $request->setOrderId('123456') + ->setAmount(25.4) + ->setCurrency(Currency::CODE_EUR) + ->setCardNumber('1501501501501500') + ->setSecurityCode('000') + ->setExpireMonth(1) + ->setExpireYear(2020); + if($setInstallment) { + $request->setInstallment(3); + } + return $request; + } + + protected function setupBuilder() + { + return new SaleRequestBuilder( + $this->setupConfiguration(), + new CustomCurrencyCodeFormatter(), + new MoneyFormatter(), + new MultiDigitInstallmentFormatter(), + new ExpireDateFormatter(), + new OrderIdFormatter() + ); + } +} \ No newline at end of file diff --git a/tests/Builder/PosnetBuilderFactoryTest.php b/tests/Builder/PosnetBuilderFactoryTest.php new file mode 100644 index 0000000..1a05e99 --- /dev/null +++ b/tests/Builder/PosnetBuilderFactoryTest.php @@ -0,0 +1,46 @@ +getMockBuilder(PosnetConfiguration::class)->getMock(); + + $factory = new PosnetBuilderFactory($configuration); + $this->assertInstanceOf(SaleRequestBuilder::class, $factory->createBuilder(TransactionType::SALE)); + $this->assertInstanceOf(RefundRequestBuilder::class, $factory->createBuilder(TransactionType::REFUND)); + $this->assertInstanceOf(CancelRequestBuilder::class, $factory->createBuilder(TransactionType::CANCEL)); + $this->assertInstanceOf(PreAuthorizationRequestBuilder::class, $factory->createBuilder(TransactionType::PRE_AUTHORIZATION)); + $this->assertInstanceOf(PostAuthorizationRequestBuilder::class, $factory->createBuilder(TransactionType::POST_AUTHORIZATION)); + } + + public function test_invalid_transaction_type() + { + $this->expectException(NotImplementedError::class); + + /** @var PosnetConfiguration $configuration */ + $configuration = $this->getMockBuilder(PosnetConfiguration::class)->getMock(); + + $factory = new PosnetBuilderFactory($configuration); + $factory->createBuilder('Dummy'); + } + + protected function setupConfiguration() + { + $configuration = new PosnetConfiguration();; + return $configuration; + } +} diff --git a/tests/Formatter/DecimalTest.php b/tests/Formatter/DecimalFormatterTest.php similarity index 74% rename from tests/Formatter/DecimalTest.php rename to tests/Formatter/DecimalFormatterTest.php index d9d860a..40bd8ee 100644 --- a/tests/Formatter/DecimalTest.php +++ b/tests/Formatter/DecimalFormatterTest.php @@ -1,29 +1,29 @@ expectException(InvalidArgumentException::class); $formatter->format(null); } public function test_invalid_input_alphanumeric() { - $formatter = new Decimal(); + $formatter = new DecimalFormatter(); $this->expectException(InvalidArgumentException::class); $formatter->format('bad value'); } public function test_valid_input() { - $formatter = new Decimal(); + $formatter = new DecimalFormatter(); $this->assertEquals('1.11', $formatter->format(1.114)); $this->assertEquals('1.12', $formatter->format(1.115)); } diff --git a/tests/Formatter/Gvp/ExpireDateTest.php b/tests/Formatter/Gvp/ExpireDateTest.php index b122476..088b4ce 100644 --- a/tests/Formatter/Gvp/ExpireDateTest.php +++ b/tests/Formatter/Gvp/ExpireDateTest.php @@ -1,14 +1,14 @@ assertEquals('0294', $formatter->format([2, 1994])); } } \ No newline at end of file diff --git a/tests/Formatter/IsoNumericCurrencyCodeTest.php b/tests/Formatter/IsoNumericCurrencyCodeFormatterTest.php similarity index 60% rename from tests/Formatter/IsoNumericCurrencyCodeTest.php rename to tests/Formatter/IsoNumericCurrencyCodeFormatterTest.php index f11e2d5..3fdf182 100644 --- a/tests/Formatter/IsoNumericCurrencyCodeTest.php +++ b/tests/Formatter/IsoNumericCurrencyCodeFormatterTest.php @@ -3,14 +3,14 @@ use Paranoia\Currency; use Paranoia\Exception\InvalidArgumentException; -use Paranoia\Formatter\IsoNumericCurrencyCode; +use Paranoia\Formatter\IsoNumericCurrencyCodeFormatter; use PHPUnit\Framework\TestCase; -class IsoNumericCurrencyCodeTest extends TestCase +class IsoNumericCurrencyCodeFormatterTest extends TestCase { public function test_invalid_input() { - $formatter = new IsoNumericCurrencyCode(); + $formatter = new IsoNumericCurrencyCodeFormatter(); $this->expectException(InvalidArgumentException::class); $formatter->format('BAD_CODE'); } @@ -19,9 +19,9 @@ public function getCurrencyCodes() { #TODO: Move this constants to another constant class. return [ - [Currency::CODE_EUR, IsoNumericCurrencyCode::CODE_EUR], - [Currency::CODE_USD, IsoNumericCurrencyCode::CODE_USD], - [Currency::CODE_TRY, IsoNumericCurrencyCode::CODE_TRY], + [Currency::CODE_EUR, IsoNumericCurrencyCodeFormatter::CODE_EUR], + [Currency::CODE_USD, IsoNumericCurrencyCodeFormatter::CODE_USD], + [Currency::CODE_TRY, IsoNumericCurrencyCodeFormatter::CODE_TRY], ]; } @@ -32,7 +32,7 @@ public function getCurrencyCodes() */ public function test_valid_input($currencyCode, $expected) { - $formatter = new IsoNumericCurrencyCode(); + $formatter = new IsoNumericCurrencyCodeFormatter(); $this->assertEquals($expected, $formatter->format($currencyCode)); } } diff --git a/tests/Formatter/MoneyTest.php b/tests/Formatter/MoneyFormatterTest.php similarity index 74% rename from tests/Formatter/MoneyTest.php rename to tests/Formatter/MoneyFormatterTest.php index a2109a5..19a633b 100644 --- a/tests/Formatter/MoneyTest.php +++ b/tests/Formatter/MoneyFormatterTest.php @@ -2,28 +2,28 @@ namespace Paranoia\Test\Formatter; use Paranoia\Exception\InvalidArgumentException; -use Paranoia\Formatter\Money; +use Paranoia\Formatter\MoneyFormatter; use PHPUnit\Framework\TestCase; -class MoneyTest extends TestCase +class MoneyFormatterTest extends TestCase { public function test_invalid_input_null() { - $formatter = new Money(); + $formatter = new MoneyFormatter(); $this->expectException(InvalidArgumentException::class); $formatter->format(null); } public function test_invalid_input_alphanumeric() { - $formatter = new Money(); + $formatter = new MoneyFormatter(); $this->expectException(InvalidArgumentException::class); $formatter->format('bad value'); } public function test_valid_input() { - $formatter = new Money(); + $formatter = new MoneyFormatter(); $this->assertEquals(120, $formatter->format(1.2)); $this->assertEquals(12, $formatter->format(0.12)); } diff --git a/tests/Formatter/MultiDigitInstallmentTest.php b/tests/Formatter/MultiDigitInstallmentFormatterTest.php similarity index 75% rename from tests/Formatter/MultiDigitInstallmentTest.php rename to tests/Formatter/MultiDigitInstallmentFormatterTest.php index 23ae81e..2d28d59 100644 --- a/tests/Formatter/MultiDigitInstallmentTest.php +++ b/tests/Formatter/MultiDigitInstallmentFormatterTest.php @@ -1,10 +1,10 @@ assertEquals($expected, $formatter->format($input)); } } diff --git a/tests/Formatter/NestPay/ExpireDateTest.php b/tests/Formatter/NestPay/ExpireDateTest.php index fecb526..6299a51 100644 --- a/tests/Formatter/NestPay/ExpireDateTest.php +++ b/tests/Formatter/NestPay/ExpireDateTest.php @@ -1,14 +1,14 @@ assertEquals('02/1994', $formatter->format([2, 1994])); } } \ No newline at end of file diff --git a/tests/Formatter/PosnetCurrencyCodeTest.php b/tests/Formatter/Posnet/CustomCurrencyCodeFormatterTest.php similarity index 61% rename from tests/Formatter/PosnetCurrencyCodeTest.php rename to tests/Formatter/Posnet/CustomCurrencyCodeFormatterTest.php index 718d917..0c1f968 100644 --- a/tests/Formatter/PosnetCurrencyCodeTest.php +++ b/tests/Formatter/Posnet/CustomCurrencyCodeFormatterTest.php @@ -3,14 +3,14 @@ use Paranoia\Currency; use Paranoia\Exception\InvalidArgumentException; -use Paranoia\Formatter\PosnetCurrencyCode; +use Paranoia\Formatter\Posnet\CustomCurrencyCodeFormatter; use PHPUnit\Framework\TestCase; -class PosnetCurrencyCodeTest extends TestCase +class CustomCurrencyCodeFormatterTest extends TestCase { public function test_invalid_input() { - $formatter = new PosnetCurrencyCode(); + $formatter = new CustomCurrencyCodeFormatter(); $this->expectException(InvalidArgumentException::class); $formatter->format('BAD_CODE'); } @@ -19,9 +19,9 @@ public function getCurrencyCodes() { #TODO: Move this constants to another constant class. return [ - [Currency::CODE_EUR, PosnetCurrencyCode::CODE_EUR], - [Currency::CODE_USD, PosnetCurrencyCode::CODE_USD], - [Currency::CODE_TRY, PosnetCurrencyCode::CODE_TRY], + [Currency::CODE_EUR, CustomCurrencyCodeFormatter::CODE_EUR], + [Currency::CODE_USD, CustomCurrencyCodeFormatter::CODE_USD], + [Currency::CODE_TRY, CustomCurrencyCodeFormatter::CODE_TRY], ]; } @@ -32,7 +32,7 @@ public function getCurrencyCodes() */ public function test_valid_input($currencyCode, $expected) { - $formatter = new PosnetCurrencyCode(); + $formatter = new CustomCurrencyCodeFormatter(); $this->assertEquals($expected, $formatter->format($currencyCode)); } } diff --git a/tests/Formatter/Posnet/ExpireDateTest.php b/tests/Formatter/Posnet/ExpireDateFormatterTest.php similarity index 56% rename from tests/Formatter/Posnet/ExpireDateTest.php rename to tests/Formatter/Posnet/ExpireDateFormatterTest.php index 33546bc..c1c9f92 100644 --- a/tests/Formatter/Posnet/ExpireDateTest.php +++ b/tests/Formatter/Posnet/ExpireDateFormatterTest.php @@ -1,14 +1,14 @@ assertEquals('9402', $formatter->format([2, 1994])); } } diff --git a/tests/Formatter/Posnet/OrderIdTest.php b/tests/Formatter/Posnet/OrderIdFormatterTest.php similarity index 79% rename from tests/Formatter/Posnet/OrderIdTest.php rename to tests/Formatter/Posnet/OrderIdFormatterTest.php index 22f007b..eda231d 100644 --- a/tests/Formatter/Posnet/OrderIdTest.php +++ b/tests/Formatter/Posnet/OrderIdFormatterTest.php @@ -2,14 +2,14 @@ namespace Paranoia\Test\Formatter\Posnet; use Paranoia\Exception\InvalidArgumentException; -use Paranoia\Formatter\Posnet\OrderId; +use Paranoia\Formatter\Posnet\OrderIdFormatter; use PHPUnit\Framework\TestCase; -class OrderIdTest extends TestCase +class OrderIdFormatterTest extends TestCase { public function test() { - $formatter = new OrderId(); + $formatter = new OrderIdFormatter(); $this->assertEquals(24, strlen($formatter->format('123'))); $this->assertEquals('000000000000000000000123', $formatter->format('123')); $this->assertEquals(24, strlen($formatter->format('12'))); @@ -18,7 +18,7 @@ public function test() public function test_too_long_input() { - $formatter = new OrderId(); + $formatter = new OrderIdFormatter(); $this->expectException(InvalidArgumentException::class); $this->assertEquals(24, strlen($formatter->format('123456123456123456123456123456'))); } diff --git a/tests/Formatter/SingleDigitInstallmentTest.php b/tests/Formatter/SingleDigitInstallmentFormatterTest.php similarity index 75% rename from tests/Formatter/SingleDigitInstallmentTest.php rename to tests/Formatter/SingleDigitInstallmentFormatterTest.php index bb5ee7c..1023c17 100644 --- a/tests/Formatter/SingleDigitInstallmentTest.php +++ b/tests/Formatter/SingleDigitInstallmentFormatterTest.php @@ -1,10 +1,10 @@ assertEquals($expected, $formatter->format($input)); } } diff --git a/tests/Processor/GvpProcessorFactoryTest.php b/tests/Processor/GvpProcessorFactoryTest.php new file mode 100644 index 0000000..1f72243 --- /dev/null +++ b/tests/Processor/GvpProcessorFactoryTest.php @@ -0,0 +1,39 @@ +getMockBuilder(Gvp::class)->getMock(); + $factory = new GvpProcessorFactory($configuration); + $this->assertInstanceOf(SaleResponseProcessor::class, $factory->createProcessor(TransactionType::SALE)); + $this->assertInstanceOf(RefundResponseProcessor::class, $factory->createProcessor(TransactionType::REFUND)); + $this->assertInstanceOf(CancelResponseProcessor::class, $factory->createProcessor(TransactionType::CANCEL)); + $this->assertInstanceOf(PreAuthorizationResponseProcessor::class, $factory->createProcessor(TransactionType::PRE_AUTHORIZATION)); + $this->assertInstanceOf(PostAuthorizationResponseProcessor::class, $factory->createProcessor(TransactionType::POST_AUTHORIZATION)); + } + + public function test_invalid_transaction_type() + { + $this->expectException(InvalidArgumentException::class); + + /** @var Gvp $configuration */ + $configuration = $this->getMockBuilder(Gvp::class)->getMock(); + + $factory = new GvpProcessorFactory($configuration); + $factory->createProcessor('dummy'); + } +} \ No newline at end of file diff --git a/tests/Processor/NestPayProcessorFactoryTest.php b/tests/Processor/NestPayProcessorFactoryTest.php new file mode 100644 index 0000000..ad7e803 --- /dev/null +++ b/tests/Processor/NestPayProcessorFactoryTest.php @@ -0,0 +1,39 @@ +getMockBuilder(NestPay::class)->getMock(); + $factory = new NestPayProcessorFactory($configuration); + $this->assertInstanceOf(SaleResponseProcessor::class, $factory->createProcessor(TransactionType::SALE)); + $this->assertInstanceOf(RefundResponseProcessor::class, $factory->createProcessor(TransactionType::REFUND)); + $this->assertInstanceOf(CancelResponseProcessor::class, $factory->createProcessor(TransactionType::CANCEL)); + $this->assertInstanceOf(PreAuthorizationResponseProcessor::class, $factory->createProcessor(TransactionType::PRE_AUTHORIZATION)); + $this->assertInstanceOf(PostAuthorizationResponseProcessor::class, $factory->createProcessor(TransactionType::POST_AUTHORIZATION)); + } + + public function test_invalid_transaction_type() + { + $this->expectException(InvalidArgumentException::class); + + /** @var NestPay $configuration */ + $configuration = $this->getMockBuilder(NestPay::class)->getMock(); + + $factory = new NestPayProcessorFactory($configuration); + $factory->createProcessor('dummy'); + } +} \ No newline at end of file diff --git a/tests/Processor/PosnetProcessorFactoryTest.php b/tests/Processor/PosnetProcessorFactoryTest.php new file mode 100644 index 0000000..1e248a8 --- /dev/null +++ b/tests/Processor/PosnetProcessorFactoryTest.php @@ -0,0 +1,39 @@ +getMockBuilder(Posnet::class)->getMock(); + $factory = new PosnetProcessorFactory($configuration); + $this->assertInstanceOf(SaleResponseProcessor::class, $factory->createProcessor(TransactionType::SALE)); + $this->assertInstanceOf(RefundResponseProcessor::class, $factory->createProcessor(TransactionType::REFUND)); + $this->assertInstanceOf(CancelResponseProcessor::class, $factory->createProcessor(TransactionType::CANCEL)); + $this->assertInstanceOf(PreAuthorizationResponseProcessor::class, $factory->createProcessor(TransactionType::PRE_AUTHORIZATION)); + $this->assertInstanceOf(PostAuthorizationResponseProcessor::class, $factory->createProcessor(TransactionType::POST_AUTHORIZATION)); + } + + public function test_invalid_transaction_type() + { + $this->expectException(InvalidArgumentException::class); + + /** @var Posnet $configuration */ + $configuration = $this->getMockBuilder(Posnet::class)->getMock(); + + $factory = new PosnetProcessorFactory($configuration); + $factory->createProcessor('dummy'); + } +} \ No newline at end of file diff --git a/tests/samples/request/gvp/cancel_request_with_order.xml b/tests/samples/request/gvp/cancel_request_with_order.xml new file mode 100644 index 0000000..02be6dd --- /dev/null +++ b/tests/samples/request/gvp/cancel_request_with_order.xml @@ -0,0 +1,29 @@ + + + 0.01 + TEST + + PROVRFN + DF1660575E9E8E659538DF74859BBDEB64AAB398 + PROVRFN + 123456 + + + + 123456 + + + + + 127.0.0.1 + dummy@dummy.net + + + void + 1 + + 0 + N + + + diff --git a/tests/samples/request/gvp/cancel_request_with_transaction.xml b/tests/samples/request/gvp/cancel_request_with_transaction.xml new file mode 100644 index 0000000..229010f --- /dev/null +++ b/tests/samples/request/gvp/cancel_request_with_transaction.xml @@ -0,0 +1,29 @@ + + + 0.01 + TEST + + PROVRFN + DF1660575E9E8E659538DF74859BBDEB64AAB398 + PROVRFN + 123456 + + + + 123456 + + + + + 127.0.0.1 + dummy@dummy.net + + + void + 1 + + 0 + N + 123456 + + diff --git a/tests/samples/request/gvp/postauthorization_request.xml b/tests/samples/request/gvp/postauthorization_request.xml new file mode 100644 index 0000000..f524dbb --- /dev/null +++ b/tests/samples/request/gvp/postauthorization_request.xml @@ -0,0 +1,29 @@ + + + 0.01 + TEST + + PROVAUT + B48B719EA434CA8C4B6DEC5097619D8E0D085459 + PROVAUT + 123456 + + + + 123456 + + + + + 127.0.0.1 + dummy@dummy.net + + + postauth + 2540 + 978 + 0 + N + 123456 + + diff --git a/tests/samples/request/gvp/preauthorization_request.xml b/tests/samples/request/gvp/preauthorization_request.xml new file mode 100644 index 0000000..d61f3b0 --- /dev/null +++ b/tests/samples/request/gvp/preauthorization_request.xml @@ -0,0 +1,34 @@ + + + 0.01 + TEST + + PROVAUT + 348329D565140BF80C1DEDCCD56071244B65E4EC + PROVAUT + 123456 + + + + 123456 + + + + + 127.0.0.1 + dummy@dummy.net + + + preauth + 2540 + 978 + 0 + N + + + + 1501501501501500 + 0120 + 000 + + diff --git a/tests/samples/request/gvp/refund_request.xml b/tests/samples/request/gvp/refund_request.xml new file mode 100644 index 0000000..0d3e363 --- /dev/null +++ b/tests/samples/request/gvp/refund_request.xml @@ -0,0 +1,29 @@ + + + 0.01 + TEST + + PROVRFN + 7619068BDDC974E40FD8202B7B60CF411705C1BB + PROVRFN + 123456 + + + + 123456 + + + + + 127.0.0.1 + dummy@dummy.net + + + refund + 2540 + 978 + 0 + N + + + diff --git a/tests/samples/request/gvp/sale_request_eur.xml b/tests/samples/request/gvp/sale_request_eur.xml new file mode 100644 index 0000000..e638d08 --- /dev/null +++ b/tests/samples/request/gvp/sale_request_eur.xml @@ -0,0 +1,35 @@ + + + 0.01 + TEST + + PROVAUT + 348329D565140BF80C1DEDCCD56071244B65E4EC + PROVAUT + 123456 + + + + 123456 + + + + + 127.0.0.1 + dummy@dummy.net + + + sales + + 2540 + 978 + 0 + N + + + + 1501501501501500 + 0120 + 000 + + diff --git a/tests/samples/request/gvp/sale_request_eur_with_installment.xml b/tests/samples/request/gvp/sale_request_eur_with_installment.xml new file mode 100644 index 0000000..3f991ec --- /dev/null +++ b/tests/samples/request/gvp/sale_request_eur_with_installment.xml @@ -0,0 +1,35 @@ + + + 0.01 + TEST + + PROVAUT + 348329D565140BF80C1DEDCCD56071244B65E4EC + PROVAUT + 123456 + + + + 123456 + + + + + 127.0.0.1 + dummy@dummy.net + + + sales + 3 + 2540 + 978 + 0 + N + + + + 1501501501501500 + 0120 + 000 + + diff --git a/tests/samples/request/nestpay/cancel_request_with_order.xml b/tests/samples/request/nestpay/cancel_request_with_order.xml new file mode 100644 index 0000000..8d0cdfe --- /dev/null +++ b/tests/samples/request/nestpay/cancel_request_with_order.xml @@ -0,0 +1,9 @@ + + + TEST + 123456 + TEST + TEST + Void + 123456 + diff --git a/tests/samples/request/nestpay/cancel_request_with_transaction.xml b/tests/samples/request/nestpay/cancel_request_with_transaction.xml new file mode 100644 index 0000000..f3627df --- /dev/null +++ b/tests/samples/request/nestpay/cancel_request_with_transaction.xml @@ -0,0 +1,9 @@ + + + TEST + 123456 + TEST + TEST + Void + 123456 + \ No newline at end of file diff --git a/tests/samples/request/nestpay/postauthorization_request.xml b/tests/samples/request/nestpay/postauthorization_request.xml new file mode 100644 index 0000000..ff16845 --- /dev/null +++ b/tests/samples/request/nestpay/postauthorization_request.xml @@ -0,0 +1,9 @@ + + + TEST + 123456 + TEST + TEST + PostAuth + 123456 + \ No newline at end of file diff --git a/tests/samples/request/nestpay/preauthorization_request.xml b/tests/samples/request/nestpay/preauthorization_request.xml new file mode 100644 index 0000000..6aa8972 --- /dev/null +++ b/tests/samples/request/nestpay/preauthorization_request.xml @@ -0,0 +1,14 @@ + + + TEST + 123456 + TEST + TEST + PreAuth + 123456 + 25.40 + 978 + 1501501501501500 + 000 + 01/2020 + diff --git a/tests/samples/request/nestpay/refund_request_full.xml b/tests/samples/request/nestpay/refund_request_full.xml new file mode 100644 index 0000000..964c4d3 --- /dev/null +++ b/tests/samples/request/nestpay/refund_request_full.xml @@ -0,0 +1,9 @@ + + + TEST + 123456 + TEST + TEST + Credit + 123456 + \ No newline at end of file diff --git a/tests/samples/request/nestpay/refund_request_partial.xml b/tests/samples/request/nestpay/refund_request_partial.xml new file mode 100644 index 0000000..e9b0656 --- /dev/null +++ b/tests/samples/request/nestpay/refund_request_partial.xml @@ -0,0 +1,11 @@ + + + TEST + 123456 + TEST + TEST + Credit + 123456 + 25.40 + 978 + \ No newline at end of file diff --git a/tests/samples/request/nestpay/sale_request_eur.xml b/tests/samples/request/nestpay/sale_request_eur.xml new file mode 100644 index 0000000..b5f9ff3 --- /dev/null +++ b/tests/samples/request/nestpay/sale_request_eur.xml @@ -0,0 +1,14 @@ + + + TEST + 123456 + TEST + TEST + Auth + 123456 + 25.40 + 978 + 1501501501501500 + 000 + 01/2020 + \ No newline at end of file diff --git a/tests/samples/request/nestpay/sale_request_eur_with_installment.xml b/tests/samples/request/nestpay/sale_request_eur_with_installment.xml new file mode 100644 index 0000000..d1d519f --- /dev/null +++ b/tests/samples/request/nestpay/sale_request_eur_with_installment.xml @@ -0,0 +1,15 @@ + + + TEST + 123456 + TEST + TEST + Auth + 123456 + 25.40 + 978 + 1501501501501500 + 000 + 01/2020 + 3 + \ No newline at end of file diff --git a/tests/samples/request/posnet/cancel_request.xml b/tests/samples/request/posnet/cancel_request.xml new file mode 100644 index 0000000..ecba9c2 --- /dev/null +++ b/tests/samples/request/posnet/cancel_request.xml @@ -0,0 +1,12 @@ + + + 213456 + 654321 + TEST + TEST + + sale + 12345678901 + 000000 + + diff --git a/tests/samples/request/posnet/post_authorization_request_eur.xml b/tests/samples/request/posnet/post_authorization_request_eur.xml new file mode 100644 index 0000000..23ebb62 --- /dev/null +++ b/tests/samples/request/posnet/post_authorization_request_eur.xml @@ -0,0 +1,12 @@ + + + 213456 + 654321 + TEST + TEST + + 2540 + EU + 12345678901 + + diff --git a/tests/samples/request/posnet/post_authorization_request_eur_with_installment.xml b/tests/samples/request/posnet/post_authorization_request_eur_with_installment.xml new file mode 100644 index 0000000..0d75e1f --- /dev/null +++ b/tests/samples/request/posnet/post_authorization_request_eur_with_installment.xml @@ -0,0 +1,13 @@ + + + 213456 + 654321 + TEST + TEST + + 2540 + EU + 12345678901 + 03 + + diff --git a/tests/samples/request/posnet/pre_authorization_request_eur.xml b/tests/samples/request/posnet/pre_authorization_request_eur.xml new file mode 100644 index 0000000..30e39a4 --- /dev/null +++ b/tests/samples/request/posnet/pre_authorization_request_eur.xml @@ -0,0 +1,15 @@ + + + 213456 + 654321 + TEST + TEST + + 2540 + EU + 000000000000000000123456 + 1501501501501500 + 000 + 2001 + + diff --git a/tests/samples/request/posnet/pre_authorization_request_eur_with_installment.xml b/tests/samples/request/posnet/pre_authorization_request_eur_with_installment.xml new file mode 100644 index 0000000..d0d6610 --- /dev/null +++ b/tests/samples/request/posnet/pre_authorization_request_eur_with_installment.xml @@ -0,0 +1,16 @@ + + + 213456 + 654321 + TEST + TEST + + 2540 + EU + 000000000000000000123456 + 1501501501501500 + 000 + 2001 + 03 + + diff --git a/tests/samples/request/posnet/refund_request.xml b/tests/samples/request/posnet/refund_request.xml new file mode 100644 index 0000000..73b44b7 --- /dev/null +++ b/tests/samples/request/posnet/refund_request.xml @@ -0,0 +1,12 @@ + + + 213456 + 654321 + TEST + TEST + + 2540 + EU + 12345678901 + + diff --git a/tests/samples/request/posnet/sale_request_eur.xml b/tests/samples/request/posnet/sale_request_eur.xml new file mode 100644 index 0000000..cafc20b --- /dev/null +++ b/tests/samples/request/posnet/sale_request_eur.xml @@ -0,0 +1,15 @@ + + + 213456 + 654321 + TEST + TEST + + 2540 + EU + 000000000000000000123456 + 1501501501501500 + 000 + 2001 + + diff --git a/tests/samples/request/posnet/sale_request_eur_with_installment.xml b/tests/samples/request/posnet/sale_request_eur_with_installment.xml new file mode 100644 index 0000000..e7fd21f --- /dev/null +++ b/tests/samples/request/posnet/sale_request_eur_with_installment.xml @@ -0,0 +1,16 @@ + + + 213456 + 654321 + TEST + TEST + + 2540 + EU + 000000000000000000123456 + 1501501501501500 + 000 + 2001 + 03 + +