PHP code example of sudiptpa / omnipay-nabtransact
1. Go to this page and download the library: Download sudiptpa/omnipay-nabtransact library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sudiptpa / omnipay-nabtransact example snippets
use Omnipay\Omnipay;
use Omnipay\Common\CreditCard;
$gateway = Omnipay::create('NABTransact_SecureXML');
$gateway->setMerchantId('XYZ0010');
$gateway->setTransactionPassword('abcd1234');
$gateway->setTestMode(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,
]
);
$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());
}
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());
}
$gateway = Omnipay::create('NABTransact_DirectPost');
$gateway->setMerchantId('XYZ0010');
$gateway->setTransactionPassword('abcd1234');
$gateway->setTestMode(true);
$gateway->setHasEMV3DSEnabled(true);
$card = new CreditCard([
'firstName' => 'Sujip',
'lastName' => 'Thapa',
'number' => '4444333322221111',
'expiryMonth' => '10',
'expiryYear' => '2030',
'cvv' => '123',
]);
$response = $gateway->purchase([
'amount' => '12.00',
'transactionId' => 'ORDER-ZYX8',
'transactionReference' => '11fc42b0-bb7a-41a4-8b3c-096b3fd4d402',
'currency' => 'AUD',
'card' => $card,
'clientIp' => '192.168.1.1'
])
->send();
if ($response->isRedirect()) {
$response->redirect();
}
if ($response->isSuccessful()) {
echo sprintf('Transaction %s was successful!', $response->getTransactionReference());
} else {
echo sprintf('Transaction %s failed: %s', $response->getTransactionReference(), $response->getMessage());
}
$gateway = Omnipay::create('NABTransact_DirectPost');
$gateway->setMerchantId('XYZ0010');
$gateway->setTransactionPassword('abcd1234');
$gateway->setTestMode(true);
$response = $gateway->store([
'transactionId' => 'STORE-ORDER-100',
'returnUrl' => 'http://example.com/payment/response',
'card' => $card,
])->send();
if ($response->isRedirect()) {
$response->redirect();
}
$gateway = Omnipay::create('NABTransact_DirectPost');
$gateway->setMerchantId('XYZ0010');
$gateway->setTransactionPassword('abcd1234');
$gateway->setTestMode(true);
$response = $gateway->capture([
'transactionId' => 'CAPTURE-ORDER-100',
'transactionReference' => 'NAB-ORIGINAL-TXN-ID',
'amount' => '12.00',
'currency' => 'AUD',
])->send();
if ($response->isSuccessful()) {
echo 'Capture successful: '.$response->getTransactionReference();
}
$response = $gateway->refund([
'transactionId' => 'REFUND-ORDER-100',
'transactionReference' => 'NAB-SETTLED-TXN-ID',
'amount' => '5.00',
'currency' => 'AUD',
])->send();
$response = $gateway->void([
'transactionId' => 'VOID-ORDER-100',
'transactionReference' => 'NAB-AUTH-TXN-ID',
'amount' => '12.00',
])->send();
$response = $gateway->createEMV3DSOrder([
'amount' => '12.00',
'currency' => 'AUD',
'clientIp' => '203.0.113.10',
'transactionReference' => 'ORDER-REF-100',
])->send();
if ($response->isSuccessful()) {
echo 'Order ID: '.$response->getOrderId();
echo 'Simple Token: '.$response->getSimpleToken();
}
$response = $gateway->purchase([
'amount' => '112.00',
'currency' => 'AUD',
'transactionId' => 'ORDER-ADV-100',
'card' => $card,
'returnUrl' => 'https://example.com/payment/response',
'notifyUrl' => 'https://example.com/payment/callback',
// Optional reporting/callback field control
'resultParams' => 'merchant,refid,rescode,restext',
'callbackParams' => 'merchant,refid,rescode,restext',
// Optional surcharge reporting fields
'surchargeEnabled' => true,
'surchargeAmount' => '12.00',
'surchargeRate' => '5.00',
'surchargeFee' => '7.00',
// Optional MCR route hint
'cardScheme' => 'scheme', // or 'eftpos'
])->send();
$gateway = Omnipay::create('NABTransact_UnionPay');
$gateway->setMerchantId('XYZ0010');
$gateway->setTransactionPassword('abcd1234');
$gateway->setTestMode(true);
/*
* The parameter transactionId must be alpha-numeric and 8 to 32 characters in length
*/
$response = $gateway->purchase([
'amount' => '12.00',
'transactionId' => '1234566789205067',
'currency' => 'AUD',
'returnUrl' => 'http://example.com/payment/response',
])
->send();
if ($response->isRedirect()) {
$response->redirect();
}
$gateway = Omnipay::create('NABTransact_UnionPay');
$gateway->setMerchantId('XYZ0010');
$gateway->setTransactionPassword('abcd1234');
$gateway->setTestMode(true);
$response = $gateway->completePurchase([
'amount' => '12.00',
'transactionId' => '1234566789205067',
'transactionReference' => '11fc42b0-bb7a-41a4-8b3c-096b3fd4d402',
'currency' => 'AUD',
'returnUrl' => 'http://example.com/payment/response',
])
->send();
if ($response->isSuccessful()) {
echo sprintf('Transaction %s was successful!', $response->getTransactionReference());
} else {
echo sprintf('Transaction %s failed: %s', $response->getTransactionReference(), $response->getMessage());
}
use Omnipay\NABTransact\Transport\CurlTransport;
$request = $gateway->purchase([
'amount' => '10.00',
'transactionId' => 'ORDER-1000',
'card' => $card,
]);
$request->setTransport(new CurlTransport());
$response = $request->send();