Skip to content

Add support for NotifyUrl (UrlCallback) to PxPay #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Message/PxPayAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
14 changes: 14 additions & 0 deletions src/Message/PxPayNotificationRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Omnipay\PaymentExpress\Message;

/**
* PaymentExpress PxPay Notification (Webhook, Callback) Request
*/
class PxPayNotificationRequest extends PxPayCompleteAuthorizeRequest
{
protected function createResponse($data)
{
return $this->response = new PxPayNotificationResponse($this, simplexml_load_string($data));
}
}
22 changes: 22 additions & 0 deletions src/Message/PxPayNotificationResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Omnipay\PaymentExpress\Message;

use Omnipay\Common\Message\NotificationInterface;

/**
* PaymentExpress PxPay Notification (Webhook, Callback) Response
*/
class PxPayNotificationResponse extends Response implements NotificationInterface
{
public function getTransactionStatus()
{
if ($this->isSuccessful()) {
return static::STATUS_COMPLETED;
}

// NOTE: Windcave doesn't support static::STATUS_PENDING, which would have an additional check here

return static::STATUS_FAILED;
}
}
6 changes: 6 additions & 0 deletions src/PxPayGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
46 changes: 17 additions & 29 deletions tests/Message/PxPayCreateCardRequestTest.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
<?php
/**
* @file
* Created by PhpStorm.
* User: eileen
* Date: 7/04/2016
* Time: 12:25 AM
*/

namespace Omnipay\PaymentExpress\Message;

use Omnipay\Tests\TestCase;

/**
* Class PxPayCreateCardRequestTest
* @package Omnipay\PaymentExpress\Message
*/
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());
}
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());
}
}
76 changes: 64 additions & 12 deletions tests/PxPayGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Omnipay\PaymentExpress;

use Omnipay\Common\Message\NotificationInterface;
use Omnipay\Tests\GatewayTestCase;

class PxPayGatewayTest extends GatewayTestCase
Expand All @@ -24,7 +25,7 @@ public function testAuthorizeSuccess()

$response = $this->gateway->authorize($this->options)->send();

$this->_testSuccessfulPurchase($response);
$this->_testSuccessfulPurchase($response);
}

public function testAuthorizeFailure()
Expand Down Expand Up @@ -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()
Expand All @@ -74,7 +95,7 @@ public function testPurchaseSuccess()

$response = $this->gateway->purchase($this->options)->send();

$this->_testSuccessfulPurchase($response);
$this->_testSuccessfulPurchase($response);
}

public function testPurchaseWithCardReferenceSuccess()
Expand All @@ -88,7 +109,7 @@ public function testPurchaseWithCardReferenceSuccess()

$response = $this->gateway->purchase($options)->send();

$this->_testSuccessfulPurchase($response);
$this->_testSuccessfulPurchase($response);
}

public function testPurchaseFailure()
Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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());
}

}