Skip to content

Commit cfeeba4

Browse files
authored
Added tests for UnionPay with NAB Transact (#14)
Added tests for UnionPay with NAB Transact
1 parent 851f821 commit cfeeba4

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class UnionPayCompletePurchaseRequestTest extends TestCase
8+
{
9+
public function setUp()
10+
{
11+
$this->request = new UnionPayCompletePurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
12+
}
13+
14+
public function testUnionPayCompletePurchaseSuccess()
15+
{
16+
$data = array();
17+
18+
$data['restext'] = 'Approved';
19+
$data['rescode'] = '00';
20+
$data['summarycode'] = '1';
21+
$data['txnid'] = '12345';
22+
23+
$response = new UnionPayCompletePurchaseResponse($this->getMockRequest(), $data);
24+
25+
$this->assertInstanceOf('Omnipay\NABTransact\Message\UnionPayCompletePurchaseResponse', $response);
26+
$this->assertTrue($response->isSuccessful());
27+
$this->assertFalse($response->isRedirect());
28+
$this->assertSame('12345', $response->getTransactionReference());
29+
$this->assertSame('Approved', $response->getMessage());
30+
$this->assertSame('00', $response->getCode());
31+
$this->assertTrue($response->summaryCode());
32+
}
33+
34+
public function testUnionPayCompletePurchaseFailure()
35+
{
36+
$data = array();
37+
38+
$data['restext'] = 'Error';
39+
$data['txnid'] = '12345';
40+
$data['summarycode'] = '3';
41+
$data['rescode'] = '06';
42+
43+
$response = new UnionPayCompletePurchaseResponse($this->getMockRequest(), $data);
44+
45+
$this->assertInstanceOf('Omnipay\NABTransact\Message\UnionPayCompletePurchaseResponse', $response);
46+
$this->assertFalse($response->isSuccessful());
47+
$this->assertFalse($response->isRedirect());
48+
$this->assertSame('12345', $response->getTransactionReference());
49+
$this->assertNotSame('Approved', $response->getMessage());
50+
$this->assertSame('06', $response->getCode());
51+
}
52+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class UnionPayPurchaseRequestTest extends TestCase
8+
{
9+
public function setUp()
10+
{
11+
$this->request = new UnionPayPurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
12+
13+
$this->request->initialize(
14+
array(
15+
'merchantId' => 'XYZ0010',
16+
'transactionPassword' => 'abcd1234',
17+
'amount' => '12.00',
18+
'returnUrl' => 'https://www.example.com/return',
19+
'transactionId' => 'GHJGG76756556',
20+
)
21+
);
22+
}
23+
24+
public function testFingerprint()
25+
{
26+
$data = $this->request->getData();
27+
$data['EPS_TIMESTAMP'] = '20161125123332';
28+
29+
$this->assertSame('36e686feef0ec7a53d5b6289707bc47e4bb83c95',
30+
$this->request->generateFingerprint($data));
31+
}
32+
33+
public function testPurchase()
34+
{
35+
$response = $this->request->send();
36+
37+
$this->assertInstanceOf('Omnipay\NABTransact\Message\UnionPayPurchaseResponse', $response);
38+
39+
$this->assertFalse($response->isSuccessful());
40+
$this->assertTrue($response->isRedirect());
41+
$this->assertNull($response->getTransactionReference());
42+
$this->assertNull($response->getMessage());
43+
$this->assertNull($response->getCode());
44+
45+
$this->assertStringStartsWith('https://transact.nab.com.au/live/directpostv2/authorise',
46+
$response->getRedirectUrl());
47+
$this->assertSame('GET', $response->getRedirectMethod());
48+
$this->assertArrayHasKey('EPS_FINGERPRINT', $response->getData());
49+
}
50+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class UnionPayPurchaseResponseTest extends TestCase
8+
{
9+
public function testConstruct()
10+
{
11+
$data = array('test' => '123');
12+
13+
$response = new UnionPayPurchaseResponse($this->getMockRequest(), $data, 'https://example.com/');
14+
15+
$this->assertFalse($response->isSuccessful());
16+
$this->assertTrue($response->isRedirect());
17+
$this->assertNull($response->getTransactionReference());
18+
$this->assertNull($response->getMessage());
19+
$this->assertSame($data, $response->getData());
20+
21+
$this->assertSame('https://example.com/', $response->getRedirectUrl());
22+
$this->assertSame('GET', $response->getRedirectMethod());
23+
$this->assertSame($data, $response->getRedirectData());
24+
}
25+
}

0 commit comments

Comments
 (0)