Skip to content

Commit

Permalink
Add order note if payment tokens are missing or invalid on subscripti…
Browse files Browse the repository at this point in the history
…on orders (#10438)
  • Loading branch information
zmaglica authored Feb 26, 2025
1 parent 8724369 commit 319d34c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Add an order note when a recurring payment fails or when updating the payment method fails due to a missing or invalid payment token.
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ public function scheduled_subscription_payment( $amount, $renewal_order ) {

$token = $this->get_payment_token( $renewal_order );
if ( is_null( $token ) && ! WC_Payments::is_network_saved_cards_enabled() ) {
$renewal_order->add_order_note( 'Subscription renewal failed: No saved payment method found.' );
Logger::error( 'There is no saved payment token for order #' . $renewal_order->get_id() );
// TODO: Update to use Order_Service->mark_payment_failed.
$renewal_order->update_status( 'failed' );
Expand Down Expand Up @@ -380,6 +381,7 @@ public function scheduled_subscription_payment( $amount, $renewal_order ) {
public function update_failing_payment_method( $subscription, $renewal_order ) {
$renewal_token = $this->get_payment_token( $renewal_order );
if ( is_null( $renewal_token ) ) {
$renewal_order->add_order_note( 'Unable to update subscription payment method: No valid payment token or method found.' );
Logger::error( 'Failing subscription could not be updated: there is no saved payment token for order #' . $renewal_order->get_id() );
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,15 @@ public function test_update_failing_payment_method_copies_last_method_from_renew

public function test_update_failing_payment_method_does_not_copy_method_if_renewal_has_no_method() {
$subscription = WC_Helper_Order::create_order( self::USER_ID );
$renewal_order = WC_Helper_Order::create_order( self::USER_ID );
$renewal_order = $this->createMock( WC_Order::class );

$renewal_order->expects( $this->once() )
->method( 'get_payment_tokens' )
->willReturn( [] );

$renewal_order->expects( $this->once() )
->method( 'add_order_note' )
->with( 'Unable to update subscription payment method: No valid payment token or method found.' );

$this->wcpay_gateway->update_failing_payment_method( $subscription, $renewal_order );

Expand Down

0 comments on commit 319d34c

Please sign in to comment.