0

I am facing an error in Drupal 9 Stripe module. After installing the module and setting the private and public keys, I visited the /admin/commerce/orders/84/payments/add page, and selected my newly created 'test stripe payment' as payment gateway. Then, I selected one of the payment methods that I've added from /user/18/payment-methods (Add new payment method). This redirected me to the Add payment page where there is an Amount field and two radio buttons (Authorize only and Authorize and capture) and an Add payment button. When I click on this button, the site crashes with the following error.

Error : Call to a member function getRemoteId() on null dans Drupal\commerce_stripe\Plugin\Commerce\PaymentGateway\Stripe->createPaymentIntent() (/home/mywebsite/www/web/modules/contrib/commerce_stripe/src/Plugin/Commerce/PaymentGateway/Stripe.php line 430)

The line causing the error belongs to this function. Does it mean $payment_method is null? Do you have any idea on what might be causing this error?

/**
  * {@inheritdoc}
  */
public function createPaymentIntent(OrderInterface $order, $capture = TRUE) {
  /** @var \Drupal\commerce_payment\Entity\PaymentMethodInterface $payment_method */
  $payment_method = $order->get('payment_method')->entity;

  // Line 430
  $payment_method_remote_id = $payment_method->getRemoteId();
  $customer_remote_id = $this->getRemoteCustomerId($order->getCustomer());

  $amount = $this->toMinorUnits($order->getTotalPrice());
  $order_id = $order->id();
  $capture_method = $capture ? 'automatic' : 'manual';
  $intent_array = [
    'amount' => $amount,
    'currency' => strtolower($order->getTotalPrice()->getCurrencyCode()),
    'payment_method_types' => ['card'],
    'metadata' => [
      'order_id' => $order_id,
      'store_id' => $order->getStoreId(),
    ],
    'payment_method' => $payment_method_remote_id,
    'capture_method' => $capture_method,
  ];
  if (!empty($customer_remote_id)) {
    $intent_array['customer'] = $customer_remote_id;
  }
  try {
    $intent = \Stripe\PaymentIntent::create($intent_array);
    $order->setData('stripe_intent', $intent->id)->save();
  }
  catch (\Stripe\Exception\ApiErrorException $e) {
    ErrorHelper::handleException($e);
  }
  return $intent;
}
3
  • 1
    It looks like you are using Commerce Stripe, not Stripe. Please link to the module you are using so that your question is understandable. Commented Mar 6, 2021 at 8:07
  • Hello , thank you for your comment @PatrickKenny , I have installed all of these : Stripe, Stripe examples, Commerce Stripe, Commerce Stripe - payment request button and I set the oublic and preivate keys for stripe here /admin/config/stripe.
    – jane
    Commented Mar 6, 2021 at 8:23
  • 1
    You don't need both the Stripe and the Commerce Stripe modules; you should pick one or the other because they do similar things. Commented Mar 6, 2021 at 8:27

2 Answers 2

1

Commerce Stripe is a bit of a mess at the moment. There are lots of issues that need to be fixed as you can see in the project issue queue.

You are probably experiencing the bug described on Stripe\PaymentIntent instance has invalid ID, but there is a longer discussion about how to handle this at [meta] SCA, the Stripe Review pane and recurring payments.

Basically, the issue is that Commerce Stripe does not generate a payment ID unless you go through the review pane first. That means that if you configure a standard Commerce checkout flow and go through that flow (login -> cart -> checkout, etc.), then the module will probably work. If not, you will spend hours searching the issue queue to try to debug the module.

Source: Have spent several frustrated hours over the past couple years with Commerce Stripe.

If it helps, I'm currently using the following patches just to get the module to work on my site:

    "drupal/commerce_stripe": {
        "do not load stripe library on every page": "https://www.drupal.org/files/issues/2020-02-03/3083393-21.patch",
        "skip review step by autosubmit": "https://www.drupal.org/files/issues/2020-09-16/commerce_stripe-3171411-2.patch",
        "fix 1112 errors https://www.drupal.org/project/commerce_stripe/issues/3177168": "https://www.drupal.org/files/issues/2020-10-16/3177168-2_commerce_stripe-fix_address_errors.patch",
        "fix TrustedCallbackInterface warning https://www.drupal.org/project/commerce_stripe/issues/3168822": "https://www.drupal.org/files/issues/2020-10-09/PaymentMethodAddForm%20needs%20to%20implement%20TrustedCallbackInterface%20for%20Drupal%209-3168822-14.patch"
    },
8
  • thank you so much for this detailled answer ! can you give me a link or screenshot just to know how can i configure and set a new flow ?? and if I desactivate commerce stripe and keep stripe only, could that solve the issue ?
    – jane
    Commented Mar 6, 2021 at 8:32
  • I have two workflows here : /admin/commerce/config/checkout-flows , Commerce Stripe - payment request button and a default one . so i should create a third one ? if yes how to set it as default?
    – jane
    Commented Mar 6, 2021 at 8:34
  • I tried to create a new worklfow they let me choose between two plugins Multistep - Default or Commerce Stripe payment request button Flow . If i choose the first one , i desactivated the review steps but still have same prob
    – jane
    Commented Mar 6, 2021 at 8:37
  • @jane Commerce Checkout flow docs Commented Mar 6, 2021 at 8:40
  • I went to this link and created a new workflow with everything but the review step. Then i went to configure the default order type and I selected the checkout flow that i created but there is another field which is workflow, that can be default, fulfillment with validation .. I tried them but nothing works.
    – jane
    Commented Mar 6, 2021 at 8:53
0

I had the same issue and struggle to know what actions go on what steps. These posts helped but had a lot of trial and error left to do. I thought I would post my flow for reference for others. Please note that a couple actions are custom modules that I built: (Terms and COnditions, and Need Help)

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.