From 48c30ab3ed43c7cfccb127e05ce58666774a8d42 Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Tue, 7 May 2024 13:22:27 +1000 Subject: [PATCH 1/3] Set order status to failed for testing failed recurring payments. --- includes/class-wc-gateway-dummy.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/class-wc-gateway-dummy.php b/includes/class-wc-gateway-dummy.php index c89d87f..1532255 100644 --- a/includes/class-wc-gateway-dummy.php +++ b/includes/class-wc-gateway-dummy.php @@ -166,8 +166,7 @@ public function process_subscription_payment( $amount, $order ) { if ( 'success' === $payment_result ) { $order->payment_complete(); } else { - $message = __( 'Order payment failed. To make a successful payment using Dummy Payments, please review the gateway settings.', 'woocommerce-gateway-dummy' ); - throw new Exception( $message ); + $order->update_status( 'failed', __( 'Subscription payment failed. To make a successful payment using Dummy Payments, please review the gateway settings.', 'woocommerce-gateway-dummy' ) ); } } } From 1f04d28048efaac09f9d6a020566aa4cbb98b277 Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Fri, 10 May 2024 08:31:48 +1000 Subject: [PATCH 2/3] Use failed status update for one-off and initial subscription payments. --- includes/class-wc-gateway-dummy.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/includes/class-wc-gateway-dummy.php b/includes/class-wc-gateway-dummy.php index 1532255..2ddcd19 100644 --- a/includes/class-wc-gateway-dummy.php +++ b/includes/class-wc-gateway-dummy.php @@ -133,10 +133,9 @@ public function init_form_fields() { public function process_payment( $order_id ) { $payment_result = $this->get_option( 'result' ); + $order = wc_get_order( $order_id ); if ( 'success' === $payment_result ) { - $order = wc_get_order( $order_id ); - $order->payment_complete(); // Remove cart @@ -148,8 +147,7 @@ public function process_payment( $order_id ) { 'redirect' => $this->get_return_url( $order ) ); } else { - $message = __( 'Order payment failed. To make a successful payment using Dummy Payments, please review the gateway settings.', 'woocommerce-gateway-dummy' ); - throw new Exception( $message ); + $order->update_status( 'failed', __( 'Subscription payment failed. To make a successful payment using Dummy Payments, please review the gateway settings.', 'woocommerce-gateway-dummy' ) ); } } From 554d535ec810bb1c09d8b2f29de3650f4f8358f2 Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Mon, 13 May 2024 12:25:31 +1000 Subject: [PATCH 3/3] Throw exception after marking payment failed. --- includes/class-wc-gateway-dummy.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/class-wc-gateway-dummy.php b/includes/class-wc-gateway-dummy.php index 2ddcd19..1ee205c 100644 --- a/includes/class-wc-gateway-dummy.php +++ b/includes/class-wc-gateway-dummy.php @@ -147,7 +147,9 @@ public function process_payment( $order_id ) { 'redirect' => $this->get_return_url( $order ) ); } else { - $order->update_status( 'failed', __( 'Subscription payment failed. To make a successful payment using Dummy Payments, please review the gateway settings.', 'woocommerce-gateway-dummy' ) ); + $message = __( 'Order payment failed. To make a successful payment using Dummy Payments, please review the gateway settings.', 'woocommerce-gateway-dummy' ); + $order->update_status( 'failed', $message ); + throw new Exception( $message ); } }