Skip to content

Commit cbd47e7

Browse files
benjamindavidamacneil
authored andcommitted
Add MIGS gateway
1 parent 74c9eba commit cbd47e7

18 files changed

+855
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ The following gateways are already implemented:
8888
* Dummy
8989
* GoCardless
9090
* Manual
91+
* Migs 2-Party
92+
* Migs 3-Party
9193
* Netaxept (BBS)
9294
* PayFast
9395
* Payflow Pro
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <[email protected]>
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\Migs\Message;
13+
14+
/**
15+
* GoCardless Abstract Request
16+
*/
17+
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
18+
{
19+
protected $endpoint = 'https://migs.mastercard.com.au/';
20+
21+
public function getMerchantId()
22+
{
23+
return $this->getParameter('merchantId');
24+
}
25+
26+
public function setMerchantId($value)
27+
{
28+
return $this->setParameter('merchantId', $value);
29+
}
30+
31+
public function getMerchantAccessCode()
32+
{
33+
return $this->getParameter('merchantAccessCode');
34+
}
35+
36+
public function setMerchantAccessCode($value)
37+
{
38+
return $this->setParameter('merchantAccessCode', $value);
39+
}
40+
41+
public function getSecureHash()
42+
{
43+
return $this->getParameter('secureHash');
44+
}
45+
46+
public function setSecureHash($value)
47+
{
48+
return $this->setParameter('secureHash', $value);
49+
}
50+
51+
protected function getBaseData()
52+
{
53+
$data = array();
54+
$data['vpc_Merchant'] = $this->getMerchantId();
55+
$data['vpc_AccessCode'] = $this->getMerchantAccessCode();
56+
$data['vpc_Version'] = '1';
57+
$data['vpc_Locale'] = 'en';
58+
$data['vpc_Command'] = $this->action;
59+
$data['vpc_Amount'] = $this->getAmount();
60+
$data['vpc_MerchTxnRef'] = $this->getTransactionId();
61+
$data['vpc_OrderInfo'] = $this->getDescription();
62+
$data['vpc_ReturnURL'] = $this->getReturnUrl();
63+
64+
return $data;
65+
}
66+
67+
public function getEndpoint()
68+
{
69+
return $this->endpoint;
70+
}
71+
72+
public function calculateHash($data)
73+
{
74+
ksort($data);
75+
76+
$hash = $this->getSecureHash();
77+
foreach ($data as $k => $v) {
78+
if (substr($k, 0, 4) === 'vpc_' && $k !== 'vpc_SecureHash') {
79+
$hash .= $v;
80+
}
81+
}
82+
83+
return strtoupper(md5($hash));
84+
}
85+
}

src/Omnipay/Migs/Message/Response.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <[email protected]>
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\Migs\Message;
13+
14+
use Omnipay\Common\Message\AbstractResponse;
15+
use Omnipay\Common\Message\RequestInterface;
16+
17+
/**
18+
* Migs Purchase Response
19+
*/
20+
class Response extends AbstractResponse
21+
{
22+
public function __construct(RequestInterface $request, $data)
23+
{
24+
if (!is_array($data)) {
25+
parse_str($data, $data);
26+
}
27+
28+
parent::__construct($request, $data);
29+
}
30+
31+
public function isSuccessful()
32+
{
33+
return isset($this->data['vpc_TxnResponseCode']) && "0" === $this->data['vpc_TxnResponseCode'];
34+
}
35+
36+
public function getTransactionReference()
37+
{
38+
return isset($this->data['vpc_ReceiptNo']) ? $this->data['vpc_ReceiptNo'] : null;
39+
}
40+
41+
public function getMessage()
42+
{
43+
return isset($this->data['vpc_Message']) ? $this->data['vpc_Message'] : null;
44+
}
45+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <[email protected]>
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\Migs\Message;
13+
14+
use Omnipay\Common\Exception\InvalidRequestException;
15+
16+
/**
17+
* Migs Complete Purchase Request
18+
*/
19+
class ThreePartyCompletePurchaseRequest extends AbstractRequest
20+
{
21+
public function getData()
22+
{
23+
$data = $this->httpRequest->query->all();
24+
25+
$hash = isset($data['vpc_SecureHash']) ? $data['vpc_SecureHash'] : null;
26+
if ($this->calculateHash($data) !== $hash) {
27+
throw new InvalidRequestException('Incorrect hash');
28+
}
29+
30+
return $data;
31+
}
32+
33+
public function send()
34+
{
35+
return $this->response = new Response($this, $this->getData());
36+
}
37+
38+
public function getEndpoint()
39+
{
40+
return $this->endpoint.'vpcpay';
41+
}
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <[email protected]>
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\Migs\Message;
13+
14+
/**
15+
* Migs Purchase Request
16+
*/
17+
class ThreePartyPurchaseRequest extends AbstractRequest
18+
{
19+
protected $action = 'pay';
20+
21+
public function getData()
22+
{
23+
$this->validate('amount', 'returnUrl', 'transactionId');
24+
25+
$data = $this->getBaseData();
26+
$data['vpc_SecureHash'] = $this->calculateHash($data);
27+
28+
return $data;
29+
}
30+
31+
public function send()
32+
{
33+
$redirectUrl = $this->getEndpoint().'?'.http_build_query($this->getData());
34+
35+
return $this->response = new ThreePartyPurchaseResponse($this, $this->getData(), $redirectUrl);
36+
}
37+
38+
public function getEndpoint()
39+
{
40+
return $this->endpoint.'vpcpay';
41+
}
42+
}
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 <[email protected]>
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\Migs\Message;
13+
14+
use Omnipay\Common\Message\AbstractResponse;
15+
use Omnipay\Common\Message\RequestInterface;
16+
use Omnipay\Common\Message\RedirectResponseInterface;
17+
18+
/**
19+
* Migs Purchase Response
20+
*/
21+
class ThreePartyPurchaseResponse extends AbstractResponse implements RedirectResponseInterface
22+
{
23+
protected $redirectUrl;
24+
25+
public function __construct(RequestInterface $request, $data, $redirectUrl)
26+
{
27+
parent::__construct($request, $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 'GET';
49+
}
50+
51+
public function getRedirectData()
52+
{
53+
return $this->getData();
54+
}
55+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <[email protected]>
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\Migs\Message;
13+
14+
/**
15+
* Migs Purchase Request
16+
*/
17+
class TwoPartyPurchaseRequest extends AbstractRequest
18+
{
19+
protected $action = 'pay';
20+
21+
public function getData()
22+
{
23+
$this->validate('amount', 'transactionId', 'card');
24+
25+
$this->getCard()->validate();
26+
27+
$data = $this->getBaseData();
28+
$data['vpc_CardNum'] = $this->getCard()->getNumber();
29+
$data['vpc_CardExp'] = $this->getCard()->getExpiryDate('ym');
30+
$data['vpc_CardSecurityCode'] = $this->getCard()->getCvv();
31+
$data['vpc_SecureHash'] = $this->calculateHash($data);
32+
33+
return $data;
34+
}
35+
36+
public function send()
37+
{
38+
$httpResponse = $this->httpClient->post($this->getEndpoint(), null, $this->getData())->send();
39+
40+
return $this->response = new Response($this, $httpResponse->getBody());
41+
}
42+
43+
public function getEndpoint()
44+
{
45+
return $this->endpoint.'vpcdps';
46+
}
47+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Omnipay package.
5+
*
6+
* (c) Adrian Macneil <[email protected]>
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\Migs;
13+
14+
/**
15+
* MIGS Gateway
16+
*
17+
* @link http://www.anz.com/australia/business/merchant/pdf/VPC-Dev-Kit-Integration-Notes.pdf
18+
*/
19+
class ThreePartyGateway extends TwoPartyGateway
20+
{
21+
public function getName()
22+
{
23+
return 'MIGS 3-Party';
24+
}
25+
26+
public function purchase(array $parameters = array())
27+
{
28+
return $this->createRequest('\Omnipay\Migs\Message\ThreePartyPurchaseRequest', $parameters);
29+
}
30+
31+
public function completePurchase(array $parameters = array())
32+
{
33+
return $this->createRequest('\Omnipay\Migs\Message\ThreePartyCompletePurchaseRequest', $parameters);
34+
}
35+
}

0 commit comments

Comments
 (0)