Skip to content

Commit 9900c59

Browse files
committed
Added support for EMV3DS on Direct Post API
1 parent 587f07a commit 9900c59

12 files changed

+128
-243
lines changed

src/DirectPostGateway.php

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,97 +9,66 @@
99
*/
1010
class DirectPostGateway extends AbstractGateway
1111
{
12-
/**
13-
* @var mixed
14-
*/
15-
public $transparentRedirect = true;
16-
1712
public function getName()
1813
{
1914
return 'NABTransact Direct Post';
2015
}
2116

2217
public function getDefaultParameters()
2318
{
24-
return array(
25-
'merchantId' => '',
19+
return [
20+
'merchantId' => '',
2621
'transactionPassword' => '',
27-
'testMode' => false,
28-
);
22+
'testMode' => false,
23+
];
2924
}
3025

31-
/**
32-
* @return mixed
33-
*/
3426
public function getMerchantId()
3527
{
3628
return $this->getParameter('merchantId');
3729
}
3830

39-
/**
40-
* @param $value
41-
*
42-
* @return mixed
43-
*/
4431
public function setMerchantId($value)
4532
{
4633
return $this->setParameter('merchantId', $value);
4734
}
4835

49-
/**
50-
* @return mixed
51-
*/
5236
public function getTransactionPassword()
5337
{
5438
return $this->getParameter('transactionPassword');
5539
}
5640

57-
/**
58-
* @param $value
59-
*
60-
* @return mixed
61-
*/
6241
public function setTransactionPassword($value)
6342
{
6443
return $this->setParameter('transactionPassword', $value);
6544
}
6645

67-
/**
68-
* @param array $parameters
69-
*
70-
* @return mixed
71-
*/
72-
public function authorize(array $parameters = array())
46+
public function getHasEMV3DSEnabled()
47+
{
48+
return $this->getParameter('hasEMV3DSEnabled');
49+
}
50+
51+
public function setHasEMV3DSEnabled($value)
52+
{
53+
return $this->setParameter('hasEMV3DSEnabled', $value);
54+
}
55+
56+
public function authorize(array $parameters = [])
7357
{
7458
return $this->createRequest('\Omnipay\NABTransact\Message\DirectPostAuthorizeRequest', $parameters);
7559
}
7660

77-
/**
78-
* @param array $parameters
79-
*
80-
* @return mixed
81-
*/
82-
public function completeAuthorize(array $parameters = array())
61+
public function completeAuthorize(array $parameters = [])
8362
{
8463
return $this->createRequest('\Omnipay\NABTransact\Message\DirectPostCompletePurchaseRequest', $parameters);
8564
}
8665

87-
/**
88-
* @param array $parameters
89-
*
90-
* @return mixed
91-
*/
92-
public function purchase(array $parameters = array())
66+
public function purchase(array $parameters = [])
9367
{
9468
return $this->createRequest('\Omnipay\NABTransact\Message\DirectPostPurchaseRequest', $parameters);
9569
}
9670

97-
/**
98-
* @param array $parameters
99-
*
100-
* @return mixed
101-
*/
102-
public function completePurchase(array $parameters = array())
71+
public function completePurchase(array $parameters = [])
10372
{
10473
return $this->createRequest('\Omnipay\NABTransact\Message\DirectPostCompletePurchaseRequest', $parameters);
10574
}

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/HostedPaymentGateway.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,11 @@
99
*/
1010
class HostedPaymentGateway extends AbstractGateway
1111
{
12-
/**
13-
* @param array $parameters
14-
*
15-
* @return mixed
16-
*/
1712
public function completePurchase(array $parameters = array())
1813
{
1914
return $this->createRequest('\Omnipay\NABTransact\Message\HostedPaymentCompletePurchaseRequest', $parameters);
2015
}
2116

22-
/**
23-
* @return mixed
24-
*/
2517
public function getMerchantId()
2618
{
2719
return $this->getParameter('merchantId');
@@ -32,21 +24,11 @@ public function getName()
3224
return 'NAB Hosted Payment';
3325
}
3426

35-
/**
36-
* @param array $parameters
37-
*
38-
* @return mixed
39-
*/
4027
public function purchase(array $parameters = array())
4128
{
4229
return $this->createRequest('\Omnipay\NABTransact\Message\HostedPaymentPurchaseRequest', $parameters);
4330
}
4431

45-
/**
46-
* @param $value
47-
*
48-
* @return mixed
49-
*/
5032
public function setMerchantId($value)
5133
{
5234
return $this->setParameter('merchantId', $value);

src/Message/AbstractRequest.php

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,40 @@
77
*/
88
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
99
{
10-
/**
11-
* @var mixed
12-
*/
1310
public $testEndpoint;
1411

15-
/**
16-
* @var mixed
17-
*/
1812
public $liveEndpoint;
1913

20-
/**
21-
* @return mixed
22-
*/
2314
public function getMerchantId()
2415
{
2516
return $this->getParameter('merchantId');
2617
}
2718

28-
/**
29-
* @param $value
30-
*
31-
* @return mixed
32-
*/
3319
public function setMerchantId($value)
3420
{
3521
return $this->setParameter('merchantId', $value);
3622
}
3723

38-
/**
39-
* @return mixed
40-
*/
4124
public function getTransactionPassword()
4225
{
4326
return $this->getParameter('transactionPassword');
4427
}
4528

46-
/**
47-
* @param $value
48-
*
49-
* @return mixed
50-
*/
5129
public function setTransactionPassword($value)
5230
{
5331
return $this->setParameter('transactionPassword', $value);
5432
}
5533

56-
/**
57-
* @return mixed
58-
*/
34+
public function getHasEMV3DSEnabled()
35+
{
36+
return $this->getParameter('hasEMV3DSEnabled');
37+
}
38+
39+
public function setHasEMV3DSEnabled($value)
40+
{
41+
return $this->setParameter('hasEMV3DSEnabled', $value);
42+
}
43+
5944
public function getEndpoint()
6045
{
6146
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;

src/Message/DirectPostAbstractRequest.php

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,89 @@
22

33
namespace Omnipay\NABTransact\Message;
44

5+
use Omnipay\NABTransact\Enums\TransactionType;
6+
57
/**
68
* NABTransact Direct Post Abstract Request.
79
*/
810
abstract class DirectPostAbstractRequest extends AbstractRequest
911
{
10-
/**
11-
* @var string
12-
*/
1312
public $testEndpoint = 'https://demo.transact.nab.com.au/directpostv2/authorise';
1413

15-
/**
16-
* @var string
17-
*/
1814
public $liveEndpoint = 'https://transact.nab.com.au/live/directpostv2/authorise';
1915

20-
/**
21-
* @param array $data
22-
*/
2316
public function generateFingerprint(array $data)
2417
{
25-
$hash = implode(
26-
'|',
27-
array(
28-
$data['EPS_MERCHANT'],
29-
$this->getTransactionPassword(),
30-
$data['EPS_TXNTYPE'],
31-
$data['EPS_REFERENCEID'],
32-
$data['EPS_AMOUNT'],
33-
$data['EPS_TIMESTAMP'],
34-
)
35-
);
18+
$hashable = [
19+
$data['EPS_MERCHANT'],
20+
$this->getTransactionPassword(),
21+
$data['EPS_TXNTYPE'],
22+
$data['EPS_REFERENCEID'],
23+
$data['EPS_AMOUNT'],
24+
$data['EPS_TIMESTAMP'],
25+
];
26+
27+
if ($this->hasEMV3DSEnabled()) {
28+
$hashable = array_merge(
29+
$hashable, [$data['EPS_ORDERID']]
30+
);
31+
}
32+
33+
$hash = implode('|', $hashable);
3634

3735
return sha1($hash);
3836
}
3937

40-
/**
41-
* @return mixed
42-
*/
4338
public function getBaseData()
4439
{
45-
$data = array();
40+
$data = [];
4641

4742
$data['EPS_MERCHANT'] = $this->getMerchantId();
4843
$data['EPS_TXNTYPE'] = $this->txnType;
49-
$data['EPS_IP'] = $this->getClientIp();
50-
$data['EPS_AMOUNT'] = $this->getAmount();
5144
$data['EPS_REFERENCEID'] = $this->getTransactionId();
45+
$data['EPS_AMOUNT'] = $this->getAmount();
5246
$data['EPS_TIMESTAMP'] = gmdate('YmdHis');
53-
$data['EPS_FINGERPRINT'] = $this->generateFingerprint($data);
5447
$data['EPS_RESULTURL'] = $this->getReturnUrl();
55-
$data['EPS_CALLBACKURL'] = $this->getNotifyUrl() ?: $this->getReturnUrl();
48+
$data['EPS_IP'] = $this->getClientIp();
5649
$data['EPS_REDIRECT'] = 'TRUE';
57-
$data['EPS_CURRENCY'] = $this->getCurrency();
50+
51+
if ($this->getNotifyUrl()) {
52+
$data['EPS_CALLBACKURL'] = $this->getNotifyUrl();
53+
}
54+
55+
if ($currency = $this->getCurrency()) {
56+
$data['EPS_CURRENCY'] = $currency;
57+
}
58+
59+
$card = $this->getCard();
60+
61+
if ($billingPostcode = $card->getBillingPostcode()) {
62+
$data['EPS_ZIPCODE'] = $billingPostcode;
63+
}
64+
65+
if ($billingCity = $card->getBillingCity()) {
66+
$data['EPS_TOWN'] = $billingCity;
67+
}
68+
69+
if ($billingCountry = $card->getBillingCountry()) {
70+
$data['EPS_BILLINGCOUNTRY'] = $billingCountry;
71+
}
72+
73+
if ($shippingCountry = $card->getShippingCountry()) {
74+
$data['EPS_DELIVERYCOUNTRY'] = $shippingCountry;
75+
}
76+
77+
if ($emailAddress = $card->getEmail()) {
78+
$data['EPS_EMAILADDRESS'] = $emailAddress;
79+
}
80+
81+
if ($this->hasEMV3DSEnabled()) {
82+
$data['EPS_ORDERID'] = $this->getTransactionReference();
83+
84+
$data['EPS_TXNTYPE'] = TransactionType::PAYMENT_3DS_EMV3DS;
85+
}
86+
87+
$data['EPS_FINGERPRINT'] = $this->generateFingerprint($data);
5888

5989
return $data;
6090
}

0 commit comments

Comments
 (0)