From dcde256b8d43c3432d026150ae0ed119fad92978 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Thu, 20 Jun 2024 16:22:06 +0200 Subject: [PATCH 01/15] Add missmatch to request lines --- inc/utils.php | 6 +----- src/Payment/OrderLines.php | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/inc/utils.php b/inc/utils.php index 4fb667d9..bdd68c75 100644 --- a/inc/utils.php +++ b/inc/utils.php @@ -186,11 +186,7 @@ function mollieWooCommerceFormatCurrencyValue($value, $currency) if (in_array($currency, $currenciesWithNoDecimals)) { return number_format($value, 0, '.', ''); } - // trying to avoid floating point issues - $value = $value * 1000; - $value = (int) $value / 1000; //drop the last decimal after the third - $value = round($value, 3); - $value = round($value, 2, PHP_ROUND_HALF_DOWN); //round down, as seems woo like it :) + return number_format($value, 2, '.', ''); } diff --git a/src/Payment/OrderLines.php b/src/Payment/OrderLines.php index de67b7c5..bf8895b8 100644 --- a/src/Payment/OrderLines.php +++ b/src/Payment/OrderLines.php @@ -64,12 +64,48 @@ public function order_lines($order, $voucherDefaultCategory) $this->process_shipping(); $this->process_fees(); $this->process_gift_cards(); + $this->process_missmatch(); return [ 'lines' => $this->get_order_lines(), ]; } + private function process_missmatch() + { + $orderTotal = $this->order->get_total(); + $orderTotalRounded = round($orderTotal, 2); + $linesTotal = array_sum(array_map(function ($line) { + return $line['totalAmount']['value']; + }, $this->order_lines)); + $orderTotalDiff = $orderTotalRounded - $linesTotal; + if (abs($orderTotalDiff) > 0) { + $missmatch = [ + 'type' => 'surcharge', + 'name' => __('Rounding difference', 'mollie-payments-for-woocommerce'), + 'quantity' => 1, + 'vatRate' => 0, + 'unitPrice' => [ + 'currency' => $this->currency, + 'value' => $this->dataHelper->formatCurrencyValue($orderTotalDiff, $this->currency), + ], + 'totalAmount' => [ + 'currency' => $this->currency, + 'value' => $this->dataHelper->formatCurrencyValue($orderTotalDiff, $this->currency), + ], + 'vatAmount' => [ + 'currency' => $this->currency, + 'value' => $this->dataHelper->formatCurrencyValue(0, $this->currency), + ], + 'metadata' => [ + 'order_item_id' => 'rounding_diff', + ], + ]; + + $this->order_lines[] = $missmatch; + } + } + /** * Get order lines formatted for Mollie Orders API. * From a890c421287155f5982df2a694e7f5be9a51febd Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Fri, 28 Jun 2024 12:26:16 +0200 Subject: [PATCH 02/15] Create 7.5.6-beta branch --- mollie-payments-for-woocommerce.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mollie-payments-for-woocommerce.php b/mollie-payments-for-woocommerce.php index 808999e0..cb57ef79 100644 --- a/mollie-payments-for-woocommerce.php +++ b/mollie-payments-for-woocommerce.php @@ -3,7 +3,7 @@ * Plugin Name: Mollie Payments for WooCommerce * Plugin URI: https://www.mollie.com * Description: Accept payments in WooCommerce with the official Mollie plugin - * Version: 7.5.5 + * Version: 7.5.6-beta * Author: Mollie * Author URI: https://www.mollie.com * Requires at least: 5.0 From e3e5fe5c5d4a85b693fa6651a79d3042d1e5ebf9 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Fri, 28 Jun 2024 12:40:37 +0200 Subject: [PATCH 03/15] Add Truslty method --- src/PaymentMethods/Trustly.php | 32 +++++++++++++++++++++++++++++ src/Shared/SharedDataDictionary.php | 1 + 2 files changed, 33 insertions(+) create mode 100644 src/PaymentMethods/Trustly.php diff --git a/src/PaymentMethods/Trustly.php b/src/PaymentMethods/Trustly.php new file mode 100644 index 00000000..05179fbb --- /dev/null +++ b/src/PaymentMethods/Trustly.php @@ -0,0 +1,32 @@ + 'trustly', + 'defaultTitle' => __('Trustly', 'mollie-payments-for-woocommerce'), + 'settingsDescription' => '', + 'defaultDescription' => '', + 'paymentFields' => false, + 'instructions' => true, + 'supports' => [ + 'products', + 'refunds', + ], + 'filtersOnBuild' => false, + 'confirmationDelayed' => true, + 'SEPA' => false, + ]; + } + + public function getFormFields($generalFormFields): array + { + return $generalFormFields; + } +} diff --git a/src/Shared/SharedDataDictionary.php b/src/Shared/SharedDataDictionary.php index a78fcd26..b76cd074 100644 --- a/src/Shared/SharedDataDictionary.php +++ b/src/Shared/SharedDataDictionary.php @@ -35,6 +35,7 @@ class SharedDataDictionary 'Mollie_WC_Gateway_Twint', 'Mollie_WC_Gateway_Bancomatpay', 'Mollie_WC_Gateway_Alma', + 'Mollie_WC_Gateway_Trustly' ]; public const MOLLIE_OPTIONS_NAMES = [ From a78768d2d0d1e07f20687bdc5e4765dae1671d61 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Fri, 28 Jun 2024 12:52:34 +0200 Subject: [PATCH 04/15] Check if string before preg_match --- src/Payment/MollieObject.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Payment/MollieObject.php b/src/Payment/MollieObject.php index 84f70d42..bd00a7c6 100644 --- a/src/Payment/MollieObject.php +++ b/src/Payment/MollieObject.php @@ -1079,7 +1079,7 @@ protected function getFormatedPhoneNumber(string $phone) $phone = transformPhoneToNLFormat($phone); //check that $phone is in E164 format or can be changed by api - if (preg_match('/^\+[1-9]\d{10,13}$|^[1-9]\d{9,13}$/', $phone)) { + if (is_string($phone) && preg_match('/^\+[1-9]\d{10,13}$|^[1-9]\d{9,13}$/', $phone)) { return $phone; } return null; From b63cce4dec76c4184c58efbb287269478a2a2bb5 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Fri, 28 Jun 2024 13:20:07 +0200 Subject: [PATCH 05/15] Fix PHP notice in MollieObject --- src/Payment/MollieObject.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Payment/MollieObject.php b/src/Payment/MollieObject.php index bd00a7c6..7eac75ed 100644 --- a/src/Payment/MollieObject.php +++ b/src/Payment/MollieObject.php @@ -543,7 +543,7 @@ protected function setOrderPaidAndProcessed(WC_Order $order) protected function isOrderPaymentStartedByOtherGateway(WC_Order $order) { // Get the current payment method id for the order - $payment_method_id = $order->get_meta('_payment_method', true); + $payment_method_id = $order->get_payment_method(); // If the current payment method id for the order is not Mollie, return true return strpos($payment_method_id, 'mollie') === false; } From f27dc87ed12f08d897238a5067740a92330cc111 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Fri, 28 Jun 2024 14:12:02 +0200 Subject: [PATCH 06/15] Bail CapturePayment if is not mollie payment --- src/MerchantCapture/Capture/Action/CapturePayment.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/MerchantCapture/Capture/Action/CapturePayment.php b/src/MerchantCapture/Capture/Action/CapturePayment.php index 41fd5ab7..983fd452 100644 --- a/src/MerchantCapture/Capture/Action/CapturePayment.php +++ b/src/MerchantCapture/Capture/Action/CapturePayment.php @@ -13,6 +13,11 @@ class CapturePayment extends AbstractPaymentCaptureAction public function __invoke() { try { + $payment = $this->order->get_payment_method(); + if (strpos($payment, 'mollie') === false ) { + return; + } + $paymentId = $this->order->get_meta('_mollie_payment_id'); if (!$paymentId) { From df5f4fe55259a325b2e5fbd5d5ecb1d9e98b5abe Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Wed, 3 Jul 2024 08:33:08 +0200 Subject: [PATCH 07/15] Add trustly icon --- public/images/trustly.svg | 1 + 1 file changed, 1 insertion(+) create mode 100644 public/images/trustly.svg diff --git a/public/images/trustly.svg b/public/images/trustly.svg new file mode 100644 index 00000000..fefc5da1 --- /dev/null +++ b/public/images/trustly.svg @@ -0,0 +1 @@ + From 43b4a78a2c2bc66986a5b5702565ebc07b1d940f Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Wed, 3 Jul 2024 08:38:47 +0200 Subject: [PATCH 08/15] Fix CS --- src/Shared/SharedDataDictionary.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Shared/SharedDataDictionary.php b/src/Shared/SharedDataDictionary.php index b76cd074..3519fdde 100644 --- a/src/Shared/SharedDataDictionary.php +++ b/src/Shared/SharedDataDictionary.php @@ -35,7 +35,7 @@ class SharedDataDictionary 'Mollie_WC_Gateway_Twint', 'Mollie_WC_Gateway_Bancomatpay', 'Mollie_WC_Gateway_Alma', - 'Mollie_WC_Gateway_Trustly' + 'Mollie_WC_Gateway_Trustly', ]; public const MOLLIE_OPTIONS_NAMES = [ From 2f2276ad1d4de0067e385ec4a96e9850dbf8c3b2 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Wed, 3 Jul 2024 08:44:45 +0200 Subject: [PATCH 09/15] Fix CS --- src/MerchantCapture/Capture/Action/CapturePayment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MerchantCapture/Capture/Action/CapturePayment.php b/src/MerchantCapture/Capture/Action/CapturePayment.php index 983fd452..8d50f699 100644 --- a/src/MerchantCapture/Capture/Action/CapturePayment.php +++ b/src/MerchantCapture/Capture/Action/CapturePayment.php @@ -14,7 +14,7 @@ public function __invoke() { try { $payment = $this->order->get_payment_method(); - if (strpos($payment, 'mollie') === false ) { + if (strpos($payment, 'mollie') === false) { return; } From e4a924797eabdcd22aa967aec4a8a08d93afdb99 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Mon, 8 Jul 2024 09:03:07 +0200 Subject: [PATCH 10/15] Update transaction test --- tests/php/Functional/Payment/PaymentServiceTest.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/php/Functional/Payment/PaymentServiceTest.php b/tests/php/Functional/Payment/PaymentServiceTest.php index 52e7e8bc..3f9bf40a 100644 --- a/tests/php/Functional/Payment/PaymentServiceTest.php +++ b/tests/php/Functional/Payment/PaymentServiceTest.php @@ -98,9 +98,7 @@ public function processPayment_Order_success(){ 'wc_clean' => null, ] ); - $gateway->expects($this->once()) - ->method('getSelectedIssuer') - ->willReturn('ideal_INGBNL2A'); + $expectedRequestToMollie = $this->expectedRequestData($wcOrder); $orderEndpoints->method('create')->with($expectedRequestToMollie); @@ -212,7 +210,7 @@ private function wcOrder($id, $orderKey) [ 'get_id' => $id, 'get_order_key' => $orderKey, - 'get_total' => '20', + 'get_total' => '40', 'get_items' => [$this->wcOrderItem()], 'get_billing_first_name' => 'billingggivenName', 'get_billing_last_name' => 'billingfamilyName', @@ -307,7 +305,7 @@ private function expectedRequestData($order){ return [ 'amount' => [ 'currency' => 'EUR', - 'value' => '20.00' + 'value' => '40.00' ], 'redirectUrl' => 'https://webshop.example.org/wc-api/mollie_return?order_id=1&key=wc_order_hxZniP1zDcnM8', @@ -317,7 +315,7 @@ private function expectedRequestData($order){ 'ideal', 'payment' => [ - 'issuer' => 'ideal_INGBNL2A' + 'issuer' => null ], 'locale' => 'en_US', 'billingAddress' => $this->billingAddress($order), From 0761cd7e25405e87be5bf208a92a70775e278a8d Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Mon, 8 Jul 2024 09:22:05 +0200 Subject: [PATCH 11/15] Update transaction test for php8 --- tests/php/Functional/Payment/PaymentServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/php/Functional/Payment/PaymentServiceTest.php b/tests/php/Functional/Payment/PaymentServiceTest.php index 3f9bf40a..acf34319 100644 --- a/tests/php/Functional/Payment/PaymentServiceTest.php +++ b/tests/php/Functional/Payment/PaymentServiceTest.php @@ -210,7 +210,7 @@ private function wcOrder($id, $orderKey) [ 'get_id' => $id, 'get_order_key' => $orderKey, - 'get_total' => '40', + 'get_total' => 40.00, 'get_items' => [$this->wcOrderItem()], 'get_billing_first_name' => 'billingggivenName', 'get_billing_last_name' => 'billingfamilyName', From 7610eed7f1ad85a7ec8dc9be9b3befbcf35ea689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carmen=20Maym=C3=B3?= <45061744+mmaymo@users.noreply.github.com> Date: Mon, 8 Jul 2024 09:32:32 +0200 Subject: [PATCH 12/15] Update version --- mollie-payments-for-woocommerce.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mollie-payments-for-woocommerce.php b/mollie-payments-for-woocommerce.php index cb57ef79..7e9d56bd 100644 --- a/mollie-payments-for-woocommerce.php +++ b/mollie-payments-for-woocommerce.php @@ -3,7 +3,7 @@ * Plugin Name: Mollie Payments for WooCommerce * Plugin URI: https://www.mollie.com * Description: Accept payments in WooCommerce with the official Mollie plugin - * Version: 7.5.6-beta + * Version: 7.6.0 * Author: Mollie * Author URI: https://www.mollie.com * Requires at least: 5.0 @@ -12,7 +12,7 @@ * Domain Path: /languages * License: GPLv2 or later * WC requires at least: 3.9 - * WC tested up to: 8.9 + * WC tested up to: 9.0 * Requires PHP: 7.2 * Requires Plugins: woocommerce */ From 0e501709ef919f8c5558e85470dc97198f40317e Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Mon, 8 Jul 2024 13:25:22 +0200 Subject: [PATCH 13/15] Cast get_total to float before rounding --- src/Payment/OrderLines.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Payment/OrderLines.php b/src/Payment/OrderLines.php index bf8895b8..1c76bbf3 100644 --- a/src/Payment/OrderLines.php +++ b/src/Payment/OrderLines.php @@ -73,7 +73,7 @@ public function order_lines($order, $voucherDefaultCategory) private function process_missmatch() { - $orderTotal = $this->order->get_total(); + $orderTotal = (float) $this->order->get_total(); $orderTotalRounded = round($orderTotal, 2); $linesTotal = array_sum(array_map(function ($line) { return $line['totalAmount']['value']; From 18ba6747bddb9f03a706b9738bc7f10d80056f8e Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Mon, 8 Jul 2024 16:49:31 +0200 Subject: [PATCH 14/15] Add Giropay notice --- src/PaymentMethods/Giropay.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/PaymentMethods/Giropay.php b/src/PaymentMethods/Giropay.php index 31e2ec00..4e3d8e20 100644 --- a/src/PaymentMethods/Giropay.php +++ b/src/PaymentMethods/Giropay.php @@ -27,6 +27,15 @@ protected function getConfig(): array public function getFormFields($generalFormFields): array { - return $generalFormFields; + $notice = ['notice' => [ + 'title' => + sprintf(__('%s Paydirekt, the owner of Giropay, has decided to deprecate Giropay. On Monday, 24 June 2024, Mollie was informed that Giropay would cease onboarding new merchants and processing new payments after 30 June 2024. No action is needed from your side. Mollie will automatically remove Giropay as a payment option from your Checkout by 30 June. +Subscription renewals and refunds will continue to be processed as usual beyond June 30. More details can be found in the %s Giropay Deprecation FAQ. %s', 'mollie-payments-for-woocommerce'), '

','', '

'), + 'type' => 'title', + 'class' => 'notice notice-warning', + 'css' => 'padding:20px;', + + ]]; + return array_merge($notice, $generalFormFields); } } From 9f79a2d77742de9820581466231a8f813cc7b79e Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Wed, 10 Jul 2024 09:41:33 +0200 Subject: [PATCH 15/15] Fix CS --- src/PaymentMethods/Giropay.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/PaymentMethods/Giropay.php b/src/PaymentMethods/Giropay.php index 4e3d8e20..f7e700fe 100644 --- a/src/PaymentMethods/Giropay.php +++ b/src/PaymentMethods/Giropay.php @@ -27,15 +27,24 @@ protected function getConfig(): array public function getFormFields($generalFormFields): array { - $notice = ['notice' => [ - 'title' => - sprintf(__('%s Paydirekt, the owner of Giropay, has decided to deprecate Giropay. On Monday, 24 June 2024, Mollie was informed that Giropay would cease onboarding new merchants and processing new payments after 30 June 2024. No action is needed from your side. Mollie will automatically remove Giropay as a payment option from your Checkout by 30 June. -Subscription renewals and refunds will continue to be processed as usual beyond June 30. More details can be found in the %s Giropay Deprecation FAQ. %s', 'mollie-payments-for-woocommerce'), '

','', '

'), - 'type' => 'title', - 'class' => 'notice notice-warning', - 'css' => 'padding:20px;', - - ]]; + $notice = [ + 'notice' => [ + 'title' => + sprintf( + __( + '%1$s Paydirekt, the owner of Giropay, has decided to deprecate Giropay. On Monday, 24 June 2024, Mollie was informed that Giropay would cease onboarding new merchants and processing new payments after 30 June 2024. No action is needed from your side. Mollie will automatically remove Giropay as a payment option from your Checkout by 30 June. +Subscription renewals and refunds will continue to be processed as usual beyond June 30. More details can be found in the %2$s Giropay Deprecation FAQ. %3$s', + 'mollie-payments-for-woocommerce' + ), + '

', + '', + '

' + ), + 'type' => 'title', + 'class' => 'notice notice-warning', + 'css' => 'padding:20px;', + ], + ]; return array_merge($notice, $generalFormFields); } }