Skip to content

Commit 737ed4f

Browse files
committed
Add Buckaroo gateway
1 parent 181f99c commit 737ed4f

File tree

9 files changed

+511
-0
lines changed

9 files changed

+511
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ The following gateways are already implemented:
9191
* 2Checkout
9292
* Authorize.Net AIM
9393
* Authorize.Net SIM
94+
* Buckaroo
9495
* CardSave
9596
* Dummy
9697
* GoCardless

src/Omnipay/Buckaroo/Gateway.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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\Buckaroo;
13+
14+
use Omnipay\Common\AbstractGateway;
15+
16+
/**
17+
* Buckaroo Gateway
18+
*/
19+
class Gateway extends AbstractGateway
20+
{
21+
public function getName()
22+
{
23+
return 'Buckaroo';
24+
}
25+
26+
public function getDefaultParameters()
27+
{
28+
return array(
29+
'merchantId' => '',
30+
'secret' => '',
31+
'testMode' => false,
32+
);
33+
}
34+
35+
public function getMerchantId()
36+
{
37+
return $this->getParameter('merchantId');
38+
}
39+
40+
public function setMerchantId($value)
41+
{
42+
return $this->setParameter('merchantId', $value);
43+
}
44+
45+
public function getSecret()
46+
{
47+
return $this->getParameter('secret');
48+
}
49+
50+
public function setSecret($value)
51+
{
52+
return $this->setParameter('secret', $value);
53+
}
54+
55+
public function purchase(array $parameters = array())
56+
{
57+
return $this->createRequest('\Omnipay\Buckaroo\Message\PurchaseRequest', $parameters);
58+
}
59+
60+
public function completePurchase(array $parameters = array())
61+
{
62+
return $this->createRequest('\Omnipay\Buckaroo\Message\CompletePurchaseRequest', $parameters);
63+
}
64+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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\Buckaroo\Message;
13+
14+
use Omnipay\Common\Exception\InvalidRequestException;
15+
16+
/**
17+
* Buckaroo Complete Purchase Request
18+
*/
19+
class CompletePurchaseRequest extends PurchaseRequest
20+
{
21+
public function getData()
22+
{
23+
$this->validate('merchantId', 'secret', 'amount');
24+
25+
if (strtolower($this->httpRequest->request->get('bpe_signature2')) !== $this->generateResponseSignature()) {
26+
throw new InvalidRequestException('Incorrect signature');
27+
}
28+
29+
return $this->httpRequest->request->all();
30+
}
31+
32+
public function generateResponseSignature()
33+
{
34+
return md5(
35+
$this->httpRequest->request->get('bpe_trx').
36+
$this->httpRequest->request->get('bpe_timestamp').
37+
$this->getMerchantId().
38+
$this->getTransactionId().
39+
$this->getCurrency().
40+
$this->getAmountInteger().
41+
$this->httpRequest->request->get('bpe_result').
42+
(int) $this->getTestMode().
43+
$this->getSecret()
44+
);
45+
}
46+
47+
public function send()
48+
{
49+
return $this->response = new CompletePurchaseResponse($this, $this->getData());
50+
}
51+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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\Buckaroo\Message;
13+
14+
use Omnipay\Common\Message\AbstractResponse;
15+
16+
/**
17+
* Buckaroo Complete Purchase Response
18+
*/
19+
class CompletePurchaseResponse extends AbstractResponse
20+
{
21+
const CC_SUCCESS = '100';
22+
const PAYPAL_SUCCESS = '121';
23+
const IDEAL_SUCCESS = '801';
24+
25+
public function isSuccessful()
26+
{
27+
$success_codes = array(
28+
static::CC_SUCCESS,
29+
static::PAYPAL_SUCCESS,
30+
static::IDEAL_SUCCESS,
31+
);
32+
33+
return in_array($this->getCode(), $success_codes);
34+
}
35+
36+
public function getTransactionReference()
37+
{
38+
if (isset($this->data['bpe_trx'])) {
39+
return $this->data['bpe_trx'];
40+
}
41+
}
42+
43+
public function getCode()
44+
{
45+
if (isset($this->data['bpe_result'])) {
46+
return $this->data['bpe_result'];
47+
}
48+
}
49+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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\Buckaroo\Message;
13+
14+
use Omnipay\Common\Message\AbstractRequest;
15+
16+
/**
17+
* Buckaroo Purchase Request
18+
*/
19+
class PurchaseRequest extends AbstractRequest
20+
{
21+
protected $endpoint = 'https://payment.buckaroo.nl/sslplus/request_for_authorization.asp';
22+
23+
public function getMerchantId()
24+
{
25+
return $this->getParameter('merchantId');
26+
}
27+
28+
public function setMerchantId($value)
29+
{
30+
return $this->setParameter('merchantId', $value);
31+
}
32+
33+
public function getSecret()
34+
{
35+
return $this->getParameter('secret');
36+
}
37+
38+
public function setSecret($value)
39+
{
40+
return $this->setParameter('secret', $value);
41+
}
42+
43+
public function getData()
44+
{
45+
$this->validate('merchantId', 'secret', 'amount', 'returnUrl');
46+
47+
$data = array();
48+
$data['BPE_Merchant'] = $this->getMerchantId();
49+
$data['BPE_Amount'] = $this->getAmountInteger();
50+
$data['BPE_Currency'] = $this->getCurrency();
51+
$data['BPE_Language'] = 'EN';
52+
$data['BPE_Mode'] = (int) $this->getTestMode();
53+
$data['BPE_Invoice'] = $this->getTransactionId();
54+
$data['BPE_Return_Success'] = $this->getReturnUrl();
55+
$data['BPE_Return_Reject'] = $this->getReturnUrl();
56+
$data['BPE_Return_Error'] = $this->getReturnUrl();
57+
$data['BPE_Return_Method'] = 'POST';
58+
$data['BPE_Signature2'] = $this->generateSignature($data);
59+
60+
return $data;
61+
}
62+
63+
public function generateSignature($data)
64+
{
65+
return md5(
66+
$data['BPE_Merchant'].
67+
$data['BPE_Invoice'].
68+
$data['BPE_Amount'].
69+
$data['BPE_Currency'].
70+
$data['BPE_Mode'].
71+
$this->getSecret()
72+
);
73+
}
74+
75+
public function send()
76+
{
77+
return $this->response = new PurchaseResponse($this, $this->getData());
78+
}
79+
80+
public function getEndpoint()
81+
{
82+
return $this->endpoint;
83+
}
84+
}
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 <[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\Buckaroo\Message;
13+
14+
use Omnipay\Common\Message\AbstractResponse;
15+
use Omnipay\Common\Message\RedirectResponseInterface;
16+
17+
/**
18+
* Buckaroo Purchase Response
19+
*/
20+
class PurchaseResponse extends AbstractResponse implements RedirectResponseInterface
21+
{
22+
public function isSuccessful()
23+
{
24+
return false;
25+
}
26+
27+
public function isRedirect()
28+
{
29+
return true;
30+
}
31+
32+
public function getRedirectUrl()
33+
{
34+
return $this->getRequest()->getEndpoint();
35+
}
36+
37+
public function getRedirectMethod()
38+
{
39+
return 'POST';
40+
}
41+
42+
public function getRedirectData()
43+
{
44+
return $this->data;
45+
}
46+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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\Buckaroo;
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 testPurchase()
26+
{
27+
$request = $this->gateway->purchase(array('amount' => '10.00'));
28+
29+
$this->assertInstanceOf('Omnipay\Buckaroo\Message\PurchaseRequest', $request);
30+
$this->assertSame('10.00', $request->getAmount());
31+
}
32+
33+
public function testPurchaseReturn()
34+
{
35+
$request = $this->gateway->completePurchase(array('amount' => '10.00'));
36+
37+
$this->assertInstanceOf('Omnipay\Buckaroo\Message\CompletePurchaseRequest', $request);
38+
$this->assertSame('10.00', $request->getAmount());
39+
}
40+
}

0 commit comments

Comments
 (0)