Skip to content

Commit ddf42ea

Browse files
committed
Add SecurePay Direct Post gateway
1 parent e23fa9d commit ddf42ea

12 files changed

+639
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ The following gateways are already implemented:
101101
* Pin Payments
102102
* Sage Pay Direct
103103
* Sage Pay Server
104+
* SecurePay Direct Post
104105
* Stripe
105106
* WorldPay
106107

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <adrian@adrianmacneil.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Omnipay\SecurePay;
13+
14+
use Omnipay\Common\AbstractGateway;
15+
16+
/**
17+
* SecurePay Direct Post Gateway
18+
*
19+
* @link http://www.securepay.com.au/uploads/Integration%20Guides/Direct_Post_Integration_Guide.pdf
20+
*/
21+
class DirectPostGateway extends AbstractGateway
22+
{
23+
public function getName()
24+
{
25+
return 'SecurePay Direct Post';
26+
}
27+
28+
public function getDefaultParameters()
29+
{
30+
return array(
31+
'merchantId' => '',
32+
'transactionPassword' => '',
33+
'testMode' => false,
34+
);
35+
}
36+
37+
public function getMerchantId()
38+
{
39+
return $this->getParameter('merchantId');
40+
}
41+
42+
public function setMerchantId($value)
43+
{
44+
return $this->setParameter('merchantId', $value);
45+
}
46+
47+
public function getTransactionPassword()
48+
{
49+
return $this->getParameter('transactionPassword');
50+
}
51+
52+
public function setTransactionPassword($value)
53+
{
54+
return $this->setParameter('transactionPassword', $value);
55+
}
56+
57+
public function authorize(array $parameters = array())
58+
{
59+
return $this->createRequest('\Omnipay\SecurePay\Message\DirectPostAuthorizeRequest', $parameters);
60+
}
61+
62+
public function completeAuthorize(array $parameters = array())
63+
{
64+
return $this->createRequest('\Omnipay\SecurePay\Message\DirectPostCompletePurchaseRequest', $parameters);
65+
}
66+
67+
public function purchase(array $parameters = array())
68+
{
69+
return $this->createRequest('\Omnipay\SecurePay\Message\DirectPostPurchaseRequest', $parameters);
70+
}
71+
72+
public function completePurchase(array $parameters = array())
73+
{
74+
return $this->createRequest('\Omnipay\SecurePay\Message\DirectPostCompletePurchaseRequest', $parameters);
75+
}
76+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <adrian@adrianmacneil.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Omnipay\SecurePay\Message;
13+
14+
use Omnipay\Common\Message\AbstractRequest;
15+
16+
/**
17+
* SecurePay Direct Post Abstract Request
18+
*/
19+
abstract class DirectPostAbstractRequest extends AbstractRequest
20+
{
21+
public $testEndpoint = 'https://api.securepay.com.au/test/directpost/authorise';
22+
public $liveEndpoint = 'https://api.securepay.com.au/live/directpost/authorise';
23+
24+
public function getMerchantId()
25+
{
26+
return $this->getParameter('merchantId');
27+
}
28+
29+
public function setMerchantId($value)
30+
{
31+
return $this->setParameter('merchantId', $value);
32+
}
33+
34+
public function getTransactionPassword()
35+
{
36+
return $this->getParameter('transactionPassword');
37+
}
38+
39+
public function setTransactionPassword($value)
40+
{
41+
return $this->setParameter('transactionPassword', $value);
42+
}
43+
44+
public function getEndpoint()
45+
{
46+
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
47+
}
48+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <adrian@adrianmacneil.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Omnipay\SecurePay\Message;
13+
14+
/**
15+
* SecurePay Direct Post Authorize Request
16+
*/
17+
class DirectPostAuthorizeRequest extends DirectPostAbstractRequest
18+
{
19+
public $txnType = '1';
20+
21+
public function getData()
22+
{
23+
$this->validate('amount', 'returnUrl');
24+
25+
$data = array();
26+
$data['EPS_MERCHANT'] = $this->getMerchantId();
27+
$data['EPS_TXNTYPE'] = $this->txnType;
28+
$data['EPS_IP'] = $this->getClientIp();
29+
$data['EPS_AMOUNT'] = $this->getAmountDecimal();
30+
$data['EPS_REFERENCEID'] = $this->getTransactionId();
31+
$data['EPS_TIMESTAMP'] = gmdate('YmdHis');
32+
$data['EPS_FINGERPRINT'] = $this->generateFingerprint($data);
33+
$data['EPS_RESULTURL'] = $this->getReturnUrl();
34+
$data['EPS_CURRENCY'] = $this->getCurrency();
35+
36+
return $data;
37+
}
38+
39+
public function generateFingerprint(array $data)
40+
{
41+
$hash = implode(
42+
'|',
43+
array(
44+
$data['EPS_MERCHANT'],
45+
$this->getTransactionPassword(),
46+
$data['EPS_TXNTYPE'],
47+
$data['EPS_REFERENCEID'],
48+
$data['EPS_AMOUNT'],
49+
$data['EPS_TIMESTAMP'],
50+
)
51+
);
52+
53+
return sha1($hash);
54+
}
55+
56+
public function send()
57+
{
58+
return $this->response = new DirectPostAuthorizeResponse($this, $this->getData(), $this->getEndpoint());
59+
}
60+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <adrian@adrianmacneil.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Omnipay\SecurePay\Message;
13+
14+
use Omnipay\Common\Message\AbstractResponse;
15+
use Omnipay\Common\Message\RequestInterface;
16+
17+
/**
18+
* SecurePay Direct Post Authorize Response
19+
*/
20+
class DirectPostAuthorizeResponse extends AbstractResponse
21+
{
22+
protected $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+
public function getRedirectUrl()
42+
{
43+
return $this->redirectUrl;
44+
}
45+
46+
public function getRedirectMethod()
47+
{
48+
return 'POST';
49+
}
50+
51+
public function getRedirectData()
52+
{
53+
return $this->getData();
54+
}
55+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <adrian@adrianmacneil.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Omnipay\SecurePay\Message;
13+
14+
use Omnipay\Common\Exception\InvalidRequestException;
15+
16+
/**
17+
* SecurePay Direct Post Complete Purchase Request
18+
*/
19+
class DirectPostCompletePurchaseRequest extends DirectPostAbstractRequest
20+
{
21+
public function getData()
22+
{
23+
$data = $this->httpRequest->request->all();
24+
25+
if ($this->generateResponseFingerprint($data) !== $this->httpRequest->request->get('fingerprint')) {
26+
throw new InvalidRequestException('Invalid fingerprint');
27+
}
28+
29+
return $data;
30+
}
31+
32+
public function generateResponseFingerprint($data)
33+
{
34+
$fields = implode(
35+
'|',
36+
array(
37+
$data['merchant'],
38+
$this->getTransactionPassword(),
39+
$data['refid'],
40+
$this->getAmountDecimal(),
41+
$data['timestamp'],
42+
$data['summarycode'],
43+
)
44+
);
45+
46+
return sha1($fields);
47+
}
48+
49+
public function send()
50+
{
51+
return $this->response = new DirectPostCompletePurchaseResponse($this, $this->getData());
52+
}
53+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <adrian@adrianmacneil.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Omnipay\SecurePay\Message;
13+
14+
use Omnipay\Common\Message\AbstractResponse;
15+
16+
/**
17+
* SecurePay Direct Post Complete Purchase Response
18+
*/
19+
class DirectPostCompletePurchaseResponse extends AbstractResponse
20+
{
21+
public function isSuccessful()
22+
{
23+
return isset($this->data['summarycode']) && $this->data['summarycode'] == 1;
24+
}
25+
26+
public function getMessage()
27+
{
28+
if (isset($this->data['restext'])) {
29+
return $this->data['restext'];
30+
}
31+
}
32+
33+
public function getCode()
34+
{
35+
if (isset($this->data['rescode'])) {
36+
return $this->data['rescode'];
37+
}
38+
}
39+
40+
public function getTransactionReference()
41+
{
42+
if (isset($this->data['txnid'])) {
43+
return $this->data['txnid'];
44+
}
45+
}
46+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <adrian@adrianmacneil.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Omnipay\SecurePay\Message;
13+
14+
/**
15+
* SecurePay Direct Post Purchase Request
16+
*/
17+
class DirectPostPurchaseRequest extends DirectPostAuthorizeRequest
18+
{
19+
public $txnType = '0';
20+
}

0 commit comments

Comments
 (0)