medusa icon indicating copy to clipboard operation
medusa copied to clipboard

You cannot complete a cart without a payment session.

Open Saadchr opened this issue 1 year ago • 4 comments

Hello,

I am using the default medusa starter. I encountered this issue both in local development in production Sometimes, when the customer places an order, there is an error:

Error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.

Processing cart.updated which has 0 subscribers

172.71.130.184 - - [06/Feb/2024:19:29:52 +0000] "GET /store/regions HTTP/1.1" 200 2315 "-" "Vercel Edge Functions"

You cannot complete a cart without a payment session.

Saadchr avatar Feb 06 '24 19:02 Saadchr

Hi there, I am investigating on probably the same situation and want to add my findings (v1.20.1) with manual payment.

It seems to me the POST call to /store/carts/{cart_id}/payment-sessions is creating payment session DB entries with empty cart id (frequently, not always) and therefore the 'You cannot complete a cart without a payment session' error.

This seems to be some kind of race condition issue, as it happens for a random amount of times while going through the checkout stages (Each stage triggers a new POST call to the payment-sessions endpoint). Once the cart id is set on a payment session, all is going fine.

In my test 7 payment_session rows where created while going through the checkout, while seeing the error @Saadchr describes on the review step. One more browser reload created a payment_session with cart id and so I was able to place the order. image

It is also worth noting, that when ever I attempt to run the POST call from an external http client, the payment_session entry ist created with a cart ID. With the possibility of having race conditions in mind, I applied another delayed call to the UIs CheckoutForm component as a workaround. This one has a 100% success rate of creating payment sessions with proper cart id.

  setTimeout(() => {
    createPaymentSessions(cartId)
  },2000);

donduni avatar Feb 08 '24 14:02 donduni

@donduni Have you found a definitive solution to this probable race condition? Do you think giving a very small value the the ms argument would be fine ? setTimeout(() => { createPaymentSessions(cartId) },1);

Saadchr avatar Feb 19 '24 22:02 Saadchr

Hi, Any update concerning this critical issue? I want to deploy my store to the public in a few days and as cash on delivery is my unique payment method, I am afraid running on same issues.

Saadchr avatar Mar 11 '24 19:03 Saadchr

Encountered the same issue. Had to manually do a db query each time to set the cart_id on the payment_session table right before confirming payment. This way, the cart_id is present always before. This is a workaround and the issue should be fixed

kevinrobert3 avatar Apr 21 '24 07:04 kevinrobert3