Skip to content

Commit 5320f31

Browse files
committed
Added more tests
1 parent f2519bc commit 5320f31

File tree

7 files changed

+244
-7
lines changed

7 files changed

+244
-7
lines changed

index.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
require __DIR__ . "/vendor/autoload.php";
3+
4+
use Omnipay\Common\CreditCard;
5+
use Omnipay\Omnipay;
6+
7+
$gateway = Omnipay::create('NABTransact_SecureXML');
8+
9+
$gateway->setMerchantId('XYZ0010');
10+
$gateway->setTransactionPassword('abcd1234');
11+
12+
$gateway->setTestMode(true);
13+
14+
$card = new CreditCard([
15+
'firstName' => 'Sujip',
16+
'lastName' => 'Thapa',
17+
'number' => '4444333322221111',
18+
'expiryMonth' => "10",
19+
'expiryYear' => "2030",
20+
'cvv' => "123",
21+
]);
22+
23+
$response = $gateway->purchase([
24+
'amount' => '12.00',
25+
'transactionId' => "ORDER-ZYX8",
26+
'currency' => "AUD",
27+
'card' => $card,
28+
])
29+
->send();
30+
31+
$message = sprintf(
32+
'Transaction with reference code (%s) - %s',
33+
$response->getTransactionReference(),
34+
$response->getMessage()
35+
);
36+
37+
echo $message;

src/Message/SecureXMLAbstractRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public function generateMessageId()
5656
}
5757

5858
/**
59-
* Get the messageID for the request.
59+
* Get the messageID or generated one based on timestamp.
6060
*
61-
* @return string User-supplied messageID or generated one based on timestamp.
61+
* @return string
6262
*/
6363
public function getMessageId()
6464
{
@@ -150,7 +150,7 @@ protected function getBasePaymentXMLWithCard()
150150
$card->addChild('cardNumber', $this->getCard()->getNumber());
151151
$card->addChild('cvv', $this->getCard()->getCvv());
152152
$card->addChild('expiryDate', $this->getCard()->getExpiryDate('m/y'));
153-
$card->addChild('cardHolderName', $this->getCardHolderName());
153+
$card->addChild('cardHolderName', $this->getCard()->getName());
154154
$card->addChild('recurringflag', 'no');
155155

156156
return $xml;

src/Message/SecureXMLRefundRequest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class SecureXMLRefundRequest extends SecureXMLAbstractRequest
2828
public function getData()
2929
{
3030
$xml = $this->getBasePaymentXML();
31-
$xml->Payment->TxnList->Txn->addChild('txnID', $this->getTransactionReference());
31+
$xml->Payment->TxnList->Txn->addChild('txnID', $this->getTransactionId());
32+
$xml->Payment->TxnList->Txn->addChild('purchaseOrderNo', $this->getTransactionReference());
3233

3334
return $xml;
3435
}

src/Message/SecureXMLResponse.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ public function getStatusCode()
4242
return (string) $this->data->Status->statusCode;
4343
}
4444

45+
/**
46+
* Gateway RequestType if available.
47+
*
48+
* @return string
49+
*/
50+
public function getRequestType()
51+
{
52+
return (string) $this->data->RequestType;
53+
}
54+
4555
/**
4656
* Gateway approved string if available.
4757
*
@@ -91,7 +101,7 @@ public function getMessage()
91101
public function getTransactionReference()
92102
{
93103
return $this->hasTransaction()
94-
? (string) $this->data->Payment->TxnList->Txn->txnID
104+
? (string) $this->data->Payment->TxnList->Txn->purchaseOrderNo
95105
: null;
96106
}
97107

@@ -134,10 +144,10 @@ public function getTransactionCurrency()
134144
*
135145
* @return mixed
136146
*/
137-
public function getTransactionCurrencySource()
147+
public function getTransactionSource()
138148
{
139149
return $this->hasTransaction()
140-
? (string) $this->data->Payment->TxnList->Txn->currency
150+
? (string) $this->data->Payment->TxnList->Txn->txnSource
141151
: null;
142152
}
143153

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class SecureXMLAuthorizeRequestTest extends TestCase
8+
{
9+
public function setUp()
10+
{
11+
$this->request = new SecureXMLAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest());
12+
13+
$this->request->initialize(
14+
array(
15+
'merchantId' => 'XYZ0010',
16+
'transactionPassword' => 'abcd1234',
17+
'testMode' => true,
18+
'amount' => '12.00',
19+
'transactionId' => '1234',
20+
'card' => array(
21+
'number' => '4444333322221111',
22+
'expiryMonth' => '10',
23+
'expiryYear' => '2030',
24+
'cvv' => '123',
25+
'cardHolderName' => 'Sujip Thapa',
26+
),
27+
)
28+
);
29+
}
30+
31+
public function testSendSuccess()
32+
{
33+
$data = array();
34+
35+
$data['RequestType'] = "Payment";
36+
$data['statusDescription'] = "Normal";
37+
$data['statusCode'] = "000";
38+
$data['apiVersion'] = "xml-4.2";
39+
$data['txnType'] = "10";
40+
$data['txnSource'] = "23";
41+
$data['amount'] = "12.00";
42+
$data['currency'] = "AUD";
43+
$data['approved'] = "Yes";
44+
$data['responseCode'] = "00";
45+
$data['responseText'] = "Approved";
46+
$data['txnID'] = "1234";
47+
$data['cardDescription'] = "Visa";
48+
$data['expiryDate'] = "10/30";
49+
$data['cardType'] = "6";
50+
51+
$response = new SecureXMLResponse($this->getMockRequest(), $data);
52+
53+
$response = $this->request->send();
54+
55+
$data = $response->getData();
56+
57+
$this->assertInstanceOf('Omnipay\NABTransact\Message\SecureXMLResponse', $response);
58+
59+
$this->assertTrue($response->isSuccessful());
60+
$this->assertFalse($response->isRedirect());
61+
$this->assertSame('23', $response->getTransactionSource());
62+
$this->assertSame('AUD', $response->getTransactionCurrency());
63+
$this->assertSame('1200', $response->getTransactionAmount());
64+
$this->assertNotNull($response->getSettlementDate());
65+
$this->assertNotNull($response->getTransactionId());
66+
$this->assertSame('Approved', $response->getMessage());
67+
$this->assertSame('00', $response->getCode());
68+
$this->assertSame('10', (string) $data->Payment->TxnList->Txn->txnType);
69+
}
70+
71+
public function testSetMessageId()
72+
{
73+
$this->request->setMessageId('8af793f9af34bea0cf40f5fc011e0c');
74+
$this->assertSame('8af793f9af34bea0cf40f5fc011e0c', $this->request->getMessageId());
75+
}
76+
77+
public function testAutogeneratedMessageId()
78+
{
79+
$this->assertNotNull($this->request->getMessageId());
80+
$this->assertSame(30, strlen($this->request->getMessageId()));
81+
}
82+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact\Message;
4+
5+
use Omnipay\NABTransact\Message\SecureXMLEchoTestRequest;
6+
use Omnipay\NABTransact\Message\SecureXMLResponse;
7+
use Omnipay\Tests\TestCase;
8+
9+
class SecureXMLEchoTestRequestTest extends TestCase
10+
{
11+
public function setUp()
12+
{
13+
$this->request = new SecureXMLEchoTestRequest($this->getHttpClient(), $this->getHttpRequest());
14+
15+
$this->request->initialize(
16+
array(
17+
'merchantId' => 'XYZ0010',
18+
'transactionPassword' => 'abcd1234',
19+
'testMode' => true,
20+
)
21+
);
22+
}
23+
24+
public function testSuccess()
25+
{
26+
$data = array();
27+
28+
$data['RequestType'] = "Echo";
29+
$data['statusDescription'] = "Normal";
30+
$data['statusCode'] = "000";
31+
$data['apiVersion'] = "xml-4.2";
32+
33+
$response = new SecureXMLResponse($this->getMockRequest(), $data);
34+
35+
$response = $this->request->send();
36+
$data = $response->getData();
37+
38+
$this->assertInstanceOf('Omnipay\NABTransact\Message\SecureXMLResponse', $response);
39+
$this->assertSame('Normal', $response->getMessage());
40+
$this->assertFalse($response->isRedirect());
41+
$this->assertSame('000', $response->getStatusCode());
42+
}
43+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class SecureXMLPurchaseRequestTest extends TestCase
8+
{
9+
public function setUp()
10+
{
11+
$this->request = new SecureXMLPurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
12+
13+
$this->request->initialize(
14+
array(
15+
'merchantId' => 'XYZ0010',
16+
'transactionPassword' => 'abcd1234',
17+
'testMode' => true,
18+
'amount' => '12.00',
19+
'transactionId' => '1234',
20+
'card' => array(
21+
'number' => '4444333322221111',
22+
'expiryMonth' => '10',
23+
'expiryYear' => '2030',
24+
'cvv' => '123',
25+
'cardHolderName' => 'Sujip Thapa',
26+
),
27+
)
28+
);
29+
}
30+
31+
public function testSendSuccess()
32+
{
33+
$data = array();
34+
35+
$data['RequestType'] = "Payment";
36+
$data['statusDescription'] = "Normal";
37+
$data['statusCode'] = "000";
38+
$data['apiVersion'] = "xml-4.2";
39+
$data['txnType'] = "10";
40+
$data['txnSource'] = "23";
41+
$data['amount'] = "12.00";
42+
$data['currency'] = "AUD";
43+
$data['approved'] = "Yes";
44+
$data['responseCode'] = "00";
45+
$data['responseText'] = "Approved";
46+
$data['cardDescription'] = "Visa";
47+
$data['expiryDate'] = "10/30";
48+
$data['cardType'] = "6";
49+
50+
$response = new SecureXMLResponse($this->getMockRequest(), $data);
51+
52+
$response = $this->request->send();
53+
$data = $response->getData();
54+
55+
$this->assertInstanceOf('Omnipay\NABTransact\Message\SecureXMLResponse', $response);
56+
57+
$this->assertTrue($response->isSuccessful());
58+
$this->assertFalse($response->isRedirect());
59+
$this->assertSame('0', (string) $data->Payment->TxnList->Txn->txnType);
60+
$this->assertSame('1234', $response->getTransactionReference());
61+
$this->assertSame('00', $response->getCode());
62+
$this->assertSame('Approved', $response->getMessage());
63+
}
64+
}

0 commit comments

Comments
 (0)