Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions includes/Framework/PaymentGateway/Payment_Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 (
! $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(
Expand Down
Loading