Skip to content

Commit

Permalink
Fix Cash App Pay reuse of tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrosa committed Jul 10, 2024
1 parent 877e803 commit 72a6be7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,14 @@ private function process_payment_with_deferred_intent( int $order_id ) {

// Create a payment intent, or update an existing one associated with the order.
$payment_intent = $this->process_payment_intent_for_order( $order, $payment_information );
} elseif ( $payment_information['is_using_saved_payment_method'] && 'cashapp' === $selected_payment_type ) {
// If the payment method is Cash App Pay and the order has no cost, mark the order as paid.
$order->payment_complete();

return [
'result' => 'success',
'redirect' => '',
];
} else {
$payment_intent = $this->process_setup_intent_for_order( $order, $payment_information );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,6 @@ public function get_retrievable_type() {
return $this->get_id();
}

/**
* Determines whether Cash App Pay is enabled at checkout.
*
* @param int $order_id The order ID.
* @param string $account_domestic_currency The account's default currency.
*
* @return bool Whether Cash App Pay is enabled at checkout.
*/
public function is_enabled_at_checkout( $order_id = null, $account_domestic_currency = null ) {
/**
* Cash App Pay is incapable of processing zero amount payments with saved payment methods.
*
* This is because setup intents with a saved payment method (token) fail. While we wait for a solution to this issue, we
* disable Cash App Pay for zero amount orders.
*/
if ( ! is_add_payment_method_page() && $this->get_current_order_amount() <= 0 ) {
return false;
}

return parent::is_enabled_at_checkout( $order_id, $account_domestic_currency );
}

/**
* Creates a Cash App Pay payment token for the customer.
*
Expand Down Expand Up @@ -130,10 +108,10 @@ public function order_received_text_for_wallet_failure( $text, $order ) {
$redirect_status = wc_clean( wp_unslash( $_GET['redirect_status'] ) );
}
if ( $order && $this->id === $order->get_payment_method() && 'failed' === $redirect_status ) {
$text = '<p class="woocommerce-error">';
$text = '<p class="woocommerce-error">';
$text .= esc_html( 'Unfortunately your order cannot be processed as the payment method has declined your transaction. Please attempt your purchase again.' );
$text .= '</p>';
$text .= '<p class="woocommerce-notice woocommerce-notice--error woocommerce-thankyou-order-failed-actions">';
$text .= '</p>';
$text .= '<p class="woocommerce-notice woocommerce-notice--error woocommerce-thankyou-order-failed-actions">';
$text .= '<a href="' . esc_url( $order->get_checkout_payment_url() ) . '" class="button pay">' . esc_html( 'Pay' ) . '</a>';
if ( is_user_logged_in() ) {
$text .= '<a href="' . esc_url( wc_get_page_permalink( 'myaccount' ) ) . '" class="button pay">' . esc_html( 'My account' ) . '</a>';
Expand Down

0 comments on commit 72a6be7

Please sign in to comment.