-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for UnionPay with NAB Transact (#14)
Added tests for UnionPay with NAB Transact
- Loading branch information
Showing
3 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |