diff --git a/src/Handler/Method/TwintPayment.php b/src/Handler/Method/TwintPayment.php new file mode 100644 index 000000000..51939c51b --- /dev/null +++ b/src/Handler/Method/TwintPayment.php @@ -0,0 +1,32 @@ + $orderData + * @param OrderEntity $orderEntity + * @param SalesChannelContext $salesChannelContext + * @param CustomerEntity $customer + * @return array + */ + public function processPaymentMethodSpecificParameters(array $orderData, OrderEntity $orderEntity, SalesChannelContext $salesChannelContext, CustomerEntity $customer): array + { + return $orderData; + } +} diff --git a/src/Resources/config/services/handlers.xml b/src/Resources/config/services/handlers.xml index fc21046ae..0cb06f79d 100644 --- a/src/Resources/config/services/handlers.xml +++ b/src/Resources/config/services/handlers.xml @@ -148,6 +148,13 @@ + + + + + + + diff --git a/src/Service/PaymentMethodService.php b/src/Service/PaymentMethodService.php index a511c923a..cd68ecc1a 100644 --- a/src/Service/PaymentMethodService.php +++ b/src/Service/PaymentMethodService.php @@ -23,6 +23,7 @@ use Kiener\MolliePayments\Handler\Method\PosPayment; use Kiener\MolliePayments\Handler\Method\Przelewy24Payment; use Kiener\MolliePayments\Handler\Method\SofortPayment; +use Kiener\MolliePayments\Handler\Method\TwintPayment; use Kiener\MolliePayments\Handler\Method\VoucherPayment; use Kiener\MolliePayments\MolliePayments; use Kiener\MolliePayments\Repository\Media\MediaRepository; @@ -44,7 +45,9 @@ class PaymentMethodService { - /** @var MediaService */ + /** + * @var MediaService + */ private $mediaService; /** @@ -52,7 +55,9 @@ class PaymentMethodService */ private $paymentRepository; - /** @var PluginIdProvider */ + /** + * @var PluginIdProvider + */ private $pluginIdProvider; /** @@ -60,7 +65,9 @@ class PaymentMethodService */ private $mediaRepository; - /** @var HttpClientInterface */ + /** + * @var HttpClientInterface + */ private $httpClient; @@ -267,11 +274,8 @@ public function disablePaymentMethod(string $handlerName, Context $context): voi * * @return EntityWrittenContainerEvent */ - public function setPaymentMethodActivated( - string $paymentMethodId, - bool $active, - Context $context - ): EntityWrittenContainerEvent { + public function setPaymentMethodActivated(string $paymentMethodId, bool $active, Context $context): EntityWrittenContainerEvent + { return $this->paymentRepository->upsert( [ [ @@ -385,6 +389,7 @@ public function getPaymentHandlers(): array VoucherPayment::class, In3Payment::class, PosPayment::class, + TwintPayment::class, // IngHomePayPayment::class, // not allowed anymore // DirectDebitPayment::class, // only allowed when updating subsriptions, aka => not allowed anymore ]; diff --git a/tests/PHPUnit/Service/MollieApi/Builder/Payments/TwintOrderBuilderTest.php b/tests/PHPUnit/Service/MollieApi/Builder/Payments/TwintOrderBuilderTest.php new file mode 100644 index 000000000..ed85d1c6a --- /dev/null +++ b/tests/PHPUnit/Service/MollieApi/Builder/Payments/TwintOrderBuilderTest.php @@ -0,0 +1,67 @@ +router->method('generate')->willReturn($redirectWebhookUrl); + $paymentMethod = TwintPayment::PAYMENT_METHOD_NAME; + + $this->paymentHandler = new KlarnaPayLaterPayment( + $this->loggerService, + new FakeContainer() + ); + + $transactionId = Uuid::randomHex(); + $amountTotal = 27.0; + $taxStatus = CartPrice::TAX_STATE_GROSS; + $currencyISO = 'EUR'; + + $currency = new CurrencyEntity(); + $currency->setId(Uuid::randomHex()); + $currency->setIsoCode($currencyISO); + + $orderNumber = 'foo number'; + $lineItems = $this->getDummyLineItems(); + + $order = $this->getOrderEntity($amountTotal, $taxStatus, $currencyISO, $lineItems, $orderNumber); + + $actual = $this->builder->buildOrderPayload($order, $transactionId, $paymentMethod, $this->salesChannelContext, $this->paymentHandler, []); + + $expectedOrderLifeTime = (new DateTime())->setTimezone(new DateTimeZone('UTC')) + ->modify(sprintf('+%d day', $this->expiresAt)) + ->format('Y-m-d'); + + $expected = [ + 'amount' => (new MollieOrderPriceBuilder())->build($amountTotal, $currencyISO), + 'locale' => $this->localeCode, + 'method' => $paymentMethod, + 'orderNumber' => $orderNumber, + 'payment' => ['webhookUrl' => $redirectWebhookUrl], + 'redirectUrl' => $redirectWebhookUrl, + 'webhookUrl' => $redirectWebhookUrl, + 'lines' => $this->getExpectedLineItems($taxStatus, $lineItems, $currency), + 'billingAddress' => $this->getExpectedTestAddress($this->address, $this->email), + 'shippingAddress' => $this->getExpectedTestAddress($this->address, $this->email), + 'expiresAt' => $expectedOrderLifeTime + ]; + + self::assertSame($expected, $actual); + } +} diff --git a/tests/PHPUnit/Service/PaymentMethodServiceTest.php b/tests/PHPUnit/Service/PaymentMethodServiceTest.php index 9e03666d5..ab4b30848 100644 --- a/tests/PHPUnit/Service/PaymentMethodServiceTest.php +++ b/tests/PHPUnit/Service/PaymentMethodServiceTest.php @@ -22,6 +22,7 @@ use Kiener\MolliePayments\Handler\Method\PosPayment; use Kiener\MolliePayments\Handler\Method\Przelewy24Payment; use Kiener\MolliePayments\Handler\Method\SofortPayment; +use Kiener\MolliePayments\Handler\Method\TwintPayment; use Kiener\MolliePayments\Handler\Method\VoucherPayment; use Kiener\MolliePayments\Repository\Media\MediaRepositoryInterface; use Kiener\MolliePayments\Repository\PaymentMethod\PaymentMethodRepositoryInterface; @@ -70,8 +71,7 @@ protected function setUp(): void $paymentMethod->setId('id-123'); $paymentMethod->setHandlerIdentifier('handler-id-123'); - $this->context = $this->createMock(Context::class); - ; + $this->context = $this->createMock(Context::class);; $this->mediaRepository = new FakeMediaRepository(new MediaDefinition()); $this->paymentMethodRepository = new FakePaymentMethodRepository($paymentMethod); @@ -113,6 +113,7 @@ public function testSupportedMethods(): void VoucherPayment::class, In3Payment::class, PosPayment::class, + TwintPayment::class, ]; $handlers = $this->paymentMethodService->getPaymentHandlers();