diff --git a/composer.json b/composer.json index d4712ec4..16fd1d9c 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "buckaroo/sdk", "description": "Buckaroo payment SDK", "license": "MIT", - "version": "1.11.0", + "version": "1.12.0", "type": "library", "require": { "php": ">=7.4|^8.0", diff --git a/example/transactions/tinka.php b/example/transactions/tinka.php deleted file mode 100644 index deb26f2a..00000000 --- a/example/transactions/tinka.php +++ /dev/null @@ -1,81 +0,0 @@ -method('tinka')->pay([ - 'amountDebit' => 3.5, - 'order' => uniqid(), - 'invoice' => uniqid(), - 'description' => 'This is a test order', - 'paymentMethod' => 'Credit', - 'deliveryMethod' => 'Locker', - 'deliveryDate' => '2030-01-01', - 'articles' => [ - [ - 'type' => 1, - 'description' => 'Blue Toy Car', - 'brand' => 'Ford Focus', - 'manufacturer' => 'Ford', - 'color' => 'Red', - 'size' => 'Small', - 'quantity' => '1', - 'price' => '3.5', - 'unitCode' => 'test', - ], - ], - 'customer' => [ - 'gender' => Gender::MALE, - 'firstName' => 'Buck', - 'lastName' => 'Aroo', - 'initials' => 'BA', - 'birthDate' => '1990-01-01', - ], - 'billing' => [ - 'recipient' => [ - 'lastNamePrefix' => 'the', - ], - 'email' => 'billingcustomer@buckaroo.nl', - 'phone' => [ - 'mobile' => '0109876543', - ], - 'address' => [ - 'street' => 'Hoofdstraat', - 'houseNumber' => '80', - 'houseNumberAdditional' => 'A', - 'zipcode' => '8441EE', - 'city' => 'Heerenveen', - 'country' => 'NL', - ], - ], - 'shipping' => [ - 'recipient' => [ - 'lastNamePrefix' => 'the', - ], - 'email' => 'billingcustomer@buckaroo.nl', - 'phone' => [ - 'mobile' => '0109876543', - ], - 'address' => [ - 'street' => 'Hoofdstraat', - 'houseNumber' => '80', - 'houseNumberAdditional' => 'A', - 'zipcode' => '8441EE', - 'city' => 'Heerenveen', - 'country' => 'NL', - ], - ], -]); - -//Refund -$response = $buckaroo->method('tinka')->refund([ - 'amountCredit' => 10, - 'invoice' => 'testinvoice 123', - 'originalTransactionKey' => '2D04704995B74D679AACC59F87XXXXXX', -]); diff --git a/phpcs.xml b/phpcs.xml index e60e272d..e3e1b7c2 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -16,6 +16,7 @@ src/PaymentMethods/iDeal/iDeal.php src/PaymentMethods/iDealQR/iDealQR.php src/PaymentMethods/iDin/iDin.php + src/PaymentMethods/iDealProcessing/iDealProcessing.php diff --git a/src/PaymentMethods/PaymentFacade.php b/src/PaymentMethods/PaymentFacade.php index 584472ac..76d65d68 100644 --- a/src/PaymentMethods/PaymentFacade.php +++ b/src/PaymentMethods/PaymentFacade.php @@ -166,8 +166,13 @@ public function paymentMethod(): PaymentMethod */ public function __call(?string $name, array $arguments) { - if (method_exists($this->paymentMethod, $name)) - { + if (method_exists($this->paymentMethod, $name)) { + if($name === 'setServiceVersion') { + $this->paymentMethod->setServiceVersion($arguments[0]); + + return $this; + } + $this->paymentMethod->setPayload((new PayloadService($arguments[0] ?? []))->toArray()); return $this->paymentMethod->$name(); diff --git a/src/PaymentMethods/PaymentMethod.php b/src/PaymentMethods/PaymentMethod.php index 3041656c..0a1cf3a8 100644 --- a/src/PaymentMethods/PaymentMethod.php +++ b/src/PaymentMethods/PaymentMethod.php @@ -171,6 +171,16 @@ public function serviceVersion(): int return $this->serviceVersion; } + /** + * @return PaymentInterface + */ + public function setServiceVersion(int $serviceVersion): PaymentInterface + { + $this->serviceVersion = $serviceVersion; + + return $this; + } + /** * @param bool|null $isManually * @return $this diff --git a/src/PaymentMethods/PaymentMethodFactory.php b/src/PaymentMethods/PaymentMethodFactory.php index 2840b750..325405e2 100644 --- a/src/PaymentMethods/PaymentMethodFactory.php +++ b/src/PaymentMethods/PaymentMethodFactory.php @@ -27,8 +27,8 @@ use Buckaroo\PaymentMethods\iDin\iDin; use Buckaroo\PaymentMethods\SEPA\SEPA; use Buckaroo\PaymentMethods\iDeal\iDeal; +use Buckaroo\PaymentMethods\iDealProcessing\iDealProcessing; use Buckaroo\PaymentMethods\MBWay\MBWay; -use Buckaroo\PaymentMethods\Tinka\Tinka; use Buckaroo\Exceptions\BuckarooException; use Buckaroo\PaymentMethods\Alipay\Alipay; use Buckaroo\PaymentMethods\In3Old\In3Old; @@ -92,7 +92,8 @@ class PaymentMethodFactory ], CreditClick::class => ['creditclick'], CreditManagement::class => ['credit_management'], - iDeal::class => ['ideal', 'idealprocessing'], + iDeal::class => ['ideal'], + iDealProcessing::class => ['idealprocessing'], iDealQR::class => ['ideal_qr'], iDin::class => ['idin'], In3::class => ['in3'], @@ -113,14 +114,12 @@ class PaymentMethodFactory ExternalPayment::class => ['externalpayment'], Emandates::class => ['emandates'], Sofort::class => ['sofort', 'sofortueberweisung'], - Tinka::class => ['tinka'], Marketplaces::class => ['marketplaces'], NoServiceSpecifiedPayment::class => ['noservice'], Payconiq::class => ['payconiq'], Przelewy24::class => ['przelewy24'], PointOfSale::class => ['pospayment'], Giropay::class => ['giropay'], - NoServiceSpecifiedPayment::class => ['noservice'], GiftCard::class => [ 'giftcard', 'westlandbon', 'babygiftcard', 'babyparkgiftcard', 'beautywellness', 'boekenbon', 'boekenvoordeel', diff --git a/src/PaymentMethods/Tinka/Models/Pay.php b/src/PaymentMethods/Tinka/Models/Pay.php deleted file mode 100644 index 7991be1b..00000000 --- a/src/PaymentMethods/Tinka/Models/Pay.php +++ /dev/null @@ -1,137 +0,0 @@ - [ - 'groupType' => 'Article', - ], - ]; - - /** - * @param $billing - * @return Recipient - */ - public function billing($billing = null) - { - if (is_array($billing)) - { - $this->billingRecipient = new Recipient('Billing', $billing); - $this->shippingRecipient = new Recipient('Billing', $billing); - } - - return $this->billingRecipient; - } - - /** - * @param $shipping - * @return Recipient - */ - public function shipping($shipping = null) - { - if (is_array($shipping)) - { - $this->shippingRecipient = new Recipient('Shipping', $shipping); - } - - return $this->shippingRecipient; - } - - /** - * @param $customer - * @return CustomerAdapter - */ - public function customer($customer = null) - { - if (is_array($customer)) - { - $this->customer = new CustomerAdapter(new Person($customer)); - } - - return $this->customer; - } - - /** - * @param array|null $articles - * @return array - */ - public function articles(?array $articles = null) - { - if (is_array($articles)) - { - foreach ($articles as $article) - { - $this->articles[] = new ArticleAdapter(new Article($article)); - } - } - - return $this->articles; - } -} diff --git a/src/PaymentMethods/Tinka/Models/Recipient.php b/src/PaymentMethods/Tinka/Models/Recipient.php deleted file mode 100644 index b266423a..00000000 --- a/src/PaymentMethods/Tinka/Models/Recipient.php +++ /dev/null @@ -1,132 +0,0 @@ -type = $type; - - parent::__construct($values); - } - - /** - * @param $recipient - * @return CustomerAdapter - */ - public function recipient($recipient = null) - { - if (is_array($recipient)) - { - $this->recipient = new CustomerAdapter(new Person($recipient)); - } - - return $this->recipient; - } - - /** - * @param $address - * @return AddressAdapter - */ - public function address($address = null) - { - if (is_array($address)) - { - $this->address = new AddressAdapter(new Address($address)); - } - - return $this->address; - } - - /** - * @param $phone - * @return PhoneAdapter - */ - public function phone($phone = null) - { - if (is_array($phone)) - { - $this->phone = new PhoneAdapter(new Phone($phone)); - } - - return $this->phone; - } - - /** - * @param $email - * @return Email - */ - public function email($email = null) - { - if (is_string($email)) - { - $this->email = new Email($email); - } - - return $this->email; - } - - /** - * @param string $key - * @return string|null - */ - public function getGroupType(string $key): ?string - { - return $this->type . 'Customer'; - } -} diff --git a/src/PaymentMethods/Tinka/Service/ParameterKeys/AddressAdapter.php b/src/PaymentMethods/Tinka/Service/ParameterKeys/AddressAdapter.php deleted file mode 100644 index bd316ace..00000000 --- a/src/PaymentMethods/Tinka/Service/ParameterKeys/AddressAdapter.php +++ /dev/null @@ -1,32 +0,0 @@ - 'StreetNumber', - 'houseNumberAdditional' => 'StreetNumberAdditional', - 'zipcode' => 'PostalCode', - ]; -} diff --git a/src/PaymentMethods/Tinka/Service/ParameterKeys/ArticleAdapter.php b/src/PaymentMethods/Tinka/Service/ParameterKeys/ArticleAdapter.php deleted file mode 100644 index 79f51acc..00000000 --- a/src/PaymentMethods/Tinka/Service/ParameterKeys/ArticleAdapter.php +++ /dev/null @@ -1,30 +0,0 @@ - 'UnitGrossPrice', - ]; -} diff --git a/src/PaymentMethods/Tinka/Service/ParameterKeys/CustomerAdapter.php b/src/PaymentMethods/Tinka/Service/ParameterKeys/CustomerAdapter.php deleted file mode 100644 index f868f4e8..00000000 --- a/src/PaymentMethods/Tinka/Service/ParameterKeys/CustomerAdapter.php +++ /dev/null @@ -1,31 +0,0 @@ - 'PrefixLastName', - 'birthDate' => 'DateOfBirth', - ]; -} diff --git a/src/PaymentMethods/Tinka/Service/ParameterKeys/PhoneAdapter.php b/src/PaymentMethods/Tinka/Service/ParameterKeys/PhoneAdapter.php deleted file mode 100644 index e9638788..00000000 --- a/src/PaymentMethods/Tinka/Service/ParameterKeys/PhoneAdapter.php +++ /dev/null @@ -1,30 +0,0 @@ - 'Phone' - ]; -} diff --git a/src/PaymentMethods/Tinka/Tinka.php b/src/PaymentMethods/Tinka/Tinka.php deleted file mode 100644 index 0363ae78..00000000 --- a/src/PaymentMethods/Tinka/Tinka.php +++ /dev/null @@ -1,37 +0,0 @@ -payload)); - } -} diff --git a/src/PaymentMethods/Tinka/Models/Article.php b/src/PaymentMethods/iDealProcessing/Models/Pay.php similarity index 80% rename from src/PaymentMethods/Tinka/Models/Article.php rename to src/PaymentMethods/iDealProcessing/Models/Pay.php index 1ad39f07..5e10d05c 100644 --- a/src/PaymentMethods/Tinka/Models/Article.php +++ b/src/PaymentMethods/iDealProcessing/Models/Pay.php @@ -18,9 +18,11 @@ * @license https://tldrlegal.com/license/mit-license */ -namespace Buckaroo\PaymentMethods\Tinka\Models; +namespace Buckaroo\PaymentMethods\iDealProcessing\Models; -class Article extends \Buckaroo\Models\Article +use Buckaroo\Models\ServiceParameter; + +class Pay extends ServiceParameter { - protected string $color; + protected string $issuer; } diff --git a/src/PaymentMethods/iDealProcessing/iDealProcessing.php b/src/PaymentMethods/iDealProcessing/iDealProcessing.php new file mode 100644 index 00000000..1dbe949c --- /dev/null +++ b/src/PaymentMethods/iDealProcessing/iDealProcessing.php @@ -0,0 +1,75 @@ +payload)); + } + + /** + * @param Model|null $model + * @return TransactionResponse + */ + public function payRemainder(?Model $model = null): TransactionResponse + { + return parent::payRemainder($model ?? new Pay($this->payload)); + } + + /** + * @return array + * @throws BuckarooException + */ + public function issuers(): array + { + $this->serviceVersion = 2; + + return $this->traitIssuers(); + } +} diff --git a/src/Resources/Constants/ResponseStatus.php b/src/Resources/Constants/ResponseStatus.php index f4f5414a..cb59462d 100644 --- a/src/Resources/Constants/ResponseStatus.php +++ b/src/Resources/Constants/ResponseStatus.php @@ -33,6 +33,7 @@ class ResponseStatus public const BUCKAROO_STATUSCODE_PENDING_PROCESSING = '791'; public const BUCKAROO_STATUSCODE_WAITING_ON_CONSUMER = '792'; public const BUCKAROO_STATUSCODE_PAYMENT_ON_HOLD = '793'; + public const BUCKAROO_STATUSCODE_PENDING_APPROVAL = '794'; public const BUCKAROO_STATUSCODE_CANCELLED_BY_USER = '890'; public const BUCKAROO_STATUSCODE_CANCELLED_BY_MERCHANT = '891'; diff --git a/src/Transaction/Response/TransactionResponse.php b/src/Transaction/Response/TransactionResponse.php index e4e3085d..c6b9bbf4 100644 --- a/src/Transaction/Response/TransactionResponse.php +++ b/src/Transaction/Response/TransactionResponse.php @@ -83,6 +83,14 @@ public function isRejected(): bool return $this->getStatusCode() == ResponseStatus::BUCKAROO_STATUSCODE_REJECTED; } + /** + * @return bool + */ + public function isPendingApproval(): bool + { + return $this->getStatusCode() == ResponseStatus::BUCKAROO_STATUSCODE_PENDING_APPROVAL; + } + /** * @return bool */ diff --git a/tests/Buckaroo/Payments/AfterpayTest.php b/tests/Buckaroo/Payments/AfterpayTest.php index a92d30d0..bec23abd 100644 --- a/tests/Buckaroo/Payments/AfterpayTest.php +++ b/tests/Buckaroo/Payments/AfterpayTest.php @@ -31,7 +31,7 @@ class AfterpayTest extends BuckarooTestCase */ public function it_creates_a_afterpay_payment() { - $response = $this->buckaroo->method('afterpay')->pay($this->getPaymentPayload()); + $response = $this->buckaroo->method('afterpay')->setServiceVersion(3)->pay($this->getPaymentPayload()); $this->assertTrue($response->isSuccess()); } diff --git a/tests/Buckaroo/Payments/IdealProcessingTest.php b/tests/Buckaroo/Payments/IdealProcessingTest.php new file mode 100644 index 00000000..cb4b3845 --- /dev/null +++ b/tests/Buckaroo/Payments/IdealProcessingTest.php @@ -0,0 +1,90 @@ +paymentPayload = [ + 'invoice' => uniqid(), + 'amountDebit' => 10.10, + 'issuer' => 'ABNANL2A', + 'pushURL' => 'https://buckaroo.dev/push', + 'returnURL' => 'https://buckaroo.dev/return', + 'clientIP' => [ + 'address' => '123.456.789.123', + 'type' => 0, + ], + 'customParameters' => [ + 'CustomerBillingFirstName' => 'test' + ], + 'additionalParameters' => [ + 'initiated_by_magento' => 1, + 'service_action' => 'something', + ], + ]; + } + + /** + * @return void + * @test + */ + public function it_get_idealprocessing_issuers() + { + $response = $this->buckaroo->method('idealprocessing')->issuers(); + + $this->assertIsArray($response); + foreach ($response as $item) + { + $this->assertIsArray($item); + $this->assertArrayHasKey('id', $item); + $this->assertArrayHasKey('name', $item); + } + } + + /** + * @return void + * @test + */ + public function it_creates_a_idealprocessing_payment() + { + $response = $this->buckaroo->method('idealprocessing')->pay($this->paymentPayload); + + $this->assertTrue($response->isPendingProcessing()); + } +} diff --git a/tests/Buckaroo/Payments/IdealTest.php b/tests/Buckaroo/Payments/IdealTest.php index 6b402c10..c7cb886d 100644 --- a/tests/Buckaroo/Payments/IdealTest.php +++ b/tests/Buckaroo/Payments/IdealTest.php @@ -100,7 +100,7 @@ public function it_get_ideal_issuers() */ public function it_creates_a_ideal_payment() { - $response = $this->buckaroo->method('idealprocessing')->pay($this->paymentPayload); + $response = $this->buckaroo->method('ideal')->pay($this->paymentPayload); $this->assertTrue($response->isPendingProcessing()); } diff --git a/tests/Buckaroo/Payments/TinkaTest.php b/tests/Buckaroo/Payments/TinkaTest.php deleted file mode 100644 index e4689423..00000000 --- a/tests/Buckaroo/Payments/TinkaTest.php +++ /dev/null @@ -1,118 +0,0 @@ -buckaroo->method('tinka')->pay($this->getPaymentPayload()); - - $this->assertTrue($response->isPendingProcessing()); - } - - /** - * @test - */ - public function it_creates_a_tinka_refund() - { - $response = $this->buckaroo->method('tinka')->refund([ - 'amountCredit' => 10, - 'invoice' => 'testinvoice 123', - 'originalTransactionKey' => '2D04704995B74D679AACC59F87XXXXXX', - ]); - - $this->assertTrue($response->isFailed()); - } - - private function getPaymentPayload(): array - { - return [ - 'amountDebit' => 3.5, - 'order' => uniqid(), - 'invoice' => uniqid(), - 'description' => 'This is a test order', - 'paymentMethod' => 'Credit', - 'deliveryMethod' => 'Locker', - 'deliveryDate' => '2030-01-01', - 'articles' => [ - [ - 'type' => 1, - 'description' => 'Blue Toy Car', - 'brand' => 'Ford Focus', - 'manufacturer' => 'Ford', - 'color' => 'Red', - 'size' => 'Small', - 'quantity' => '1', - 'price' => '3.5', - 'unitCode' => 'test', - ], - ], - 'customer' => [ - 'gender' => Gender::MALE, - 'firstName' => 'Buck', - 'lastName' => 'Aroo', - 'initials' => 'BA', - 'birthDate' => '1990-01-01', - ], - 'billing' => [ - 'recipient' => [ - 'lastNamePrefix' => 'the', - ], - 'email' => 'billingcustomer@buckaroo.nl', - 'phone' => [ - 'mobile' => '0109876543', - ], - 'address' => [ - 'street' => 'Hoofdstraat', - 'houseNumber' => '80', - 'houseNumberAdditional' => 'A', - 'zipcode' => '8441EE', - 'city' => 'Heerenveen', - 'country' => 'NL', - ], - ], - 'shipping' => [ - 'recipient' => [ - 'lastNamePrefix' => 'the', - ], - 'email' => 'billingcustomer@buckaroo.nl', - 'phone' => [ - 'mobile' => '0109876543', - ], - 'address' => [ - 'street' => 'Hoofdstraat', - 'houseNumber' => '80', - 'houseNumberAdditional' => 'A', - 'zipcode' => '8441EE', - 'city' => 'Heerenveen', - 'country' => 'NL', - ], - ], - ]; - } -}