diff --git a/src/PaymentMethods/PaymentInitiation/PaymentInitiation.php b/src/PaymentMethods/PaymentInitiation/PaymentInitiation.php index 5c3cbafd..0dbb018f 100644 --- a/src/PaymentMethods/PaymentInitiation/PaymentInitiation.php +++ b/src/PaymentMethods/PaymentInitiation/PaymentInitiation.php @@ -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']; @@ -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(); + } } diff --git a/src/PaymentMethods/iDeal/iDeal.php b/src/PaymentMethods/iDeal/iDeal.php index 2596c684..dbd07614 100644 --- a/src/PaymentMethods/iDeal/iDeal.php +++ b/src/PaymentMethods/iDeal/iDeal.php @@ -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 */ @@ -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(); } } diff --git a/src/Services/TraitHelpers/HasIssuers.php b/src/Services/TraitHelpers/HasIssuers.php new file mode 100644 index 00000000..0b928237 --- /dev/null +++ b/src/Services/TraitHelpers/HasIssuers.php @@ -0,0 +1,59 @@ +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; + } +} diff --git a/tests/Buckaroo/Payments/IdealTest.php b/tests/Buckaroo/Payments/IdealTest.php index a8f5c177..efab199d 100644 --- a/tests/Buckaroo/Payments/IdealTest.php +++ b/tests/Buckaroo/Payments/IdealTest.php @@ -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 diff --git a/tests/Buckaroo/Payments/PaymentInitiation.php b/tests/Buckaroo/Payments/PaymentInitiation.php index 3759c63d..fd6f5cc0 100644 --- a/tests/Buckaroo/Payments/PaymentInitiation.php +++ b/tests/Buckaroo/Payments/PaymentInitiation.php @@ -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