Skip to content

Commit cd341c6

Browse files
authored
Merge pull request #34 from moddengine/cs-risk-xml
Added support for risk management xml endpoint
2 parents 943bc62 + 9c83fc8 commit cd341c6

File tree

4 files changed

+146
-0
lines changed

4 files changed

+146
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,47 @@ The following gateways are provided by this package:
6565
}
6666

6767
```
68+
69+
70+
### NAB Transact SecureXML API with Risk Management
71+
72+
```php
73+
use Omnipay\Omnipay;
74+
use Omnipay\Common\CreditCard;
75+
76+
$gateway = Omnipay::create('NABTransact_SecureXML');
77+
$gateway->setMerchantId('XYZ0010');
78+
$gateway->setTransactionPassword('abcd1234');
79+
$gateway->setTestMode(true);
80+
$gateway->setRiskManagement(true);
81+
82+
$card = new CreditCard([
83+
'firstName' => 'Sujip',
84+
'lastName' => 'Thapa',
85+
'number' => '4444333322221111',
86+
'expiryMonth' => '06',
87+
'expiryYear' => '2030',
88+
'cvv' => '123',
89+
]
90+
);
91+
92+
$transaction = $gateway->purchase([
93+
'amount' => '10.00',
94+
'currency' => 'AUD',
95+
'transactionId' => 'XYZ100',
96+
'card' => $card,
97+
'ip' => '1.1.1.1',
98+
]
99+
);
100+
101+
$response = $transaction->send();
102+
103+
if ($response->isSuccessful()) {
104+
echo sprintf('Transaction %s was successful!', $response->getTransactionReference());
105+
} else {
106+
echo sprintf('Transaction %s failed: %s', $response->getTransactionReference(), $response->getMessage());
107+
}
108+
68109
### NAB Transact DirectPost v2
69110

70111
```php
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact\Message;
4+
5+
/**
6+
* NABTransact SecureXML Purchase Request.
7+
*/
8+
class SecureXMLRiskPurchaseRequest extends SecureXMLAbstractRequest
9+
{
10+
/**
11+
* @var string
12+
*/
13+
public $liveEndpoint = 'https://transact.nab.com.au/riskmgmt/payment';
14+
15+
/**
16+
* @var string
17+
*/
18+
public $testEndpoint = 'https://demo.transact.nab.com.au/riskmgmt/payment';
19+
20+
/**
21+
* @var int
22+
*/
23+
protected $txnType = 0;
24+
25+
/**
26+
* @var array
27+
*/
28+
protected $requiredFields = ['amount', 'card', 'transactionId', 'ip'];
29+
30+
public function setIp($value)
31+
{
32+
$this->setParameter('ip', $value);
33+
}
34+
35+
public function getIp()
36+
{
37+
return $this->getParameter('ip');
38+
}
39+
40+
/**
41+
* @return string
42+
*/
43+
public function getData()
44+
{
45+
$xml = $this->getBasePaymentXMLWithCard();
46+
47+
$buyer = $xml->addChild('BuyerInfo');
48+
$buyer->addChild('ip', $this->getIp('ip'));
49+
$card = $this->getCard();
50+
if ($firstName = $card->getFirstName()) {
51+
$buyer->addChild('firstName', $firstName);
52+
}
53+
if ($lastName = $card->getLastName()) {
54+
$buyer->addChild('firstName', $lastName);
55+
}
56+
if ($postCode = $card->getBillingPostcode()) {
57+
$buyer->addChild('zipcode', $postCode);
58+
}
59+
if ($city = $card->getBillingCity()) {
60+
$buyer->addChild('town', $city);
61+
}
62+
if ($country = $card->getBillingCountry()) {
63+
$buyer->addChild('billingCountry', $country);
64+
}
65+
if ($email = $card->getEmail()) {
66+
$buyer->addChild('emailAddress', $email);
67+
}
68+
69+
return $xml;
70+
}
71+
}

src/SecureXMLGateway.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ public function setMerchantId($value)
3939
return $this->setParameter('merchantId', $value);
4040
}
4141

42+
/**
43+
* @return string
44+
*/
45+
public function getRiskManagement()
46+
{
47+
return $this->getParameter('riskManagement');
48+
}
49+
50+
/**
51+
* @param $value
52+
*/
53+
public function setRiskManagement($value)
54+
{
55+
return $this->setParameter('riskManagement', $value);
56+
}
57+
4258
/**
4359
* @return string
4460
*/
@@ -82,6 +98,10 @@ public function capture(array $parameters = [])
8298
*/
8399
public function purchase(array $parameters = [])
84100
{
101+
if ($this->getRiskManagement()) {
102+
return $this->createRequest('\Omnipay\NABTransact\Message\SecureXMLRiskPurchaseRequest', $parameters);
103+
}
104+
85105
return $this->createRequest('\Omnipay\NABTransact\Message\SecureXMLPurchaseRequest', $parameters);
86106
}
87107

tests/SecureXMLGatewayTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ public function testPurchase()
4747
$this->assertSame('10.00', $request->getAmount());
4848
}
4949

50+
public function testPurchaseRiskManaged()
51+
{
52+
$gateway = clone $this->gateway;
53+
$gateway->setRiskManagement(true);
54+
$request = $gateway->purchase(['card' => $this->getValidCard(), 'transactionId' => 'Test1234', 'ip' => '1.1.1.1', 'amount' => '25.00']);
55+
56+
$this->assertInstanceOf('\Omnipay\NABTransact\Message\SecureXMLRiskPurchaseRequest', $request);
57+
$this->assertSame('25.00', $request->getAmount());
58+
$this->assertContains(
59+
'<BuyerInfo><ip>1.1.1.1</ip><firstName>Example</firstName><firstName>User</firstName><zipcode>12345</zipcode><town>Billstown</town><billingCountry>US</billingCountry></BuyerInfo>',
60+
(string) $request->getData()->asXml()
61+
);
62+
}
63+
5064
public function testRefund()
5165
{
5266
$request = $this->gateway->refund(['amount' => '10.00', 'transactionId' => 'Order-YKHU67']);

0 commit comments

Comments
 (0)