Skip to content

Commit 47972ec

Browse files
committed
Add Mollie gateway
1 parent c72374f commit 47972ec

14 files changed

+607
-0
lines changed

src/Omnipay/Mollie/Gateway.php

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 <[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\Mollie;
13+
14+
use Omnipay\Common\AbstractGateway;
15+
16+
/**
17+
* Mollie (iDeal) Gateway
18+
*
19+
* @link https://www.mollie.nl/support/documentatie/betaaldiensten/ideal/en/
20+
*/
21+
class Gateway extends AbstractGateway
22+
{
23+
public function getName()
24+
{
25+
return 'Mollie';
26+
}
27+
28+
public function getDefaultParameters()
29+
{
30+
return array(
31+
'partnerId' => '',
32+
'testMode' => '',
33+
);
34+
}
35+
36+
public function getPartnerId()
37+
{
38+
return $this->getParameter('partnerId');
39+
}
40+
41+
public function setPartnerId($value)
42+
{
43+
return $this->setParameter('partnerId', $value);
44+
}
45+
46+
public function fetchIssuers(array $parameters = array())
47+
{
48+
return $this->createRequest('\Omnipay\Mollie\Message\FetchIssuersRequest', $parameters);
49+
}
50+
51+
public function purchase(array $parameters = array())
52+
{
53+
return $this->createRequest('\Omnipay\Mollie\Message\PurchaseRequest', $parameters);
54+
}
55+
56+
public function completePurchase(array $parameters = array())
57+
{
58+
return $this->createRequest('\Omnipay\Mollie\Message\CompletePurchaseRequest', $parameters);
59+
}
60+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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\Mollie\Message;
13+
14+
/**
15+
* Mollie Abstract Request
16+
*/
17+
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
18+
{
19+
protected $endpoint = 'https://secure.mollie.nl/xml/ideal';
20+
21+
public function getPartnerId()
22+
{
23+
return $this->getParameter('partnerId');
24+
}
25+
26+
public function setPartnerId($value)
27+
{
28+
return $this->setParameter('partnerId', $value);
29+
}
30+
31+
public function getIssuer()
32+
{
33+
return $this->getParameter('issuer');
34+
}
35+
36+
public function setIssuer($value)
37+
{
38+
return $this->setParameter('issuer', $value);
39+
}
40+
41+
protected function getBaseData()
42+
{
43+
$data = array();
44+
45+
if ($this->getTestMode()) {
46+
$data['testmode'] = 'true';
47+
}
48+
49+
return $data;
50+
}
51+
52+
public function send()
53+
{
54+
$httpResponse = $this->httpClient->post($this->endpoint, null, $this->getData())->send();
55+
56+
// echo "\n"; echo $httpResponse; echo "\n"; exit;
57+
return $this->response = new Response($this, $httpResponse->xml());
58+
}
59+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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\Mollie\Message;
13+
14+
/**
15+
* Mollie Complete Purchase Request
16+
*/
17+
class CompletePurchaseRequest extends AbstractRequest
18+
{
19+
public function getData()
20+
{
21+
$this->validate('partnerId');
22+
23+
$data = $this->getBaseData();
24+
$data['a'] = 'check';
25+
$data['partnerid'] = $this->getPartnerId();
26+
$data['transaction_id'] = $this->httpRequest->query->get('transaction_id');
27+
28+
return $data;
29+
}
30+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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\Mollie\Message;
13+
14+
/**
15+
* Mollie Fetch Issuers Request
16+
*/
17+
class FetchIssuersRequest extends AbstractRequest
18+
{
19+
public function getData()
20+
{
21+
$data = $this->getBaseData();
22+
$data['a'] = 'banklist';
23+
24+
return $data;
25+
}
26+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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\Mollie\Message;
13+
14+
/**
15+
* Mollie Purchase Request
16+
*/
17+
class PurchaseRequest extends AbstractRequest
18+
{
19+
public function getData()
20+
{
21+
$this->validate('partnerId', 'amount', 'issuer', 'returnUrl', 'notifyUrl');
22+
23+
$data = $this->getBaseData();
24+
$data['a'] = 'fetch';
25+
$data['partnerid'] = $this->getPartnerId();
26+
$data['returnurl'] = $this->getReturnUrl();
27+
$data['reporturl'] = $this->getNotifyUrl();
28+
$data['bank_id'] = $this->getIssuer();
29+
$data['amount'] = $this->getAmount();
30+
$data['description'] = $this->getDescription();
31+
32+
return $data;
33+
}
34+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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\Mollie\Message;
13+
14+
use Omnipay\Common\Message\AbstractResponse;
15+
use Omnipay\Common\Message\RedirectResponseInterface;
16+
17+
/**
18+
* Mollie Response
19+
*/
20+
class Response extends AbstractResponse implements RedirectResponseInterface
21+
{
22+
public function isSuccessful()
23+
{
24+
if ($this->isRedirect()) {
25+
return false;
26+
}
27+
28+
return 'error' !== (string) $this->data->item['type'];
29+
}
30+
31+
public function isRedirect()
32+
{
33+
return isset($this->data->order->URL);
34+
}
35+
36+
public function getRedirectUrl()
37+
{
38+
if ($this->isRedirect()) {
39+
return (string) $this->data->order->URL;
40+
}
41+
}
42+
43+
public function getRedirectMethod()
44+
{
45+
return 'GET';
46+
}
47+
48+
public function getRedirectData()
49+
{
50+
return null;
51+
}
52+
53+
public function getTransactionReference()
54+
{
55+
if (isset($this->data->order)) {
56+
return (string) $this->data->order->transaction_id;
57+
}
58+
}
59+
60+
public function getMessage()
61+
{
62+
if (isset($this->data->item)) {
63+
return (string) $this->data->item->message;
64+
} elseif (isset($this->data->order)) {
65+
return (string) $this->data->order->message;
66+
} else {
67+
return (string) $this->data->message;
68+
}
69+
}
70+
71+
public function getCode()
72+
{
73+
if (isset($this->data->item)) {
74+
return (string) $this->data->item->errorcode;
75+
}
76+
}
77+
78+
/**
79+
* Get an associateive array of banks returned from a fetchIssuers request
80+
*/
81+
public function getIssuers()
82+
{
83+
if (isset($this->data->bank)) {
84+
$issuers = array();
85+
86+
foreach ($this->data->bank as $bank) {
87+
$bank_id = (string) $bank->bank_id;
88+
$issuers[$bank_id] = (string) $bank->bank_name;
89+
}
90+
91+
return $issuers;
92+
}
93+
}
94+
}

tests/Omnipay/Mollie/GatewayTest.php

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 <[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\Mollie;
13+
14+
use Omnipay\GatewayTestCase;
15+
16+
class GatewayTest extends GatewayTestCase
17+
{
18+
public function setUp()
19+
{
20+
parent::setUp();
21+
22+
$this->gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest());
23+
}
24+
25+
public function testFetchIssuers()
26+
{
27+
$request = $this->gateway->fetchIssuers(array('partnerId' => 'abc123'));
28+
29+
$this->assertInstanceOf('Omnipay\Mollie\Message\FetchIssuersRequest', $request);
30+
$this->assertSame('abc123', $request->getPartnerId());
31+
}
32+
33+
public function testPurchase()
34+
{
35+
$request = $this->gateway->purchase(array('amount' => 123));
36+
37+
$this->assertInstanceOf('Omnipay\Mollie\Message\PurchaseRequest', $request);
38+
$this->assertSame(123, $request->getAmount());
39+
}
40+
41+
public function testPurchaseReturn()
42+
{
43+
$request = $this->gateway->completePurchase(array('amount' => 123));
44+
45+
$this->assertInstanceOf('Omnipay\Mollie\Message\CompletePurchaseRequest', $request);
46+
$this->assertSame(123, $request->getAmount());
47+
}
48+
}

0 commit comments

Comments
 (0)