diff --git a/src/Message/PxPayAuthorizeRequest.php b/src/Message/PxPayAuthorizeRequest.php index 8b3d67f..d6549d1 100644 --- a/src/Message/PxPayAuthorizeRequest.php +++ b/src/Message/PxPayAuthorizeRequest.php @@ -273,6 +273,10 @@ public function getData() $data->Opt = $this->getOpt(); } + if ($this->getNotifyUrl()) { + $data->UrlCallback = $this->getNotifyUrl(); + } + if ($this->getForcePaymentMethod()) { $data->ForcePaymentMethod = $this->getForcePaymentMethod(); } diff --git a/src/Message/PxPayNotificationRequest.php b/src/Message/PxPayNotificationRequest.php new file mode 100644 index 0000000..3e1554c --- /dev/null +++ b/src/Message/PxPayNotificationRequest.php @@ -0,0 +1,14 @@ +response = new PxPayNotificationResponse($this, simplexml_load_string($data)); + } +} diff --git a/src/Message/PxPayNotificationResponse.php b/src/Message/PxPayNotificationResponse.php new file mode 100644 index 0000000..d1fe5a9 --- /dev/null +++ b/src/Message/PxPayNotificationResponse.php @@ -0,0 +1,22 @@ +isSuccessful()) { + return static::STATUS_COMPLETED; + } + + // NOTE: Windcave doesn't support static::STATUS_PENDING, which would have an additional check here + + return static::STATUS_FAILED; + } +} diff --git a/src/PxPayGateway.php b/src/PxPayGateway.php index f708cdc..f5a74e9 100644 --- a/src/PxPayGateway.php +++ b/src/PxPayGateway.php @@ -105,4 +105,10 @@ public function completeCreateCard(array $parameters = array()) { return $this->completeAuthorize($parameters); } + + public function acceptNotification(array $parameters = array()) + { + // NOTE: Windcave does not send full data (only result codes identical to completeAuthorize), so it needs send() + return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPayNotificationRequest', $parameters)->send(); + } } diff --git a/tests/Message/PxPayCreateCardRequestTest.php b/tests/Message/PxPayCreateCardRequestTest.php index 58161da..8fd9523 100644 --- a/tests/Message/PxPayCreateCardRequestTest.php +++ b/tests/Message/PxPayCreateCardRequestTest.php @@ -1,35 +1,23 @@ getHttpClient(), $this->getHttpRequest()); - $request->initialize( - array( - 'returnUrl' => 'abc123', - 'action' => 'Purchase', - ) - ); - $request->getData(); - $this->assertEquals('Purchase', $request->getAction()); - } +class PxPayCreateCardRequestTest extends TestCase +{ + /** + * Test that we can set the action to purchase. + */ + public function testCreateCardPurchaseSuccess() + { + $request = new PxPayCreateCardRequest($this->getHttpClient(), $this->getHttpRequest()); + $request->initialize( + array( + 'returnUrl' => 'abc123', + 'action' => 'Purchase', + ) + ); + $request->getData(); + $this->assertEquals('Purchase', $request->getAction()); + } } diff --git a/tests/PxPayGatewayTest.php b/tests/PxPayGatewayTest.php index cfc620b..dce7244 100644 --- a/tests/PxPayGatewayTest.php +++ b/tests/PxPayGatewayTest.php @@ -2,6 +2,7 @@ namespace Omnipay\PaymentExpress; +use Omnipay\Common\Message\NotificationInterface; use Omnipay\Tests\GatewayTestCase; class PxPayGatewayTest extends GatewayTestCase @@ -24,7 +25,7 @@ public function testAuthorizeSuccess() $response = $this->gateway->authorize($this->options)->send(); - $this->_testSuccessfulPurchase($response); + $this->_testSuccessfulPurchase($response); } public function testAuthorizeFailure() @@ -65,7 +66,27 @@ public function testAuthorizeWithTransactionDataSuccess() $response = $request->send(); - $this->_testSuccessfulPurchase($response); + $this->_testSuccessfulPurchase($response); + } + + public function testAuthorizeWithAllUrls() + { + $this->setMockHttpResponse('PxPayPurchaseSuccess.txt'); + + $options = array_merge($this->options, array( + 'cancelUrl' => 'https://www.example.com/cancel', + 'notifyUrl' => 'https://www.example.com/notify', + )); + + $request = $this->gateway->authorize($options); + + $this->assertSame($options['returnUrl'], $request->getReturnUrl()); + $this->assertSame($options['cancelUrl'], $request->getCancelUrl()); + $this->assertSame($options['notifyUrl'], $request->getNotifyUrl()); + + $response = $request->send(); + + $this->_testSuccessfulPurchase($response); } public function testPurchaseSuccess() @@ -74,7 +95,7 @@ public function testPurchaseSuccess() $response = $this->gateway->purchase($this->options)->send(); - $this->_testSuccessfulPurchase($response); + $this->_testSuccessfulPurchase($response); } public function testPurchaseWithCardReferenceSuccess() @@ -88,7 +109,7 @@ public function testPurchaseWithCardReferenceSuccess() $response = $this->gateway->purchase($options)->send(); - $this->_testSuccessfulPurchase($response); + $this->_testSuccessfulPurchase($response); } public function testPurchaseFailure() @@ -172,6 +193,36 @@ public function testCompleteAuthorizeFailure() $this->assertSame('Length of the data to decrypt is invalid.', $response->getMessage()); } + public function testAcceptNotificationSuccess() + { + $this->getHttpRequest()->query->replace(array('result' => 'abc123')); + + $this->setMockHttpResponse('PxPayCompletePurchaseSuccess.txt'); + + $response = $this->gateway->acceptNotification($this->options); + + $this->assertTrue($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertSame('0000000103f5dc65', $response->getTransactionReference()); + $this->assertSame('APPROVED', $response->getMessage()); + $this->assertSame(NotificationInterface::STATUS_COMPLETED, $response->getTransactionStatus()); + } + + public function testAcceptNotificationFailure() + { + $this->getHttpRequest()->query->replace(array('result' => 'abc123')); + + $this->setMockHttpResponse('PxPayCompletePurchaseFailure.txt'); + + $response = $this->gateway->acceptNotification($this->options); + + $this->assertFalse($response->isSuccessful()); + $this->assertFalse($response->isRedirect()); + $this->assertNull($response->getTransactionReference()); + $this->assertSame('Length of the data to decrypt is invalid.', $response->getMessage()); + $this->assertSame(NotificationInterface::STATUS_FAILED, $response->getTransactionStatus()); + } + public function testCompleteCreateCardSuccess() { $this->getHttpRequest()->query->replace(array('result' => 'abc123')); @@ -302,13 +353,14 @@ public function testTestModeEnabled() private function _testSuccessfulPurchase($response) { - $this->assertFalse($response->isSuccessful()); - $this->assertTrue($response->isRedirect()); - $this->assertNull($response->getTransactionReference()); - $this->assertNull($response->getMessage()); - $this->assertSame('https://sec.windcave.com/pxpay/pxpay.aspx?userid=Developer&request=v5H7JrBTzH-4Whs__1iQnz4RGSb9qxRKNR4kIuDP8kIkQzIDiIob9GTIjw_9q_AdRiR47ViWGVx40uRMu52yz2mijT39YtGeO7cZWrL5rfnx0Mc4DltIHRnIUxy1EO1srkNpxaU8fT8_1xMMRmLa-8Fd9bT8Oq0BaWMxMquYa1hDNwvoGs1SJQOAJvyyKACvvwsbMCC2qJVyN0rlvwUoMtx6gGhvmk7ucEsPc_Cyr5kNl3qURnrLKxINnS0trdpU4kXPKOlmT6VacjzT1zuj_DnrsWAPFSFq-hGsow6GpKKciQ0V0aFbAqECN8rl_c-aZWFFy0gkfjnUM4qp6foS0KMopJlPzGAgMjV6qZ0WfleOT64c3E-FRLMP5V_-mILs8a', - $response->getRedirectUrl()); - $this->assertSame('GET', $response->getRedirectMethod()); + $this->assertFalse($response->isSuccessful()); + $this->assertTrue($response->isRedirect()); + $this->assertNull($response->getTransactionReference()); + $this->assertNull($response->getMessage()); + $this->assertSame( + 'https://sec.windcave.com/pxpay/pxpay.aspx?userid=Developer&request=v5H7JrBTzH-4Whs__1iQnz4RGSb9qxRKNR4kIuDP8kIkQzIDiIob9GTIjw_9q_AdRiR47ViWGVx40uRMu52yz2mijT39YtGeO7cZWrL5rfnx0Mc4DltIHRnIUxy1EO1srkNpxaU8fT8_1xMMRmLa-8Fd9bT8Oq0BaWMxMquYa1hDNwvoGs1SJQOAJvyyKACvvwsbMCC2qJVyN0rlvwUoMtx6gGhvmk7ucEsPc_Cyr5kNl3qURnrLKxINnS0trdpU4kXPKOlmT6VacjzT1zuj_DnrsWAPFSFq-hGsow6GpKKciQ0V0aFbAqECN8rl_c-aZWFFy0gkfjnUM4qp6foS0KMopJlPzGAgMjV6qZ0WfleOT64c3E-FRLMP5V_-mILs8a', + $response->getRedirectUrl() + ); + $this->assertSame('GET', $response->getRedirectMethod()); } - }