From 31e7c62550ec744091d05019f0fdc7e632f7162b Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Fri, 27 Dec 2024 16:14:16 +0100 Subject: [PATCH] Fix cs --- inc/utils.php | 6 +- .../ApplePayButton/ResponsesToApple.php | 1 - .../PayPalButton/PayPalAjaxRequests.php | 3 +- src/Gateway/DeprecatedGatewayBuilder.php | 1 - src/Gateway/GatewayModule.php | 23 ++++---- src/Gateway/MolliePaymentGatewayHandler.php | 55 ++----------------- src/Gateway/Refund/RefundProcessor.php | 10 ++-- src/Gateway/inc/services.php | 12 ++-- src/Payment/MollieObject.php | 7 +-- src/Payment/MollieOrder.php | 18 ++++-- src/Payment/MollieOrderService.php | 3 +- src/Payment/MolliePayment.php | 9 +-- src/Payment/PaymentModule.php | 2 - src/Payment/PaymentProcessor.php | 16 ++---- ...dSequenceTypeForSubscriptionsDecorator.php | 4 +- ...corator.php => ApplePayTokenDecorator.php} | 2 +- .../Request/Decorators/CardTokenDecorator.php | 2 +- .../Decorators/RequestDecoratorInterface.php | 2 +- .../Decorators/SelectedIssuerDecorator.php | 6 +- .../Decorators/StoreCustomerDecorator.php | 5 +- src/Payment/Request/RequestFactory.php | 10 +++- .../Strategies/OrderRequestStrategy.php | 5 +- .../Strategies/PaymentRequestStrategy.php | 4 +- .../Strategies/RequestStrategyInterface.php | 3 +- src/Payment/inc/services.php | 1 - .../BancomatpayFieldsStrategy.php | 10 ++-- .../BillieFieldsStrategy.php | 11 ++-- .../CreditcardFieldsStrategy.php | 12 ++-- .../In3FieldsStrategy.php | 10 ++-- .../NoopPaymentFieldsRenderer.php | 3 +- .../PaymentFieldsStrategiesTrait.php | 14 ++--- .../General/MultiCountrySettingsField.php | 2 +- src/Settings/Page/Section/Advanced.php | 2 +- .../MollieSepaRecurringGatewayHandler.php | 26 +++------ .../MollieSubscriptionGatewayHandler.php | 38 +++++++++---- 35 files changed, 145 insertions(+), 193 deletions(-) rename src/Payment/Request/Decorators/{ApplePaytokenDecorator.php => ApplePayTokenDecorator.php} (95%) diff --git a/inc/utils.php b/inc/utils.php index c852be50..b5a544b3 100644 --- a/inc/utils.php +++ b/inc/utils.php @@ -165,8 +165,10 @@ function mollieWooCommerceIsVoucherEnabled() */ function mollieWooCommerceIsMollieGateway($gateway) { - if ((is_string($gateway) && strpos($gateway, 'mollie_wc_gateway_') !== false) - || (is_object($gateway) && strpos($gateway->id, 'mollie_wc_gateway_') !== false)) { + if ( + (is_string($gateway) && strpos($gateway, 'mollie_wc_gateway_') !== false) + || (is_object($gateway) && strpos($gateway->id, 'mollie_wc_gateway_') !== false) + ) { return true; } return false; diff --git a/src/Buttons/ApplePayButton/ResponsesToApple.php b/src/Buttons/ApplePayButton/ResponsesToApple.php index 9945729c..d09608e5 100644 --- a/src/Buttons/ApplePayButton/ResponsesToApple.php +++ b/src/Buttons/ApplePayButton/ResponsesToApple.php @@ -126,7 +126,6 @@ private function reorderShippingMethods(array $methods, array $selectedShippingM return array_merge($reordered_methods, array_values($methods)); } - /** * Returns a success response to be handled by the script */ diff --git a/src/Buttons/PayPalButton/PayPalAjaxRequests.php b/src/Buttons/PayPalButton/PayPalAjaxRequests.php index 30e65bc3..f6cea621 100644 --- a/src/Buttons/PayPalButton/PayPalAjaxRequests.php +++ b/src/Buttons/PayPalButton/PayPalAjaxRequests.php @@ -4,6 +4,7 @@ namespace Mollie\WooCommerce\Buttons\PayPalButton; +use Inpsyde\PaymentGateway\PaymentGateway; use Mollie\WooCommerce\Gateway\Surcharge; use Mollie\WooCommerce\Notice\NoticeInterface; use Mollie\WooCommerce\Shared\GatewaySurchargeHandler; @@ -31,7 +32,7 @@ class PayPalAjaxRequests * * @param $gateway */ - public function __construct($gateway, NoticeInterface $notice, Logger $logger) + public function __construct(PaymentGateway $gateway, NoticeInterface $notice, Logger $logger) { $this->gateway = $gateway; $this->notice = $notice; diff --git a/src/Gateway/DeprecatedGatewayBuilder.php b/src/Gateway/DeprecatedGatewayBuilder.php index 31e8fbe6..8db665d7 100644 --- a/src/Gateway/DeprecatedGatewayBuilder.php +++ b/src/Gateway/DeprecatedGatewayBuilder.php @@ -109,5 +109,4 @@ public function instantiatePaymentMethodGateways(ContainerInterface $container): } return $gateways; } - } diff --git a/src/Gateway/GatewayModule.php b/src/Gateway/GatewayModule.php index f6ec22cb..98e77378 100644 --- a/src/Gateway/GatewayModule.php +++ b/src/Gateway/GatewayModule.php @@ -75,18 +75,17 @@ public function run(ContainerInterface $container): bool static function ($gateways) use ($container) { $deprecatedGatewayHelpers = $container->get('__deprecated.gateway_helpers'); foreach ($gateways as $gateway) { + $isMolliegateway = is_string($gateway) && strpos($gateway, 'mollie_wc_gateway_') !== false + || is_object($gateway) && strpos($gateway->id, 'mollie_wc_gateway_') !== false; + if (!$isMolliegateway) { + continue; + } - $isMolliegateway = is_string($gateway) && strpos($gateway, 'mollie_wc_gateway_') !== false - || is_object($gateway) && strpos($gateway->id, 'mollie_wc_gateway_') !== false; - if (!$isMolliegateway) { - continue; - } - - $isSubscriptiongateway = $gateway->supports('subscriptions'); - if ($isSubscriptiongateway) { - $deprecatedGatewayHelpers[$gateway->id]->addSubscriptionFilters($gateway); - } - } + $isSubscriptiongateway = $gateway->supports('subscriptions'); + if ($isSubscriptiongateway) { + $deprecatedGatewayHelpers[$gateway->id]->addSubscriptionFilters($gateway); + } + } return $gateways; }, 30 @@ -149,7 +148,6 @@ static function () { // Set order to paid and processed when eventually completed without Mollie add_action('woocommerce_payment_complete', [$this, 'setOrderPaidByOtherGateway'], 10, 1); - $surchargeService = $container->get(Surcharge::class); assert($surchargeService instanceof Surcharge); $this->gatewaySurchargeHandling($surchargeService); @@ -194,7 +192,6 @@ public function services(): array static $services; if ($services === null) { - $services = require_once __DIR__ . '/inc/services.php'; } diff --git a/src/Gateway/MolliePaymentGatewayHandler.php b/src/Gateway/MolliePaymentGatewayHandler.php index 4d3c1084..83d57b0a 100644 --- a/src/Gateway/MolliePaymentGatewayHandler.php +++ b/src/Gateway/MolliePaymentGatewayHandler.php @@ -30,9 +30,9 @@ class MolliePaymentGatewayHandler /** * Recurring total, zero does not define a recurring total * - * @var int + * @var array */ - protected $recurring_totals = 0; + protected $recurring_totals = []; /** * @var PaymentMethodI */ @@ -82,6 +82,9 @@ class MolliePaymentGatewayHandler */ protected $pluginId; + protected string $enabled; + protected string $id; + /** * */ @@ -114,7 +117,6 @@ public function __construct( // Use gateway class name as gateway id $this->gatewayId(); - if (!has_action('woocommerce_thankyou_' . $this->id)) { add_action( 'woocommerce_thankyou_' . $this->id, @@ -140,8 +142,6 @@ public function __construct( [$this->mollieOrderService, 'onWebhookAction'] ); - - // Adjust title and text on Order Received page in some cases, see issue #166 add_filter('the_title', [$this, 'onOrderReceivedTitle'], 10, 2); add_filter( @@ -151,13 +151,12 @@ public function __construct( 2 ); - $isEnabledAtWoo = $this->paymentMethod->getProperty('enabled') ? $this->paymentMethod->getProperty('enabled') : 'yes'; $this->enabled = $isEnabledAtWoo; - if ($this->enabled && $this->paymentMethod->getProperty('filtersOnBuild')) { + if ($this->enabled === 'yes' && $this->paymentMethod->getProperty('filtersOnBuild')) { $this->paymentMethod->filtersOnBuild(); } //$this->refundProcessor = new RefundProcessor($this); @@ -183,7 +182,6 @@ public function pluginId() return $this->pluginId; } - protected function gatewayId() { $paymentMethodId = $this->paymentMethod->getProperty('id'); @@ -191,7 +189,6 @@ protected function gatewayId() return $this->id; } - /** * Check if the gateway is available for use * @@ -283,23 +280,6 @@ public function get_recurring_total() return $this->recurring_totals; } - /** - * @param int $orderId - * - * @return array - */ - public function process_payment($orderId) - { - $order = wc_get_order($orderId); - if (!$order) { - return $this->noOrderPaymentFailure($orderId); - } - $paymentMethod = $this->paymentMethod; - $redirectUrl = $this->get_return_url($order); - $this->paymentProcessor->setGateway($this); - return $this->paymentProcessor->processPayment($orderId, $order, $paymentMethod, $redirectUrl); - } - /** * @param $order * @param $payment @@ -409,30 +389,7 @@ public function getReturnRedirectUrlForOrder(WC_Order $order): string */ return $returnRedirect; } - /** - * @param $orderId - * @return string[] - */ - protected function noOrderPaymentFailure($orderId): array - { - $this->logger->debug( - $this->id . ': Could not process payment, order ' . $orderId . ' not found.' - ); - - $this->notice->addNotice( - 'error', - sprintf( - /* translators: Placeholder 1: order id. */ - __( - 'Could not load order %s', - 'mollie-payments-for-woocommerce' - ), - $orderId - ) - ); - return ['result' => 'failure']; - } /** * Retrieve the payment object * diff --git a/src/Gateway/Refund/RefundProcessor.php b/src/Gateway/Refund/RefundProcessor.php index 540db0a0..1d16e22b 100644 --- a/src/Gateway/Refund/RefundProcessor.php +++ b/src/Gateway/Refund/RefundProcessor.php @@ -11,7 +11,7 @@ class RefundProcessor implements RefundProcessorInterface { private $deprecatedGatewayHelper; - public function __construct( $deprecatedGatewayHelper) + public function __construct($deprecatedGatewayHelper) { $this->deprecatedGatewayHelper = $deprecatedGatewayHelper; } @@ -44,10 +44,10 @@ public function refundOrderPayment(WC_Order $wcOrder, $amount = null, $reason = // Mollie Payment object not found if (!$payment_object_id) { - $error_message = __("Can\'t process refund. Could not find Mollie Payment object id for order $order_id.", 'mollie-payments-for-woocommerce'); + $error_message = __("Can\'t process refund. Could not find Mollie Payment object id for order %s.", 'mollie-payments-for-woocommerce'); $this->deprecatedGatewayHelper->getLogger()->debug( - __METHOD__ . ' - ' . $error_message + __METHOD__ . ' - ' . sprintf($error_message, $order_id) ); throw new Exception($error_message); @@ -66,9 +66,9 @@ public function refundOrderPayment(WC_Order $wcOrder, $amount = null, $reason = } if (!$payment_object || !is_object($payment_object)) { - $error_message = __("Can\'t process refund. Could not find Mollie Payment object data for order $order_id.", 'mollie-payments-for-woocommerce'); + $error_message = __("Can\'t process refund. Could not find Mollie Payment object data for order %s.", 'mollie-payments-for-woocommerce'); $this->deprecatedGatewayHelper->getLogger()->debug( - __METHOD__ . ' - ' . $error_message + __METHOD__ . ' - ' . sprintf($error_message, $order_id) ); throw new Exception($error_message); diff --git a/src/Gateway/inc/services.php b/src/Gateway/inc/services.php index af92029f..8e95d09c 100644 --- a/src/Gateway/inc/services.php +++ b/src/Gateway/inc/services.php @@ -213,9 +213,8 @@ assert($notice instanceof AdminNotice); $logger = $container->get(Logger::class); assert($logger instanceof Logger); - $paypalGateway = isset($container->get('__deprecated.gateway_helpers')['mollie_wc_gateway_paypal']) ? $container->get( - '__deprecated.gateway_helpers' - )['mollie_wc_gateway_paypal'] : false; + $paymentGateways = $container->get('payment_gateways'); + $paypalGateway = $paymentGateways['mollie_wc_gateway_paypal']; $pluginUrl = $container->get('shared.plugin_url'); $ajaxRequests = new PayPalAjaxRequests($paypalGateway, $notice, $logger); $data = new DataToPayPal($pluginUrl); @@ -283,7 +282,6 @@ ]; $paymentMethods = SharedDataDictionary::GATEWAY_CLASSNAMES; - $dynamicServices = []; foreach ($paymentMethods as $paymentMethod) { $gatewayId = strtolower($paymentMethod); @@ -298,8 +296,7 @@ $paymentProcessor->setGateway($deprecatedGatewayHelper); return $paymentProcessor; }; - $dynamicServices["payment_gateway.$gatewayId.refund_processor"] = static function (ContainerInterface $container - ) use ($gatewayId): RefundProcessorInterface { + $dynamicServices["payment_gateway.$gatewayId.refund_processor"] = static function (ContainerInterface $container) use ($gatewayId): RefundProcessorInterface { $getProperty = $container->get('gateway.getMethodPropertyByGatewayId'); $supports = $getProperty($gatewayId, 'supports'); $supportsRefunds = $supports && in_array('refunds', $supports, true); @@ -370,7 +367,7 @@ }; $dynamicServices["payment_gateway.$gatewayId.availability_callback"] = new Factory( ['__deprecated.gateway_helpers'], - static function (array $gatewayInstances) use($gatewayId): callable { + static function (array $gatewayInstances) use ($gatewayId): callable { return static function ($gateway) use ($gatewayInstances, $gatewayId): bool { return $gatewayInstances[$gatewayId]->is_available($gateway); }; @@ -397,7 +394,6 @@ static function (array $gatewayInstances) use($gatewayId): callable { $supports = array_merge($supports, $subscriptionHooks); } return $supports; - }; $dynamicServices["payment_gateway.$gatewayId.settings_field_renderer.multi_select_countries"] = static function (ContainerInterface $container) use ($gatewayId) { $paymentMethods = $container->get('gateway.paymentMethods'); diff --git a/src/Payment/MollieObject.php b/src/Payment/MollieObject.php index db86cd62..7d40e199 100644 --- a/src/Payment/MollieObject.php +++ b/src/Payment/MollieObject.php @@ -62,8 +62,8 @@ public function __construct( Settings $settingsHelper, string $pluginId, RequestFactory $requestFactory - ) - { + ) { + $this->data = $data; $this->logger = $logger; $this->paymentFactory = $paymentFactory; @@ -414,8 +414,7 @@ public function getActiveMolliePayment($order_id, $use_cache = true) try { $mollie_order = $this->paymentFactory->getPaymentObject( - $mollie_order, - $this->paymentMethod + $mollie_order ); } catch (ApiException $exception) { $this->logger->debug($exception->getMessage()); diff --git a/src/Payment/MollieOrder.php b/src/Payment/MollieOrder.php index a8b26d73..de914145 100644 --- a/src/Payment/MollieOrder.php +++ b/src/Payment/MollieOrder.php @@ -19,7 +19,6 @@ 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; @@ -60,8 +59,8 @@ public function __construct( Logger $logger, OrderLines $orderLines, RequestFactory $requestFactory - ) - { + ) { + $this->data = $data; $this->orderItemsRefunder = $orderItemsRefunder; $this->pluginId = $pluginId; @@ -99,7 +98,6 @@ public function getPaymentRequestData($order, $customerId, $voucherDefaultCatego return $this->requestFactory->createRequest('order', $order, $customerId); } - public function setActiveMolliePayment($orderId) { self::$paymentId = $this->getMolliePaymentIdFromPaymentObject(); @@ -157,7 +155,15 @@ public function getMollieCustomerIbanDetailsFromPaymentObject($payment = null) $ibanDetails = []; if (isset($payment->_embedded->payments[0]->id)) { - $actualPayment = new MolliePayment($payment->_embedded->payments[0]->id, $this->pluginId, $this->apiHelper, $this->settingsHelper, $this->dataHelper, $this->logger); + $actualPayment = new MolliePayment( + $payment->_embedded->payments[0]->id, + $this->pluginId, + $this->apiHelper, + $this->settingsHelper, + $this->dataHelper, + $this->logger, + $this->requestFactory + ); $actualPayment = $actualPayment->getPaymentObject($actualPayment->data); /** * @var Payment $actualPayment @@ -921,7 +927,7 @@ protected function processOrderItemsRefund( unset($items[$item->get_id()]); } - public function setOrder( $data) + public function setOrder($data) { $this->data = $data; } diff --git a/src/Payment/MollieOrderService.php b/src/Payment/MollieOrderService.php index e55045d2..65a74f37 100644 --- a/src/Payment/MollieOrderService.php +++ b/src/Payment/MollieOrderService.php @@ -115,8 +115,7 @@ public function onWebhookAction() // Load the payment from Mollie, do not use cache try { $payment_object = $this->paymentFactory->getPaymentObject( - $payment_object_id, - null + $payment_object_id ); } catch (ApiException $exception) { $this->httpResponse->setHttpResponseCode(400); diff --git a/src/Payment/MolliePayment.php b/src/Payment/MolliePayment.php index b5810b1e..456d2bc1 100644 --- a/src/Payment/MolliePayment.php +++ b/src/Payment/MolliePayment.php @@ -15,7 +15,6 @@ 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_Subscriptions_Manager; @@ -26,7 +25,6 @@ class MolliePayment extends MollieObject public const ACTION_AFTER_REFUND_PAYMENT_CREATED = 'mollie-payments-for-woocommerce' . '_refund_payment_created'; protected $pluginId; - public function __construct( $data, string $pluginId, @@ -35,8 +33,8 @@ public function __construct( Data $dataHelper, Logger $logger, RequestFactory $requestFactory - ) - { + ) { + $this->data = $data; $this->pluginId = $pluginId; $this->apiHelper = $apiHelper; @@ -74,7 +72,6 @@ public function getPaymentObject($paymentId, $testMode = false, $useCache = true public function getPaymentRequestData($order, $customerId, $voucherDefaultCategory = Voucher::NO_CATEGORY) { return $this->requestFactory->createRequest('payment', $order, $customerId); - } /** @@ -476,7 +473,7 @@ protected function maybeUpdateStatus( $this->updateOrderStatus($order, $newOrderStatus); } - public function setPayment( $data) + public function setPayment($data) { $this->data = $data; } diff --git a/src/Payment/PaymentModule.php b/src/Payment/PaymentModule.php index f1b86f61..ba6e406e 100644 --- a/src/Payment/PaymentModule.php +++ b/src/Payment/PaymentModule.php @@ -50,7 +50,6 @@ public function services(): array static $services; if ($services === null) { - $services = require_once __DIR__ . '/inc/services.php'; } @@ -308,7 +307,6 @@ public function onOrderDetails(WC_Order $order, ContainerInterface $container) return; } - $oldGatewayInstances = $container->get('__deprecated.gateway_helpers'); $mollieGatewayHelper = $oldGatewayInstances[$gateway->id]; $mollieGatewayHelper->displayInstructions($order); diff --git a/src/Payment/PaymentProcessor.php b/src/Payment/PaymentProcessor.php index b9f4e685..0afef51c 100644 --- a/src/Payment/PaymentProcessor.php +++ b/src/Payment/PaymentProcessor.php @@ -83,7 +83,6 @@ public function __construct( public function setGateway($gateway) { $this->deprecatedGatewayHelper = $gateway; - } public function processPayment($order, $paymentGateway): array @@ -335,7 +334,6 @@ protected function processAsMollieOrder( $order, $customer_id, $this->voucherDefaultCategory, - ); $data = array_filter($paymentRequestData); @@ -529,6 +527,7 @@ protected function processPaymentForMollie( $customer_id, $apiKey ) { + $paymentMethod = $this->deprecatedGatewayHelper->paymentMethod(); // // PROCESS REGULAR PAYMENT AS MOLLIE ORDER @@ -546,8 +545,7 @@ protected function processPaymentForMollie( $paymentObject = $this->processAsMolliePayment( $order, $customer_id, - $apiKey, - $paymentMethod + $apiKey ); return $paymentObject; } @@ -576,9 +574,7 @@ protected function processPaymentForMollie( $paymentObject = $this->processAsMolliePayment( $order, $customer_id, - $apiKey, - $paymentMethod - ); + $apiKey); } return $paymentObject; @@ -591,7 +587,7 @@ protected function processPaymentForMollie( protected function saveMollieInfo($order, $payment) { // Get correct Mollie Payment Object - $payment_object = $this->paymentFactory->getPaymentObject($payment, $this->deprecatedGatewayHelper->paymentMethod()); + $payment_object = $this->paymentFactory->getPaymentObject($payment); // Set active Mollie payment $payment_object->setActiveMolliePayment($order->get_id()); @@ -690,9 +686,7 @@ protected function subsSwitchCompleted($order): array protected function processValidMandate($order, ?string $customerId, $apiKey): bool { $paymentObject = $this->paymentFactory->getPaymentObject( - self::PAYMENT_METHOD_TYPE_PAYMENT, - $this->deprecatedGatewayHelper->paymentMethod() - ); + self::PAYMENT_METHOD_TYPE_PAYMENT); $paymentRequestData = $paymentObject->getPaymentRequestData($order, $customerId); $data = array_filter($paymentRequestData); $data = apply_filters('woocommerce_' . $this->deprecatedGatewayHelper->id . '_args', $data, $order); diff --git a/src/Payment/Request/Decorators/AddSequenceTypeForSubscriptionsDecorator.php b/src/Payment/Request/Decorators/AddSequenceTypeForSubscriptionsDecorator.php index b2995e1b..71c02e98 100644 --- a/src/Payment/Request/Decorators/AddSequenceTypeForSubscriptionsDecorator.php +++ b/src/Payment/Request/Decorators/AddSequenceTypeForSubscriptionsDecorator.php @@ -10,7 +10,7 @@ class AddSequenceTypeForSubscriptionsDecorator implements RequestDecoratorInterface { private Data $dataHelper; - private String $pluginId; + private string $pluginId; public function __construct($dataHelper, $pluginId) { @@ -42,7 +42,7 @@ private function addSequenceTypeForSubscriptionsFirstPayments($orderId, $gateway private function addSequenceTypeFirst($requestData, $context) { - if($context === 'order') { + if ($context === 'order') { $requestData['payment']['sequenceType'] = 'first'; } elseif ($context === 'payment') { $requestData['sequenceType'] = 'first'; diff --git a/src/Payment/Request/Decorators/ApplePaytokenDecorator.php b/src/Payment/Request/Decorators/ApplePayTokenDecorator.php similarity index 95% rename from src/Payment/Request/Decorators/ApplePaytokenDecorator.php rename to src/Payment/Request/Decorators/ApplePayTokenDecorator.php index 6a7eb6b2..cff73317 100644 --- a/src/Payment/Request/Decorators/ApplePaytokenDecorator.php +++ b/src/Payment/Request/Decorators/ApplePayTokenDecorator.php @@ -16,7 +16,7 @@ public function decorate(array $requestData, WC_Order $order, $context = null): return $requestData; } $encodedApplePayToken = wp_json_encode($applePayToken); - if($context === 'order') { + if ($context === 'order') { $requestData['payment']['applePayToken'] = $encodedApplePayToken; } elseif ($context === 'payment') { $requestData['applePayToken'] = $encodedApplePayToken; diff --git a/src/Payment/Request/Decorators/CardTokenDecorator.php b/src/Payment/Request/Decorators/CardTokenDecorator.php index 9fb02b1f..6ab55441 100644 --- a/src/Payment/Request/Decorators/CardTokenDecorator.php +++ b/src/Payment/Request/Decorators/CardTokenDecorator.php @@ -13,7 +13,7 @@ public function decorate(array $requestData, WC_Order $order, $context = null): $cardToken = mollieWooCommerceCardToken(); if ($cardToken && isset($requestData['payment']) && $context === 'order') { $requestData['payment']['cardToken'] = $cardToken; - }elseif ($cardToken && isset($requestData['payment']) && $context === 'payment') { + } elseif ($cardToken && isset($requestData['payment']) && $context === 'payment') { $requestData['cardToken'] = $cardToken; } return $requestData; diff --git a/src/Payment/Request/Decorators/RequestDecoratorInterface.php b/src/Payment/Request/Decorators/RequestDecoratorInterface.php index cbf0f7d3..68736d4e 100644 --- a/src/Payment/Request/Decorators/RequestDecoratorInterface.php +++ b/src/Payment/Request/Decorators/RequestDecoratorInterface.php @@ -6,5 +6,5 @@ interface RequestDecoratorInterface { - public function decorate(array $requestData, WC_Order $order, String $context = null): array; + public function decorate(array $requestData, WC_Order $order, string $context = null): array; } diff --git a/src/Payment/Request/Decorators/SelectedIssuerDecorator.php b/src/Payment/Request/Decorators/SelectedIssuerDecorator.php index d208b27a..bdbd1267 100644 --- a/src/Payment/Request/Decorators/SelectedIssuerDecorator.php +++ b/src/Payment/Request/Decorators/SelectedIssuerDecorator.php @@ -18,16 +18,16 @@ public function __construct($pluginId) public function decorate(array $requestData, WC_Order $order, $context = null): array { $gateway = wc_get_payment_gateway_by_order($order); - if(!$gateway) { + if (!$gateway) { return $requestData; } $gatewayId = $gateway->id; $selectedIssuer = $this->getSelectedIssuer($gatewayId); - if(empty($selectedIssuer)) { + if (empty($selectedIssuer)) { return $requestData; } - if($context === 'order') { + if ($context === 'order') { $requestData['payment']['issuer'] = $selectedIssuer; } elseif ($context === 'payment') { $requestData['issuer'] = $selectedIssuer; diff --git a/src/Payment/Request/Decorators/StoreCustomerDecorator.php b/src/Payment/Request/Decorators/StoreCustomerDecorator.php index d9cd56e4..5092d256 100644 --- a/src/Payment/Request/Decorators/StoreCustomerDecorator.php +++ b/src/Payment/Request/Decorators/StoreCustomerDecorator.php @@ -15,15 +15,14 @@ public function __construct(Settings $settingsHelper) $this->settingsHelper = $settingsHelper; } - public function decorate(array $requestData, WC_Order $order, $context = null): array { $storeCustomer = $this->settingsHelper->shouldStoreCustomer(); $customerId = $order->get_meta('_mollie_customer_id'); - if(!$storeCustomer || !$customerId) { + if (!$storeCustomer || !$customerId) { return $requestData; } - if($context === 'order') { + if ($context === 'order') { $requestData['payment']['customerId'] = $customerId; } elseif ($context === 'payment') { $requestData['customerId'] = $customerId; diff --git a/src/Payment/Request/RequestFactory.php b/src/Payment/Request/RequestFactory.php index 3a8316c6..37a3f84e 100644 --- a/src/Payment/Request/RequestFactory.php +++ b/src/Payment/Request/RequestFactory.php @@ -6,10 +6,13 @@ use Psr\Container\ContainerInterface; use WC_Order; -class RequestFactory { +class RequestFactory +{ private $container; - public function __construct(ContainerInterface $container) { + public function __construct(ContainerInterface $container) + { + $this->container = $container; } @@ -21,7 +24,8 @@ public function __construct(ContainerInterface $container) { * @param string $customerId Customer ID for the request. * @return array The generated request data. */ - public function createRequest(string $type, WC_Order $order, string $customerId): array { + public function createRequest(string $type, WC_Order $order, string $customerId): array + { // Use the container to fetch the appropriate strategy. $serviceName = "request.strategy.{$type}"; $strategy = $this->container->get($serviceName); diff --git a/src/Payment/Request/Strategies/OrderRequestStrategy.php b/src/Payment/Request/Strategies/OrderRequestStrategy.php index 0df3ac5a..348398db 100644 --- a/src/Payment/Request/Strategies/OrderRequestStrategy.php +++ b/src/Payment/Request/Strategies/OrderRequestStrategy.php @@ -13,11 +13,14 @@ class OrderRequestStrategy implements RequestStrategyInterface private Settings $settingsHelper; private array $decorators; - public function __construct($dataHelper, $settingsHelper, array $decorators) { + public function __construct($dataHelper, $settingsHelper, array $decorators) + { + $this->dataHelper = $dataHelper; $this->settingsHelper = $settingsHelper; $this->decorators = $decorators; } + public function createRequest(WC_Order $order, string $customerId): array { $settingsHelper = $this->settingsHelper; diff --git a/src/Payment/Request/Strategies/PaymentRequestStrategy.php b/src/Payment/Request/Strategies/PaymentRequestStrategy.php index 15c02431..0413362e 100644 --- a/src/Payment/Request/Strategies/PaymentRequestStrategy.php +++ b/src/Payment/Request/Strategies/PaymentRequestStrategy.php @@ -11,12 +11,14 @@ class PaymentRequestStrategy implements RequestStrategyInterface private $settingsHelper; private array $decorators; + public function __construct($dataHelper, $settingsHelper, array $decorators) + { - public function __construct($dataHelper, $settingsHelper, array $decorators) { $this->dataHelper = $dataHelper; $this->settingsHelper = $settingsHelper; $this->decorators = $decorators; } + public function createRequest(WC_Order $order, string $customerId): array { diff --git a/src/Payment/Request/Strategies/RequestStrategyInterface.php b/src/Payment/Request/Strategies/RequestStrategyInterface.php index f3e9f0c9..dc67afe8 100644 --- a/src/Payment/Request/Strategies/RequestStrategyInterface.php +++ b/src/Payment/Request/Strategies/RequestStrategyInterface.php @@ -4,6 +4,7 @@ use WC_Order; -interface RequestStrategyInterface { +interface RequestStrategyInterface +{ public function createRequest(WC_Order $order, string $customerId): array; } diff --git a/src/Payment/inc/services.php b/src/Payment/inc/services.php index 0c7f448d..1b83f2b2 100644 --- a/src/Payment/inc/services.php +++ b/src/Payment/inc/services.php @@ -2,7 +2,6 @@ declare(strict_types=1); - use Mollie\WooCommerce\Gateway\Refund\OrderItemsRefunder; use Mollie\WooCommerce\Payment\MollieObject; use Mollie\WooCommerce\Payment\MollieOrder; diff --git a/src/PaymentMethods/PaymentFieldsStrategies/BancomatpayFieldsStrategy.php b/src/PaymentMethods/PaymentFieldsStrategies/BancomatpayFieldsStrategy.php index c32f991d..e8783c32 100644 --- a/src/PaymentMethods/PaymentFieldsStrategies/BancomatpayFieldsStrategy.php +++ b/src/PaymentMethods/PaymentFieldsStrategies/BancomatpayFieldsStrategy.php @@ -43,15 +43,15 @@ protected function phoneNumber($phoneValue) return '

diff --git a/src/PaymentMethods/PaymentFieldsStrategies/BillieFieldsStrategy.php b/src/PaymentMethods/PaymentFieldsStrategies/BillieFieldsStrategy.php index 806bec11..f7e6f06c 100644 --- a/src/PaymentMethods/PaymentFieldsStrategies/BillieFieldsStrategy.php +++ b/src/PaymentMethods/PaymentFieldsStrategies/BillieFieldsStrategy.php @@ -39,22 +39,21 @@ protected function company() return '

'; } - public function getFieldMarkup($gateway, $dataHelper) { return ""; diff --git a/src/PaymentMethods/PaymentFieldsStrategies/CreditcardFieldsStrategy.php b/src/PaymentMethods/PaymentFieldsStrategies/CreditcardFieldsStrategy.php index f86049d6..5cececc7 100644 --- a/src/PaymentMethods/PaymentFieldsStrategies/CreditcardFieldsStrategy.php +++ b/src/PaymentMethods/PaymentFieldsStrategies/CreditcardFieldsStrategy.php @@ -19,12 +19,12 @@ public function execute($gateway, $dataHelper): string $output = '
'; $output .= '

'; $output .= sprintf( - esc_html__( - '%1$s Secure payments provided by %2$s', - 'mollie-payments-for-woocommerce' - ), - wp_kses($this->lockIcon($dataHelper), $allowedHtml), - wp_kses($this->mollieLogo($dataHelper), $allowedHtml) + esc_html__( + '%1$s Secure payments provided by %2$s', + 'mollie-payments-for-woocommerce' + ), + wp_kses($this->lockIcon($dataHelper), $allowedHtml), + wp_kses($this->mollieLogo($dataHelper), $allowedHtml) ); $output .= '

'; diff --git a/src/PaymentMethods/PaymentFieldsStrategies/In3FieldsStrategy.php b/src/PaymentMethods/PaymentFieldsStrategies/In3FieldsStrategy.php index 42609bdf..a67c0d47 100644 --- a/src/PaymentMethods/PaymentFieldsStrategies/In3FieldsStrategy.php +++ b/src/PaymentMethods/PaymentFieldsStrategies/In3FieldsStrategy.php @@ -49,13 +49,13 @@ protected function phoneNumber($phoneValue) $phoneValue = $phoneValue ?: ''; $html = '

'; $html .= ''; + 'Phone', + 'mollie-payments-for-woocommerce' + ) . ''; $html .= ''; $html .= ''; + self::FIELD_PHONE + ) . '" placeholder="+316xxxxxxxx" value="' . esc_attr($phoneValue) . '" autocomplete="phone">'; $html .= '

'; return $html; } diff --git a/src/PaymentMethods/PaymentFieldsStrategies/NoopPaymentFieldsRenderer.php b/src/PaymentMethods/PaymentFieldsStrategies/NoopPaymentFieldsRenderer.php index f06d7cf7..0e08599a 100644 --- a/src/PaymentMethods/PaymentFieldsStrategies/NoopPaymentFieldsRenderer.php +++ b/src/PaymentMethods/PaymentFieldsStrategies/NoopPaymentFieldsRenderer.php @@ -6,12 +6,11 @@ class NoopPaymentFieldsRenderer implements PaymentFieldsRendererInterface { - /** * @inheritDoc */ public function renderFields(): string { - // TODO: Implement renderFields() method. + return ''; } } diff --git a/src/PaymentMethods/PaymentFieldsStrategies/PaymentFieldsStrategiesTrait.php b/src/PaymentMethods/PaymentFieldsStrategies/PaymentFieldsStrategiesTrait.php index 9b7d37ae..45ff27bb 100644 --- a/src/PaymentMethods/PaymentFieldsStrategies/PaymentFieldsStrategiesTrait.php +++ b/src/PaymentMethods/PaymentFieldsStrategies/PaymentFieldsStrategiesTrait.php @@ -16,15 +16,15 @@ protected function dateOfBirth($birthValue) $birthValue = $birthValue ?: ''; $html = '

'; $html .= ''; + 'Birthdate', + 'mollie-payments-for-woocommerce' + ) . ''; $html .= ''; $html .= ''; + self::FIELD_BIRTHDATE + ) . '" id="' . esc_attr(self::FIELD_BIRTHDATE) . '" value="' . esc_attr( + $birthValue + ) . '" autocomplete="birthdate">'; $html .= '

'; return $html; } diff --git a/src/Settings/General/MultiCountrySettingsField.php b/src/Settings/General/MultiCountrySettingsField.php index b6ca2321..fcc723f5 100644 --- a/src/Settings/General/MultiCountrySettingsField.php +++ b/src/Settings/General/MultiCountrySettingsField.php @@ -7,7 +7,6 @@ class MultiCountrySettingsField implements SettingsFieldRendererInterface { - /** * @var mixed */ @@ -22,6 +21,7 @@ public function render(string $fieldId, array $fieldConfig, PaymentGateway $gate { return $this->multiSelectCountry($this->paymentMethod); } + public function multiSelectCountry($paymentMethod) { $selections = (array)$paymentMethod->getProperty('allowed_countries', []); diff --git a/src/Settings/Page/Section/Advanced.php b/src/Settings/Page/Section/Advanced.php index bb90fb09..7afe0678 100644 --- a/src/Settings/Page/Section/Advanced.php +++ b/src/Settings/Page/Section/Advanced.php @@ -111,7 +111,7 @@ public function config(): array 'type' => 'select', 'options' => [ PaymentProcessor::PAYMENT_METHOD_TYPE_ORDER => ucfirst( - PaymentProcessor::PAYMENT_METHOD_TYPE_ORDER + PaymentProcessor::PAYMENT_METHOD_TYPE_ORDER ) . ' (' . __('default', 'mollie-payments-for-woocommerce') . ')', PaymentProcessor::PAYMENT_METHOD_TYPE_PAYMENT => ucfirst( diff --git a/src/Subscription/MollieSepaRecurringGatewayHandler.php b/src/Subscription/MollieSepaRecurringGatewayHandler.php index 3ccaa069..5512acd6 100644 --- a/src/Subscription/MollieSepaRecurringGatewayHandler.php +++ b/src/Subscription/MollieSepaRecurringGatewayHandler.php @@ -7,6 +7,7 @@ use DateInterval; use DateTime; use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Resources\Payment; use Mollie\Api\Types\SequenceType; use Mollie\WooCommerce\Gateway\MolliePaymentGatewayHandler; use Mollie\WooCommerce\Notice\NoticeInterface; @@ -64,22 +65,9 @@ public function __construct( $pluginId, $apiHelper ); - $directDebit = new MolliePaymentGatewayHandler( - $directDebitPaymentMethod, - $paymentProcessor, - $orderInstructionsService, - $mollieOrderService, - $dataService, - $logger, - $notice, - $httpResponse, - $mollieObject, - $paymentFactory, - $pluginId - ); - if ($directDebit->enabled === 'yes') { - - $this->recurringMollieMethod = $directDebit; + $directDebitSettings = get_option('mollie_wc_gateway_directdebit_settings'); + if ($directDebitSettings['enabled'] === 'yes') { + $this->recurringMollieMethod = $directDebitPaymentMethod; } return $this; } @@ -91,7 +79,7 @@ protected function getRecurringMollieMethodId() { $result = null; if ($this->recurringMollieMethod) { - $result = $this->recurringMollieMethod->paymentMethod()->getProperty('id'); + $result = $this->recurringMollieMethod->getProperty('id'); } return $result; @@ -104,7 +92,7 @@ protected function getRecurringMollieMethodTitle() { $result = null; if ($this->recurringMollieMethod) { - $result = $this->recurringMollieMethod->paymentMethod()->getProperty('title'); + $result = $this->recurringMollieMethod->getProperty('title'); } return $result; @@ -166,7 +154,7 @@ protected function addPendingPaymentOrder($renewal_order) } /** - * @param null $payment + * @param Payment $payment * @return string */ protected function getPaymentMethodTitle($payment) diff --git a/src/Subscription/MollieSubscriptionGatewayHandler.php b/src/Subscription/MollieSubscriptionGatewayHandler.php index 67da07a8..9890c8f1 100644 --- a/src/Subscription/MollieSubscriptionGatewayHandler.php +++ b/src/Subscription/MollieSubscriptionGatewayHandler.php @@ -89,12 +89,18 @@ public function __construct( ); } - public function addSubscriptionFilters($gateway) { + public function addSubscriptionFilters($gateway) + { + if (class_exists('WC_Subscriptions_Order')) { - add_action('woocommerce_scheduled_subscription_payment_' . $gateway->id, - static function ($renewal_total, WC_Order $renewal_order) use ($gateway) { + add_action( + 'woocommerce_scheduled_subscription_payment_' . $gateway->id, + function ($renewal_total, WC_Order $renewal_order) use ($gateway) { $this->scheduled_subscription_payment($renewal_total, $renewal_order, $gateway); - }, 10, 3); + }, + 10, + 3 + ); // A resubscribe order to record a customer resubscribing to an expired or cancelled subscription. add_action('wcs_resubscribe_order_created', [ $this, 'delete_resubscribe_meta' ], 10); @@ -104,14 +110,22 @@ static function ($renewal_total, WC_Order $renewal_order) use ($gateway) { add_action('woocommerce_subscription_failing_payment_method_updated_mollie', [ $this, 'update_failing_payment_method' ], 10, 2); - add_filter('woocommerce_subscription_payment_meta', - static function ($payment_meta, $subscription) use ($gateway) { + add_filter( + 'woocommerce_subscription_payment_meta', + function ($payment_meta, $subscription) use ($gateway) { return $this->add_subscription_payment_meta($payment_meta, $subscription, $gateway); - }, 10, 3); - add_action('woocommerce_subscription_validate_payment_meta', - static function ($payment_method_id, $payment_meta) use ($gateway) { + }, + 10, + 3 + ); + add_action( + 'woocommerce_subscription_validate_payment_meta', + function ($payment_method_id, $payment_meta) use ($gateway) { $this->validate_subscription_payment_meta($payment_method_id, $payment_meta, $gateway); - }, 10, 2); + }, + 10, + 2 + ); } } @@ -483,7 +497,7 @@ public function delete_renewal_meta($renewal_order) */ public function add_subscription_payment_meta($payment_meta, $subscription, $gateway) { - if($gateway->id !== $subscription->get_payment_method()) { + if ($gateway->id !== $subscription->get_payment_method()) { return $payment_meta; } $parent = $subscription->get_parent(); @@ -586,7 +600,7 @@ public function restore_mollie_customer_id_and_mandate($mollie_customer_id, $mol $subscription_id = $subscription->get_id(); // Get full payment object from Mollie API - $payment_object_resource = $this->paymentFactory->getPaymentObject($mollie_payment_id, $this->paymentMethod()); + $payment_object_resource = $this->paymentFactory->getPaymentObject($mollie_payment_id); // // If there is no known customer ID, try to get it from the API