Order payment method removed when canceling from PayPal

Created on 8 June 2016, over 9 years ago
Updated 18 August 2025, about 2 months ago

When using the PayPal's Express Checkout payment method, if the user cancels the payment from the PayPal website, his order's payment method is removed:

  // Display a message indicating the customer initiatied cancellation.
  drupal_set_message(t('You have canceled checkout at PayPal but may resume the checkout process here when you are ready.'));

  // Remove the payment information from the order data array.
  $flow = $order->data['commerce_paypal_ec']['flow'];
  unset($order->data['commerce_paypal_ec']);
  unset($order->data['payment_method']);

After canceling, the user is redirected to the Drupal commerce review Checkout pane, and can then confirm his order without any payment method.
The fact that it is possible to complete an order without a valid payment method is indeed a Drupal Commerce issue, but the PayPal EC module should not remove the payment method in the first place.

Attached patch moves theses unsets to the express flow...

  // Whether the order was executed through the Express checkout button.
  $flow = $order->data['commerce_paypal_ec']['flow'];

  // If the customer initially redirected to PayPal from the cart form...
  if ($flow == 'ec') {
    // Remove the payment information from the order data array.
    unset($order->data['commerce_paypal_ec']);
    unset($order->data['payment_method']);
    // Send them back to the shopping cart page instead of the previous page in
    // the checkout process.
    commerce_order_status_update($order, 'cart', FALSE, NULL, t('Customer canceled Express Checkout at PayPal.'));
    drupal_goto('cart');
  }
πŸ› Bug report
Status

Closed: outdated

Version

2.0

Component

PayPal EC

Created by

πŸ‡«πŸ‡·France adrien.felipe

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024