Changeset 3339885
- Timestamp:
- 08/05/2025 09:16:42 PM (7 months ago)
- Location:
- woocommerce-gateway-gocardless
- Files:
-
- 12 edited
- 1 copied
-
tags/2.9.7 (copied) (copied from woocommerce-gateway-gocardless/trunk)
-
tags/2.9.7/changelog.txt (modified) (1 diff)
-
tags/2.9.7/includes/class-wc-gocardless-api.php (modified) (2 diffs)
-
tags/2.9.7/includes/class-wc-gocardless-gateway-addons.php (modified) (2 diffs)
-
tags/2.9.7/includes/class-wc-gocardless-gateway.php (modified) (1 diff)
-
tags/2.9.7/readme.txt (modified) (2 diffs)
-
tags/2.9.7/woocommerce-gateway-gocardless.php (modified) (3 diffs)
-
trunk/changelog.txt (modified) (1 diff)
-
trunk/includes/class-wc-gocardless-api.php (modified) (2 diffs)
-
trunk/includes/class-wc-gocardless-gateway-addons.php (modified) (2 diffs)
-
trunk/includes/class-wc-gocardless-gateway.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/woocommerce-gateway-gocardless.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woocommerce-gateway-gocardless/tags/2.9.7/changelog.txt
r3321344 r3339885 1 1 *** GoCardless for WooCommerce Changelog *** 2 3 2025-08-05 - version 2.9.7 4 * Add - Improved subscription cancellation by cancelling "Pending Submission" payments and preventing retries on non-cancellable payments. 5 * Fix - Ensure webhook events are handled properly without any issues. 6 * Dev - Bump WordPress minimum supported version to 6.7. 7 * Dev - Bump WooCommerce "tested up to" version 10.1. 8 * Dev - Bump WooCommerce minimum supported version to 9.9. 2 9 3 10 2025-07-02 - version 2.9.6 -
woocommerce-gateway-gocardless/tags/2.9.7/includes/class-wc-gocardless-api.php
r3294262 r3339885 403 403 404 404 /** 405 * Update payment. 406 * 407 * @param string $payment_id Payment ID. 408 * @param array $params Parameters to update payment. 409 * 410 * @return array|WP_Error 411 */ 412 public static function update_payment( $payment_id, $params = array() ) { 413 $args = array( 414 'method' => 'PUT', 415 'body' => wp_json_encode( array( 'payments' => $params ) ), 416 ); 417 418 return self::_request( 'payments/' . $payment_id, $args ); 419 } 420 421 /** 405 422 * Get a single payment from given payment_id. 406 423 * … … 418 435 * @param string $payment_id Payment ID. 419 436 * 420 * @return array 437 * @return array|WP_Error 421 438 */ 422 439 public static function cancel_payment( $payment_id ) { -
woocommerce-gateway-gocardless/tags/2.9.7/includes/class-wc-gocardless-gateway-addons.php
r3239558 r3339885 30 30 add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); 31 31 add_action( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); 32 33 // Cancel in-progress payment on subscription cancellation. 34 add_action( 'woocommerce_subscription_pending-cancel_' . $this->id, array( $this, 'maybe_cancel_subscription_payment' ) ); 35 add_action( 'woocommerce_subscription_cancelled_' . $this->id, array( $this, 'maybe_cancel_subscription_payment' ) ); 32 36 } 33 37 … … 324 328 } 325 329 } 330 331 /** 332 * Cancel the order payment on subscription cancellation. 333 * 334 * If the payment is pending submission, we can cancel it. 335 * Otherwise, update the retry_if_possible to false to avoid the payment being retried (except for paid_out and cancelled payment states). 336 * 337 * @since 2.9.7 338 * 339 * @param WC_Subscription $subscription Subscription object. 340 */ 341 public function maybe_cancel_subscription_payment( $subscription ) { 342 if ( ! $subscription ) { 343 return; 344 } 345 wc_gocardless()->log( sprintf( '%s - Subscription cancelled/Pending cancellation, checking if payment should be cancelled', __METHOD__ ) ); 346 347 $last_order = $subscription->get_last_order( 'all' ); 348 if ( ! $last_order ) { 349 return; 350 } 351 352 $payment_id = $this->get_order_resource( $last_order->get_id(), 'payment', 'id' ); 353 $payment = WC_GoCardless_API::get_payment( $payment_id ); 354 if ( is_wp_error( $payment ) || empty( $payment['payments'] ) ) { 355 wc_gocardless()->log( sprintf( '%s - Failed to retrieve payment.', __METHOD__ ) ); 356 return; 357 } 358 359 $gocardless_status = $payment['payments']['status'] ?? ''; 360 wc_gocardless()->log( sprintf( '%s - GoCardless payment status: %s', __METHOD__, $gocardless_status ) ); 361 362 // If the payment is pending submission, we can cancel it. 363 if ( 'pending_submission' === $gocardless_status ) { 364 $response = WC_GoCardless_API::cancel_payment( $payment_id ); 365 if ( ! is_wp_error( $response ) ) { 366 wc_gocardless()->log( sprintf( '%s - Payment cancelled', __METHOD__ ) ); 367 } else { 368 wc_gocardless()->log( sprintf( '%s - Failed to cancel payment: %s', __METHOD__, $response->get_error_message() ) ); 369 } 370 } elseif ( 371 ! in_array( 372 $gocardless_status, 373 array( 374 'paid_out', 375 'cancelled', 376 ), 377 true 378 ) 379 ) { 380 // We can't cancel the payment, so we update it to not retry if possible to avoid the payment being retried. 381 $response = WC_GoCardless_API::update_payment( $payment_id, array( 'retry_if_possible' => false ) ); 382 if ( ! is_wp_error( $response ) ) { 383 wc_gocardless()->log( sprintf( '%s - Payment updated with retry_if_possible set to false', __METHOD__ ) ); 384 } else { 385 wc_gocardless()->log( sprintf( '%s - Failed to update payment: %s', __METHOD__, $response->get_error_message() ) ); 386 } 387 } 388 } 326 389 } -
woocommerce-gateway-gocardless/tags/2.9.7/includes/class-wc-gocardless-gateway.php
r3321344 r3339885 1633 1633 wc_gocardless()->log( sprintf( '%s - Handling webhook. Payload: %s', __METHOD__, print_r( $payload, true ) ) ); 1634 1634 1635 $args = array( $payload ); 1636 1637 // Process the webhook payload asynchronously. 1638 $action_id = WC()->queue()->schedule_single( 1639 WC()->call_function( 'time' ) + 1, 1640 'woocommerce_gocardless_process_webhook_payload_async', 1641 $args, 1642 'woocommerce-gocardless-webhook' 1643 ); 1644 1645 // If the action is not scheduled, return error to GoCardless, to get a retry. 1646 if ( empty( $action_id ) ) { 1635 $webhook_payload = $payload; 1636 $schedule_failed = false; 1637 1638 /* 1639 * Loop through each event to schedule the action for each event separately. 1640 * This is to avoid the issue where the webhook payload is too large and the action not get scheduled. 1641 * 1642 * @see https://github.com/gocardless/woocommerce-gateway-gocardless/issues/79 1643 */ 1644 foreach ( $payload['events'] as $event ) { 1645 // Update the webhook payload with the current event only. 1646 $webhook_payload['events'] = array( $event ); 1647 1648 // Schedule the action to process the webhook payload asynchronously. 1649 $action_id = WC()->queue()->schedule_single( 1650 time() + 1, 1651 'woocommerce_gocardless_process_webhook_payload_async', 1652 array( $webhook_payload ), 1653 'woocommerce-gocardless-webhook' 1654 ); 1655 1656 // If any action fail to schedule, mark the schedule as failed, and return error to GoCardless, to get a retry. 1657 if ( empty( $action_id ) ) { 1658 $schedule_failed = true; 1659 break; 1660 } 1661 1662 $webhook_payload['events'] = array(); 1663 wc_gocardless()->log( sprintf( '%s - Action scheduled with ID %d, to process webhook.', __METHOD__, $action_id ) ); 1664 } 1665 1666 // Return error to GoCardless, to get a retry. 1667 if ( $schedule_failed ) { 1647 1668 wc_gocardless()->log( sprintf( '%s - Failed to schedule action to process webhook.', __METHOD__ ) ); 1648 1669 header( 'HTTP/1.1 500 Internal Server Error' ); 1649 1670 throw new Exception( esc_html__( 'Failed to schedule action to process webhook.', 'woocommerce-gateway-gocardless' ) ); 1650 1671 } 1651 1652 wc_gocardless()->log( sprintf( '%s - Action scheduled with ID %d, to process webhook.', __METHOD__, $action_id ) );1653 1672 } catch ( Exception $e ) { 1654 1673 wc_gocardless()->log( sprintf( '%s - Error when handling webhook: %s', __METHOD__, $e->getMessage() ) ); -
woocommerce-gateway-gocardless/tags/2.9.7/readme.txt
r3321344 r3339885 3 3 Tags: gocardless, woocommerce, direct debit, instant bank pay 4 4 Tested up to: 6.8 5 Stable tag: 2.9. 65 Stable tag: 2.9.7 6 6 License: GPL-3.0-or-later 7 7 License URI: https://spdx.org/licenses/GPL-3.0-or-later.html … … 140 140 141 141 == Changelog == 142 143 = 2.9.7 - 2025-08-05 = 144 * Add - Improved subscription cancellation by cancelling "Pending Submission" payments and preventing retries on non-cancellable payments. 145 * Fix - Ensure webhook events are handled properly without any issues. 146 * Dev - Bump WordPress minimum supported version to 6.7. 147 * Dev - Bump WooCommerce "tested up to" version 10.1. 148 * Dev - Bump WooCommerce minimum supported version to 9.9. 142 149 143 150 = 2.9.6 - 2025-07-02 = -
woocommerce-gateway-gocardless/tags/2.9.7/woocommerce-gateway-gocardless.php
r3321344 r3339885 4 4 * Plugin URI: https://www.woocommerce.com/products/gocardless/ 5 5 * Description: Extends both WooCommerce and WooCommerce Subscriptions with the GoCardless Payment Gateway. A GoCardless merchant account is required. 6 * Version: 2.9. 67 * Requires at least: 6. 66 * Version: 2.9.7 7 * Requires at least: 6.7 8 8 * Requires PHP: 7.4 9 9 * PHP tested up to: 8.3 … … 13 13 * License URI: https://spdx.org/licenses/GPL-3.0-or-later.html 14 14 * Requires Plugins: woocommerce 15 * WC requires at least: 9. 816 * WC tested up to: 10. 015 * WC requires at least: 9.9 16 * WC tested up to: 10.1 17 17 * 18 18 * Copyright: © 2023-2025 WooCommerce … … 39 39 * @var string 40 40 */ 41 public $version = '2.9. 6'; // WRCS: DEFINED_VERSION.41 public $version = '2.9.7'; // WRCS: DEFINED_VERSION. 42 42 43 43 /** -
woocommerce-gateway-gocardless/trunk/changelog.txt
r3321344 r3339885 1 1 *** GoCardless for WooCommerce Changelog *** 2 3 2025-08-05 - version 2.9.7 4 * Add - Improved subscription cancellation by cancelling "Pending Submission" payments and preventing retries on non-cancellable payments. 5 * Fix - Ensure webhook events are handled properly without any issues. 6 * Dev - Bump WordPress minimum supported version to 6.7. 7 * Dev - Bump WooCommerce "tested up to" version 10.1. 8 * Dev - Bump WooCommerce minimum supported version to 9.9. 2 9 3 10 2025-07-02 - version 2.9.6 -
woocommerce-gateway-gocardless/trunk/includes/class-wc-gocardless-api.php
r3294262 r3339885 403 403 404 404 /** 405 * Update payment. 406 * 407 * @param string $payment_id Payment ID. 408 * @param array $params Parameters to update payment. 409 * 410 * @return array|WP_Error 411 */ 412 public static function update_payment( $payment_id, $params = array() ) { 413 $args = array( 414 'method' => 'PUT', 415 'body' => wp_json_encode( array( 'payments' => $params ) ), 416 ); 417 418 return self::_request( 'payments/' . $payment_id, $args ); 419 } 420 421 /** 405 422 * Get a single payment from given payment_id. 406 423 * … … 418 435 * @param string $payment_id Payment ID. 419 436 * 420 * @return array 437 * @return array|WP_Error 421 438 */ 422 439 public static function cancel_payment( $payment_id ) { -
woocommerce-gateway-gocardless/trunk/includes/class-wc-gocardless-gateway-addons.php
r3239558 r3339885 30 30 add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); 31 31 add_action( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); 32 33 // Cancel in-progress payment on subscription cancellation. 34 add_action( 'woocommerce_subscription_pending-cancel_' . $this->id, array( $this, 'maybe_cancel_subscription_payment' ) ); 35 add_action( 'woocommerce_subscription_cancelled_' . $this->id, array( $this, 'maybe_cancel_subscription_payment' ) ); 32 36 } 33 37 … … 324 328 } 325 329 } 330 331 /** 332 * Cancel the order payment on subscription cancellation. 333 * 334 * If the payment is pending submission, we can cancel it. 335 * Otherwise, update the retry_if_possible to false to avoid the payment being retried (except for paid_out and cancelled payment states). 336 * 337 * @since 2.9.7 338 * 339 * @param WC_Subscription $subscription Subscription object. 340 */ 341 public function maybe_cancel_subscription_payment( $subscription ) { 342 if ( ! $subscription ) { 343 return; 344 } 345 wc_gocardless()->log( sprintf( '%s - Subscription cancelled/Pending cancellation, checking if payment should be cancelled', __METHOD__ ) ); 346 347 $last_order = $subscription->get_last_order( 'all' ); 348 if ( ! $last_order ) { 349 return; 350 } 351 352 $payment_id = $this->get_order_resource( $last_order->get_id(), 'payment', 'id' ); 353 $payment = WC_GoCardless_API::get_payment( $payment_id ); 354 if ( is_wp_error( $payment ) || empty( $payment['payments'] ) ) { 355 wc_gocardless()->log( sprintf( '%s - Failed to retrieve payment.', __METHOD__ ) ); 356 return; 357 } 358 359 $gocardless_status = $payment['payments']['status'] ?? ''; 360 wc_gocardless()->log( sprintf( '%s - GoCardless payment status: %s', __METHOD__, $gocardless_status ) ); 361 362 // If the payment is pending submission, we can cancel it. 363 if ( 'pending_submission' === $gocardless_status ) { 364 $response = WC_GoCardless_API::cancel_payment( $payment_id ); 365 if ( ! is_wp_error( $response ) ) { 366 wc_gocardless()->log( sprintf( '%s - Payment cancelled', __METHOD__ ) ); 367 } else { 368 wc_gocardless()->log( sprintf( '%s - Failed to cancel payment: %s', __METHOD__, $response->get_error_message() ) ); 369 } 370 } elseif ( 371 ! in_array( 372 $gocardless_status, 373 array( 374 'paid_out', 375 'cancelled', 376 ), 377 true 378 ) 379 ) { 380 // We can't cancel the payment, so we update it to not retry if possible to avoid the payment being retried. 381 $response = WC_GoCardless_API::update_payment( $payment_id, array( 'retry_if_possible' => false ) ); 382 if ( ! is_wp_error( $response ) ) { 383 wc_gocardless()->log( sprintf( '%s - Payment updated with retry_if_possible set to false', __METHOD__ ) ); 384 } else { 385 wc_gocardless()->log( sprintf( '%s - Failed to update payment: %s', __METHOD__, $response->get_error_message() ) ); 386 } 387 } 388 } 326 389 } -
woocommerce-gateway-gocardless/trunk/includes/class-wc-gocardless-gateway.php
r3321344 r3339885 1633 1633 wc_gocardless()->log( sprintf( '%s - Handling webhook. Payload: %s', __METHOD__, print_r( $payload, true ) ) ); 1634 1634 1635 $args = array( $payload ); 1636 1637 // Process the webhook payload asynchronously. 1638 $action_id = WC()->queue()->schedule_single( 1639 WC()->call_function( 'time' ) + 1, 1640 'woocommerce_gocardless_process_webhook_payload_async', 1641 $args, 1642 'woocommerce-gocardless-webhook' 1643 ); 1644 1645 // If the action is not scheduled, return error to GoCardless, to get a retry. 1646 if ( empty( $action_id ) ) { 1635 $webhook_payload = $payload; 1636 $schedule_failed = false; 1637 1638 /* 1639 * Loop through each event to schedule the action for each event separately. 1640 * This is to avoid the issue where the webhook payload is too large and the action not get scheduled. 1641 * 1642 * @see https://github.com/gocardless/woocommerce-gateway-gocardless/issues/79 1643 */ 1644 foreach ( $payload['events'] as $event ) { 1645 // Update the webhook payload with the current event only. 1646 $webhook_payload['events'] = array( $event ); 1647 1648 // Schedule the action to process the webhook payload asynchronously. 1649 $action_id = WC()->queue()->schedule_single( 1650 time() + 1, 1651 'woocommerce_gocardless_process_webhook_payload_async', 1652 array( $webhook_payload ), 1653 'woocommerce-gocardless-webhook' 1654 ); 1655 1656 // If any action fail to schedule, mark the schedule as failed, and return error to GoCardless, to get a retry. 1657 if ( empty( $action_id ) ) { 1658 $schedule_failed = true; 1659 break; 1660 } 1661 1662 $webhook_payload['events'] = array(); 1663 wc_gocardless()->log( sprintf( '%s - Action scheduled with ID %d, to process webhook.', __METHOD__, $action_id ) ); 1664 } 1665 1666 // Return error to GoCardless, to get a retry. 1667 if ( $schedule_failed ) { 1647 1668 wc_gocardless()->log( sprintf( '%s - Failed to schedule action to process webhook.', __METHOD__ ) ); 1648 1669 header( 'HTTP/1.1 500 Internal Server Error' ); 1649 1670 throw new Exception( esc_html__( 'Failed to schedule action to process webhook.', 'woocommerce-gateway-gocardless' ) ); 1650 1671 } 1651 1652 wc_gocardless()->log( sprintf( '%s - Action scheduled with ID %d, to process webhook.', __METHOD__, $action_id ) );1653 1672 } catch ( Exception $e ) { 1654 1673 wc_gocardless()->log( sprintf( '%s - Error when handling webhook: %s', __METHOD__, $e->getMessage() ) ); -
woocommerce-gateway-gocardless/trunk/readme.txt
r3321344 r3339885 3 3 Tags: gocardless, woocommerce, direct debit, instant bank pay 4 4 Tested up to: 6.8 5 Stable tag: 2.9. 65 Stable tag: 2.9.7 6 6 License: GPL-3.0-or-later 7 7 License URI: https://spdx.org/licenses/GPL-3.0-or-later.html … … 140 140 141 141 == Changelog == 142 143 = 2.9.7 - 2025-08-05 = 144 * Add - Improved subscription cancellation by cancelling "Pending Submission" payments and preventing retries on non-cancellable payments. 145 * Fix - Ensure webhook events are handled properly without any issues. 146 * Dev - Bump WordPress minimum supported version to 6.7. 147 * Dev - Bump WooCommerce "tested up to" version 10.1. 148 * Dev - Bump WooCommerce minimum supported version to 9.9. 142 149 143 150 = 2.9.6 - 2025-07-02 = -
woocommerce-gateway-gocardless/trunk/woocommerce-gateway-gocardless.php
r3321344 r3339885 4 4 * Plugin URI: https://www.woocommerce.com/products/gocardless/ 5 5 * Description: Extends both WooCommerce and WooCommerce Subscriptions with the GoCardless Payment Gateway. A GoCardless merchant account is required. 6 * Version: 2.9. 67 * Requires at least: 6. 66 * Version: 2.9.7 7 * Requires at least: 6.7 8 8 * Requires PHP: 7.4 9 9 * PHP tested up to: 8.3 … … 13 13 * License URI: https://spdx.org/licenses/GPL-3.0-or-later.html 14 14 * Requires Plugins: woocommerce 15 * WC requires at least: 9. 816 * WC tested up to: 10. 015 * WC requires at least: 9.9 16 * WC tested up to: 10.1 17 17 * 18 18 * Copyright: © 2023-2025 WooCommerce … … 39 39 * @var string 40 40 */ 41 public $version = '2.9. 6'; // WRCS: DEFINED_VERSION.41 public $version = '2.9.7'; // WRCS: DEFINED_VERSION. 42 42 43 43 /**
Note: See TracChangeset
for help on using the changeset viewer.