Skip to content

Commit

Permalink
Added tests for UnionPay with NAB Transact (#14)
Browse files Browse the repository at this point in the history
Added tests for UnionPay with NAB Transact
  • Loading branch information
sudiptpa authored Nov 28, 2016
1 parent 851f821 commit cfeeba4
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/Message/UnionPayCompletePurchaseRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Omnipay\NABTransact\Message;

use Omnipay\Tests\TestCase;

class UnionPayCompletePurchaseRequestTest extends TestCase
{
public function setUp()
{
$this->request = new UnionPayCompletePurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
}

public function testUnionPayCompletePurchaseSuccess()
{
$data = array();

$data['restext'] = 'Approved';
$data['rescode'] = '00';
$data['summarycode'] = '1';
$data['txnid'] = '12345';

$response = new UnionPayCompletePurchaseResponse($this->getMockRequest(), $data);

$this->assertInstanceOf('Omnipay\NABTransact\Message\UnionPayCompletePurchaseResponse', $response);
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('12345', $response->getTransactionReference());
$this->assertSame('Approved', $response->getMessage());
$this->assertSame('00', $response->getCode());
$this->assertTrue($response->summaryCode());
}

public function testUnionPayCompletePurchaseFailure()
{
$data = array();

$data['restext'] = 'Error';
$data['txnid'] = '12345';
$data['summarycode'] = '3';
$data['rescode'] = '06';

$response = new UnionPayCompletePurchaseResponse($this->getMockRequest(), $data);

$this->assertInstanceOf('Omnipay\NABTransact\Message\UnionPayCompletePurchaseResponse', $response);
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertSame('12345', $response->getTransactionReference());
$this->assertNotSame('Approved', $response->getMessage());
$this->assertSame('06', $response->getCode());
}
}
50 changes: 50 additions & 0 deletions tests/Message/UnionPayPurchaseRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Omnipay\NABTransact\Message;

use Omnipay\Tests\TestCase;

class UnionPayPurchaseRequestTest extends TestCase
{
public function setUp()
{
$this->request = new UnionPayPurchaseRequest($this->getHttpClient(), $this->getHttpRequest());

$this->request->initialize(
array(
'merchantId' => 'XYZ0010',
'transactionPassword' => 'abcd1234',
'amount' => '12.00',
'returnUrl' => 'https://www.example.com/return',
'transactionId' => 'GHJGG76756556',
)
);
}

public function testFingerprint()
{
$data = $this->request->getData();
$data['EPS_TIMESTAMP'] = '20161125123332';

$this->assertSame('36e686feef0ec7a53d5b6289707bc47e4bb83c95',
$this->request->generateFingerprint($data));
}

public function testPurchase()
{
$response = $this->request->send();

$this->assertInstanceOf('Omnipay\NABTransact\Message\UnionPayPurchaseResponse', $response);

$this->assertFalse($response->isSuccessful());
$this->assertTrue($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getMessage());
$this->assertNull($response->getCode());

$this->assertStringStartsWith('https://transact.nab.com.au/live/directpostv2/authorise',
$response->getRedirectUrl());
$this->assertSame('GET', $response->getRedirectMethod());
$this->assertArrayHasKey('EPS_FINGERPRINT', $response->getData());
}
}
25 changes: 25 additions & 0 deletions tests/Message/UnionPayPurchaseResponseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Omnipay\NABTransact\Message;

use Omnipay\Tests\TestCase;

class UnionPayPurchaseResponseTest extends TestCase
{
public function testConstruct()
{
$data = array('test' => '123');

$response = new UnionPayPurchaseResponse($this->getMockRequest(), $data, 'https://example.com/');

$this->assertFalse($response->isSuccessful());
$this->assertTrue($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getMessage());
$this->assertSame($data, $response->getData());

$this->assertSame('https://example.com/', $response->getRedirectUrl());
$this->assertSame('GET', $response->getRedirectMethod());
$this->assertSame($data, $response->getRedirectData());
}
}

0 comments on commit cfeeba4

Please sign in to comment.