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;
}