Skip to content

Commit dfeb46b

Browse files
committed
Added DirectPost v2
1 parent 7baeab2 commit dfeb46b

10 files changed

+578
-0
lines changed

src/DirectPostGateway.php

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact;
4+
5+
use Omnipay\Common\AbstractGateway;
6+
7+
/**
8+
* NABTransact Direct Post Gateway
9+
*/
10+
class DirectPostGateway extends AbstractGateway
11+
{
12+
/**
13+
* @var mixed
14+
*/
15+
public $transparentRedirect = true;
16+
17+
public function getName()
18+
{
19+
return 'NABTransact Direct Post';
20+
}
21+
22+
public function getDefaultParameters()
23+
{
24+
return array(
25+
'merchantId' => '',
26+
'transactionPassword' => '',
27+
'testMode' => false,
28+
);
29+
}
30+
31+
/**
32+
* @return mixed
33+
*/
34+
public function getMerchantId()
35+
{
36+
return $this->getParameter('merchantId');
37+
}
38+
39+
/**
40+
* @param $value
41+
* @return mixed
42+
*/
43+
public function setMerchantId($value)
44+
{
45+
return $this->setParameter('merchantId', $value);
46+
}
47+
48+
/**
49+
* @return mixed
50+
*/
51+
public function getTransactionPassword()
52+
{
53+
return $this->getParameter('transactionPassword');
54+
}
55+
56+
/**
57+
* @param $value
58+
* @return mixed
59+
*/
60+
public function setTransactionPassword($value)
61+
{
62+
return $this->setParameter('transactionPassword', $value);
63+
}
64+
65+
/**
66+
* @param array $parameters
67+
* @return mixed
68+
*/
69+
public function authorize(array $parameters = array())
70+
{
71+
return $this->createRequest('\Omnipay\NABTransact\Message\DirectPostAuthorizeRequest', $parameters);
72+
}
73+
74+
/**
75+
* @param array $parameters
76+
* @return mixed
77+
*/
78+
public function completeAuthorize(array $parameters = array())
79+
{
80+
return $this->createRequest('\Omnipay\NABTransact\Message\DirectPostCompletePurchaseRequest', $parameters);
81+
}
82+
83+
/**
84+
* @param array $parameters
85+
* @return mixed
86+
*/
87+
public function purchase(array $parameters = array())
88+
{
89+
return $this->createRequest('\Omnipay\NABTransact\Message\DirectPostPurchaseRequest', $parameters);
90+
}
91+
92+
/**
93+
* @param array $parameters
94+
* @return mixed
95+
*/
96+
public function completePurchase(array $parameters = array())
97+
{
98+
return $this->createRequest('\Omnipay\NABTransact\Message\DirectPostCompletePurchaseRequest', $parameters);
99+
}
100+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact\Message;
4+
5+
/**
6+
* NABTransact Direct Post Abstract Request
7+
*/
8+
abstract class DirectPostAbstractRequest extends AbstractRequest
9+
{
10+
/**
11+
* @var string
12+
*/
13+
public $testEndpoint = 'https://transact.nab.com.au/test/directpostv2/authorise';
14+
15+
/**
16+
* @var string
17+
*/
18+
public $liveEndpoint = 'https://transact.nab.com.au/live/directpostv2/authorise';
19+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact\Message;
4+
5+
/**
6+
* NABTransact Direct Post Authorize Request
7+
*/
8+
class DirectPostAuthorizeRequest extends DirectPostAbstractRequest
9+
{
10+
/**
11+
* @var string
12+
*/
13+
public $txnType = '1';
14+
15+
/**
16+
* @return mixed
17+
*/
18+
public function getData()
19+
{
20+
$this->validate('amount', 'returnUrl', 'card');
21+
22+
$data = array();
23+
$data['EPS_MERCHANT'] = $this->getMerchantId();
24+
$data['EPS_TXNTYPE'] = $this->txnType;
25+
$data['EPS_IP'] = $this->getClientIp();
26+
$data['EPS_AMOUNT'] = $this->getAmount();
27+
$data['EPS_REFERENCEID'] = $this->getTransactionId();
28+
$data['EPS_TIMESTAMP'] = gmdate('YmdHis');
29+
$data['EPS_FINGERPRINT'] = $this->generateFingerprint($data);
30+
$data['EPS_RESULTURL'] = $this->getReturnUrl();
31+
$data['EPS_CALLBACKURL'] = $this->getNotifyUrl() ?: $this->getReturnUrl();
32+
$data['EPS_REDIRECT'] = 'TRUE';
33+
$data['EPS_CURRENCY'] = $this->getCurrency();
34+
35+
$data = array_replace($data, $this->getCardData());
36+
37+
return $data;
38+
}
39+
40+
/**
41+
* @param array $data
42+
*/
43+
public function generateFingerprint(array $data)
44+
{
45+
$hash = implode(
46+
'|',
47+
array(
48+
$data['EPS_MERCHANT'],
49+
$this->getTransactionPassword(),
50+
$data['EPS_TXNTYPE'],
51+
$data['EPS_REFERENCEID'],
52+
$data['EPS_AMOUNT'],
53+
$data['EPS_TIMESTAMP'],
54+
)
55+
);
56+
57+
return sha1($hash);
58+
}
59+
60+
/**
61+
* @param $data
62+
* @return mixed
63+
*/
64+
public function sendData($data)
65+
{
66+
return $this->response = new DirectPostAuthorizeResponse($this, $data, $this->getEndpoint());
67+
}
68+
69+
/**
70+
* @return mixed
71+
*/
72+
protected function getCardData()
73+
{
74+
$this->getCard()->validate();
75+
76+
$data = array();
77+
78+
$data['EPS_CARDNUMBER'] = $this->getCard()->getNumber();
79+
$data['EPS_EXPIRYMONTH'] = $this->getCard()->getExpiryMonth();
80+
$data['EPS_EXPIRYYEAR'] = $this->getCard()->getExpiryYear();
81+
$data['EPS_CCV'] = $this->getCard()->getCvv();
82+
83+
return $data;
84+
}
85+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact\Message;
4+
5+
use Omnipay\Common\Message\AbstractResponse;
6+
use Omnipay\Common\Message\RedirectResponseInterface;
7+
use Omnipay\Common\Message\RequestInterface;
8+
9+
/**
10+
* NABTransact Direct Post Authorize Response
11+
*/
12+
class DirectPostAuthorizeResponse extends AbstractResponse implements RedirectResponseInterface
13+
{
14+
/**
15+
* @var mixed
16+
*/
17+
protected $redirectUrl;
18+
19+
/**
20+
* @param RequestInterface $request
21+
* @param $data
22+
* @param $redirectUrl
23+
*/
24+
public function __construct(RequestInterface $request, $data, $redirectUrl)
25+
{
26+
$this->request = $request;
27+
$this->data = $data;
28+
$this->redirectUrl = $redirectUrl;
29+
}
30+
31+
public function isSuccessful()
32+
{
33+
return false;
34+
}
35+
36+
public function isRedirect()
37+
{
38+
return true;
39+
}
40+
41+
/**
42+
* @return mixed
43+
*/
44+
public function getRedirectUrl()
45+
{
46+
return $this->redirectUrl;
47+
}
48+
49+
public function getRedirectMethod()
50+
{
51+
return 'POST';
52+
}
53+
54+
/**
55+
* @return mixed
56+
*/
57+
public function getRedirectData()
58+
{
59+
return $this->getData();
60+
}
61+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact\Message;
4+
5+
use Omnipay\Common\Exception\InvalidRequestException;
6+
7+
/**
8+
* NABTransact Direct Post Complete Purchase Request
9+
*/
10+
class DirectPostCompletePurchaseRequest extends DirectPostAbstractRequest
11+
{
12+
/**
13+
* @return mixed
14+
*/
15+
public function getData()
16+
{
17+
$data = $this->httpRequest->query->all();
18+
19+
if ($this->generateResponseFingerprint($data) !== $this->httpRequest->query->get('fingerprint')) {
20+
throw new InvalidRequestException('Invalid fingerprint');
21+
}
22+
23+
return $data;
24+
}
25+
26+
/**
27+
* @param $data
28+
*/
29+
public function generateResponseFingerprint($data)
30+
{
31+
$fields = implode(
32+
'|',
33+
array(
34+
$data['merchant'],
35+
$this->getTransactionPassword(),
36+
$data['refid'],
37+
$this->getAmount(),
38+
$data['timestamp'],
39+
$data['summarycode'],
40+
)
41+
);
42+
43+
return sha1($fields);
44+
}
45+
46+
/**
47+
* @param $data
48+
* @return mixed
49+
*/
50+
public function sendData($data)
51+
{
52+
return $this->response = new DirectPostCompletePurchaseResponse($this, $data);
53+
}
54+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact\Message;
4+
5+
use Omnipay\Common\Message\AbstractResponse;
6+
7+
/**
8+
* NABTransact Direct Post Complete Purchase Response
9+
*/
10+
class DirectPostCompletePurchaseResponse extends AbstractResponse
11+
{
12+
public function isSuccessful()
13+
{
14+
return isset($this->data['summarycode']) && $this->data['summarycode'] == 1;
15+
}
16+
17+
/**
18+
* @return mixed
19+
*/
20+
public function getMessage()
21+
{
22+
if (isset($this->data['restext'])) {
23+
return $this->data['restext'];
24+
}
25+
}
26+
27+
/**
28+
* @return mixed
29+
*/
30+
public function getCode()
31+
{
32+
if (isset($this->data['rescode'])) {
33+
return $this->data['rescode'];
34+
}
35+
}
36+
37+
/**
38+
* @return mixed
39+
*/
40+
public function getTransactionReference()
41+
{
42+
if (isset($this->data['txnid'])) {
43+
return $this->data['txnid'];
44+
}
45+
}
46+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact\Message;
4+
5+
/**
6+
* NABTransact Direct Post Purchase Request
7+
*/
8+
class DirectPostPurchaseRequest extends DirectPostAuthorizeRequest
9+
{
10+
/**
11+
* @var string
12+
*/
13+
public $txnType = '0';
14+
}

0 commit comments

Comments
 (0)