From 86c4ab39237e9decc2a92da3dafc574f471455cf Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Mon, 1 Dec 2025 18:37:14 +0530 Subject: [PATCH 1/2] Skip marking the order as 'On Hold' when saving the card fails after a successful charge. --- .../Framework/PaymentGateway/Payment_Gateway.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/includes/Framework/PaymentGateway/Payment_Gateway.php b/includes/Framework/PaymentGateway/Payment_Gateway.php index 1651c02f..3afbb8c0 100644 --- a/includes/Framework/PaymentGateway/Payment_Gateway.php +++ b/includes/Framework/PaymentGateway/Payment_Gateway.php @@ -2094,8 +2094,18 @@ protected function maybe_tokenize( $response, $order ) { $order = $this->get_payment_tokens_handler()->create_token( $order, $response ); } catch ( \Exception $e ) { - // handle the case of a "tokenize-after-sale" request failing by marking the order as on-hold with an explanatory note - if ( ! $response->transaction_held() && ! ( $this->supports( self::FEATURE_CREDIT_CARD_AUTHORIZATION ) && $this->perform_credit_card_authorization( $order ) ) ) { + /* + * Handle the request failing by marking the order as on-hold with an explanatory note + * + * Exclude the tokenize_after_sale() case, to avoid marking the order as on-hold when tokenization is done after sale. + * This is for handling the edge case where Square successfully charge for the order, but failed to tokenize/save the same card. + * @see https://linear.app/a8c/issue/SQUARE-208/store-then-charge-cards + */ + if ( + ! $response->transaction_held() && + ! ( $this->supports( self::FEATURE_CREDIT_CARD_AUTHORIZATION ) && $this->perform_credit_card_authorization( $order ) ) && + ! $this->tokenize_after_sale() + ) { // transaction has already been successful, but we've encountered an issue with the post-tokenization, add an order note to that effect and continue on $message = sprintf( From c24f324abcf605083316506a15425495dd2ca1f7 Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Mon, 1 Dec 2025 19:01:00 +0530 Subject: [PATCH 2/2] Apply doc comment update suggestion. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- includes/Framework/PaymentGateway/Payment_Gateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Framework/PaymentGateway/Payment_Gateway.php b/includes/Framework/PaymentGateway/Payment_Gateway.php index 3afbb8c0..721d2173 100644 --- a/includes/Framework/PaymentGateway/Payment_Gateway.php +++ b/includes/Framework/PaymentGateway/Payment_Gateway.php @@ -2098,7 +2098,7 @@ protected function maybe_tokenize( $response, $order ) { * Handle the request failing by marking the order as on-hold with an explanatory note * * Exclude the tokenize_after_sale() case, to avoid marking the order as on-hold when tokenization is done after sale. - * This is for handling the edge case where Square successfully charge for the order, but failed to tokenize/save the same card. + * This is for handling the edge case where Square successfully charged for the order, but failed to tokenize/save the same card. * @see https://linear.app/a8c/issue/SQUARE-208/store-then-charge-cards */ if (