diff --git a/Components/Constants/PaymentMethod.php b/Components/Constants/PaymentMethod.php index bf436a2f..83c9e15d 100644 --- a/Components/Constants/PaymentMethod.php +++ b/Components/Constants/PaymentMethod.php @@ -28,4 +28,5 @@ class PaymentMethod const APPLEPAY_DIRECT = "applepaydirect"; const VOUCHERS = "voucher"; const IN3 = "in3"; + const TWINT = "twint"; } diff --git a/Components/Installer/PaymentMethods/PaymentMethodsInstaller.php b/Components/Installer/PaymentMethods/PaymentMethodsInstaller.php index 4479e3aa..6f395516 100644 --- a/Components/Installer/PaymentMethods/PaymentMethodsInstaller.php +++ b/Components/Installer/PaymentMethods/PaymentMethodsInstaller.php @@ -119,6 +119,7 @@ public static function getSupportedPaymentMethods() PaymentMethod::SOFORT, PaymentMethod::VOUCHERS, PaymentMethod::IN3, + PaymentMethod::TWINT, ]; } diff --git a/Components/Payment/Provider/ActivePaymentMethodsProvider.php b/Components/Payment/Provider/ActivePaymentMethodsProvider.php index b9efeb92..e8feebbb 100644 --- a/Components/Payment/Provider/ActivePaymentMethodsProvider.php +++ b/Components/Payment/Provider/ActivePaymentMethodsProvider.php @@ -115,18 +115,12 @@ private function getActivePaymentMethodsForShop(Shop $shop, array $parameters = { $mollieApiClient = $this->mollieApiFactory->create($shop->getId()); - # adds resource to parameters if not in array - if (!in_array('resource', $parameters, true)) { - $parameters['resource'] = 'orders'; - } - - # adds wallets to parameters if not in array - if (!in_array('includeWallets', $parameters, true)) { - $parameters['includeWallets'] = 'applepay'; - } - - return $mollieApiClient->methods - ->allActive($parameters) + $methods = $mollieApiClient->methods + ->allAvailable($parameters) ->getArrayCopy(); + + return array_filter($methods, function ($method) { + return $method->status == 'activated'; + }); } } diff --git a/Services/Mollie/Payments/PaymentFactory.php b/Services/Mollie/Payments/PaymentFactory.php index d269ef31..b63c3600 100644 --- a/Services/Mollie/Payments/PaymentFactory.php +++ b/Services/Mollie/Payments/PaymentFactory.php @@ -24,6 +24,7 @@ use MollieShopware\Services\Mollie\Payments\Requests\SepaDirectDebit; use MollieShopware\Services\Mollie\Payments\Requests\SliceIt; use MollieShopware\Services\Mollie\Payments\Requests\Sofort; +use MollieShopware\Services\Mollie\Payments\Requests\Twint; use MollieShopware\Services\Mollie\Payments\Requests\Voucher; class PaymentFactory @@ -99,6 +100,9 @@ public function createByPaymentName($paymentMethod) case PaymentMethod::IN3: return new In3(); + + case PaymentMethod::TWINT: + return new Twint(); } throw new \Exception('Payment handler not found for: ' . $paymentMethod); diff --git a/Services/Mollie/Payments/Requests/Twint.php b/Services/Mollie/Payments/Requests/Twint.php new file mode 100644 index 00000000..43274693 --- /dev/null +++ b/Services/Mollie/Payments/Requests/Twint.php @@ -0,0 +1,24 @@ + { molliePaymentScreen.selectAuthorized(); + } else if (payment.key === 'twint') { + + molliePaymentScreen.selectAuthorized(); + } else if (payment.key === 'giftcard') { mollieGiftCardsScreen.selectBeautyCards(); diff --git a/Tests/PHPUnit/Components/Constants/PaymentMethodTypeTest.php b/Tests/PHPUnit/Components/Constants/PaymentMethodTypeTest.php index ebc0b832..f696d741 100644 --- a/Tests/PHPUnit/Components/Constants/PaymentMethodTypeTest.php +++ b/Tests/PHPUnit/Components/Constants/PaymentMethodTypeTest.php @@ -59,6 +59,7 @@ public function getPaymentMethods() [false, PaymentMethod::KLARNA_PAY_LATER], [false, PaymentMethod::KLARNA_PAY_NOW], [false, PaymentMethod::KLARNA_SLICE_IT], + [false, PaymentMethod::TWINT], [false, PaymentMethod::VOUCHERS], # ---------------------------------------------- [true, PaymentMethod::PAYPAL], diff --git a/Tests/PHPUnit/Services/Mollie/Payments/Requests/TwintTest.php b/Tests/PHPUnit/Services/Mollie/Payments/Requests/TwintTest.php new file mode 100644 index 00000000..b4f9c655 --- /dev/null +++ b/Tests/PHPUnit/Services/Mollie/Payments/Requests/TwintTest.php @@ -0,0 +1,136 @@ +payment = new Twint(); + + $this->addressInvoice = $this->getAddressFixture1(); + $this->addressShipping = $this->getAddressFixture2(); + $this->lineItem = $this->getLineItemFixture(); + + $this->payment->setPayment( + new Payment( + 'UUID-123', + 'Order UUID-123', + '20004', + $this->addressInvoice, + $this->addressShipping, + 49.98, + [$this->lineItem], + 'CHF', + 'de_DE', + 'https://local/redirect', + 'https://local/notify' + ) + ); + } + + /** + * This test verifies that the Payments-API request + * for our payment is correct. + * Please note, Twint does not work with the payments API + * so this is just an empty array + */ + public function testPaymentsAPI() + { + $expected = [ + 'method' => 'twint', + 'amount' => [ + 'currency' => 'CHF', + 'value' => '49.98', + ], + 'description' => 'Payment UUID-123', + 'redirectUrl' => 'https://local/redirect', + 'webhookUrl' => 'https://local/notify', + 'locale' => 'de_DE', + ]; + + $requestBody = $this->payment->buildBodyPaymentsAPI(); + + $this->assertEquals($expected, $requestBody); + } + + /** + * This test verifies that the Orders-API request + * for our payment is correct. + */ + public function testOrdersAPI() + { + $expected = [ + 'method' => 'twint', + 'amount' => [ + 'currency' => 'CHF', + 'value' => '49.98', + ], + 'redirectUrl' => 'https://local/redirect', + 'webhookUrl' => 'https://local/notify', + 'locale' => 'de_DE', + 'orderNumber' => '20004', + 'payment' => [ + 'webhookUrl' => 'https://local/notify', + ], + 'billingAddress' => $this->getExpectedAddressStructure($this->addressInvoice), + 'shippingAddress' => $this->getExpectedAddressStructure($this->addressShipping), + 'lines' => [ + $this->getExpectedLineItemStructure($this->lineItem), + ], + 'metadata' => [], + ]; + + $requestBody = $this->payment->buildBodyOrdersAPI(); + + $this->assertSame($expected, $requestBody); + } + + /** + * This test verifies that we can set a custom expiration date + * for our Orders API request. + */ + public function testExpirationDate() + { + $dueInDays = 5; + $expectedDueDate = date('Y-m-d', strtotime(' + ' . $dueInDays . ' day')); + + $this->payment->setExpirationDays($dueInDays); + $request = $this->payment->buildBodyOrdersAPI(); + + $this->assertEquals($expectedDueDate, $request['expiresAt']); + } +} diff --git a/plugin.xml b/plugin.xml index 4312ed13..a6a352a5 100644 --- a/plugin.xml +++ b/plugin.xml @@ -44,6 +44,14 @@ https://github.com/mollie/Shopware/wiki + + + - Neue Zahlungsmethode "Twint" ist nun verfügbar. + + + - New payment method "Twint" is now available. + +