Skip to content

Commit 208e6c7

Browse files
committed
Added few more tests for XML API
1 parent b185de5 commit 208e6c7

6 files changed

+172
-11
lines changed

src/Message/SecureXMLResponse.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ public function getCode()
8585
}
8686

8787
/**
88-
* @return string Gateway failure message or transaction message if
89-
* available.
88+
* Gateway failure message or transaction message if available.
89+
*
90+
* @return string
9091
*/
9192
public function getMessage()
9293
{
@@ -95,6 +96,16 @@ public function getMessage()
9596
: (string) $this->data->Status->statusDescription;
9697
}
9798

99+
/**
100+
* Gateway message timestamp if available.
101+
*
102+
* @return string
103+
*/
104+
public function getMessageTimestamp()
105+
{
106+
return (string) $this->data->MessageInfo->messageTimestamp;
107+
}
108+
98109
/**
99110
* @return string Unique NABTransact bank transaction reference.
100111
*/

tests/Message/SecureXMLAuthorizeRequestTest.php

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ public function setUp()
1212

1313
$this->request->initialize(
1414
array(
15-
'merchantId' => 'XYZ0010',
15+
'merchantId' => 'XYZ0010',
1616
'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',
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',
2525
'cardHolderName' => 'Sujip Thapa',
2626
),
2727
)
@@ -68,6 +68,62 @@ public function testSendSuccess()
6868
$this->assertSame('10', (string) $data->Payment->TxnList->Txn->txnType);
6969
}
7070

71+
public function testSendFailure()
72+
{
73+
$this->setMockHttpResponse('SecureXMLAuthorizeRequestFail.txt');
74+
$response = $this->request->send();
75+
76+
$this->assertInstanceOf('Omnipay\NABTransact\Message\SecureXMLResponse', $response);
77+
78+
$this->assertFalse($response->isSuccessful());
79+
$this->assertFalse($response->isRedirect());
80+
$this->assertSame('510', $response->getCode());
81+
$this->assertSame('Unable To Connect To Server', $response->getMessage());
82+
$this->assertSame('20161122083125000+345', $response->getMessageTimestamp());
83+
}
84+
85+
public function testInsufficientFundsFailure()
86+
{
87+
$this->setMockHttpResponse('SecureXMLAuthorizeRequestInsufficientFundsFail.txt');
88+
$response = $this->request->send();
89+
90+
$this->assertInstanceOf('Omnipay\NABTransact\Message\SecureXMLResponse', $response);
91+
92+
$this->assertFalse($response->isSuccessful());
93+
$this->assertFalse($response->isRedirect());
94+
$this->assertNull($response->getTransactionReference());
95+
$this->assertSame('51', $response->getCode());
96+
$this->assertSame('Insufficient Funds', $response->getMessage());
97+
}
98+
99+
public function testInvalidMerchantFailure()
100+
{
101+
$this->setMockHttpResponse('SecureXMLAuthorizeRequestInvalidMerchantFail.txt');
102+
$response = $this->request->send();
103+
104+
$this->assertInstanceOf('Omnipay\NABTransact\Message\SecureXMLResponse', $response);
105+
106+
$this->assertFalse($response->isSuccessful());
107+
$this->assertFalse($response->isRedirect());
108+
$this->assertNull($response->getTransactionReference());
109+
$this->assertSame('504', $response->getCode());
110+
$this->assertSame('Invalid merchant ABC0030', $response->getMessage());
111+
}
112+
113+
public function testInvalidMerchantIDFailure()
114+
{
115+
$this->setMockHttpResponse('SecureXMLAuthorizeRequestInvalidMerchantIDFail.txt');
116+
$response = $this->request->send();
117+
118+
$this->assertInstanceOf('Omnipay\NABTransact\Message\SecureXMLResponse', $response);
119+
120+
$this->assertFalse($response->isSuccessful());
121+
$this->assertFalse($response->isRedirect());
122+
$this->assertNull($response->getTransactionReference());
123+
$this->assertSame('504', $response->getCode());
124+
$this->assertSame('Invalid merchant ID', $response->getMessage());
125+
}
126+
71127
public function testSetMessageId()
72128
{
73129
$this->request->setMessageId('8af793f9af34bea0cf40f5fc011e0c');
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
HTTP/1.1 100 Continue
2+
Server: Microsoft-IIS/5.0
3+
Date: Mon, 19 Apr 2004 06:19:48 GMT
4+
HTTP/1.1 200 OK
5+
Server: Microsoft-IIS/5.0
6+
Date: Mon, 19 Apr 2004 06:20:01 GMT
7+
Content-Type: text/xml;charset=ISO-8859-1
8+
Content-Length: 929
9+
10+
<?xml version="1.0" encoding="UTF-8"?>
11+
<NABTransactMessage>
12+
<MessageInfo>
13+
<messageID>8af793f9af34bea0cf40f5fb79f383</messageID>
14+
<messageTimestamp>20161122083125000+345</messageTimestamp>
15+
<apiVersion>xml-4.2</apiVersion>
16+
</MessageInfo>
17+
<MerchantInfo>
18+
<merchantID>XYZ0010</merchantID>
19+
</MerchantInfo>
20+
<RequestType>Payment</RequestType>
21+
<Status>
22+
<statusCode>510</statusCode>
23+
<statusDescription>Unable To Connect To Server</statusDescription>
24+
</Status>
25+
</NABTransactMessage>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
HTTP/1.1 100 Continue
2+
Server: Microsoft-IIS/5.0
3+
Date: Mon, 19 Apr 2004 06:19:48 GMT
4+
HTTP/1.1 200 OK
5+
Server: Microsoft-IIS/5.0
6+
Date: Mon, 19 Apr 2004 06:20:01 GMT
7+
Content-Type: text/xml;charset=ISO-8859-1
8+
Content-Length: 929
9+
10+
<?xml version="1.0" encoding="UTF-8"?>
11+
<SecurePayMessage>
12+
<MessageInfo>
13+
<messageID>8af793f9af34bea0cf40f5fc011e0c</messageID>
14+
<messageTimestamp>20161122083125000+345</messageTimestamp>
15+
<apiVersion>xml-4.2</apiVersion>
16+
</MessageInfo>
17+
<RequestType>Payment</RequestType>
18+
<MerchantInfo>
19+
<merchantID>XYZ0010</merchantID>
20+
</MerchantInfo>
21+
<Status>
22+
<statusCode>51</statusCode>
23+
<statusDescription>Insufficient Funds</statusDescription>
24+
</Status>
25+
</SecurePayMessage>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
HTTP/1.1 100 Continue
2+
Server: Microsoft-IIS/5.0
3+
Date: Mon, 19 Apr 2004 06:19:48 GMT
4+
HTTP/1.1 200 OK
5+
Server: Microsoft-IIS/5.0
6+
Date: Mon, 19 Apr 2004 06:20:01 GMT
7+
Content-Type: text/xml;charset=ISO-8859-1
8+
Content-Length: 929
9+
10+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
11+
<SecurePayMessage>
12+
<MessageInfo>
13+
<messageID>5ef083567a7fe09111ecf709761f9d</messageID>
14+
<messageTimestamp>20151704120553321000+600</messageTimestamp>
15+
<apiVersion>xml-4.2</apiVersion>
16+
</MessageInfo>
17+
<RequestType>Payment</RequestType>
18+
<MerchantInfo>
19+
<merchantID>XYZ0040</merchantID>
20+
</MerchantInfo>
21+
<Status>
22+
<statusCode>504</statusCode>
23+
<statusDescription>Invalid merchant ABC0030</statusDescription>
24+
</Status>
25+
<Payment>
26+
<TxnList count="0"/>
27+
</Payment>
28+
</SecurePayMessage>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
HTTP/1.1 100 Continue
2+
Server: Microsoft-IIS/5.0
3+
Date: Mon, 19 Apr 2004 06:19:48 GMT
4+
HTTP/1.1 200 OK
5+
Server: Microsoft-IIS/5.0
6+
Date: Mon, 19 Apr 2004 06:20:01 GMT
7+
Content-Type: text/xml;charset=ISO-8859-1
8+
Content-Length: 929
9+
10+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
11+
<SecurePayMessage>
12+
<Status>
13+
<statusCode>504</statusCode>
14+
<statusDescription>Invalid merchant ID</statusDescription>
15+
</Status>
16+
</SecurePayMessage>

0 commit comments

Comments
 (0)