Skip to content

Commit b2ea67e

Browse files
committed
Introducing Hosted Payment Page
1 parent e469890 commit b2ea67e

File tree

4 files changed

+227
-0
lines changed

4 files changed

+227
-0
lines changed

src/HostedPaymentGateway.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
* @return mixed
15+
*/
16+
public function completePurchase(array $parameters = array())
17+
{
18+
return $this->createRequest('\Omnipay\NABTransact\Message\HostedPaymentCompletePurchaseRequest', $parameters);
19+
}
20+
21+
public function getName()
22+
{
23+
return 'NAB Hosted Payment';
24+
}
25+
26+
/**
27+
* @param array $parameters
28+
* @return mixed
29+
*/
30+
public function purchase(array $parameters = array())
31+
{
32+
return $this->createRequest('\Omnipay\NABTransact\Message\HostedPaymentPurchaseRequest', $parameters);
33+
}
34+
}
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: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
* @return mixed
74+
*/
75+
public function sendData($data)
76+
{
77+
return $this->response = new HostedPaymentPurchaseResponse($this, $data, $this->getEndpoint());
78+
}
79+
80+
/**
81+
* @param $value
82+
*
83+
* @return mixed
84+
*/
85+
public function setPaymentAlertEmail($value)
86+
{
87+
return $this->setParameter('paymentAlertEmail', $value);
88+
}
89+
90+
/**
91+
* @param $value
92+
* @return mixed
93+
*/
94+
public function setReturnUrlText($value)
95+
{
96+
return $this->getParameter('returnUrlText', $value);
97+
}
98+
99+
/**
100+
* @param $value
101+
*
102+
* @return mixed
103+
*/
104+
public function setTransactionReference($value)
105+
{
106+
return $this->setParameter('transactionReference', $value);
107+
}
108+
}
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)