Skip to content

Commit 704f541

Browse files
authored
Merge pull request #4 from sudiptpa/tests/added
More tests
2 parents f2519bc + 7a87c91 commit 704f541

File tree

7 files changed

+243
-7
lines changed

7 files changed

+243
-7
lines changed

index.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
require __DIR__.'/vendor/autoload.php';
4+
5+
use Omnipay\Common\CreditCard;
6+
use Omnipay\Omnipay;
7+
8+
$gateway = Omnipay::create('NABTransact_SecureXML');
9+
10+
$gateway->setMerchantId('XYZ0010');
11+
$gateway->setTransactionPassword('abcd1234');
12+
13+
$gateway->setTestMode(true);
14+
15+
$card = new CreditCard(array(
16+
'firstName' => 'Sujip',
17+
'lastName' => 'Thapa',
18+
'number' => '4444333322221111',
19+
'expiryMonth' => '10',
20+
'expiryYear' => '2030',
21+
'cvv' => '123',
22+
));
23+
24+
$response = $gateway->purchase(array(
25+
'amount' => '12.00',
26+
'transactionId' => 'ORDER-ZYX8',
27+
'currency' => 'AUD',
28+
'card' => $card,
29+
))
30+
->send();
31+
32+
$message = sprintf(
33+
'Transaction with reference code (%s) - %s',
34+
$response->getTransactionReference(),
35+
$response->getMessage()
36+
);
37+
38+
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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
class SecureXMLEchoTestRequestTest extends TestCase
8+
{
9+
public function setUp()
10+
{
11+
$this->request = new SecureXMLEchoTestRequest($this->getHttpClient(), $this->getHttpRequest());
12+
13+
$this->request->initialize(
14+
array(
15+
'merchantId' => 'XYZ0010',
16+
'transactionPassword' => 'abcd1234',
17+
'testMode' => true,
18+
)
19+
);
20+
}
21+
22+
public function testSuccess()
23+
{
24+
$data = array();
25+
26+
$data['RequestType'] = 'Echo';
27+
$data['statusDescription'] = 'Normal';
28+
$data['statusCode'] = '000';
29+
$data['apiVersion'] = 'xml-4.2';
30+
31+
$response = new SecureXMLResponse($this->getMockRequest(), $data);
32+
33+
$response = $this->request->send();
34+
$data = $response->getData();
35+
36+
$this->assertInstanceOf('Omnipay\NABTransact\Message\SecureXMLResponse', $response);
37+
$this->assertSame('Normal', $response->getMessage());
38+
$this->assertFalse($response->isRedirect());
39+
$this->assertSame('000', $response->getStatusCode());
40+
}
41+
}
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)