After some debugging (see comments and original post below) I've found that Paypal Checkout strongly depends on the "Review" checkout pane being active and placed on the "Review" step.

In other words, unlike other configurations (i.e, Express Checkout), the "Review" step/pane cannot be skipped.

The lack of documentation / logged information makes it more difficult to find out this configuration dependency.

My proposed solution is to either document this need (via docs or logging messages) or get rid of this need (feature request).

Hello;

I've been trying to make Paypal Checkout work to no avail.

I tested both on my localhost and full-fledged servers, with https enabled.
I tested both live and sandbox modes.
I tested alpha and dev versions of the module.

I create a Paypal Gateway and introduce my api key and secret. It connexts succesfully.

When trying to pay an order, I get an error and the following logs:

(commerce_paypal) Client error: `PATCH https://api.paypal.com/v2/checkout/orders/` resulted in a `404 Not Found` response
(commerce_payment) Could not retrieve the order from PayPal with the following remote_id: .

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

idiaz.roncero created an issue. See original summary.

jsacksick’s picture

It looks like the remote_Id we get from PayPal wasn't stored in the payment method remote_id field... Maybe something wrong happened when creating/approving the order?

Could you try to debug CheckoutController::onCreate or CheckoutController::onApprove? See if it enters there... And also check if you have other info in the logs?

idiaz.roncero’s picture

Title: Paypal Checkout not working » Paypal Checkout not working on commerce_license product types/orders
Category: Support request » Bug report

Hello,

Found out the following:

- There are no other info on the logs.
- I had this patch for direct checkout (no cart). Disabled it, it is still not working.
- The product i'm adding to the order uses commerce_license to sell a role, and sets a different type of checkout flow, line item and order. Tried to add a "default" product (with a default line item, and a default order type, and a default checkout flow), andit works.

So, this is something related to commerce_license module. Good to know.

I'll continue debugging this but in the meantime i'll update the title. It might help people with the same problem.

idiaz.roncero’s picture

Issue summary: View changes
idiaz.roncero’s picture

Ok, I finally found the issue:

The review pane

My "commerce_license" product checkout flow wasn't featuring the "Review" pane - I choose not to show it to shorten the process.

This configuration worked when using Paypal Express Checkout, but it fails on Paypal Checkout.

To add confusion, it was failing silently (maybe because this checkout flow was defined before the new "Paypal Checkout" gateway was added to the module). So, this module configuration requirement wasn't either explicited nor threw any error / log / message.

Proposed improvements:
- Document the need to have a review checkout pane.
- Log a message on the watchdog / error on screen when review pane is not available and Paypal Checkout is active.
- Or... make PayPal Checkout usable without the review pane.

idiaz.roncero’s picture

Title: Paypal Checkout not working on commerce_license product types/orders » Paypal Checkout not working without "Review" pane active
Category: Bug report » Feature request
Priority: Major » Minor

Changed category, title and priority of issue.

idiaz.roncero’s picture

Issue summary: View changes
idiaz.roncero’s picture

Issue summary: View changes
jsacksick’s picture

The proposed improvements sound good, feel free to send patches / edit the documentation page (I'd be more than happy to review).

The reason why the Smart payment buttons are shown on the review page is that it's hard to show them directly from the PaymentInformation pane for various reasons:

  1. If PayPal Checkout is the only option available, the option isn't even shown in Checkout (See #2907504: Display payment method in the CheckoutPane Payment informations even if only single payment gateway available).
  2. It'd be confusing in terms of UX to show payment logos below the radio buttons.
  3. The checkout panes at this point are not yet validated/saved meaning the shipping/promotions might not be applied yet (Which means we wouldn't send the correct data to PayPal.

Or... make PayPal Checkout usable without the review pane.

It is usable... It just needs some custom code, if you need to adapt it to your custom flow.

The only thing you'd have to do is something like the following:

    $form['paypal_smart_payment_buttons'] = [
      '#type' => 'commerce_paypal_smart_payment_buttons',
      '#commit' => FALSE,
      '#order' => $order,
      '#payment_gateway' => $payment_gateway,
      '#weight' => 100,
    ];
jsacksick’s picture

FYI we have a documentation page that needs to be updated to describe the 2 different flows (i.e the "shortcut" flow where you initiate the payment from the cart page, and the "mark" flow, when PayPal is being used just like another regular payment gateway).

See https://www.drupal.org/node/3042053.

jsacksick’s picture

bojanz’s picture

If we define the buttons in an offsite-form as well, then anyone without a Review step would still get the PayPal buttons on the separate Payment step. It's bad UX, and I don't know why anyone would do it (VS just having a Review step), but it's better than nothing.

joelseguin’s picture

As per #10, I can't seem to get the "Mark flow" working. No issues with the "Shortcut flow" though.

Maybe someone can elaborate a bit more on what is needed for the "Mark flow" to work properly. I've made sure to make use of the Review step.

I'm also thinking that the "Shortcut flow" is an interesting idea. It seems to work well, but I'm finding it a little confusing that the user has two options. I wonder if we could just offer the user with one option: the "Shortcut flow" if desired by a site builder?

jsacksick’s picture

Status: Active » Closed (outdated)

As suggested by Bojan in #12, we actually already provide an offsite form in the event no "review" step is present, so I believe this issue is now outdated.

brooke_heaton’s picture

I'm having the same issue with a checkout process that involves only 'order_information' and 'payment' steps, but no review step. The information in #12 does not appear to be correct. I simply see an error and no offsite form. The error is a `commerce_payment` error of:

Cannot create the payment without the PayPal order ID.

brooke_heaton’s picture

To clarify #9 as a solution is not entirely accurate and may simply be out of date. I'm using this in a form_alter successfully.

$cart_provider = \Drupal::service('commerce_cart.cart_provider');
$carts = $cart_provider->getCarts();
if($carts) {
$order = array_shift($carts); // This works if you assume one cart
$payment_gateway_storage = \Drupal::service('entity_type.manager')->getStorage('commerce_payment_gateway');
$paypal_payment_gateway = $payment_gateway_storage->load('machine_name_of_your_paypal_gateway');
$builder = \Drupal::service('commerce_paypal.smart_payment_buttons_builder');
$form["payment_information"]['paypal_smart_payment_buttons'] = $builder->build($order, $paypal_payment_gateway, FALSE);
}
poker10’s picture

Status: Closed (outdated) » Active

I don't think this is outdated. PayPal Checkout does not seems to work without review step in the default configuration.

Cannot create the payment without the PayPal order ID.

@brooke_heaton Can you please elaborate, which form you are altering in the mentioned form_alter? Thanks!

Edit: Just to be sure, I mean the "mark" flow, not the payment buttons (shortcut). It is a bit unfortunate, that this is not working, because Express checkout is deprecated and therefore there is no working offsite option in 8.x version of this modules without the review step. But I will understand if this is "won't fix".