From 578f2b4ca008c2fef3e12a1546a4fccb1483f841 Mon Sep 17 00:00:00 2001 From: Ibrahim Gunduz Date: Tue, 1 May 2018 14:11:48 +0000 Subject: [PATCH] Created processor tests --- src/Event/TransactionEvent.php | 99 ------------------- src/Pos/AbstractPos.php | 46 ++++----- src/Processor/Gvp/BaseResponseProcessor.php | 17 +++- .../Posnet/BaseResponseProcessor.php | 7 +- .../Gvp/CancelResponseProcessorTest.php | 71 +++++++++++++ ...PostAuthorizationResponseProcessorTest.php | 71 +++++++++++++ .../PreAuthorizationResponseProcessorTest.php | 71 +++++++++++++ .../Gvp/RefundResponseProcessorTest.php | 71 +++++++++++++ .../Gvp/SaleResponseProcessorTest.php | 71 +++++++++++++ .../Posnet/CancelResponseProcessorTest.php | 71 +++++++++++++ ...PostAuthorizationResponseProcessorTest.php | 71 +++++++++++++ .../PreAuthorizationResponseProcessorTest.php | 71 +++++++++++++ .../Posnet/RefundResponseProcessorTest.php | 71 +++++++++++++ .../Posnet/SaleResponseProcessorTest.php | 71 +++++++++++++ tests/samples/response/gvp/cancel_failed.xml | 42 ++++++++ .../response/gvp/cancel_successful.xml | 42 ++++++++ .../gvp/post_authorization_failed.xml | 31 ++++++ .../gvp/post_authorization_successful.xml | 32 ++++++ .../response/gvp/pre_authorization_failed.xml | 42 ++++++++ .../gvp/pre_authorization_successful.xml | 42 ++++++++ tests/samples/response/gvp/refund_failed.xml | 35 +++++++ .../response/gvp/refund_successful.xml | 42 ++++++++ tests/samples/response/gvp/sale_failed.xml | 42 ++++++++ .../samples/response/gvp/sale_successful.xml | 42 ++++++++ .../samples/response/posnet/cancel_failed.xml | 6 ++ .../response/posnet/cancel_successful.xml | 6 ++ .../posnet/post_authorization_failed.xml | 6 ++ .../posnet/post_authorization_successful.xml | 39 ++++++++ .../posnet/pre_authorization_failed.xml | 6 ++ .../posnet/pre_authorization_successful.xml | 39 ++++++++ .../samples/response/posnet/refund_failed.xml | 6 ++ .../response/posnet/refund_successful.xml | 39 ++++++++ tests/samples/response/posnet/sale_failed.xml | 6 ++ .../response/posnet/sale_successful.xml | 39 ++++++++ 34 files changed, 1329 insertions(+), 134 deletions(-) delete mode 100644 src/Event/TransactionEvent.php create mode 100644 tests/Processor/Gvp/CancelResponseProcessorTest.php create mode 100644 tests/Processor/Gvp/PostAuthorizationResponseProcessorTest.php create mode 100644 tests/Processor/Gvp/PreAuthorizationResponseProcessorTest.php create mode 100644 tests/Processor/Gvp/RefundResponseProcessorTest.php create mode 100644 tests/Processor/Gvp/SaleResponseProcessorTest.php create mode 100644 tests/Processor/Posnet/CancelResponseProcessorTest.php create mode 100644 tests/Processor/Posnet/PostAuthorizationResponseProcessorTest.php create mode 100644 tests/Processor/Posnet/PreAuthorizationResponseProcessorTest.php create mode 100644 tests/Processor/Posnet/RefundResponseProcessorTest.php create mode 100644 tests/Processor/Posnet/SaleResponseProcessorTest.php create mode 100644 tests/samples/response/gvp/cancel_failed.xml create mode 100644 tests/samples/response/gvp/cancel_successful.xml create mode 100644 tests/samples/response/gvp/post_authorization_failed.xml create mode 100644 tests/samples/response/gvp/post_authorization_successful.xml create mode 100644 tests/samples/response/gvp/pre_authorization_failed.xml create mode 100644 tests/samples/response/gvp/pre_authorization_successful.xml create mode 100644 tests/samples/response/gvp/refund_failed.xml create mode 100644 tests/samples/response/gvp/refund_successful.xml create mode 100644 tests/samples/response/gvp/sale_failed.xml create mode 100644 tests/samples/response/gvp/sale_successful.xml create mode 100644 tests/samples/response/posnet/cancel_failed.xml create mode 100644 tests/samples/response/posnet/cancel_successful.xml create mode 100644 tests/samples/response/posnet/post_authorization_failed.xml create mode 100644 tests/samples/response/posnet/post_authorization_successful.xml create mode 100644 tests/samples/response/posnet/pre_authorization_failed.xml create mode 100644 tests/samples/response/posnet/pre_authorization_successful.xml create mode 100644 tests/samples/response/posnet/refund_failed.xml create mode 100644 tests/samples/response/posnet/refund_successful.xml create mode 100644 tests/samples/response/posnet/sale_failed.xml create mode 100644 tests/samples/response/posnet/sale_successful.xml diff --git a/src/Event/TransactionEvent.php b/src/Event/TransactionEvent.php deleted file mode 100644 index 7119b82..0000000 --- a/src/Event/TransactionEvent.php +++ /dev/null @@ -1,99 +0,0 @@ -request = $request; - $this->response = $response; - $this->transactionType = $transactionType; - $this->exception = $exception; - } - - /** - * @param \Exception $exception - */ - public function setException($exception) - { - $this->exception = $exception; - } - - /** - * @return \Exception - */ - public function getException() - { - return $this->exception; - } - - /** - * @param \Paranoia\Request $request - */ - public function setRequest($request) - { - $this->request = $request; - } - - /** - * @return \Paranoia\Request - */ - public function getRequest() - { - return $this->request; - } - - /** - * @param \Paranoia\Response\ResponseInterface $response - */ - public function setResponse($response) - { - $this->response = $response; - } - - /** - * @return \Paranoia\Response\ResponseInterface - */ - public function getResponse() - { - return $this->response; - } - - /** - * @param string $transactionType - */ - public function setTransactionType($transactionType) - { - $this->transactionType = $transactionType; - } - - /** - * @return string - */ - public function getTransactionType() - { - return $this->transactionType; - } -} diff --git a/src/Pos/AbstractPos.php b/src/Pos/AbstractPos.php index 99db0e3..c02c7c2 100644 --- a/src/Pos/AbstractPos.php +++ b/src/Pos/AbstractPos.php @@ -7,6 +7,7 @@ use Paranoia\Exception\CommunicationError; use Paranoia\Request; use Paranoia\TransactionType; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; abstract class AbstractPos { @@ -15,6 +16,8 @@ abstract class AbstractPos */ protected $configuration; + /** @var EventDispatcherInterface */ + private $dispatcher; public function __construct(AbstractConfiguration $configuration) { @@ -68,6 +71,14 @@ protected function sendRequest($url, $data, $options = null) } } + private function performTransaction(Request $request, $transactionType) + { + $rawRequest = $this->buildRequest($request, $transactionType); + $rawResponse = $this->sendRequest($this->configuration->getApiUrl(), $rawRequest); + $response = $this->parseResponse($rawResponse, $transactionType); + return $response; + } + /** * @param \Paranoia\Request $request * @@ -75,10 +86,7 @@ protected function sendRequest($url, $data, $options = null) */ public function preAuthorization(Request $request) { - $rawRequest = $this->buildRequest($request, TransactionType::PRE_AUTHORIZATION); - $rawResponse = $this->sendRequest($this->configuration->getApiUrl(), $rawRequest); - $response = $this->parseResponse($rawResponse, TransactionType::PRE_AUTHORIZATION); - return $response; + return $this->performTransaction($request, TransactionType::PRE_AUTHORIZATION); } /** @@ -88,10 +96,7 @@ public function preAuthorization(Request $request) */ public function postAuthorization(Request $request) { - $rawRequest = $this->buildRequest($request, TransactionType::POST_AUTHORIZATION); - $rawResponse = $this->sendRequest($this->configuration->getApiUrl(), $rawRequest); - $response = $this->parseResponse($rawResponse, TransactionType::POST_AUTHORIZATION); - return $response; + return $this->performTransaction($request, TransactionType::POST_AUTHORIZATION); } /** @@ -101,10 +106,7 @@ public function postAuthorization(Request $request) */ public function sale(Request $request) { - $rawRequest = $this->buildRequest($request, TransactionType::SALE); - $rawResponse = $this->sendRequest($this->configuration->getApiUrl(), $rawRequest); - $response = $this->parseResponse($rawResponse, TransactionType::SALE); - return $response; + return $this->performTransaction($request, TransactionType::SALE); } /** @@ -114,10 +116,7 @@ public function sale(Request $request) */ public function refund(Request $request) { - $rawRequest = $this->buildRequest($request, TransactionType::REFUND); - $rawResponse = $this->sendRequest($this->configuration->getApiUrl(), $rawRequest); - $response = $this->parseResponse($rawResponse, TransactionType::REFUND); - return $response; + return $this->performTransaction($request, TransactionType::REFUND); } /** @@ -127,10 +126,7 @@ public function refund(Request $request) */ public function cancel(Request $request) { - $rawRequest = $this->buildRequest($request, TransactionType::CANCEL); - $rawResponse = $this->sendRequest($this->configuration->getApiUrl(), $rawRequest); - $response = $this->parseResponse($rawResponse, TransactionType::CANCEL); - return $response; + return $this->performTransaction($request, TransactionType::CANCEL); } /** @@ -140,10 +136,7 @@ public function cancel(Request $request) */ public function pointQuery(Request $request) { - $rawRequest = $this->buildRequest($request, TransactionType::POINT_INQUIRY); - $rawResponse = $this->sendRequest($this->configuration->getApiUrl(), $rawRequest); - $response = $this->parseResponse($rawResponse, TransactionType::POINT_INQUIRY); - return $response; + return $this->performTransaction($request, TransactionType::POINT_INQUIRY); } /** @@ -153,9 +146,6 @@ public function pointQuery(Request $request) */ public function pointUsage(Request $request) { - $rawRequest = $this->buildRequest($request, TransactionType::POINT_USAGE); - $rawResponse = $this->sendRequest($this->configuration->getApiUrl(), $rawRequest); - $response = $this->parseResponse($rawResponse, TransactionType::POINT_USAGE); - return $response; + return $this->performTransaction($request, TransactionType::POINT_USAGE); } } diff --git a/src/Processor/Gvp/BaseResponseProcessor.php b/src/Processor/Gvp/BaseResponseProcessor.php index c1989db..c66d46a 100644 --- a/src/Processor/Gvp/BaseResponseProcessor.php +++ b/src/Processor/Gvp/BaseResponseProcessor.php @@ -36,8 +36,19 @@ private function prepareErrorDetails(\SimpleXMLElement $xml, PaymentResponse $re */ private function prepareTransactionDetails(\SimpleXMLElement $xml, PaymentResponse $response) { - $response->setOrderId((string)$xml->Order->OrderID); - $response->setTransactionId((string)$xml->Transaction->RetrefNum); + if (property_exists($xml, 'Order') && property_exists($xml->Order, 'OrderID')) { + $response->setOrderId((string)$xml->Order->OrderID); + } + + if (property_exists($xml, 'Transaction')) { + if (property_exists($xml->Transaction, 'RetrefNum')) { + $response->setTransactionId((string)$xml->Transaction->RetrefNum); + } + + if (property_exists($xml->Transaction, 'AuthCode')) { + $response->setAuthCode((string)$xml->Transaction->AuthCode); + } + } } /** @@ -57,7 +68,7 @@ protected function processCommonResponse($rawResponse) } $this->validateResponse($xml); $response->setIsSuccess('00' == (string)$xml->Transaction->Response->Code); - $response->setResponseCode((string)$xml->Transaction->ReasonCode); + $response->setResponseCode((string)$xml->Transaction->Response->ReasonCode); if (!$response->isSuccess()) { $this->prepareErrorDetails($xml, $response); } else { diff --git a/src/Processor/Posnet/BaseResponseProcessor.php b/src/Processor/Posnet/BaseResponseProcessor.php index 9bea6c0..5ca3fe1 100644 --- a/src/Processor/Posnet/BaseResponseProcessor.php +++ b/src/Processor/Posnet/BaseResponseProcessor.php @@ -13,13 +13,12 @@ abstract class BaseResponseProcessor extends AbstractResponseProcessor */ private function prepareErrorDetails(\SimpleXMLElement $xml, PaymentResponse $response) { - $response->setResponseCode((string)$xml->respCode); $errorMessages = array(); if (property_exists($xml, 'respCode')) { - $errorMessages[] = sprintf('Error: %s', (string)$xml->respCode); + $response->setResponseCode((string)$xml->respCode); } if (property_exists($xml, 'respText')) { - $errorMessages[] = sprintf('Error Message: %s ', (string)$xml->respText); + $errorMessages[] = sprintf('%s ', (string)$xml->respText); } $errorMessage = implode(' ', $errorMessages); $response->setResponseMessage($errorMessage); @@ -36,7 +35,7 @@ private function prepareTransactionDetails(\SimpleXMLElement $xml, PaymentRespon } $response->setTransactionId((string)$xml->hostlogkey); if (property_exists($xml, 'authCode')) { - $response->setOrderId((string)$xml->authCode); + $response->setAuthCode((string)$xml->authCode); } } diff --git a/tests/Processor/Gvp/CancelResponseProcessorTest.php b/tests/Processor/Gvp/CancelResponseProcessorTest.php new file mode 100644 index 0000000..9490b66 --- /dev/null +++ b/tests/Processor/Gvp/CancelResponseProcessorTest.php @@ -0,0 +1,71 @@ +getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new CancelResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(true, $response->isSuccess()); + $this->assertEquals('311616674771', $response->getTransactionId()); + $this->assertEquals('489787', $response->getAuthCode()); + $this->assertEquals('1476', $response->getOrderId()); + } + + public function test_failed_response() + { + $rawResponse = file_get_contents( + __DIR__ . '/../../samples/response/gvp/cancel_failed.xml' + ); + + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new CancelResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(false, $response->isSuccess()); + $this->assertEquals(null, $response->getTransactionId()); + $this->assertEquals(null, $response->getOrderId()); + $this->assertEquals('0202', $response->getResponseCode()); + $this->assertEquals('Error Message: ›ptal edebileceiniz birden fazla i˛lem var, RRN bilgisi gonderi System Error Message: ErrorId: 0202', $response->getResponseMessage()); + } + + /** + * @dataProvider badResponses + * @param string $rawResponse + */ + public function test_bad_response($rawResponse) + { + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new CancelResponseProcessor($configuration); + + $this->expectException(BadResponseException::class); + $processor->process($rawResponse); + } + + public function badResponses() + { + return [ + [null], + [''], + ['DUMMY'], + [1], + ]; + } + +} diff --git a/tests/Processor/Gvp/PostAuthorizationResponseProcessorTest.php b/tests/Processor/Gvp/PostAuthorizationResponseProcessorTest.php new file mode 100644 index 0000000..0596ac4 --- /dev/null +++ b/tests/Processor/Gvp/PostAuthorizationResponseProcessorTest.php @@ -0,0 +1,71 @@ +getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new PostAuthorizationResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(true, $response->isSuccess()); + $this->assertEquals('105809652539', $response->getTransactionId()); + $this->assertEquals('914729', $response->getAuthCode()); + $this->assertEquals('SIST2E8748F43EA24754912E365D637B91D8', $response->getOrderId()); + } + + public function test_failed_response() + { + $rawResponse = file_get_contents( + __DIR__ . '/../../samples/response/gvp/post_authorization_failed.xml' + ); + + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new PostAuthorizationResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(false, $response->isSuccess()); + $this->assertEquals(null, $response->getTransactionId()); + $this->assertEquals(null, $response->getOrderId()); + $this->assertEquals('54', $response->getResponseCode()); + $this->assertEquals('Error Message: ›˛leminizi gerÁekle˛tiremiyoruz.Tekrar deneyiniz System Error Message: SON KULLANMA TARIHI HATALI', $response->getResponseMessage()); + } + + /** + * @dataProvider badResponses + * @param string $rawResponse + */ + public function test_bad_response($rawResponse) + { + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new PostAuthorizationResponseProcessor($configuration); + + $this->expectException(BadResponseException::class); + $processor->process($rawResponse); + } + + public function badResponses() + { + return [ + [null], + [''], + ['DUMMY'], + [1], + ]; + } + +} diff --git a/tests/Processor/Gvp/PreAuthorizationResponseProcessorTest.php b/tests/Processor/Gvp/PreAuthorizationResponseProcessorTest.php new file mode 100644 index 0000000..f4b5db1 --- /dev/null +++ b/tests/Processor/Gvp/PreAuthorizationResponseProcessorTest.php @@ -0,0 +1,71 @@ +getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new PreAuthorizationResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(true, $response->isSuccess()); + $this->assertEquals('311710676052', $response->getTransactionId()); + $this->assertEquals('412290', $response->getAuthCode()); + $this->assertEquals('SISTFA03907C0DB14A38B3BA380722891160', $response->getOrderId()); + } + + public function test_failed_response() + { + $rawResponse = file_get_contents( + __DIR__ . '/../../samples/response/gvp/pre_authorization_failed.xml' + ); + + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new PreAuthorizationResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(false, $response->isSuccess()); + $this->assertEquals(null, $response->getTransactionId()); + $this->assertEquals(null, $response->getOrderId()); + $this->assertEquals('54', $response->getResponseCode()); + $this->assertEquals('Error Message: ›˛leminizi gerÁekle˛tiremiyoruz.Tekrar deneyiniz System Error Message: SON KULLANMA TARIHI HATALI', $response->getResponseMessage()); + } + + /** + * @dataProvider badResponses + * @param string $rawResponse + */ + public function test_bad_response($rawResponse) + { + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new PreAuthorizationResponseProcessor($configuration); + + $this->expectException(BadResponseException::class); + $processor->process($rawResponse); + } + + public function badResponses() + { + return [ + [null], + [''], + ['DUMMY'], + [1], + ]; + } + +} diff --git a/tests/Processor/Gvp/RefundResponseProcessorTest.php b/tests/Processor/Gvp/RefundResponseProcessorTest.php new file mode 100644 index 0000000..a4163ea --- /dev/null +++ b/tests/Processor/Gvp/RefundResponseProcessorTest.php @@ -0,0 +1,71 @@ +getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new RefundResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(true, $response->isSuccess()); + $this->assertEquals('311616674771', $response->getTransactionId()); + $this->assertEquals('489787', $response->getAuthCode()); + $this->assertEquals('1476', $response->getOrderId()); + } + + public function test_failed_response() + { + $rawResponse = file_get_contents( + __DIR__ . '/../../samples/response/gvp/refund_failed.xml' + ); + + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new RefundResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(false, $response->isSuccess()); + $this->assertEquals(null, $response->getTransactionId()); + $this->assertEquals(null, $response->getOrderId()); + $this->assertEquals('0214', $response->getResponseCode()); + $this->assertEquals('Error Message: ›ade tutar˝, sat˝˛ tutar˝ndan b¸y¸k olamaz System Error Message: ErrorId: 0214', $response->getResponseMessage()); + } + + /** + * @dataProvider badResponses + * @param string $rawResponse + */ + public function test_bad_response($rawResponse) + { + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new RefundResponseProcessor($configuration); + + $this->expectException(BadResponseException::class); + $processor->process($rawResponse); + } + + public function badResponses() + { + return [ + [null], + [''], + ['DUMMY'], + [1], + ]; + } + +} diff --git a/tests/Processor/Gvp/SaleResponseProcessorTest.php b/tests/Processor/Gvp/SaleResponseProcessorTest.php new file mode 100644 index 0000000..5475673 --- /dev/null +++ b/tests/Processor/Gvp/SaleResponseProcessorTest.php @@ -0,0 +1,71 @@ +getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new SaleResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(true, $response->isSuccess()); + $this->assertEquals('311710676028', $response->getTransactionId()); + $this->assertEquals('245093', $response->getAuthCode()); + $this->assertEquals('SISTC157B93B81C74BB88C6CA1C15D0CA338', $response->getOrderId()); + } + + public function test_failed_response() + { + $rawResponse = file_get_contents( + __DIR__ . '/../../samples/response/gvp/sale_failed.xml' + ); + + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new SaleResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(false, $response->isSuccess()); + $this->assertEquals(null, $response->getTransactionId()); + $this->assertEquals(null, $response->getOrderId()); + $this->assertEquals('54', $response->getResponseCode()); + $this->assertEquals('Error Message: ›˛leminizi gerÁekle˛tiremiyoruz.Tekrar deneyiniz System Error Message: SON KULLANMA TARIHI HATALI', $response->getResponseMessage()); + } + + /** + * @dataProvider badResponses + * @param string $rawResponse + */ + public function test_bad_response($rawResponse) + { + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new SaleResponseProcessor($configuration); + + $this->expectException(BadResponseException::class); + $processor->process($rawResponse); + } + + public function badResponses() + { + return [ + [null], + [''], + ['DUMMY'], + [1], + ]; + } + +} diff --git a/tests/Processor/Posnet/CancelResponseProcessorTest.php b/tests/Processor/Posnet/CancelResponseProcessorTest.php new file mode 100644 index 0000000..42f10a5 --- /dev/null +++ b/tests/Processor/Posnet/CancelResponseProcessorTest.php @@ -0,0 +1,71 @@ +getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new CancelResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(true, $response->isSuccess()); + $this->assertEquals('0001000009P0503281', $response->getTransactionId()); + $this->assertEquals('000000', $response->getAuthCode()); + $this->assertEquals(null, $response->getOrderId()); + } + + public function test_failed_response() + { + $rawResponse = file_get_contents( + __DIR__ . '/../../samples/response/posnet/cancel_failed.xml' + ); + + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new CancelResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(false, $response->isSuccess()); + $this->assertEquals(null, $response->getTransactionId()); + $this->assertEquals(null, $response->getOrderId()); + $this->assertEquals('0225', $response->getResponseCode()); + $this->assertEquals('ONAYLANMADI:0225 ISL. YAPILAMIY 0225 ', $response->getResponseMessage()); + } + + /** + * @dataProvider badResponses + * @param string $rawResponse + */ + public function test_bad_response($rawResponse) + { + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new CancelResponseProcessor($configuration); + + $this->expectException(BadResponseException::class); + $processor->process($rawResponse); + } + + public function badResponses() + { + return [ + [null], + [''], + ['DUMMY'], + [1], + ]; + } + +} diff --git a/tests/Processor/Posnet/PostAuthorizationResponseProcessorTest.php b/tests/Processor/Posnet/PostAuthorizationResponseProcessorTest.php new file mode 100644 index 0000000..5eaab1a --- /dev/null +++ b/tests/Processor/Posnet/PostAuthorizationResponseProcessorTest.php @@ -0,0 +1,71 @@ +getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new PostAuthorizationResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(true, $response->isSuccess()); + $this->assertEquals('0001000004P0503281', $response->getTransactionId()); + $this->assertEquals('007912', $response->getAuthCode()); + $this->assertEquals(null, $response->getOrderId()); // Posnet does not provide orderId + } + + public function test_failed_response() + { + $rawResponse = file_get_contents( + __DIR__ . '/../../samples/response/posnet/post_authorization_failed.xml' + ); + + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new PostAuthorizationResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(false, $response->isSuccess()); + $this->assertEquals(null, $response->getTransactionId()); + $this->assertEquals(null, $response->getOrderId()); + $this->assertEquals('0225', $response->getResponseCode()); + $this->assertEquals('ONAYLANMADI:0225 ISL. YAPILAMIY 0225 ', $response->getResponseMessage()); + } + + /** + * @dataProvider badResponses + * @param string $rawResponse + */ + public function test_bad_response($rawResponse) + { + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new PostAuthorizationResponseProcessor($configuration); + + $this->expectException(BadResponseException::class); + $processor->process($rawResponse); + } + + public function badResponses() + { + return [ + [null], + [''], + ['DUMMY'], + [1], + ]; + } + +} diff --git a/tests/Processor/Posnet/PreAuthorizationResponseProcessorTest.php b/tests/Processor/Posnet/PreAuthorizationResponseProcessorTest.php new file mode 100644 index 0000000..9ffef22 --- /dev/null +++ b/tests/Processor/Posnet/PreAuthorizationResponseProcessorTest.php @@ -0,0 +1,71 @@ +getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new PreAuthorizationResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(true, $response->isSuccess()); + $this->assertEquals('0001000004P0503281', $response->getTransactionId()); + $this->assertEquals('007912', $response->getAuthCode()); + $this->assertEquals(null, $response->getOrderId()); // Posnet does not provide orderId + } + + public function test_failed_response() + { + $rawResponse = file_get_contents( + __DIR__ . '/../../samples/response/posnet/pre_authorization_failed.xml' + ); + + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new PreAuthorizationResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(false, $response->isSuccess()); + $this->assertEquals(null, $response->getTransactionId()); + $this->assertEquals(null, $response->getOrderId()); + $this->assertEquals('0225', $response->getResponseCode()); + $this->assertEquals('ONAYLANMADI:0225 ISL. YAPILAMIY 0225 ', $response->getResponseMessage()); + } + + /** + * @dataProvider badResponses + * @param string $rawResponse + */ + public function test_bad_response($rawResponse) + { + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new PreAuthorizationResponseProcessor($configuration); + + $this->expectException(BadResponseException::class); + $processor->process($rawResponse); + } + + public function badResponses() + { + return [ + [null], + [''], + ['DUMMY'], + [1], + ]; + } + +} diff --git a/tests/Processor/Posnet/RefundResponseProcessorTest.php b/tests/Processor/Posnet/RefundResponseProcessorTest.php new file mode 100644 index 0000000..dba2239 --- /dev/null +++ b/tests/Processor/Posnet/RefundResponseProcessorTest.php @@ -0,0 +1,71 @@ +getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new RefundResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(true, $response->isSuccess()); + $this->assertEquals('0001000004P0503281', $response->getTransactionId()); + $this->assertEquals('007912', $response->getAuthCode()); + $this->assertEquals(null, $response->getOrderId()); + } + + public function test_failed_response() + { + $rawResponse = file_get_contents( + __DIR__ . '/../../samples/response/posnet/refund_failed.xml' + ); + + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new RefundResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(false, $response->isSuccess()); + $this->assertEquals(null, $response->getTransactionId()); + $this->assertEquals(null, $response->getOrderId()); + $this->assertEquals('0225', $response->getResponseCode()); + $this->assertEquals('ONAYLANMADI:0225 ISL. YAPILAMIY 0225 ', $response->getResponseMessage()); + } + + /** + * @dataProvider badResponses + * @param string $rawResponse + */ + public function test_bad_response($rawResponse) + { + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new RefundResponseProcessor($configuration); + + $this->expectException(BadResponseException::class); + $processor->process($rawResponse); + } + + public function badResponses() + { + return [ + [null], + [''], + ['DUMMY'], + [1], + ]; + } + +} diff --git a/tests/Processor/Posnet/SaleResponseProcessorTest.php b/tests/Processor/Posnet/SaleResponseProcessorTest.php new file mode 100644 index 0000000..aec24c5 --- /dev/null +++ b/tests/Processor/Posnet/SaleResponseProcessorTest.php @@ -0,0 +1,71 @@ +getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new SaleResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(true, $response->isSuccess()); + $this->assertEquals('0001000004P0503281', $response->getTransactionId()); + $this->assertEquals('007912', $response->getAuthCode()); + $this->assertEquals(null, $response->getOrderId()); // Posnet does not provide orderId + } + + public function test_failed_response() + { + $rawResponse = file_get_contents( + __DIR__ . '/../../samples/response/posnet/sale_failed.xml' + ); + + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new SaleResponseProcessor($configuration); + $response = $processor->process($rawResponse); + $this->assertInstanceOf(PaymentResponse::class, $response); + $this->assertEquals(false, $response->isSuccess()); + $this->assertEquals(null, $response->getTransactionId()); + $this->assertEquals(null, $response->getOrderId()); + $this->assertEquals('0225', $response->getResponseCode()); + $this->assertEquals('ONAYLANMADI:0225 ISL. YAPILAMIY 0225 ', $response->getResponseMessage()); + } + + /** + * @dataProvider badResponses + * @param string $rawResponse + */ + public function test_bad_response($rawResponse) + { + /** @var AbstractConfiguration $configuration */ + $configuration = $this->getMockBuilder(AbstractConfiguration::class)->getMock(); + $processor = new SaleResponseProcessor($configuration); + + $this->expectException(BadResponseException::class); + $processor->process($rawResponse); + } + + public function badResponses() + { + return [ + [null], + [''], + ['DUMMY'], + [1], + ]; + } + +} diff --git a/tests/samples/response/gvp/cancel_failed.xml b/tests/samples/response/gvp/cancel_failed.xml new file mode 100644 index 0000000..508b5d5 --- /dev/null +++ b/tests/samples/response/gvp/cancel_failed.xml @@ -0,0 +1,42 @@ + + + + + PROVRFN + XXXX + 30691292 + 3424113 + + + 127.0.0.1 + eticaret@garanti.com.tr + + + 1476 + + + + + GVPS + 92 + 0202 + Declined + ›ptal edebileceiniz birden fazla i˛lem var, RRN bilgisi gonderi + ErrorId: 0202 + + 311617674819 + + 000008 + 000038 + 20130426 17:16:51 + 554960******3012 + + + 6FD41A05196DB5EB6145D6DF1720F881DCC9AAB9 + + + + + + + \ No newline at end of file diff --git a/tests/samples/response/gvp/cancel_successful.xml b/tests/samples/response/gvp/cancel_successful.xml new file mode 100644 index 0000000..83063e0 --- /dev/null +++ b/tests/samples/response/gvp/cancel_successful.xml @@ -0,0 +1,42 @@ + + + + + PROVRFN + XXXX + 30691292 + 3424113 + + + 127.0.0.1 + eticaret@garanti.com.tr + + + 1476 + + + + + HOST + 00 + 00 + Approved + + + + 311616674771 + 489787 + 000008 + 000029 + 20130426 16:55:31 + 554960******3012 + + BONUS + D73C3E2106BCAD517CB1F7C20ECF3B8279C14868 + + + + + + + \ No newline at end of file diff --git a/tests/samples/response/gvp/post_authorization_failed.xml b/tests/samples/response/gvp/post_authorization_failed.xml new file mode 100644 index 0000000..6c64214 --- /dev/null +++ b/tests/samples/response/gvp/post_authorization_failed.xml @@ -0,0 +1,31 @@ + + + + + SISTE20C15E38F1446AF92DABFB4059E87F6 + + + + + HOST + 54 + 54 + Declined + ›˛leminizi gerÁekle˛tiremiyoruz.Tekrar deneyiniz + SON KULLANMA TARIHI HATALI + + 105809652540 + + 000574 + 000510 + 20110227 09:40:48 + + HA*** YIL*** + 8D8E2BE7FC080AD985CA0506C50479035FC2C206 + + + + + + + \ No newline at end of file diff --git a/tests/samples/response/gvp/post_authorization_successful.xml b/tests/samples/response/gvp/post_authorization_successful.xml new file mode 100644 index 0000000..995000e --- /dev/null +++ b/tests/samples/response/gvp/post_authorization_successful.xml @@ -0,0 +1,32 @@ + + + + + SIST2E8748F43EA24754912E365D637B91D8 + + + + + HOST + 00 + 00 + Approved + + + + 105809652539 + 914729 + 000574 + 000509 + 20110227 09:26:12 + + HA*** YIL*** + 6F39EA85C6A5BBA9040F40FA7C8F199C70D7343A + + + + + + + + \ No newline at end of file diff --git a/tests/samples/response/gvp/pre_authorization_failed.xml b/tests/samples/response/gvp/pre_authorization_failed.xml new file mode 100644 index 0000000..6813506 --- /dev/null +++ b/tests/samples/response/gvp/pre_authorization_failed.xml @@ -0,0 +1,42 @@ + + + + + PROVAUT + XXXX + 30691292 + 3424113 + + + 127.0.0.1 + eticaret@garanti.com.tr + + + SISTF94AC1AC943B4FE8BBB8B20FB82FA7BB + + + + + HOST + 54 + 54 + Declined + ›˛leminizi gerÁekle˛tiremiyoruz.Tekrar deneyiniz + SON KULLANMA TARIHI HATALI + + 311710676031 + + 000008 + 000052 + 20130427 10:26:04 + 554960******3012 + PE*** PEL** TON*** + BONUS + D2F5BA37A98C5DDDC34B28FA56FF03FC782713BD + + + + + + + diff --git a/tests/samples/response/gvp/pre_authorization_successful.xml b/tests/samples/response/gvp/pre_authorization_successful.xml new file mode 100644 index 0000000..614dbf4 --- /dev/null +++ b/tests/samples/response/gvp/pre_authorization_successful.xml @@ -0,0 +1,42 @@ + + + + + PROVAUT + XXXX + 30691292 + 3424113 + + + 127.0.0.1 + eticaret@garanti.com.tr + + + SISTFA03907C0DB14A38B3BA380722891160 + + + + + HOST + 00 + 00 + Approved + + + + 311710676052 + 412290 + 000008 + 000057 + 20130427 10:40:07 + 554960******3012 + PE*** PEL** TON*** + BONUS + 70FB1A7B9C874498FF2A5874EA6DEF7A17C2E7A5 + + + + + + + diff --git a/tests/samples/response/gvp/refund_failed.xml b/tests/samples/response/gvp/refund_failed.xml new file mode 100644 index 0000000..09e0fdd --- /dev/null +++ b/tests/samples/response/gvp/refund_failed.xml @@ -0,0 +1,35 @@ + + + + + PROVRFN + XXXX + 30691292 + 3424113 + + 127.0.0.1 + eticaret@garanti.com.tr + + 1476 + + + + GVPS + 92 + 0214 + Declined + ›ade tutar˝, sat˝˛ tutar˝ndan b¸y¸k olamaz + ErrorId: 0214 + 311616674775 + + 000008 + 000030 + 20130426 16:56:35 + + + + 34F10F1DAAA651C8B7AF421BEB8E497794E27851 + + + + diff --git a/tests/samples/response/gvp/refund_successful.xml b/tests/samples/response/gvp/refund_successful.xml new file mode 100644 index 0000000..fb041a1 --- /dev/null +++ b/tests/samples/response/gvp/refund_successful.xml @@ -0,0 +1,42 @@ + + + + + PROVRFN + XXXX + 30691292 + 3424113 + + + 127.0.0.1 + eticaret@garanti.com.tr + + + 1476 + + + + + HOST + 00 + 00 + Approved + + + + 311616674771 + 489787 + 000008 + 000029 + 20130426 16:55:31 + 554960******3012 + + BONUS + D73C3E2106BCAD517CB1F7C20ECF3B8279C14868 + + + + + + + \ No newline at end of file diff --git a/tests/samples/response/gvp/sale_failed.xml b/tests/samples/response/gvp/sale_failed.xml new file mode 100644 index 0000000..6813506 --- /dev/null +++ b/tests/samples/response/gvp/sale_failed.xml @@ -0,0 +1,42 @@ + + + + + PROVAUT + XXXX + 30691292 + 3424113 + + + 127.0.0.1 + eticaret@garanti.com.tr + + + SISTF94AC1AC943B4FE8BBB8B20FB82FA7BB + + + + + HOST + 54 + 54 + Declined + ›˛leminizi gerÁekle˛tiremiyoruz.Tekrar deneyiniz + SON KULLANMA TARIHI HATALI + + 311710676031 + + 000008 + 000052 + 20130427 10:26:04 + 554960******3012 + PE*** PEL** TON*** + BONUS + D2F5BA37A98C5DDDC34B28FA56FF03FC782713BD + + + + + + + diff --git a/tests/samples/response/gvp/sale_successful.xml b/tests/samples/response/gvp/sale_successful.xml new file mode 100644 index 0000000..93356e2 --- /dev/null +++ b/tests/samples/response/gvp/sale_successful.xml @@ -0,0 +1,42 @@ + + + + + PROVAUT + XXXX + 30691292 + 3424113 + + + 127.0.0.1 + eticaret@garanti.com.tr + + + SISTC157B93B81C74BB88C6CA1C15D0CA338 + + + + + HOST + 00 + 00 + Approved + + + + 311710676028 + 245093 + 000008 + 000051 + 20130427 10:24:26 + 554960******3012 + PE*** PEL** TON*** + BONUS + 8B4BCA794C748337183EA62D75F901549541C95C + + + + + + + diff --git a/tests/samples/response/posnet/cancel_failed.xml b/tests/samples/response/posnet/cancel_failed.xml new file mode 100644 index 0000000..e37c080 --- /dev/null +++ b/tests/samples/response/posnet/cancel_failed.xml @@ -0,0 +1,6 @@ + + + 0 + 0225 + ONAYLANMADI:0225 ISL. YAPILAMIY 0225 + \ No newline at end of file diff --git a/tests/samples/response/posnet/cancel_successful.xml b/tests/samples/response/posnet/cancel_successful.xml new file mode 100644 index 0000000..cd2e4fd --- /dev/null +++ b/tests/samples/response/posnet/cancel_successful.xml @@ -0,0 +1,6 @@ + + + 1 + 0001000009P0503281 + 000000 + \ No newline at end of file diff --git a/tests/samples/response/posnet/post_authorization_failed.xml b/tests/samples/response/posnet/post_authorization_failed.xml new file mode 100644 index 0000000..e37c080 --- /dev/null +++ b/tests/samples/response/posnet/post_authorization_failed.xml @@ -0,0 +1,6 @@ + + + 0 + 0225 + ONAYLANMADI:0225 ISL. YAPILAMIY 0225 + \ No newline at end of file diff --git a/tests/samples/response/posnet/post_authorization_successful.xml b/tests/samples/response/posnet/post_authorization_successful.xml new file mode 100644 index 0000000..c120978 --- /dev/null +++ b/tests/samples/response/posnet/post_authorization_successful.xml @@ -0,0 +1,39 @@ + + + 1 + 0001000004P0503281 + 007912 + + + 050531135646 + + + + 03 + + + 000000005000 + + + + + 00000010 + + + 000000000005 + + + 00011742 + + + 000000005871 + + \ No newline at end of file diff --git a/tests/samples/response/posnet/pre_authorization_failed.xml b/tests/samples/response/posnet/pre_authorization_failed.xml new file mode 100644 index 0000000..e37c080 --- /dev/null +++ b/tests/samples/response/posnet/pre_authorization_failed.xml @@ -0,0 +1,6 @@ + + + 0 + 0225 + ONAYLANMADI:0225 ISL. YAPILAMIY 0225 + \ No newline at end of file diff --git a/tests/samples/response/posnet/pre_authorization_successful.xml b/tests/samples/response/posnet/pre_authorization_successful.xml new file mode 100644 index 0000000..c120978 --- /dev/null +++ b/tests/samples/response/posnet/pre_authorization_successful.xml @@ -0,0 +1,39 @@ + + + 1 + 0001000004P0503281 + 007912 + + + 050531135646 + + + + 03 + + + 000000005000 + + + + + 00000010 + + + 000000000005 + + + 00011742 + + + 000000005871 + + \ No newline at end of file diff --git a/tests/samples/response/posnet/refund_failed.xml b/tests/samples/response/posnet/refund_failed.xml new file mode 100644 index 0000000..e37c080 --- /dev/null +++ b/tests/samples/response/posnet/refund_failed.xml @@ -0,0 +1,6 @@ + + + 0 + 0225 + ONAYLANMADI:0225 ISL. YAPILAMIY 0225 + \ No newline at end of file diff --git a/tests/samples/response/posnet/refund_successful.xml b/tests/samples/response/posnet/refund_successful.xml new file mode 100644 index 0000000..c120978 --- /dev/null +++ b/tests/samples/response/posnet/refund_successful.xml @@ -0,0 +1,39 @@ + + + 1 + 0001000004P0503281 + 007912 + + + 050531135646 + + + + 03 + + + 000000005000 + + + + + 00000010 + + + 000000000005 + + + 00011742 + + + 000000005871 + + \ No newline at end of file diff --git a/tests/samples/response/posnet/sale_failed.xml b/tests/samples/response/posnet/sale_failed.xml new file mode 100644 index 0000000..e37c080 --- /dev/null +++ b/tests/samples/response/posnet/sale_failed.xml @@ -0,0 +1,6 @@ + + + 0 + 0225 + ONAYLANMADI:0225 ISL. YAPILAMIY 0225 + \ No newline at end of file diff --git a/tests/samples/response/posnet/sale_successful.xml b/tests/samples/response/posnet/sale_successful.xml new file mode 100644 index 0000000..c120978 --- /dev/null +++ b/tests/samples/response/posnet/sale_successful.xml @@ -0,0 +1,39 @@ + + + 1 + 0001000004P0503281 + 007912 + + + 050531135646 + + + + 03 + + + 000000005000 + + + + + 00000010 + + + 000000000005 + + + 00011742 + + + 000000005871 + + \ No newline at end of file