From 3b1e75a00f73446dca947d39e5a8b6e58e8e5551 Mon Sep 17 00:00:00 2001 From: Matic Luznar Date: Tue, 1 Aug 2023 09:13:23 +0200 Subject: [PATCH 1/3] Show notice to user if payment is not successful --- src/Gateway/MolliePaymentGateway.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Gateway/MolliePaymentGateway.php b/src/Gateway/MolliePaymentGateway.php index f71438a8..a176fd44 100644 --- a/src/Gateway/MolliePaymentGateway.php +++ b/src/Gateway/MolliePaymentGateway.php @@ -570,6 +570,12 @@ public function getReturnRedirectUrlForOrder(WC_Order $order): string if ($order_status_cancelled_payments === 'cancelled') { return $this->get_return_url($order); } else { + + wc_add_notice(__( + 'You have cancelled your payment. Please complete your order with a different payment method.', + 'mollie-payments-for-woocommerce' + ), "error"); + $this->notice->addNotice( 'notice', __( @@ -591,6 +597,12 @@ public function getReturnRedirectUrlForOrder(WC_Order $order): string && !$payment->isPaid() && !$payment->isAuthorized() ) { + + wc_add_notice(__( + 'Your payment was not successful. Please complete your order with a different payment method.', + 'mollie-payments-for-woocommerce' + ), "error"); + $this->notice->addNotice( 'notice', __( @@ -605,6 +617,12 @@ public function getReturnRedirectUrlForOrder(WC_Order $order): string $this->paymentMethod->debugGiftcardDetails($payment, $order); } } catch (UnexpectedValueException $exc) { + + wc_add_notice(__( + 'Your payment was not successful. Please complete your order with a different payment method.', + 'mollie-payments-for-woocommerce' + ), "error"); + $this->notice->addNotice( 'notice', __( From c93a39ba3a0f233fb62047e4fbfca3c355c55204 Mon Sep 17 00:00:00 2001 From: Matic Luznar Date: Tue, 1 Aug 2023 09:25:04 +0200 Subject: [PATCH 2/3] Fix spacing phpcs errors --- src/Gateway/MolliePaymentGateway.php | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/src/Gateway/MolliePaymentGateway.php b/src/Gateway/MolliePaymentGateway.php index a176fd44..32117df6 100644 --- a/src/Gateway/MolliePaymentGateway.php +++ b/src/Gateway/MolliePaymentGateway.php @@ -570,12 +570,7 @@ public function getReturnRedirectUrlForOrder(WC_Order $order): string if ($order_status_cancelled_payments === 'cancelled') { return $this->get_return_url($order); } else { - - wc_add_notice(__( - 'You have cancelled your payment. Please complete your order with a different payment method.', - 'mollie-payments-for-woocommerce' - ), "error"); - + wc_add_notice(__('You have cancelled your payment. Please complete your order with a different payment method.', 'mollie-payments-for-woocommerce'), "error"); $this->notice->addNotice( 'notice', __( @@ -583,7 +578,6 @@ public function getReturnRedirectUrlForOrder(WC_Order $order): string 'mollie-payments-for-woocommerce' ) ); - // Return to order payment page return $failedRedirect; } @@ -597,12 +591,7 @@ public function getReturnRedirectUrlForOrder(WC_Order $order): string && !$payment->isPaid() && !$payment->isAuthorized() ) { - - wc_add_notice(__( - 'Your payment was not successful. Please complete your order with a different payment method.', - 'mollie-payments-for-woocommerce' - ), "error"); - + wc_add_notice(__('Your payment was not successful. Please complete your order with a different payment method.', 'mollie-payments-for-woocommerce'), "error"); $this->notice->addNotice( 'notice', __( @@ -617,12 +606,7 @@ public function getReturnRedirectUrlForOrder(WC_Order $order): string $this->paymentMethod->debugGiftcardDetails($payment, $order); } } catch (UnexpectedValueException $exc) { - - wc_add_notice(__( - 'Your payment was not successful. Please complete your order with a different payment method.', - 'mollie-payments-for-woocommerce' - ), "error"); - + wc_add_notice(__('Your payment was not successful. Please complete your order with a different payment method.', 'mollie-payments-for-woocommerce'), "error"); $this->notice->addNotice( 'notice', __( From bd741a7933119ffe6a4dbef6eeee09c766212bd3 Mon Sep 17 00:00:00 2001 From: Matic Luznar Date: Tue, 1 Aug 2023 11:40:59 +0200 Subject: [PATCH 3/3] Create FrontendNotice class and use it in the MolliePaymentGateway module. --- src/Gateway/GatewayModule.php | 5 +++-- src/Gateway/MolliePaymentGateway.php | 9 +++------ src/Notice/FrontendNotice.php | 13 +++++++++++++ src/Notice/NoticeModule.php | 6 +++--- 4 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 src/Notice/FrontendNotice.php diff --git a/src/Gateway/GatewayModule.php b/src/Gateway/GatewayModule.php index b4c8a062..a7411952 100644 --- a/src/Gateway/GatewayModule.php +++ b/src/Gateway/GatewayModule.php @@ -18,6 +18,7 @@ use Mollie\WooCommerce\Buttons\PayPalButton\PayPalButtonHandler; use Mollie\WooCommerce\Gateway\Voucher\MaybeDisableGateway; use Mollie\WooCommerce\Notice\AdminNotice; +use Mollie\WooCommerce\Notice\FrontendNotice; use Mollie\WooCommerce\Notice\NoticeInterface; use Mollie\WooCommerce\Payment\MollieObject; use Mollie\WooCommerce\Payment\MollieOrderService; @@ -495,8 +496,8 @@ public function instantiatePaymentMethodGateways(ContainerInterface $container): { $logger = $container->get(Logger::class); assert($logger instanceof Logger); - $notice = $container->get(AdminNotice::class); - assert($notice instanceof AdminNotice); + $notice = $container->get(FrontendNotice::class); + assert($notice instanceof FrontendNotice); $paymentService = $container->get(PaymentService::class); assert($paymentService instanceof PaymentService); $mollieOrderService = $container->get(MollieOrderService::class); diff --git a/src/Gateway/MolliePaymentGateway.php b/src/Gateway/MolliePaymentGateway.php index 32117df6..c0992203 100644 --- a/src/Gateway/MolliePaymentGateway.php +++ b/src/Gateway/MolliePaymentGateway.php @@ -570,9 +570,8 @@ public function getReturnRedirectUrlForOrder(WC_Order $order): string if ($order_status_cancelled_payments === 'cancelled') { return $this->get_return_url($order); } else { - wc_add_notice(__('You have cancelled your payment. Please complete your order with a different payment method.', 'mollie-payments-for-woocommerce'), "error"); $this->notice->addNotice( - 'notice', + 'error', __( 'You have cancelled your payment. Please complete your order with a different payment method.', 'mollie-payments-for-woocommerce' @@ -591,9 +590,8 @@ public function getReturnRedirectUrlForOrder(WC_Order $order): string && !$payment->isPaid() && !$payment->isAuthorized() ) { - wc_add_notice(__('Your payment was not successful. Please complete your order with a different payment method.', 'mollie-payments-for-woocommerce'), "error"); $this->notice->addNotice( - 'notice', + 'error', __( 'Your payment was not successful. Please complete your order with a different payment method.', 'mollie-payments-for-woocommerce' @@ -606,9 +604,8 @@ public function getReturnRedirectUrlForOrder(WC_Order $order): string $this->paymentMethod->debugGiftcardDetails($payment, $order); } } catch (UnexpectedValueException $exc) { - wc_add_notice(__('Your payment was not successful. Please complete your order with a different payment method.', 'mollie-payments-for-woocommerce'), "error"); $this->notice->addNotice( - 'notice', + 'error', __( 'Your payment was not successful. Please complete your order with a different payment method.', 'mollie-payments-for-woocommerce' diff --git a/src/Notice/FrontendNotice.php b/src/Notice/FrontendNotice.php new file mode 100644 index 00000000..02c59bef --- /dev/null +++ b/src/Notice/FrontendNotice.php @@ -0,0 +1,13 @@ + static function (): AdminNotice { return new AdminNotice(); }, + FrontendNotice::class => static function (): FrontendNotice { + return new FrontendNotice(); + }, ]; } }