Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add method to get issuers for PayByBank #152

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/PaymentMethods/PaymentInitiation/PaymentInitiation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

namespace Buckaroo\PaymentMethods\PaymentInitiation;

use Buckaroo\Exceptions\BuckarooException;
use Buckaroo\Models\Model;
use Buckaroo\PaymentMethods\PayablePaymentMethod;
use Buckaroo\PaymentMethods\PaymentInitiation\Models\Pay;
use Buckaroo\Services\TraitHelpers\HasIssuers;
use Buckaroo\Transaction\Response\TransactionResponse;

class PaymentInitiation extends PayablePaymentMethod
{
use HasIssuers {
issuers as traitIssuers;
}
protected string $paymentName = 'PayByBank';
protected array $requiredConfigFields = ['currency', 'returnURL', 'returnURLCancel', 'pushURL'];

Expand All @@ -20,4 +25,15 @@ public function pay(?Model $model = null): TransactionResponse
{
return parent::pay($model ?? new Pay($this->payload));
}

/**
* @return array
* @throws BuckarooException
*/
public function issuers(): array
{
$this->serviceVersion = 1;

return $this->traitIssuers();
}
}
34 changes: 9 additions & 25 deletions src/PaymentMethods/iDeal/iDeal.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@

namespace Buckaroo\PaymentMethods\iDeal;

use Buckaroo\Exceptions\BuckarooException;
use Buckaroo\Models\Model;
use Buckaroo\PaymentMethods\iDeal\Models\Pay;
use Buckaroo\PaymentMethods\PayablePaymentMethod;
use Buckaroo\Transaction\Request\TransactionRequest;
use Buckaroo\Services\TraitHelpers\HasIssuers;
use Buckaroo\Transaction\Response\TransactionResponse;

class iDeal extends PayablePaymentMethod
{
use HasIssuers {
issuers as traitIssuers;
}

/**
* @var string
*/
Expand Down Expand Up @@ -72,33 +77,12 @@ public function instantRefund(?Model $model = null):TransactionResponse

/**
* @return array
* @throws \Buckaroo\Exceptions\BuckarooException
* @throws BuckarooException
*/
public function issuers(): array
{
$request = new TransactionRequest;

try
{
$response = $this->client->specification($request, 'ideal', 2);
} catch (BuckarooException $e)
{
return [];
}

$issuerList = [];
if (isset($response->data()['Actions']['0']['RequestParameters'][0]['ListItemDescriptions']))
{
$issuersData = $response->data()['Actions']['0']['RequestParameters'][0]['ListItemDescriptions'];
if (count($issuersData) > 0)
{
foreach ($issuersData as $issuer)
{
$issuerList[] = ['id' => $issuer['Value'], 'name' => $issuer['Description']];
}
}
}
$this->serviceVersion = 2;

return $issuerList;
return $this->traitIssuers();
}
}
59 changes: 59 additions & 0 deletions src/Services/TraitHelpers/HasIssuers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* It is available through the world-wide-web at this URL:
* https://tldrlegal.com/license/mit-license
* If you are unable to obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please contact [email protected] for more information.
*
* @copyright Copyright (c) Buckaroo B.V.
* @license https://tldrlegal.com/license/mit-license
*/

namespace Buckaroo\Services\TraitHelpers;

use Buckaroo\Exceptions\BuckarooException;
use Buckaroo\Transaction\Request\TransactionRequest;

trait HasIssuers
{
/**
* @return array
* @throws BuckarooException
*/
public function issuers(): array
{
$request = new TransactionRequest;

try
{
$response = $this->client->specification($request, $this->paymentName, $this->serviceVersion());
} catch (BuckarooException $e)
{
return [];
}

$issuerList = [];
if (isset($response->data()['Actions']['0']['RequestParameters'][0]['ListItemDescriptions']))
{
$issuersData = $response->data()['Actions']['0']['RequestParameters'][0]['ListItemDescriptions'];
if (count($issuersData) > 0)
{
foreach ($issuersData as $issuer)
{
$issuerList[] = ['id' => $issuer['Value'], 'name' => $issuer['Description']];
}
}
}

return $issuerList;
}
}
17 changes: 17 additions & 0 deletions tests/Buckaroo/Payments/IdealTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ protected function setUp(): void
];
}

/**
* @return void
* @test
*/
public function it_get_ideal_issuers()
{
$response = $this->buckaroo->method('ideal')->issuers();

$this->assertIsArray($response);
foreach ($response as $item)
{
$this->assertIsArray($item);
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('name', $item);
}
}

/**
* @return void
* @test
Expand Down
16 changes: 16 additions & 0 deletions tests/Buckaroo/Payments/PaymentInitiation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@

class PaymentInitiation extends BuckarooTestCase
{
/**
* @return void
* @test
*/
public function it_get_payment_initiation_issuers()
{
$response = $this->buckaroo->method('paybybank')->issuers();

$this->assertIsArray($response);
foreach ($response as $item)
{
$this->assertIsArray($item);
$this->assertArrayHasKey('id', $item);
$this->assertArrayHasKey('name', $item);
}
}

/**
* @test
Expand Down
Loading