Skip to content

Commit

Permalink
Merge pull request #36 from sudiptpa/fix/adding-emv-3dsc
Browse files Browse the repository at this point in the history
Added EMV 3DSC
  • Loading branch information
sudiptpa committed Dec 6, 2022
2 parents cd341c6 + 6716b1a commit b076bdc
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 15 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ The following gateways are provided by this package:
} else {
echo sprintf('Transaction %s failed: %s', $response->getTransactionReference(), $response->getMessage());
}
```

### NAB Transact DirectPost v2

Expand All @@ -113,8 +114,8 @@ The following gateways are provided by this package:

$gateway->setMerchantId('XYZ0010');
$gateway->setTransactionPassword('abcd1234');

$gateway->setTestMode(true);
$gateway->setHasEMV3DSEnabled(true);

$card = new CreditCard(array(
'firstName' => 'Sujip',
Expand All @@ -128,8 +129,10 @@ The following gateways are provided by this package:
$response = $gateway->purchase(array(
'amount' => '12.00',
'transactionId' => 'ORDER-ZYX8',
'transactionReference' => '11fc42b0-bb7a-41a4-8b3c-096b3fd4d402'
'currency' => 'AUD',
'card' => $card,
'clientIp' => '192.168.1.1'
))
->send();

Expand Down Expand Up @@ -185,6 +188,7 @@ The following gateways are provided by this package:
$response = $gateway->completePurchase(array(
'amount' => '12.00',
'transactionId' => '1234566789205067',
'transactionReference' => '11fc42b0-bb7a-41a4-8b3c-096b3fd4d402'
'currency' => 'AUD',
'returnUrl' => 'http://example.com/payment/response',
))
Expand Down
18 changes: 13 additions & 5 deletions src/DirectPostGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
*/
class DirectPostGateway extends AbstractGateway
{
/**
* @var bool
*/
public $transparentRedirect = true;

public function getName()
{
return 'NABTransact Direct Post';
Expand Down Expand Up @@ -62,6 +57,19 @@ public function setTransactionPassword($value)
return $this->setParameter('transactionPassword', $value);
}

public function getHasEMV3DSEnabled()
{
return $this->getParameter('hasEMV3DSEnabled');
}

/**
* @param $value
*/
public function setHasEMV3DSEnabled($value)
{
return $this->setParameter('hasEMV3DSEnabled', $value);
}

/**
* @param array $parameters
*
Expand Down
20 changes: 20 additions & 0 deletions src/Enums/TransactionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Omnipay\NABTransact\Enums;

class TransactionType
{
const NORMAL_PAYMENT = 0;
const NORMAL_PREAUTH = 1;

const PAYMENT_RISK_MANAGEMENT = 2;
const PREAUTH_RISK_MANAGEMENT = 3;

const PAYMENT_3DS_EMV3DS = 4;
const PREAUTH_3DS_EMV3DS = 5;

const PAYMENT_RISK_MANAGEMENT_3DS_EMV3DS = 6;
const PREAUTH_RISK_MANAGEMENT_3DS_EMV3DS = 7;

const STORE_ONLY = 8;
}
13 changes: 13 additions & 0 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ public function setTransactionPassword($value)
return $this->setParameter('transactionPassword', $value);
}

public function getHasEMV3DSEnabled()
{
return $this->getParameter('hasEMV3DSEnabled');
}

/**
* @param $value
*/
public function setHasEMV3DSEnabled($value)
{
return $this->setParameter('hasEMV3DSEnabled', $value);
}

/**
* @return string
*/
Expand Down
60 changes: 53 additions & 7 deletions src/Message/DirectPostAbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Omnipay\NABTransact\Message;

use Omnipay\NABTransact\Enums\TransactionType;

/**
* NABTransact Direct Post Abstract Request.
*/
Expand All @@ -22,14 +24,23 @@ abstract class DirectPostAbstractRequest extends AbstractRequest
*/
public function generateFingerprint(array $data)
{
$hash = implode('|', [
$hashable = [
$data['EPS_MERCHANT'],
$this->getTransactionPassword(),
$data['EPS_TXNTYPE'],
$data['EPS_REFERENCEID'],
$data['EPS_AMOUNT'],
$data['EPS_TIMESTAMP'],
]);
];

if ($this->getHasEMV3DSEnabled()) {
$hashable = array_merge(
$hashable,
[$data['EPS_ORDERID']]
);
}

$hash = implode('|', $hashable);

return hash_hmac('sha256', $hash, $this->getTransactionPassword());
}
Expand All @@ -43,15 +54,50 @@ public function getBaseData()

$data['EPS_MERCHANT'] = $this->getMerchantId();
$data['EPS_TXNTYPE'] = $this->txnType;
$data['EPS_IP'] = $this->getClientIp();
$data['EPS_AMOUNT'] = $this->getAmount();
$data['EPS_REFERENCEID'] = $this->getTransactionId();
$data['EPS_AMOUNT'] = $this->getAmount();
$data['EPS_TIMESTAMP'] = gmdate('YmdHis');
$data['EPS_FINGERPRINT'] = $this->generateFingerprint($data);
$data['EPS_RESULTURL'] = $this->getReturnUrl();
$data['EPS_CALLBACKURL'] = $this->getNotifyUrl() ?: $this->getReturnUrl();
$data['EPS_IP'] = $this->getClientIp();
$data['EPS_REDIRECT'] = 'TRUE';
$data['EPS_CURRENCY'] = $this->getCurrency();

if ($this->getNotifyUrl()) {
$data['EPS_CALLBACKURL'] = $this->getNotifyUrl();
}

if ($currency = $this->getCurrency()) {
$data['EPS_CURRENCY'] = $currency;
}

$card = $this->getCard();

if ($billingPostcode = $card->getBillingPostcode()) {
$data['EPS_ZIPCODE'] = $billingPostcode;
}

if ($billingCity = $card->getBillingCity()) {
$data['EPS_TOWN'] = $billingCity;
}

if ($billingCountry = $card->getBillingCountry()) {
$data['EPS_BILLINGCOUNTRY'] = $billingCountry;
}

if ($shippingCountry = $card->getShippingCountry()) {
$data['EPS_DELIVERYCOUNTRY'] = $shippingCountry;
}

if ($emailAddress = $card->getEmail()) {
$data['EPS_EMAILADDRESS'] = $emailAddress;
}

if ($this->getHasEMV3DSEnabled()) {
$data['EPS_ORDERID'] = $this->getTransactionReference();

$data['EPS_TXNTYPE'] = TransactionType::PAYMENT_3DS_EMV3DS;
}

$data['EPS_FINGERPRINT'] = $this->generateFingerprint($data);

return $data;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Message/DirectPostCompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ public function getData()
*/
public function generateResponseFingerprint($data)
{
$hash = implode('|', [
$hashable = [
$data['merchant'],
$this->getTransactionPassword(),
$data['refid'],
$this->getAmount(),
$data['timestamp'],
$data['summarycode'],
]);
];

$hash = implode('|', $hashable);

return hash_hmac('sha256', $hash, $this->getTransactionPassword());
}
Expand Down
50 changes: 50 additions & 0 deletions src/Message/DirectPostWebhookRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Omnipay\NABTransact\Message;

class DirectPostWebhookRequest extends DirectPostAbstractRequest
{
private $data = [];

public function __construct($data = [])
{
$this->data = $data;
}

public function generateResponseFingerprint($data)
{
$hashable = [
$data['merchant'],
$data['txn_password'],
$data['refid'],
$data['amount'],
$data['timestamp'],
$data['summarycode'],
];

$hash = implode('|', $hashable);

return hash_hmac('sha256', $hash, $data['txn_password']);
}

public function vefiyFingerPrint($fingerprint)
{
$data = $this->data;

if ($fingerprint !== $this->generateResponseFingerprint($data)) {
$data['restext'] = $data['restext'].', Invalid fingerprint.';
$data['summarycode'] = 3;
}

return new DirectPostCompletePurchaseResponse($this, $data);
}

public function getData()
{
return $this->data;
}

public function sendData($data)
{
}
}
3 changes: 3 additions & 0 deletions src/Message/SecureXMLRiskPurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ 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);
}
Expand Down

0 comments on commit b076bdc

Please sign in to comment.