Skip to content

Commit

Permalink
Merge pull request #17 from DennisHendrickx/master
Browse files Browse the repository at this point in the history
Added support for iDeal issuer
  • Loading branch information
delatbabel authored Jun 22, 2016
2 parents 9645115 + 4c01d7c commit aeadff6
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/BuckarooGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public function setSecretKey($value)
return $this->setParameter('secretKey', $value);
}

public function purchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\Buckaroo\Message\PurchaseRequest', $parameters);
}

public function completePurchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\Buckaroo\Message\CompletePurchaseRequest', $parameters);
Expand Down
4 changes: 4 additions & 0 deletions src/Message/IdealPurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public function getData()
$data = parent::getData();
$data['Brq_payment_method'] = 'ideal';

if ($this->getIssuer()) {
$data['Brq_service_ideal_issuer'] = $this->getIssuer();
}

return $data;
}
}
22 changes: 22 additions & 0 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Omnipay\Buckaroo\Message;

/**
* Buckaroo Purchase Request.
*
* With this purchase request Buckaroo will show all payment options configured for the website (websiteKey).
* The user must choose the payment method on the Buckaroo page.
*/
class PurchaseRequest extends AbstractRequest
{
public function getData()
{
$data = parent::getData();
unset($data['Brq_payment_method']);
unset($data['Brq_service_ideal_issuer']);
unset($data['Brq_requestedservices']);

return $data;
}
}
28 changes: 28 additions & 0 deletions tests/BuckarooGatewayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Omnipay\Buckaroo;

use Omnipay\Tests\GatewayTestCase;

class BuckarooGatewayTest extends GatewayTestCase
{
/**
* @var BuckarooGateway
*/
protected $gateway;

public function setUp()
{
parent::setUp();

$this->gateway = new BuckarooGateway($this->getHttpClient(), $this->getHttpRequest());
}

public function testPurchase()
{
$request = $this->gateway->purchase(array('amount' => '10.00'));

$this->assertInstanceOf('Omnipay\Buckaroo\Message\PurchaseRequest', $request);
$this->assertSame('10.00', $request->getAmount());
}
}
28 changes: 27 additions & 1 deletion tests/IdealGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace Omnipay\Buckaroo;

use Omnipay\Buckaroo\Message\IdealPurchaseRequest;
use Omnipay\Tests\GatewayTestCase;

class IdealGatewayTest extends GatewayTestCase
{
public function setUp()
{
parent::setUp();

$this->gateway = new IdealGateway($this->getHttpClient(), $this->getHttpRequest());
}

Expand All @@ -20,4 +21,29 @@ public function testPurchase()
$this->assertInstanceOf('Omnipay\Buckaroo\Message\IdealPurchaseRequest', $request);
$this->assertSame('10.00', $request->getAmount());
}

public function testIdealIssuerChosen()
{
/** @var IdealPurchaseRequest $request */
$request = $this->gateway->purchase(array(
'amount' => '10.00',
'returnUrl' => 'https://www.example.com/return',
'issuer' => 'TRIONL2U'
));

$data = $request->getData();

$this->assertSame('TRIONL2U', $data['Brq_service_ideal_issuer']);
}

public function testIdealIssuerIsNotRequired()
{
/** @var IdealPurchaseRequest $request */
$request = $this->gateway->purchase(array(
'amount' => '10.00',
'returnUrl' => 'https://www.example.com/return',
));

$this->assertNotContains('Brq_service_ideal_issuer', $request->getData());
}
}
2 changes: 1 addition & 1 deletion tests/Message/AbstractRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Mockery as m;
use Omnipay\Tests\TestCase;

class PurchaseRequestTest extends TestCase
class AbstractRequestTest extends TestCase
{
public function setUp()
{
Expand Down
57 changes: 57 additions & 0 deletions tests/Message/PurchaseRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Omnipay\Buckaroo\Message;

use Omnipay\Tests\TestCase;

class PurchaseRequestTest extends TestCase
{
/**
* @var PurchaseRequest
*/
protected $request;

public function setUp()
{
$this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'websiteKey' => 'web',
'secretKey' => 'secret',
'amount' => '12.00',
'returnUrl' => 'https://www.example.com/return',
)
);
}

public function testGetData()
{
$this->request->initialize(array(
'websiteKey' => 'web',
'secretKey' => 'secret',
'amount' => '12.00',
'currency' => 'EUR',
'testMode' => true,
'transactionId' => 13,
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
'culture' => 'nl-NL',
'paymentMethod' => 'mastercard',
'issuer' => 'RABONL2U',
));

$data = $this->request->getData();

$this->assertSame('web', $data['Brq_websitekey']);
$this->assertSame('12.00', $data['Brq_amount']);
$this->assertSame('EUR', $data['Brq_currency']);
$this->assertSame(13, $data['Brq_invoicenumber']);
$this->assertSame('https://www.example.com/return', $data['Brq_return']);
$this->assertSame('https://www.example.com/cancel', $data['Brq_returncancel']);
$this->assertSame('nl-NL', $data['Brq_culture']);

$this->assertNotContains('Brq_payment_method', $data);
$this->assertNotContains('Brq_service_ideal_issuer', $data);
$this->assertNotContains('Brq_requestedservices', $data);
}
}

0 comments on commit aeadff6

Please sign in to comment.