|
2 | 2 |
|
3 | 3 | namespace Omnipay\NABTransact\Message; |
4 | 4 |
|
| 5 | +use Omnipay\NABTransact\Enums\TransactionType; |
| 6 | + |
5 | 7 | /** |
6 | 8 | * NABTransact Direct Post Abstract Request. |
7 | 9 | */ |
8 | 10 | abstract class DirectPostAbstractRequest extends AbstractRequest |
9 | 11 | { |
10 | | - /** |
11 | | - * @var string |
12 | | - */ |
13 | 12 | public $testEndpoint = 'https://demo.transact.nab.com.au/directpostv2/authorise'; |
14 | 13 |
|
15 | | - /** |
16 | | - * @var string |
17 | | - */ |
18 | 14 | public $liveEndpoint = 'https://transact.nab.com.au/live/directpostv2/authorise'; |
19 | 15 |
|
20 | | - /** |
21 | | - * @param array $data |
22 | | - */ |
23 | 16 | public function generateFingerprint(array $data) |
24 | 17 | { |
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); |
36 | 34 |
|
37 | 35 | return sha1($hash); |
38 | 36 | } |
39 | 37 |
|
40 | | - /** |
41 | | - * @return mixed |
42 | | - */ |
43 | 38 | public function getBaseData() |
44 | 39 | { |
45 | | - $data = array(); |
| 40 | + $data = []; |
46 | 41 |
|
47 | 42 | $data['EPS_MERCHANT'] = $this->getMerchantId(); |
48 | 43 | $data['EPS_TXNTYPE'] = $this->txnType; |
49 | | - $data['EPS_IP'] = $this->getClientIp(); |
50 | | - $data['EPS_AMOUNT'] = $this->getAmount(); |
51 | 44 | $data['EPS_REFERENCEID'] = $this->getTransactionId(); |
| 45 | + $data['EPS_AMOUNT'] = $this->getAmount(); |
52 | 46 | $data['EPS_TIMESTAMP'] = gmdate('YmdHis'); |
53 | | - $data['EPS_FINGERPRINT'] = $this->generateFingerprint($data); |
54 | 47 | $data['EPS_RESULTURL'] = $this->getReturnUrl(); |
55 | | - $data['EPS_CALLBACKURL'] = $this->getNotifyUrl() ?: $this->getReturnUrl(); |
| 48 | + $data['EPS_IP'] = $this->getClientIp(); |
56 | 49 | $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); |
58 | 88 |
|
59 | 89 | return $data; |
60 | 90 | } |
|
0 commit comments