Skip to content

Commit b076bdc

Browse files
authored
Merge pull request #36 from sudiptpa/fix/adding-emv-3dsc
Added EMV 3DSC
2 parents cd341c6 + 6716b1a commit b076bdc

8 files changed

+161
-15
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ The following gateways are provided by this package:
105105
} else {
106106
echo sprintf('Transaction %s failed: %s', $response->getTransactionReference(), $response->getMessage());
107107
}
108+
```
108109

109110
### NAB Transact DirectPost v2
110111

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

114115
$gateway->setMerchantId('XYZ0010');
115116
$gateway->setTransactionPassword('abcd1234');
116-
117117
$gateway->setTestMode(true);
118+
$gateway->setHasEMV3DSEnabled(true);
118119

119120
$card = new CreditCard(array(
120121
'firstName' => 'Sujip',
@@ -128,8 +129,10 @@ The following gateways are provided by this package:
128129
$response = $gateway->purchase(array(
129130
'amount' => '12.00',
130131
'transactionId' => 'ORDER-ZYX8',
132+
'transactionReference' => '11fc42b0-bb7a-41a4-8b3c-096b3fd4d402'
131133
'currency' => 'AUD',
132134
'card' => $card,
135+
'clientIp' => '192.168.1.1'
133136
))
134137
->send();
135138

@@ -185,6 +188,7 @@ The following gateways are provided by this package:
185188
$response = $gateway->completePurchase(array(
186189
'amount' => '12.00',
187190
'transactionId' => '1234566789205067',
191+
'transactionReference' => '11fc42b0-bb7a-41a4-8b3c-096b3fd4d402'
188192
'currency' => 'AUD',
189193
'returnUrl' => 'http://example.com/payment/response',
190194
))

src/DirectPostGateway.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
*/
1212
class DirectPostGateway extends AbstractGateway
1313
{
14-
/**
15-
* @var bool
16-
*/
17-
public $transparentRedirect = true;
18-
1914
public function getName()
2015
{
2116
return 'NABTransact Direct Post';
@@ -62,6 +57,19 @@ public function setTransactionPassword($value)
6257
return $this->setParameter('transactionPassword', $value);
6358
}
6459

60+
public function getHasEMV3DSEnabled()
61+
{
62+
return $this->getParameter('hasEMV3DSEnabled');
63+
}
64+
65+
/**
66+
* @param $value
67+
*/
68+
public function setHasEMV3DSEnabled($value)
69+
{
70+
return $this->setParameter('hasEMV3DSEnabled', $value);
71+
}
72+
6573
/**
6674
* @param array $parameters
6775
*

src/Enums/TransactionType.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact\Enums;
4+
5+
class TransactionType
6+
{
7+
const NORMAL_PAYMENT = 0;
8+
const NORMAL_PREAUTH = 1;
9+
10+
const PAYMENT_RISK_MANAGEMENT = 2;
11+
const PREAUTH_RISK_MANAGEMENT = 3;
12+
13+
const PAYMENT_3DS_EMV3DS = 4;
14+
const PREAUTH_3DS_EMV3DS = 5;
15+
16+
const PAYMENT_RISK_MANAGEMENT_3DS_EMV3DS = 6;
17+
const PREAUTH_RISK_MANAGEMENT_3DS_EMV3DS = 7;
18+
19+
const STORE_ONLY = 8;
20+
}

src/Message/AbstractRequest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ public function setTransactionPassword($value)
4949
return $this->setParameter('transactionPassword', $value);
5050
}
5151

52+
public function getHasEMV3DSEnabled()
53+
{
54+
return $this->getParameter('hasEMV3DSEnabled');
55+
}
56+
57+
/**
58+
* @param $value
59+
*/
60+
public function setHasEMV3DSEnabled($value)
61+
{
62+
return $this->setParameter('hasEMV3DSEnabled', $value);
63+
}
64+
5265
/**
5366
* @return string
5467
*/

src/Message/DirectPostAbstractRequest.php

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Omnipay\NABTransact\Message;
44

5+
use Omnipay\NABTransact\Enums\TransactionType;
6+
57
/**
68
* NABTransact Direct Post Abstract Request.
79
*/
@@ -22,14 +24,23 @@ abstract class DirectPostAbstractRequest extends AbstractRequest
2224
*/
2325
public function generateFingerprint(array $data)
2426
{
25-
$hash = implode('|', [
27+
$hashable = [
2628
$data['EPS_MERCHANT'],
2729
$this->getTransactionPassword(),
2830
$data['EPS_TXNTYPE'],
2931
$data['EPS_REFERENCEID'],
3032
$data['EPS_AMOUNT'],
3133
$data['EPS_TIMESTAMP'],
32-
]);
34+
];
35+
36+
if ($this->getHasEMV3DSEnabled()) {
37+
$hashable = array_merge(
38+
$hashable,
39+
[$data['EPS_ORDERID']]
40+
);
41+
}
42+
43+
$hash = implode('|', $hashable);
3344

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

4455
$data['EPS_MERCHANT'] = $this->getMerchantId();
4556
$data['EPS_TXNTYPE'] = $this->txnType;
46-
$data['EPS_IP'] = $this->getClientIp();
47-
$data['EPS_AMOUNT'] = $this->getAmount();
4857
$data['EPS_REFERENCEID'] = $this->getTransactionId();
58+
$data['EPS_AMOUNT'] = $this->getAmount();
4959
$data['EPS_TIMESTAMP'] = gmdate('YmdHis');
50-
$data['EPS_FINGERPRINT'] = $this->generateFingerprint($data);
5160
$data['EPS_RESULTURL'] = $this->getReturnUrl();
52-
$data['EPS_CALLBACKURL'] = $this->getNotifyUrl() ?: $this->getReturnUrl();
61+
$data['EPS_IP'] = $this->getClientIp();
5362
$data['EPS_REDIRECT'] = 'TRUE';
54-
$data['EPS_CURRENCY'] = $this->getCurrency();
63+
64+
if ($this->getNotifyUrl()) {
65+
$data['EPS_CALLBACKURL'] = $this->getNotifyUrl();
66+
}
67+
68+
if ($currency = $this->getCurrency()) {
69+
$data['EPS_CURRENCY'] = $currency;
70+
}
71+
72+
$card = $this->getCard();
73+
74+
if ($billingPostcode = $card->getBillingPostcode()) {
75+
$data['EPS_ZIPCODE'] = $billingPostcode;
76+
}
77+
78+
if ($billingCity = $card->getBillingCity()) {
79+
$data['EPS_TOWN'] = $billingCity;
80+
}
81+
82+
if ($billingCountry = $card->getBillingCountry()) {
83+
$data['EPS_BILLINGCOUNTRY'] = $billingCountry;
84+
}
85+
86+
if ($shippingCountry = $card->getShippingCountry()) {
87+
$data['EPS_DELIVERYCOUNTRY'] = $shippingCountry;
88+
}
89+
90+
if ($emailAddress = $card->getEmail()) {
91+
$data['EPS_EMAILADDRESS'] = $emailAddress;
92+
}
93+
94+
if ($this->getHasEMV3DSEnabled()) {
95+
$data['EPS_ORDERID'] = $this->getTransactionReference();
96+
97+
$data['EPS_TXNTYPE'] = TransactionType::PAYMENT_3DS_EMV3DS;
98+
}
99+
100+
$data['EPS_FINGERPRINT'] = $this->generateFingerprint($data);
55101

56102
return $data;
57103
}

src/Message/DirectPostCompletePurchaseRequest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ public function getData()
2828
*/
2929
public function generateResponseFingerprint($data)
3030
{
31-
$hash = implode('|', [
31+
$hashable = [
3232
$data['merchant'],
3333
$this->getTransactionPassword(),
3434
$data['refid'],
3535
$this->getAmount(),
3636
$data['timestamp'],
3737
$data['summarycode'],
38-
]);
38+
];
39+
40+
$hash = implode('|', $hashable);
3941

4042
return hash_hmac('sha256', $hash, $this->getTransactionPassword());
4143
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact\Message;
4+
5+
class DirectPostWebhookRequest extends DirectPostAbstractRequest
6+
{
7+
private $data = [];
8+
9+
public function __construct($data = [])
10+
{
11+
$this->data = $data;
12+
}
13+
14+
public function generateResponseFingerprint($data)
15+
{
16+
$hashable = [
17+
$data['merchant'],
18+
$data['txn_password'],
19+
$data['refid'],
20+
$data['amount'],
21+
$data['timestamp'],
22+
$data['summarycode'],
23+
];
24+
25+
$hash = implode('|', $hashable);
26+
27+
return hash_hmac('sha256', $hash, $data['txn_password']);
28+
}
29+
30+
public function vefiyFingerPrint($fingerprint)
31+
{
32+
$data = $this->data;
33+
34+
if ($fingerprint !== $this->generateResponseFingerprint($data)) {
35+
$data['restext'] = $data['restext'].', Invalid fingerprint.';
36+
$data['summarycode'] = 3;
37+
}
38+
39+
return new DirectPostCompletePurchaseResponse($this, $data);
40+
}
41+
42+
public function getData()
43+
{
44+
return $this->data;
45+
}
46+
47+
public function sendData($data)
48+
{
49+
}
50+
}

src/Message/SecureXMLRiskPurchaseRequest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ public function getData()
4545
$xml = $this->getBasePaymentXMLWithCard();
4646

4747
$buyer = $xml->addChild('BuyerInfo');
48+
4849
$buyer->addChild('ip', $this->getIp('ip'));
50+
4951
$card = $this->getCard();
52+
5053
if ($firstName = $card->getFirstName()) {
5154
$buyer->addChild('firstName', $firstName);
5255
}

0 commit comments

Comments
 (0)