-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from sudiptpa/upgrade/nab-direct-postv2
NAB Transact direct post v2
- Loading branch information
Showing
11 changed files
with
661 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
namespace Omnipay\NABTransact; | ||
|
||
use Omnipay\Common\AbstractGateway; | ||
|
||
/** | ||
* NABTransact Direct Post Gateway. | ||
*/ | ||
class DirectPostGateway extends AbstractGateway | ||
{ | ||
/** | ||
* @var mixed | ||
*/ | ||
public $transparentRedirect = true; | ||
|
||
public function getName() | ||
{ | ||
return 'NABTransact Direct Post'; | ||
} | ||
|
||
public function getDefaultParameters() | ||
{ | ||
return array( | ||
'merchantId' => '', | ||
'transactionPassword' => '', | ||
'testMode' => false, | ||
); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getMerchantId() | ||
{ | ||
return $this->getParameter('merchantId'); | ||
} | ||
|
||
/** | ||
* @param $value | ||
* | ||
* @return mixed | ||
*/ | ||
public function setMerchantId($value) | ||
{ | ||
return $this->setParameter('merchantId', $value); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getTransactionPassword() | ||
{ | ||
return $this->getParameter('transactionPassword'); | ||
} | ||
|
||
/** | ||
* @param $value | ||
* | ||
* @return mixed | ||
*/ | ||
public function setTransactionPassword($value) | ||
{ | ||
return $this->setParameter('transactionPassword', $value); | ||
} | ||
|
||
/** | ||
* @param array $parameters | ||
* | ||
* @return mixed | ||
*/ | ||
public function authorize(array $parameters = array()) | ||
{ | ||
return $this->createRequest('\Omnipay\NABTransact\Message\DirectPostAuthorizeRequest', $parameters); | ||
} | ||
|
||
/** | ||
* @param array $parameters | ||
* | ||
* @return mixed | ||
*/ | ||
public function completeAuthorize(array $parameters = array()) | ||
{ | ||
return $this->createRequest('\Omnipay\NABTransact\Message\DirectPostCompletePurchaseRequest', $parameters); | ||
} | ||
|
||
/** | ||
* @param array $parameters | ||
* | ||
* @return mixed | ||
*/ | ||
public function purchase(array $parameters = array()) | ||
{ | ||
return $this->createRequest('\Omnipay\NABTransact\Message\DirectPostPurchaseRequest', $parameters); | ||
} | ||
|
||
/** | ||
* @param array $parameters | ||
* | ||
* @return mixed | ||
*/ | ||
public function completePurchase(array $parameters = array()) | ||
{ | ||
return $this->createRequest('\Omnipay\NABTransact\Message\DirectPostCompletePurchaseRequest', $parameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Omnipay\NABTransact\Message; | ||
|
||
/** | ||
* NABTransact Direct Post Abstract Request. | ||
*/ | ||
abstract class DirectPostAbstractRequest extends AbstractRequest | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $testEndpoint = 'https://transact.nab.com.au/test/directpostv2/authorise'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $liveEndpoint = 'https://transact.nab.com.au/live/directpostv2/authorise'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace Omnipay\NABTransact\Message; | ||
|
||
/** | ||
* NABTransact Direct Post Authorize Request. | ||
*/ | ||
class DirectPostAuthorizeRequest extends DirectPostAbstractRequest | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $txnType = '1'; | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getData() | ||
{ | ||
$this->validate('amount', 'returnUrl', 'card'); | ||
|
||
$data = array(); | ||
$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_TIMESTAMP'] = gmdate('YmdHis'); | ||
$data['EPS_FINGERPRINT'] = $this->generateFingerprint($data); | ||
$data['EPS_RESULTURL'] = $this->getReturnUrl(); | ||
$data['EPS_CALLBACKURL'] = $this->getNotifyUrl() ?: $this->getReturnUrl(); | ||
$data['EPS_REDIRECT'] = 'TRUE'; | ||
$data['EPS_CURRENCY'] = $this->getCurrency(); | ||
|
||
$data = array_replace($data, $this->getCardData()); | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* @param array $data | ||
*/ | ||
public function generateFingerprint(array $data) | ||
{ | ||
$hash = implode( | ||
'|', | ||
array( | ||
$data['EPS_MERCHANT'], | ||
$this->getTransactionPassword(), | ||
$data['EPS_TXNTYPE'], | ||
$data['EPS_REFERENCEID'], | ||
$data['EPS_AMOUNT'], | ||
$data['EPS_TIMESTAMP'], | ||
) | ||
); | ||
|
||
return sha1($hash); | ||
} | ||
|
||
/** | ||
* @param $data | ||
* | ||
* @return mixed | ||
*/ | ||
public function sendData($data) | ||
{ | ||
return $this->response = new DirectPostAuthorizeResponse($this, $data, $this->getEndpoint()); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
protected function getCardData() | ||
{ | ||
$this->getCard()->validate(); | ||
|
||
$data = array(); | ||
|
||
$data['EPS_CARDNUMBER'] = $this->getCard()->getNumber(); | ||
$data['EPS_EXPIRYMONTH'] = $this->getCard()->getExpiryMonth(); | ||
$data['EPS_EXPIRYYEAR'] = $this->getCard()->getExpiryYear(); | ||
$data['EPS_CCV'] = $this->getCard()->getCvv(); | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Omnipay\NABTransact\Message; | ||
|
||
use Omnipay\Common\Message\AbstractResponse; | ||
use Omnipay\Common\Message\RedirectResponseInterface; | ||
use Omnipay\Common\Message\RequestInterface; | ||
|
||
/** | ||
* NABTransact Direct Post Authorize Response. | ||
*/ | ||
class DirectPostAuthorizeResponse extends AbstractResponse implements RedirectResponseInterface | ||
{ | ||
/** | ||
* @var mixed | ||
*/ | ||
protected $redirectUrl; | ||
|
||
/** | ||
* @param RequestInterface $request | ||
* @param $data | ||
* @param $redirectUrl | ||
*/ | ||
public function __construct(RequestInterface $request, $data, $redirectUrl) | ||
{ | ||
$this->request = $request; | ||
$this->data = $data; | ||
$this->redirectUrl = $redirectUrl; | ||
} | ||
|
||
public function isSuccessful() | ||
{ | ||
return false; | ||
} | ||
|
||
public function isRedirect() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getRedirectUrl() | ||
{ | ||
return $this->redirectUrl; | ||
} | ||
|
||
public function getRedirectMethod() | ||
{ | ||
return 'POST'; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getRedirectData() | ||
{ | ||
return $this->getData(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Omnipay\NABTransact\Message; | ||
|
||
use Omnipay\Common\Exception\InvalidRequestException; | ||
|
||
/** | ||
* NABTransact Direct Post Complete Purchase Request. | ||
*/ | ||
class DirectPostCompletePurchaseRequest extends DirectPostAbstractRequest | ||
{ | ||
/** | ||
* @return mixed | ||
*/ | ||
public function getData() | ||
{ | ||
$data = $this->httpRequest->query->all(); | ||
|
||
if ($this->generateResponseFingerprint($data) !== $this->httpRequest->query->get('fingerprint')) { | ||
throw new InvalidRequestException('Invalid fingerprint'); | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* @param $data | ||
*/ | ||
public function generateResponseFingerprint($data) | ||
{ | ||
$fields = implode( | ||
'|', | ||
array( | ||
$data['merchant'], | ||
$this->getTransactionPassword(), | ||
$data['refid'], | ||
$this->getAmount(), | ||
$data['timestamp'], | ||
$data['summarycode'], | ||
) | ||
); | ||
|
||
return sha1($fields); | ||
} | ||
|
||
/** | ||
* @param $data | ||
* | ||
* @return mixed | ||
*/ | ||
public function sendData($data) | ||
{ | ||
return $this->response = new DirectPostCompletePurchaseResponse($this, $data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Omnipay\NABTransact\Message; | ||
|
||
use Omnipay\Common\Message\AbstractResponse; | ||
|
||
/** | ||
* NABTransact Direct Post Complete Purchase Response. | ||
*/ | ||
class DirectPostCompletePurchaseResponse extends AbstractResponse | ||
{ | ||
/** | ||
* @return mixed | ||
*/ | ||
public function isSuccessful() | ||
{ | ||
return $this->summaryCode() && (int) $this->getCode() == 00; | ||
} | ||
|
||
public function summaryCode() | ||
{ | ||
return isset($this->data['summarycode']) && (int) $this->data['summarycode'] == 1; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getMessage() | ||
{ | ||
if (isset($this->data['restext'])) { | ||
return $this->data['restext']; | ||
} | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getCode() | ||
{ | ||
if (isset($this->data['rescode'])) { | ||
return $this->data['rescode']; | ||
} | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getTransactionReference() | ||
{ | ||
if (isset($this->data['txnid'])) { | ||
return $this->data['txnid']; | ||
} | ||
} | ||
} |
Oops, something went wrong.