Skip to content

Commit 6f1e620

Browse files
aderuweamacneil
authored andcommitted
Add MultiSafepay gateway. Closes thephpleague#84
1 parent 928bf25 commit 6f1e620

26 files changed

+1614
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ The following gateways are already implemented:
100100
* Migs 2-Party
101101
* Migs 3-Party
102102
* Mollie
103+
* MultiSafepay
103104
* Netaxept (BBS)
104105
* Netbanx
105106
* PayFast

src/Omnipay/MultiSafepay/Gateway.php

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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\MultiSafepay;
13+
14+
use Omnipay\Common\AbstractGateway;
15+
use Omnipay\MultiSafepay\Message\FetchIssuersRequest;
16+
use Omnipay\MultiSafepay\Message\FetchPaymentMethodsRequest;
17+
18+
/**
19+
* MultiSafepay gateway.
20+
*
21+
* @link https://www.multisafepay.com/downloads/handleidingen/Handleiding_connect(ENG).pdf
22+
*/
23+
class Gateway extends AbstractGateway
24+
{
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
public function getName()
29+
{
30+
return 'MultiSafepay';
31+
}
32+
33+
/**
34+
* {@inheritdoc}
35+
*/
36+
public function getDefaultParameters()
37+
{
38+
return array(
39+
'accountId' => '',
40+
'siteId' => '',
41+
'siteCode' => '',
42+
'testMode' => false,
43+
);
44+
}
45+
46+
public function getAccountId()
47+
{
48+
return $this->getParameter('accountId');
49+
}
50+
51+
public function setAccountId($value)
52+
{
53+
return $this->setParameter('accountId', $value);
54+
}
55+
56+
public function getSiteId()
57+
{
58+
return $this->getParameter('siteId');
59+
}
60+
61+
public function setSiteId($value)
62+
{
63+
return $this->setParameter('siteId', $value);
64+
}
65+
66+
public function getSiteCode()
67+
{
68+
return $this->getParameter('siteCode');
69+
}
70+
71+
public function setSiteCode($value)
72+
{
73+
return $this->setParameter('siteCode', $value);
74+
}
75+
76+
/**
77+
* Retrieve payment methods active on the given MultiSafepay
78+
* account.
79+
*
80+
* @param array $parameters
81+
*
82+
* @return FetchPaymentMethodsRequest
83+
*/
84+
public function fetchPaymentMethods(array $parameters = array())
85+
{
86+
return $this->createRequest('\Omnipay\MultiSafepay\Message\FetchPaymentMethodsRequest', $parameters);
87+
}
88+
89+
/**
90+
* Retrieve iDEAL issuers.
91+
*
92+
* @param array $parameters
93+
*
94+
* @return FetchIssuersRequest
95+
*/
96+
public function fetchIssuers(array $parameters = array())
97+
{
98+
return $this->createRequest('\Omnipay\MultiSafepay\Message\FetchIssuersRequest', $parameters);
99+
}
100+
101+
/**
102+
* {@inheritdoc}
103+
*/
104+
public function purchase(array $parameters = array())
105+
{
106+
return $this->createRequest('\Omnipay\MultiSafepay\Message\PurchaseRequest', $parameters);
107+
}
108+
109+
/**
110+
* {@inheritdoc}
111+
*/
112+
public function completePurchase(array $parameters = array())
113+
{
114+
return $this->createRequest('\Omnipay\MultiSafepay\Message\CompletePurchaseRequest', $parameters);
115+
}
116+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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\MultiSafepay\Message;
13+
14+
use Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest;
15+
16+
abstract class AbstractRequest extends BaseAbstractRequest
17+
{
18+
protected $userAgent = 'Omnipay';
19+
protected $liveEndpoint = 'https://api.multisafepay.com/ewx/';
20+
protected $testEndpoint = 'https://testapi.multisafepay.com/ewx/';
21+
22+
public function getAccountId()
23+
{
24+
return $this->getParameter('accountId');
25+
}
26+
27+
public function setAccountId($value)
28+
{
29+
return $this->setParameter('accountId', $value);
30+
}
31+
32+
public function getSiteId()
33+
{
34+
return $this->getParameter('siteId');
35+
}
36+
37+
public function setSiteId($value)
38+
{
39+
return $this->setParameter('siteId', $value);
40+
}
41+
42+
public function getSiteCode()
43+
{
44+
return $this->getParameter('siteCode');
45+
}
46+
47+
public function setSiteCode($value)
48+
{
49+
return $this->setParameter('siteCode', $value);
50+
}
51+
52+
public function getEndpoint()
53+
{
54+
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
55+
}
56+
57+
/**
58+
* @return array
59+
*/
60+
protected function getHeaders()
61+
{
62+
return array(
63+
'User-Agent' => $this->userAgent,
64+
);
65+
}
66+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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\MultiSafepay\Message;
13+
14+
use Omnipay\Common\Message\AbstractResponse as BaseAbstractResponse;
15+
16+
abstract class AbstractResponse extends BaseAbstractResponse
17+
{
18+
/**
19+
* {@inheritdoc}
20+
*/
21+
public function getMessage()
22+
{
23+
if (isset($this->data->error)) {
24+
return (string) $this->data->error->description;
25+
}
26+
27+
return null;
28+
}
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
public function getCode()
34+
{
35+
if (isset($this->data->error)) {
36+
return (string) $this->data->error->code;
37+
}
38+
39+
return null;
40+
}
41+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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\MultiSafepay\Message;
13+
14+
use SimpleXMLElement;
15+
16+
class CompletePurchaseRequest extends PurchaseRequest
17+
{
18+
/**
19+
* {@inheritdoc}
20+
*/
21+
public function getData()
22+
{
23+
$this->validate('transactionId');
24+
25+
$data = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><status/>');
26+
$data->addAttribute('ua', $this->userAgent);
27+
28+
$merchant = $data->addChild('merchant');
29+
$merchant->addChild('account', $this->getAccountId());
30+
$merchant->addChild('site_id', $this->getSiteId());
31+
$merchant->addChild('site_secure_code', $this->getSiteCode());
32+
33+
$transaction = $data->addChild('transaction');
34+
$transaction->addChild('id', $this->getTransactionId());
35+
36+
return $data;
37+
}
38+
39+
/**
40+
* {@inheritdoc}
41+
*/
42+
public function send()
43+
{
44+
$httpResponse = $this->httpClient->post(
45+
$this->getEndpoint(),
46+
$this->getHeaders(),
47+
$this->getData()->asXML()
48+
)->send();
49+
50+
return $this->response = new CompletePurchaseResponse($this, $httpResponse->xml());
51+
}
52+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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\MultiSafepay\Message;
13+
14+
class CompletePurchaseResponse extends AbstractResponse
15+
{
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
public function isSuccessful()
20+
{
21+
return isset($this->data->ewallet->status) && 'completed' === (string) $this->data->ewallet->status;
22+
}
23+
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
public function getTransactionReference()
28+
{
29+
return isset($this->data->transaction->id) ? (string) $this->data->transaction->id : null;
30+
}
31+
32+
/**
33+
* Is the payment created, but uncompleted?
34+
*
35+
* @return boolean
36+
*/
37+
public function isInitialized()
38+
{
39+
return isset($this->data->ewallet->status) && 'initialized' === (string) $this->data->ewallet->status;
40+
}
41+
42+
/**
43+
* Is the payment created, but not yet exempted (credit cards)?
44+
*
45+
* @return boolean
46+
*/
47+
public function isUncleared()
48+
{
49+
return isset($this->data->ewallet->status) && 'uncleared' === (string) $this->data->ewallet->status;
50+
}
51+
52+
/**
53+
* Is the payment cancelled?
54+
*
55+
* @return boolean
56+
*/
57+
public function isCancelled()
58+
{
59+
return isset($this->data->ewallet->status) && 'void' === (string) $this->data->ewallet->status;
60+
}
61+
62+
/**
63+
* Is the payment rejected?
64+
*
65+
* @return boolean
66+
*/
67+
public function isRejected()
68+
{
69+
return isset($this->data->ewallet->status) && 'declined' === (string) $this->data->ewallet->status;
70+
}
71+
72+
/**
73+
* Is the payment refunded?
74+
*
75+
* @return boolean
76+
*/
77+
public function isRefunded()
78+
{
79+
return isset($this->data->ewallet->status) && 'refunded' === (string) $this->data->ewallet->status;
80+
}
81+
82+
/**
83+
* Is the payment expired?
84+
*
85+
* @return boolean
86+
*/
87+
public function isExpired()
88+
{
89+
return isset($this->data->ewallet->status) && 'expired' === (string) $this->data->ewallet->status;
90+
}
91+
92+
/**
93+
* Get raw payment status.
94+
*
95+
* @return null|string
96+
*/
97+
public function getPaymentStatus()
98+
{
99+
return isset($this->data->ewallet->status) ? (string) $this->data->ewallet->status : null;
100+
}
101+
}

0 commit comments

Comments
 (0)