#Error after Stripe payment

1 messages · Page 1 of 1 (latest)

manic rain
#

If you're using medusa-payment-stripe in version 1.1.47, can you try with 1.1.45

npm install [email protected]

Be sure to disable also Sripe-Blik in admin dashboard

#

Yeah. But install 1.1.45 because I'm having similar issue on 1.1.47 . Just want to confirm something.

#

It's either that or maybe some race condition between webhook and storefront.

#

hmm. Can you confirm with npm list if it's actually on 1.1.45

#

And you have restarted the medusa backend?

manic rain
#

Can you try by disabling the manual payment provider?

#

No, Payment. I see you already disabled now. There's probably only Stripe there. Earlier you had two

#

so 50% rate. not great not terrible 😉

#

If you go to that order and into payment section do you have Capture option there?

#

Yes, you can Capture it and it will change status to Paid

#

From what I've been told in some countries it's illegal to capture payment if items are not sent.
So it's sort of interminttent state

#

You can create an automatic capture with such subscriber in src/subscribers/AutomaticStripeSubscriber.js

class OrderSubscriber {
  constructor({ orderService, eventBusService }) {
    this.orderService_ = orderService;

    eventBusService.subscribe('order.placed', this.handleAutomaticCapture);
  }

  handleAutomaticCapture = async (data) => {
    const order = await this.orderService_.retrieve(data.id);

    await this.orderService_.capturePayment(order.id);
  };
}

export default OrderSubscriber;
#

Blik and Przelewy24 payments are automaticlly captured anyway (on stripe side). It's mostly the card payments.

#

No, haven't seen this one.

manic rain
#

Can you switch off the webhook and then try?

manic rain
#

Have you tested multiple times? Always 200?

#

Ok I kinda understand what's happening here, had similiar issue when I started with medusa.

#

Webhook is very important in production. Think about when user is in checkout, makes payment and then looses connection. The storefront would not complete the order. That's where webhook comes in. Stripe will ping the webhook about succesful payment and webhook will complete the order.

#

What is happening here is most likely that storefront and webhook are trying to complete the order at the same time

#

I have mitigated the issue by doing some checks on the storefront, like:

  1. Complete payment.
    2.Complete cart on storefront
    3.Errors out so let's fetch the order using the cart.id, maybe webhook completed the order right now.
    -> Webhook did finish the order, so show the user a success page.
  2. It might be that webhook didn't yet finish the order (no order returned), so let's try again by completing the order on the storefront. Success.
  3. I do such back and forth twice as a fail safe.

It's weird, but it works for me 100% so I refuse to touch that code.

#

Because even if you had that 500, the order was created right? Because webhook created it.

#

Yes, you will need to catch that error and do the steps I have pointed out. onPaymentCompleted is the function you're looking for

#

Maybe there's a better way, could be that the typeorm error is also a core transaction bug.

#

That is most likely not the issue. THis is a missing transaction on payment session creation. Your errors out on cart completion.

#

You can add an onError there and try with the steps

manic rain
#

I think my solution will help you. You will need to try with those steps I have pointed out.

#

Yes, there too.

manic rain
#

I don't think it should clear as the onSuccess wouldn't fire.