Skip to content

Commit 70b8e68

Browse files
authored
Merge pull request #17 from sudiptpa/feature/nab-hpp
NAB Hosted Payment Page
2 parents e469890 + a2e0f6f commit 70b8e68

File tree

4 files changed

+231
-0
lines changed

4 files changed

+231
-0
lines changed

src/HostedPaymentGateway.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact;
4+
5+
use Omnipay\Common\AbstractGateway;
6+
7+
/**
8+
* HostedPayment Gateway.
9+
*/
10+
class HostedPaymentGateway extends AbstractGateway
11+
{
12+
/**
13+
* @param array $parameters
14+
*
15+
* @return mixed
16+
*/
17+
public function completePurchase(array $parameters = array())
18+
{
19+
return $this->createRequest('\Omnipay\NABTransact\Message\HostedPaymentCompletePurchaseRequest', $parameters);
20+
}
21+
22+
public function getName()
23+
{
24+
return 'NAB Hosted Payment';
25+
}
26+
27+
/**
28+
* @param array $parameters
29+
*
30+
* @return mixed
31+
*/
32+
public function purchase(array $parameters = array())
33+
{
34+
return $this->createRequest('\Omnipay\NABTransact\Message\HostedPaymentPurchaseRequest', $parameters);
35+
}
36+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact\Message;
4+
5+
use Omnipay\Common\Message\AbstractResponse;
6+
use Omnipay\Common\Message\RequestInterface;
7+
8+
/**
9+
* NABTransact HostedPaymentCompletePurchaseResponse.
10+
*/
11+
class HostedPaymentCompletePurchaseResponse extends AbstractResponse
12+
{
13+
/**
14+
* @param RequestInterface $request
15+
* @param $data
16+
*/
17+
public function __construct(RequestInterface $request, $data)
18+
{
19+
if (!is_array($data)) {
20+
parse_str($data, $data);
21+
}
22+
23+
parent::__construct($request, $data);
24+
}
25+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
3+
namespace Omnipay\NABTransact\Message;
4+
5+
/**
6+
* HostedPayment Purchase Request.
7+
*/
8+
class HostedPaymentPurchaseRequest extends AbstractRequest
9+
{
10+
/**
11+
* @var string
12+
*/
13+
public $liveEndpoint = 'https://transact.nab.com.au/test/hpp/payment';
14+
15+
/**
16+
* @var string
17+
*/
18+
public $testEndpoint = 'https://transact.nab.com.au/live/hpp/payment';
19+
20+
/**
21+
* @return mixed
22+
*/
23+
public function getData()
24+
{
25+
$this->validate(
26+
'amount',
27+
'returnUrl',
28+
'transactionReference',
29+
'merchantId',
30+
'paymentAlertEmail'
31+
);
32+
33+
$data = array();
34+
35+
$data['vendor_name'] = $this->getMerchantId();
36+
$data['payment_alert'] = $this->getPaymentAlertEmail();
37+
$data['payment_reference'] = $this->getTransactionReference();
38+
$data['currency'] = $this->getCurrency();
39+
$data['return_link_url'] = $this->getReturnUrl();
40+
$data['reply_link_url'] = $this->getNotifyUrl() ?: $this->getReturnUrl();
41+
$data['return_link_text'] = $this->getReturnUrlText();
42+
$data['total_amount'] = $this->getAmount();
43+
44+
return $data;
45+
}
46+
47+
/**
48+
* @return mixed
49+
*/
50+
public function getPaymentAlertEmail()
51+
{
52+
return $this->getParameter('paymentAlertEmail');
53+
}
54+
55+
/**
56+
* @return mixed
57+
*/
58+
public function getReturnUrlText()
59+
{
60+
return $this->getParameter('returnUrlText');
61+
}
62+
63+
/**
64+
* @return mixed
65+
*/
66+
public function getTransactionReference()
67+
{
68+
return $this->getParameter('transactionReference');
69+
}
70+
71+
/**
72+
* @param $data
73+
*
74+
* @return mixed
75+
*/
76+
public function sendData($data)
77+
{
78+
return $this->response = new HostedPaymentPurchaseResponse($this, $data, $this->getEndpoint());
79+
}
80+
81+
/**
82+
* @param $value
83+
*
84+
* @return mixed
85+
*/
86+
public function setPaymentAlertEmail($value)
87+
{
88+
return $this->setParameter('paymentAlertEmail', $value);
89+
}
90+
91+
/**
92+
* @param $value
93+
*
94+
* @return mixed
95+
*/
96+
public function setReturnUrlText($value)
97+
{
98+
return $this->getParameter('returnUrlText', $value);
99+
}
100+
101+
/**
102+
* @param $value
103+
*
104+
* @return mixed
105+
*/
106+
public function setTransactionReference($value)
107+
{
108+
return $this->setParameter('transactionReference', $value);
109+
}
110+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 HostedPayment Purchase Response.
11+
*/
12+
class HostedPaymentPurchaseResponse 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+
parent::__construct($request, $data);
27+
$this->redirectUrl = $redirectUrl;
28+
}
29+
30+
/**
31+
* @return mixed
32+
*/
33+
public function getRedirectData()
34+
{
35+
return $this->getData();
36+
}
37+
38+
public function getRedirectMethod()
39+
{
40+
return 'GET';
41+
}
42+
43+
/**
44+
* @return mixed
45+
*/
46+
public function getRedirectUrl()
47+
{
48+
return $this->redirectUrl;
49+
}
50+
51+
public function isRedirect()
52+
{
53+
return true;
54+
}
55+
56+
public function isSuccessful()
57+
{
58+
return false;
59+
}
60+
}

0 commit comments

Comments
 (0)