Skip to content

Commit 319d34c

Browse files
authored
Add order note if payment tokens are missing or invalid on subscription orders (#10438)
1 parent 8724369 commit 319d34c

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fix
3+
4+
Add an order note when a recurring payment fails or when updating the payment method fails due to a missing or invalid payment token.

includes/compat/subscriptions/trait-wc-payment-gateway-wcpay-subscriptions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ public function scheduled_subscription_payment( $amount, $renewal_order ) {
326326

327327
$token = $this->get_payment_token( $renewal_order );
328328
if ( is_null( $token ) && ! WC_Payments::is_network_saved_cards_enabled() ) {
329+
$renewal_order->add_order_note( 'Subscription renewal failed: No saved payment method found.' );
329330
Logger::error( 'There is no saved payment token for order #' . $renewal_order->get_id() );
330331
// TODO: Update to use Order_Service->mark_payment_failed.
331332
$renewal_order->update_status( 'failed' );
@@ -380,6 +381,7 @@ public function scheduled_subscription_payment( $amount, $renewal_order ) {
380381
public function update_failing_payment_method( $subscription, $renewal_order ) {
381382
$renewal_token = $this->get_payment_token( $renewal_order );
382383
if ( is_null( $renewal_token ) ) {
384+
$renewal_order->add_order_note( 'Unable to update subscription payment method: No valid payment token or method found.' );
383385
Logger::error( 'Failing subscription could not be updated: there is no saved payment token for order #' . $renewal_order->get_id() );
384386
return;
385387
}

tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,15 @@ public function test_update_failing_payment_method_copies_last_method_from_renew
265265

266266
public function test_update_failing_payment_method_does_not_copy_method_if_renewal_has_no_method() {
267267
$subscription = WC_Helper_Order::create_order( self::USER_ID );
268-
$renewal_order = WC_Helper_Order::create_order( self::USER_ID );
268+
$renewal_order = $this->createMock( WC_Order::class );
269+
270+
$renewal_order->expects( $this->once() )
271+
->method( 'get_payment_tokens' )
272+
->willReturn( [] );
273+
274+
$renewal_order->expects( $this->once() )
275+
->method( 'add_order_note' )
276+
->with( 'Unable to update subscription payment method: No valid payment token or method found.' );
269277

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

0 commit comments

Comments
 (0)