diff --git a/README.md b/README.md index acdfd9c..8c1bbc0 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,47 @@ The following gateways are provided by this package: } ``` + + +### NAB Transact SecureXML API with Risk Management + +```php + use Omnipay\Omnipay; + use Omnipay\Common\CreditCard; + + $gateway = Omnipay::create('NABTransact_SecureXML'); + $gateway->setMerchantId('XYZ0010'); + $gateway->setTransactionPassword('abcd1234'); + $gateway->setTestMode(true); + $gateway->setRiskManagement(true); + + $card = new CreditCard([ + 'firstName' => 'Sujip', + 'lastName' => 'Thapa', + 'number' => '4444333322221111', + 'expiryMonth' => '06', + 'expiryYear' => '2030', + 'cvv' => '123', + ] + ); + + $transaction = $gateway->purchase([ + 'amount' => '10.00', + 'currency' => 'AUD', + 'transactionId' => 'XYZ100', + 'card' => $card, + 'ip' => '1.1.1.1', + ] + ); + + $response = $transaction->send(); + + if ($response->isSuccessful()) { + echo sprintf('Transaction %s was successful!', $response->getTransactionReference()); + } else { + echo sprintf('Transaction %s failed: %s', $response->getTransactionReference(), $response->getMessage()); + } + ### NAB Transact DirectPost v2 ```php diff --git a/src/Message/SecureXMLRiskPurchaseRequest.php b/src/Message/SecureXMLRiskPurchaseRequest.php new file mode 100644 index 0000000..da331e7 --- /dev/null +++ b/src/Message/SecureXMLRiskPurchaseRequest.php @@ -0,0 +1,71 @@ +setParameter('ip', $value); + } + + public function getIp() + { + return $this->getParameter('ip'); + } + + /** + * @return string + */ + public function getData() + { + $xml = $this->getBasePaymentXMLWithCard(); + + $buyer = $xml->addChild('BuyerInfo'); + $buyer->addChild('ip', $this->getIp('ip')); + $card = $this->getCard(); + if ($firstName = $card->getFirstName()) { + $buyer->addChild('firstName', $firstName); + } + if ($lastName = $card->getLastName()) { + $buyer->addChild('firstName', $lastName); + } + if ($postCode = $card->getBillingPostcode()) { + $buyer->addChild('zipcode', $postCode); + } + if ($city = $card->getBillingCity()) { + $buyer->addChild('town', $city); + } + if ($country = $card->getBillingCountry()) { + $buyer->addChild('billingCountry', $country); + } + if ($email = $card->getEmail()) { + $buyer->addChild('emailAddress', $email); + } + + return $xml; + } +} diff --git a/src/SecureXMLGateway.php b/src/SecureXMLGateway.php index 8c59777..53e7499 100644 --- a/src/SecureXMLGateway.php +++ b/src/SecureXMLGateway.php @@ -39,6 +39,22 @@ public function setMerchantId($value) return $this->setParameter('merchantId', $value); } + /** + * @return string + */ + public function getRiskManagement() + { + return $this->getParameter('riskManagement'); + } + + /** + * @param $value + */ + public function setRiskManagement($value) + { + return $this->setParameter('riskManagement', $value); + } + /** * @return string */ @@ -82,6 +98,10 @@ public function capture(array $parameters = []) */ public function purchase(array $parameters = []) { + if ($this->getRiskManagement()) { + return $this->createRequest('\Omnipay\NABTransact\Message\SecureXMLRiskPurchaseRequest', $parameters); + } + return $this->createRequest('\Omnipay\NABTransact\Message\SecureXMLPurchaseRequest', $parameters); } diff --git a/tests/SecureXMLGatewayTest.php b/tests/SecureXMLGatewayTest.php index fada77a..17a4bab 100644 --- a/tests/SecureXMLGatewayTest.php +++ b/tests/SecureXMLGatewayTest.php @@ -47,6 +47,20 @@ public function testPurchase() $this->assertSame('10.00', $request->getAmount()); } + public function testPurchaseRiskManaged() + { + $gateway = clone $this->gateway; + $gateway->setRiskManagement(true); + $request = $gateway->purchase(['card' => $this->getValidCard(), 'transactionId' => 'Test1234', 'ip' => '1.1.1.1', 'amount' => '25.00']); + + $this->assertInstanceOf('\Omnipay\NABTransact\Message\SecureXMLRiskPurchaseRequest', $request); + $this->assertSame('25.00', $request->getAmount()); + $this->assertContains( + '1.1.1.1ExampleUser12345BillstownUS', + (string) $request->getData()->asXml() + ); + } + public function testRefund() { $request = $this->gateway->refund(['amount' => '10.00', 'transactionId' => 'Order-YKHU67']);