I recently upgraded Magento from 2.3.4 to 2.4.6 and as a result updated stripe/stripe-payments
from 2.9.5 to 3.4.0.
Previously I was able to set up a quote to place an order programmatically as follows:
const PAYMENT_METHOD = 'stripe_payments';
//...
$quote = $this->cartFactory->create();
//... other quote setup
$quote->getShippingAddress()->setCollectShippingRates(true)->setShippingMethod(self::SHIPPING_METHOD);
$quote->setPaymentMethod(self::PAYMENT_METHOD);
$quote->setInventoryProcessed(false);
$this->cartRepository->save($quote);
$customerId = (int)$customer->getId();
$stripeCustomer = $this->stripeCustomerRepository->getByMagentoCustomerId($customerId);
if (empty($stripeCustomer->getId())) {
throw new BadPaymentException(__('Stripe customer is not found. Customer id: %1', $customerId));
}
$this->sessionQuote->setCustomerId($customerId);
$cards = $stripeCustomer->getCustomerCards() ?? [];
$savedCard = reset($cards);
if (!$savedCard) {
throw new BadPaymentException(__('Saved card is not found. Customer id: %1', $customerId));
}
$savedCardData = $savedCard->id . ':' . $savedCard->brand . ':' . $savedCard->last4;
$quote->getPayment()->addData([
'method' => self::PAYMENT_METHOD,
'cc_saved' => $savedCardData
]);
$this->cartRepository->save($quote);
However not when I place the order I get an error from Stripe:
[2024-10-05T22:51:10.249744+00:00] main.CRITICAL: MagentoFrameworkExceptionCouldNotSaveException: Cannot place order because a payment method was not provided. in /vendor/stripe/module-payments/Helper/Generic.php:949
Stack trace:
#0 /vendor/stripe/module-payments/Plugin/Sales/Model/Service/OrderService.php(57): StripeIntegrationPaymentsHelperGeneric->dieWithError('Cannot place or...', Object(MagentoFrameworkExceptionCouldNotSaveException))
#1 /vendor/magento/framework/Interception/Interceptor.php(135): StripeIntegrationPaymentsPluginSalesModelServiceOrderService->aroundPlace(Object(MagentoSalesModelServiceOrderServiceInterceptor), Object(Closure), Object(MagentoSalesModelOrderInterceptor))
#2 /vendor/magento/module-inventory-sales/Plugin/Sales/OrderManagement/AppendReservationsAfterOrderPlacementPlugin.php(166): MagentoSalesModelServiceOrderServiceInterceptor->MagentoFrameworkInterception{closure}(Object(MagentoSalesModelOrderInterceptor))
#3 /vendor/magento/module-inventory-sales/Plugin/Sales/OrderManagement/AppendReservationsAfterOrderPlacementPlugin.php(141): MagentoInventorySalesPluginSalesOrderManagementAppendReservationsAfterOrderPlacementPlugin->createOrder(Object(Closure), Object(MagentoSalesModelOrderInterceptor), Array, Object(MagentoInventorySalesModelSalesChannel), Object(MagentoInventorySalesApiApiDataSalesEventExtension))
#4 /vendor/magento/framework/Interception/Interceptor.php(135): MagentoInventorySalesPluginSalesOrderManagementAppendReservationsAfterOrderPlacementPlugin->aroundPlace(Object(MagentoSalesModelServiceOrderServiceInterceptor), Object(Closure), Object(MagentoSalesModelOrderInterceptor))
#5 /vendor/magento/framework/Interception/Interceptor.php(153): MagentoSalesModelServiceOrderServiceInterceptor->MagentoFrameworkInterception{closure}(Object(MagentoSalesModelOrderInterceptor))
...
I’m struggling to find any documentation. Am I setting the payment method incorrectly?