diff --git a/src/Payment/MollieOrder.php b/src/Payment/MollieOrder.php index dc9be0a8..b9618730 100644 --- a/src/Payment/MollieOrder.php +++ b/src/Payment/MollieOrder.php @@ -10,10 +10,14 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\Order; use Mollie\Api\Resources\Refund; -use Mollie\WooCommerce\Gateway\MolliePaymentGatewayHandler; +use Mollie\WooCommerce\Payment\Request\RequestFactory; use Mollie\WooCommerce\PaymentMethods\Voucher; use Mollie\WooCommerce\SDK\Api; +use Mollie\WooCommerce\Settings\Settings; +use Mollie\WooCommerce\Shared\Data; use Mollie\WooCommerce\Shared\SharedDataDictionary; +use Psr\Log\LoggerInterface as Logger; + use Psr\Log\LogLevel; use WC_Order; use WP_Error; @@ -47,13 +51,13 @@ class MollieOrder extends MollieObject public function __construct( OrderItemsRefunder $orderItemsRefunder, $data, - $pluginId, + string $pluginId, Api $apiHelper, - $settingsHelper, - $dataHelper, - $logger, + Settings $settingsHelper, + Data $dataHelper, + Logger $logger, OrderLines $orderLines, - $paymentMethod + RequestFactory $requestFactory ) { $this->data = $data; @@ -61,10 +65,10 @@ public function __construct( $this->pluginId = $pluginId; $this->apiHelper = $apiHelper; $this->settingsHelper = $settingsHelper; - $this->dataHelper = $dataHelper; $this->logger = $logger; + $this->requestFactory = $requestFactory; + $this->dataHelper = $dataHelper; $this->orderLines = $orderLines; - $this->paymentMethod = $paymentMethod; } public function getPaymentObject($paymentId, $testMode = false, $useCache = true) @@ -914,4 +918,9 @@ protected function processOrderItemsRefund( // drop item from array unset($items[$item->get_id()]); } + + public function setOrder( $data) + { + $this->data = $data; + } } diff --git a/src/Payment/MolliePayment.php b/src/Payment/MolliePayment.php index 22e22743..b5810b1e 100644 --- a/src/Payment/MolliePayment.php +++ b/src/Payment/MolliePayment.php @@ -6,17 +6,18 @@ use Inpsyde\PaymentGateway\PaymentGateway; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Resources\Order; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\Refund; -use Mollie\WooCommerce\Gateway\MolliePaymentGatewayHandler; -use Mollie\WooCommerce\Gateway\MolliePaymentGatewayI; +use Mollie\WooCommerce\Payment\Request\RequestFactory; use Mollie\WooCommerce\PaymentMethods\Voucher; use Mollie\WooCommerce\SDK\Api; +use Mollie\WooCommerce\Settings\Settings; +use Mollie\WooCommerce\Shared\Data; use Mollie\WooCommerce\Shared\SharedDataDictionary; +use Psr\Log\LoggerInterface as Logger; + use Psr\Log\LogLevel; use WC_Order; -use WC_Payment_Gateway; use WC_Subscriptions_Manager; use WP_Error; @@ -24,20 +25,25 @@ class MolliePayment extends MollieObject { public const ACTION_AFTER_REFUND_PAYMENT_CREATED = 'mollie-payments-for-woocommerce' . '_refund_payment_created'; protected $pluginId; - /** - * @var mixed - */ - private $paymentMethod; - public function __construct($data, $pluginId, Api $apiHelper, $settingsHelper, $dataHelper, $logger, $paymentMethod) + + public function __construct( + $data, + string $pluginId, + Api $apiHelper, + Settings $settingsHelper, + Data $dataHelper, + Logger $logger, + RequestFactory $requestFactory + ) { $this->data = $data; $this->pluginId = $pluginId; $this->apiHelper = $apiHelper; $this->settingsHelper = $settingsHelper; - $this->dataHelper = $dataHelper; $this->logger = $logger; - $this->paymentMethod = $paymentMethod; + $this->requestFactory = $requestFactory; + $this->dataHelper = $dataHelper; } public function getPaymentObject($paymentId, $testMode = false, $useCache = true) @@ -469,4 +475,9 @@ protected function maybeUpdateStatus( } $this->updateOrderStatus($order, $newOrderStatus); } + + public function setPayment( $data) + { + $this->data = $data; + } } diff --git a/src/Payment/PaymentFactory.php b/src/Payment/PaymentFactory.php index 97e5b308..2a88ab2f 100644 --- a/src/Payment/PaymentFactory.php +++ b/src/Payment/PaymentFactory.php @@ -12,36 +12,16 @@ class PaymentFactory { - /** - * @var Data - */ - protected $dataHelper; - /** - * @var Api - */ - protected $apiHelper; - protected $settingsHelper; - /** - * @var string - */ - protected $pluginId; - protected $logger; - /** - * @var OrderLines - */ - protected $orderLines; + private $mollieOrderFactory; + private $molliePaymentFactory; /** * PaymentFactory constructor. */ - public function __construct(Data $dataHelper, Api $apiHelper, Settings $settingsHelper, string $pluginId, $logger, OrderLines $orderLines) + public function __construct(callable $mollieOrderFactory, callable $molliePaymentFactory) { - $this->dataHelper = $dataHelper; - $this->apiHelper = $apiHelper; - $this->settingsHelper = $settingsHelper; - $this->pluginId = $pluginId; - $this->logger = $logger; - $this->orderLines = $orderLines; + $this->mollieOrderFactory = $mollieOrderFactory; + $this->molliePaymentFactory = $molliePaymentFactory; } /** @@ -49,7 +29,7 @@ public function __construct(Data $dataHelper, Api $apiHelper, Settings $settings * @return bool|MollieOrder|MolliePayment * @throws ApiException */ - public function getPaymentObject($data, $paymentMethod = null) + public function getPaymentObject($data) { if ( @@ -57,25 +37,9 @@ public function getPaymentObject($data, $paymentMethod = null) || (is_string($data) && strpos($data, 'ord_') !== false) || (is_object($data) && $data->resource === 'order') ) { - $refundLineItemsBuilder = new RefundLineItemsBuilder($this->dataHelper); - $apiKey = $this->settingsHelper->getApiKey(); - $orderItemsRefunded = new OrderItemsRefunder( - $refundLineItemsBuilder, - $this->dataHelper, - $this->apiHelper->getApiClient($apiKey)->orders - ); - - return new MollieOrder( - $orderItemsRefunded, - $data, - $this->pluginId, - $this->apiHelper, - $this->settingsHelper, - $this->dataHelper, - $this->logger, - $this->orderLines, - $paymentMethod - ); + $mollieOrder = ($this->mollieOrderFactory)(); + $mollieOrder->setOrder($data); + return $mollieOrder; } if ( @@ -83,15 +47,9 @@ public function getPaymentObject($data, $paymentMethod = null) || (!is_object($data) && strpos($data, 'tr_') !== false) || (is_object($data) && $data->resource === 'payment') ) { - return new MolliePayment( - $data, - $this->pluginId, - $this->apiHelper, - $this->settingsHelper, - $this->dataHelper, - $this->logger, - $paymentMethod - ); + $molliePayment = ($this->molliePaymentFactory)(); + $molliePayment->setPayment($data); + return $molliePayment; } return false; diff --git a/src/Payment/PaymentService.php b/src/Payment/PaymentService.php index 2464a2ca..98228509 100644 --- a/src/Payment/PaymentService.php +++ b/src/Payment/PaymentService.php @@ -459,8 +459,7 @@ protected function processAsMolliePayment( ) { $paymentObject = $this->paymentFactory->getPaymentObject( - self::PAYMENT_METHOD_TYPE_PAYMENT, - $paymentMethod + self::PAYMENT_METHOD_TYPE_PAYMENT ); $paymentRequestData = $paymentObject->getPaymentRequestData( $order, diff --git a/src/Payment/Request/Decorators/AddCustomRequestFieldsDecorator.php b/src/Payment/Request/Decorators/AddCustomRequestFieldsDecorator.php index 225e692c..437fe9b7 100644 --- a/src/Payment/Request/Decorators/AddCustomRequestFieldsDecorator.php +++ b/src/Payment/Request/Decorators/AddCustomRequestFieldsDecorator.php @@ -2,28 +2,29 @@ declare(strict_types=1); -namespace Mollie\WooCommerce\Payment\Decorator; +namespace Mollie\WooCommerce\Payment\Request\Decorators; -use Mollie\WooCommerce\Payment\Request\Decorators\RequestDecoratorInterface; -use Mollie\WooCommerce\PaymentMethods\PaymentMethodI; use Psr\Container\ContainerInterface; use WC_Order; class AddCustomRequestFieldsDecorator implements RequestDecoratorInterface { - private PaymentMethodI $paymentMethod; + private array $paymentMethods; private ContainerInterface $container; - public function __construct($paymentMethod, $container) + public function __construct($paymentMethods, $container) { - $this->paymentMethod = $paymentMethod; + $this->paymentMethods = $paymentMethods; $this->container = $container; } - public function decorate(array $requestData, WC_Order $order): array + public function decorate(array $requestData, WC_Order $order, $context = null): array { - if (property_exists($this->paymentMethod, 'paymentAPIfields')) { - $paymentAPIfields = $this->paymentMethod->paymentAPIfields; + $gateway = wc_get_payment_gateway_by_order($order); + $methodId = substr($gateway->id, strrpos($gateway->id, '_') + 1); + $paymentMethod = $this->paymentMethods[$methodId]; + if (property_exists($paymentMethod, 'paymentAPIfields')) { + $paymentAPIfields = $paymentMethod->paymentAPIfields; foreach ($paymentAPIfields as $field) { $decoratorClass = 'Mollie\\WooCommerce\\Payment\\Decorator\\' . $field; if (class_exists($decoratorClass)) { diff --git a/src/Payment/Request/Decorators/AddSequenceTypeForSubscriptionsDecorator.php b/src/Payment/Request/Decorators/AddSequenceTypeForSubscriptionsDecorator.php index 61227cd0..b2995e1b 100644 --- a/src/Payment/Request/Decorators/AddSequenceTypeForSubscriptionsDecorator.php +++ b/src/Payment/Request/Decorators/AddSequenceTypeForSubscriptionsDecorator.php @@ -2,9 +2,8 @@ declare(strict_types=1); -namespace Mollie\WooCommerce\Payment\Decorator; +namespace Mollie\WooCommerce\Payment\Request\Decorators; -use Mollie\WooCommerce\Payment\Request\Decorators\RequestDecoratorInterface; use Mollie\WooCommerce\Shared\Data; use WC_Order; @@ -19,7 +18,7 @@ public function __construct($dataHelper, $pluginId) $this->pluginId = $pluginId; } - public function decorate(array $requestData, WC_Order $order, $context): array + public function decorate(array $requestData, WC_Order $order, $context = null): array { $gateway = wc_get_payment_gateway_by_order($order); if ($gateway) { diff --git a/src/Payment/Request/Decorators/AddressDecorator.php b/src/Payment/Request/Decorators/AddressDecorator.php index 94f578e3..15e92d68 100644 --- a/src/Payment/Request/Decorators/AddressDecorator.php +++ b/src/Payment/Request/Decorators/AddressDecorator.php @@ -2,14 +2,13 @@ declare(strict_types=1); -namespace Mollie\WooCommerce\Payment\Decorator; +namespace Mollie\WooCommerce\Payment\Request\Decorators; -use Mollie\WooCommerce\Payment\Request\Decorators\RequestDecoratorInterface; use WC_Order; class AddressDecorator implements RequestDecoratorInterface { - public function decorate(array $requestData, WC_Order $order): array + public function decorate(array $requestData, WC_Order $order, $context = null): array { $isPayPalExpressOrder = $order->get_meta('_mollie_payment_method_button') === 'PayPalButton'; $billingAddress = null; diff --git a/src/Payment/Request/Decorators/ApplePaytokenDecorator.php b/src/Payment/Request/Decorators/ApplePaytokenDecorator.php index 4a4c4586..6a7eb6b2 100644 --- a/src/Payment/Request/Decorators/ApplePaytokenDecorator.php +++ b/src/Payment/Request/Decorators/ApplePaytokenDecorator.php @@ -2,14 +2,13 @@ declare(strict_types=1); -namespace Mollie\WooCommerce\Payment\Decorator; +namespace Mollie\WooCommerce\Payment\Request\Decorators; -use Mollie\WooCommerce\Payment\Request\Decorators\RequestDecoratorInterface; use WC_Order; class ApplePayTokenDecorator implements RequestDecoratorInterface { - public function decorate(array $requestData, WC_Order $order, $context): array + public function decorate(array $requestData, WC_Order $order, $context = null): array { // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $applePayToken = wc_clean(wp_unslash($_POST["token"] ?? '')); diff --git a/src/Payment/Request/Decorators/CardTokenDecorator.php b/src/Payment/Request/Decorators/CardTokenDecorator.php index 12163d89..9fb02b1f 100644 --- a/src/Payment/Request/Decorators/CardTokenDecorator.php +++ b/src/Payment/Request/Decorators/CardTokenDecorator.php @@ -2,14 +2,13 @@ declare(strict_types=1); -namespace Mollie\WooCommerce\Payment\Decorator; +namespace Mollie\WooCommerce\Payment\Request\Decorators; -use Mollie\WooCommerce\Payment\Request\Decorators\RequestDecoratorInterface; use WC_Order; class CardTokenDecorator implements RequestDecoratorInterface { - public function decorate(array $requestData, WC_Order $order, $context): array + public function decorate(array $requestData, WC_Order $order, $context = null): array { $cardToken = mollieWooCommerceCardToken(); if ($cardToken && isset($requestData['payment']) && $context === 'order') { diff --git a/src/Payment/Request/Decorators/CustomerBirthdateDecorator.php b/src/Payment/Request/Decorators/CustomerBirthdateDecorator.php index ae27cfc9..9dda9048 100644 --- a/src/Payment/Request/Decorators/CustomerBirthdateDecorator.php +++ b/src/Payment/Request/Decorators/CustomerBirthdateDecorator.php @@ -14,7 +14,7 @@ public function __construct(array $paymentMethods) $this->paymentMethods = $paymentMethods; } - public function decorate(array $requestData, WC_Order $order): array + public function decorate(array $requestData, WC_Order $order, $context = null): array { $gateway = wc_get_payment_gateway_by_order($order); if (!$gateway || !isset($gateway->id)) { diff --git a/src/Payment/Request/Decorators/OrderLinesDecorator.php b/src/Payment/Request/Decorators/OrderLinesDecorator.php index 7c1ff689..6c419519 100644 --- a/src/Payment/Request/Decorators/OrderLinesDecorator.php +++ b/src/Payment/Request/Decorators/OrderLinesDecorator.php @@ -2,10 +2,9 @@ declare(strict_types=1); -namespace Mollie\WooCommerce\Payment\Decorator; +namespace Mollie\WooCommerce\Payment\Request\Decorators; use Mollie\WooCommerce\Payment\OrderLines; -use Mollie\WooCommerce\Payment\Request\Decorators\RequestDecoratorInterface; use WC_Order; class OrderLinesDecorator implements RequestDecoratorInterface @@ -19,7 +18,7 @@ public function __construct($orderLines, $voucherDefaultCategory) $this->voucherDefaultCategory = $voucherDefaultCategory; } - public function decorate(array $requestData, WC_Order $order): array + public function decorate(array $requestData, WC_Order $order, $context = null): array { $orderLines = $this->orderLines->order_lines($order, $this->voucherDefaultCategory); $requestData['lines'] = $orderLines['lines']; diff --git a/src/Payment/Request/Decorators/PaymentDescriptionDecorator.php b/src/Payment/Request/Decorators/PaymentDescriptionDecorator.php index fc5a8e14..2292fa61 100644 --- a/src/Payment/Request/Decorators/PaymentDescriptionDecorator.php +++ b/src/Payment/Request/Decorators/PaymentDescriptionDecorator.php @@ -2,9 +2,8 @@ declare(strict_types=1); -namespace Mollie\WooCommerce\Payment\Decorator; +namespace Mollie\WooCommerce\Payment\Request\Decorators; -use Mollie\WooCommerce\Payment\Request\Decorators\RequestDecoratorInterface; use WC_Order; class PaymentDescriptionDecorator implements RequestDecoratorInterface diff --git a/src/Payment/Request/Decorators/SelectedIssuerDecorator.php b/src/Payment/Request/Decorators/SelectedIssuerDecorator.php index d8029785..d208b27a 100644 --- a/src/Payment/Request/Decorators/SelectedIssuerDecorator.php +++ b/src/Payment/Request/Decorators/SelectedIssuerDecorator.php @@ -2,9 +2,8 @@ declare(strict_types=1); -namespace Mollie\WooCommerce\Payment\Decorator; +namespace Mollie\WooCommerce\Payment\Request\Decorators; -use Mollie\WooCommerce\Payment\Request\Decorators\RequestDecoratorInterface; use WC_Order; class SelectedIssuerDecorator implements RequestDecoratorInterface @@ -16,14 +15,24 @@ public function __construct($pluginId) $this->pluginId = $pluginId; } - public function decorate(array $requestData, WC_Order $order): array + public function decorate(array $requestData, WC_Order $order, $context = null): array { $gateway = wc_get_payment_gateway_by_order($order); - if ($gateway) { - $gatewayId = $gateway->id; - $selectedIssuer = $this->getSelectedIssuer($gatewayId); + if(!$gateway) { + return $requestData; + } + + $gatewayId = $gateway->id; + $selectedIssuer = $this->getSelectedIssuer($gatewayId); + if(empty($selectedIssuer)) { + return $requestData; + } + if($context === 'order') { $requestData['payment']['issuer'] = $selectedIssuer; + } elseif ($context === 'payment') { + $requestData['issuer'] = $selectedIssuer; } + return $requestData; } diff --git a/src/Payment/Request/Decorators/StoreCustomerDecorator.php b/src/Payment/Request/Decorators/StoreCustomerDecorator.php index 77a1b1d2..d9cd56e4 100644 --- a/src/Payment/Request/Decorators/StoreCustomerDecorator.php +++ b/src/Payment/Request/Decorators/StoreCustomerDecorator.php @@ -2,9 +2,8 @@ declare(strict_types=1); -namespace Mollie\WooCommerce\Payment\Decorator; +namespace Mollie\WooCommerce\Payment\Request\Decorators; -use Mollie\WooCommerce\Payment\Request\Decorators\RequestDecoratorInterface; use Mollie\WooCommerce\Settings\Settings; use WC_Order; @@ -17,7 +16,7 @@ public function __construct(Settings $settingsHelper) } - public function decorate(array $requestData, WC_Order $order, $context): array + public function decorate(array $requestData, WC_Order $order, $context = null): array { $storeCustomer = $this->settingsHelper->shouldStoreCustomer(); $customerId = $order->get_meta('_mollie_customer_id'); diff --git a/src/Payment/Request/Decorators/UrlDecorator.php b/src/Payment/Request/Decorators/UrlDecorator.php index c5a0bc54..056d6f90 100644 --- a/src/Payment/Request/Decorators/UrlDecorator.php +++ b/src/Payment/Request/Decorators/UrlDecorator.php @@ -2,21 +2,25 @@ declare(strict_types=1); -namespace Mollie\WooCommerce\Payment\Decorator; +namespace Mollie\WooCommerce\Payment\Request\Decorators; -use Mollie\WooCommerce\Payment\Request\Decorators\RequestDecoratorInterface; use WC_Order; class UrlDecorator implements RequestDecoratorInterface { private $pluginId; + /** + * @var mixed + */ + private $logger; - public function __construct($pluginId) + public function __construct($pluginId, $logger) { $this->pluginId = $pluginId; + $this->logger = $logger; } - public function decorate(array $requestData, WC_Order $order): array + public function decorate(array $requestData, WC_Order $order, $context = null): array { $gateway = wc_get_payment_gateway_by_order($order); if ($gateway) { diff --git a/src/Payment/Request/RequestFactory.php b/src/Payment/Request/RequestFactory.php index 37ea4f55..3a8316c6 100644 --- a/src/Payment/Request/RequestFactory.php +++ b/src/Payment/Request/RequestFactory.php @@ -2,8 +2,8 @@ namespace Mollie\WooCommerce\Payment\Request; +use Mollie\WooCommerce\Payment\Request\Strategies\RequestStrategyInterface; use Psr\Container\ContainerInterface; -use Mollie\WooCommerce\Payment\Request\RequestStrategyInterface; use WC_Order; class RequestFactory { @@ -23,7 +23,8 @@ public function __construct(ContainerInterface $container) { */ public function createRequest(string $type, WC_Order $order, string $customerId): array { // Use the container to fetch the appropriate strategy. - $strategy = $this->container->get("request.strategy.{$type}"); + $serviceName = "request.strategy.{$type}"; + $strategy = $this->container->get($serviceName); if (!$strategy instanceof RequestStrategyInterface) { throw new \InvalidArgumentException("Invalid strategy for type: {$type}"); diff --git a/src/Payment/Request/Strategies/OrderRequestStrategy.php b/src/Payment/Request/Strategies/OrderRequestStrategy.php index 7d7619ea..274e7b49 100644 --- a/src/Payment/Request/Strategies/OrderRequestStrategy.php +++ b/src/Payment/Request/Strategies/OrderRequestStrategy.php @@ -1,6 +1,6 @@ id, strrpos($gateway->id, '_') + 1); $paymentLocale = $settingsHelper->getPaymentLocale(); - $paymentRequestData = [ + $requestData = [ 'amount' => [ 'currency' => $this->dataHelper ->getOrderCurrency($order), @@ -41,7 +41,6 @@ public function createRequest(WC_Order $order, string $customerId): array ) ), ], - 'description' => $paymentDescription, 'method' => $methodId, 'locale' => $paymentLocale, 'metadata' => apply_filters( @@ -52,7 +51,6 @@ public function createRequest(WC_Order $order, string $customerId): array ), ]; - $paymentRequestData = $this->addCustomRequestFields($order, $paymentRequestData); $context = 'payment'; foreach ($this->decorators as $decorator) { $requestData = $decorator->decorate($requestData, $order, $context); diff --git a/src/Payment/Request/Strategies/RequestStrategyInterface.php b/src/Payment/Request/Strategies/RequestStrategyInterface.php index 0f95ea8d..f3e9f0c9 100644 --- a/src/Payment/Request/Strategies/RequestStrategyInterface.php +++ b/src/Payment/Request/Strategies/RequestStrategyInterface.php @@ -1,6 +1,6 @@ static function (ContainerInterface $container): OrderLines { + MollieObject::class => static function (ContainerInterface $container): MollieObject { + $logger = $container->get(Logger::class); + assert($logger instanceof Logger); $data = $container->get('settings.data_helper'); + assert($data instanceof Data); + $apiHelper = $container->get('SDK.api_helper'); + assert($apiHelper instanceof Api); $pluginId = $container->get('shared.plugin_id'); - return new OrderLines($data, $pluginId); - }, - PaymentFactory::class => static function (ContainerInterface $container): PaymentFactory { + $paymentFactory = $container->get(PaymentFactory::class); + //assert($paymentFactory instanceof PaymentFactory); $settingsHelper = $container->get('settings.settings_helper'); assert($settingsHelper instanceof Settings); - $apiHelper = $container->get('SDK.api_helper'); - assert($apiHelper instanceof Api); + $requestFactory = $container->get(RequestFactory::class); + return new MollieObject($data, $logger, $paymentFactory, $apiHelper, $settingsHelper, $pluginId, $requestFactory); + }, + OrderLines::class => static function (ContainerInterface $container): OrderLines { $data = $container->get('settings.data_helper'); - assert($data instanceof Data); $pluginId = $container->get('shared.plugin_id'); - $logger = $container->get(Logger::class); - assert($logger instanceof Logger); - $orderLines = $container->get(OrderLines::class); - return new PaymentFactory($data, $apiHelper, $settingsHelper, $pluginId, $logger, $orderLines); + return new OrderLines($data, $pluginId); + }, + PaymentFactory::class => static function (ContainerInterface $container): PaymentFactory { + return new PaymentFactory( + function () use ($container) { + return new MollieOrder( + $container->get(OrderItemsRefunder::class), + 'order', + $container->get('shared.plugin_id'), + $container->get('SDK.api_helper'), + $container->get('settings.settings_helper'), + $container->get('settings.data_helper'), + $container->get(Logger::class), + $container->get(OrderLines::class), + $container->get(RequestFactory::class) + ); + }, + function () use ($container) { + return new MolliePayment( + 'payment', + $container->get('shared.plugin_id'), + $container->get('SDK.api_helper'), + $container->get('settings.settings_helper'), + $container->get('settings.data_helper'), + $container->get(Logger::class), + $container->get(RequestFactory::class) + ); + } + ); }, RequestFactory::class => static function (ContainerInterface $container): RequestFactory { return new RequestFactory($container); }, CustomerBirthdateDecorator::class => static function (ContainerInterface $container): CustomerBirthdateDecorator { - return new CustomerBirthdateDecorator($container->get('payment_methods')); + return new CustomerBirthdateDecorator($container->get('gateway.paymentMethods')); }, ApplePayTokenDecorator::class => static function (): ApplePayTokenDecorator { return new ApplePayTokenDecorator(); @@ -76,8 +110,10 @@ return new AddressDecorator(); }, UrlDecorator::class => static function (ContainerInterface $container): UrlDecorator { - $pluginId = $container->get('shared.plugin_id'); - return new UrlDecorator($pluginId); + return new UrlDecorator( + $container->get('shared.plugin_id'), + $container->get(Logger::class), + ); }, SelectedIssuerDecorator::class => static function (ContainerInterface $container): SelectedIssuerDecorator { $pluginId = $container->get('shared.plugin_id'); @@ -88,8 +124,8 @@ return new PaymentDescriptionDecorator($dataHelper); }, AddCustomRequestFieldsDecorator::class => static function (ContainerInterface $container): AddCustomRequestFieldsDecorator { - $paymentMethod = $container->get('payment.method'); - return new AddCustomRequestFieldsDecorator($paymentMethod, $container); + $paymentMethods = $container->get('gateway.paymentMethods'); + return new AddCustomRequestFieldsDecorator($paymentMethods, $container); }, 'request.strategy.order' => static function (ContainerInterface $container): RequestStrategyInterface { $dataHelper = $container->get('settings.data_helper'); @@ -113,32 +149,29 @@ 'request.strategy.payment' => static function (ContainerInterface $container): RequestStrategyInterface { $dataHelper = $container->get('settings.data_helper'); $settingsHelper = $container->get('settings.settings_helper'); - $decorators = [ - $container->get(SelectedIssuerDecorator::class), - $container->get(UrlDecorator::class), - $container->get(AddSequenceTypeForSubscriptionsDecorator::class), - $container->get(ApplePayTokenDecorator::class), - $container->get(CardTokenDecorator::class), - $container->get(StoreCustomerDecorator::class), - $container->get(PaymentDescriptionDecorator::class), - $container->get(AddCustomRequestFieldsDecorator::class), - ]; - return new PaymentRequestStrategy($dataHelper, $settingsHelper, $decorators); - }, - MollieObject::class => static function (ContainerInterface $container): MollieObject { - $logger = $container->get(Logger::class); - assert($logger instanceof Logger); - $data = $container->get('settings.data_helper'); - assert($data instanceof Data); - $apiHelper = $container->get('SDK.api_helper'); - assert($apiHelper instanceof Api); - $pluginId = $container->get('shared.plugin_id'); - $paymentFactory = $container->get(PaymentFactory::class); - assert($paymentFactory instanceof PaymentFactory); - $settingsHelper = $container->get('settings.settings_helper'); - assert($settingsHelper instanceof Settings); - $requestFactory = $container->get(RequestFactory::class); - return new MollieObject($data, $logger, $paymentFactory, $apiHelper, $settingsHelper, $pluginId, $requestFactory); + $issuer = $container->get(SelectedIssuerDecorator::class); + $url = $container->get(UrlDecorator::class); + $sequenceType = $container->get(AddSequenceTypeForSubscriptionsDecorator::class); + $cardToken = $container->get(CardTokenDecorator::class); + $applePayToken = $container->get(ApplePayTokenDecorator::class); + $storeCustomer = $container->get(StoreCustomerDecorator::class); + $paymentDescription = $container->get(PaymentDescriptionDecorator::class); + $addCustomRequestFields = $container->get(AddCustomRequestFieldsDecorator::class); + + return new PaymentRequestStrategy( + $dataHelper, + $settingsHelper, + [ + $issuer, + $url, + $sequenceType, + $cardToken, + $applePayToken, + $storeCustomer, + $paymentDescription, + $addCustomRequestFields, + ] + ); }, ]; };