#Stripe test mode does not work with customer twice

44 messages · Page 1 of 1 (latest)

signal kelp
#

Hello, my stripe integration works fine, but if i want to complete my cart with the same customer email (Guest) twice, the cart does not complete. I see that the webhooks got fetched, also in the backend there is no error.
I currently use stripe in the test mode, i think i read somewhere that this causes such a problem?

oak moat
#

No, it doesn't cause problems. And you'll need to post some logs, errors.

signal kelp
#

@oak moat there are no errors, all went fine, also the payment i can see in the stripe dashboard, but it's not captured and i think the webhook is not triggered because in my medusa backend i can't see any order

oak moat
#

You need to show the whole cart response.

signal kelp
#

i checked the stripe logs again and there is no email in the response body of /customer

#

@oak moat sry what do you mean with the whole cart response?

oak moat
#

The whole affected cart

signal kelp
#

sry didn't see that the /carts/complete is not on the screen shot

#

@oak moat

oak moat
#

I mean the whole cart in json. Please don't ping.

signal kelp
oak moat
#

Yes, you need to take care of the email. It's not there and the customer_id is null

#

There's not even a payment_session on that cart

signal kelp
#

alright ... but what's not clear for me is why it is there when i update the cart with that email for the first time?

oak moat
#

I don't know, you need to check how you're updating the cart.

signal kelp
#

sry i sent the wrong json yesterday, this is my actual response:

#

and this is the response of the cart completion:
there the email is set, but type is "cart" and not "order"

oak moat
#

It's a different cart

signal kelp
#

yes i know sry it is, because i did it twice, but nevertheless the response show that there is an email in it

#

i always get two payments in stripe, if i get the card + email it works and i get an order in the medusa backend but if it is the card + customerID it does not work

oak moat
#

I still don't understand

#

You need to show the cart that fails

#

And the payment in stripe that you think went for this cart

#

Because you're posting multiple things and I don't know what to look at

#

Also how are you confirming the payment? Show the handler

signal kelp
#

you're totally right, i'm communicating completely confusing - sry for this!
this is the payment in stripe and the response of the cart completion - this failed and i never got any order in my medusa backend

this is my code in the frontend:

const processPayment = async () => {
    const {error, paymentIntent} = await stripe.value.confirmCardPayment(clientSecret.value, {
      payment_method: {
        card: paymentElement.value,
        billing_details: {
          name: 'felix h',
          email: '[email protected]',
          phone: '',
          address: {
            city: 'address',
            country: 'at',
            line1: 'some address',
            line2: '',
            postal_code: '1234'
          }
        }
      }
    });

    console.log(error, 'there is some stripe error');
    console.log(paymentIntent, 'this is the stripe payment ident');

    const client = useMedusaClient();
    const backendData = useBackendDataStore();

    if (!backendData.cart) {
      return;
    }
    console.log(backendData.cart, 'cart');
    const completeResponse = await client.carts.complete(backendData.cart.id);
    console.log(completeResponse, 'response of cart complete');

    console.log('payment done');
```
oak moat
#

So this is not React?

signal kelp
#

nop, it's nuxt

#

sry for the poor coding style - just my code for testing, want to refactor it afterwards

oak moat
#

First thing I would sugguest is using PaymentElement from stripe instead of the legacy Elements. But this isn't the issue.

#

Where does clientSecret.value come from?

signal kelp
#
  onMounted(async () => {
    await setUpStripe();
  });

  const setUpStripe = async () => {
    // if (!process.env.STRIPE_PUBLISHABLE_KEY) {
    //   return;
    // }
    stripe.value = await loadStripe('pk_test_***');
    if (!stripe) {
      return;
    }
    const client = useMedusaClient();
    const backendData = useBackendDataStore();

    if (!backendData.cart) {
      console.warn('no cart therefore no payment possible');
      return;
    }
    const newCart = await client.carts.createPaymentSessions(backendData.cart.id);
    const isStripeAvailable = newCart.cart.payment_sessions?.some(
        (session) => (
            session.provider_id === "stripe"
        )
    );
    if (!isStripeAvailable) {
      return;
    }
    var secondCart = await client.carts.setPaymentSession(newCart.cart.id, {
      provider_id: "stripe"
    });
    clientSecret.value = secondCart.cart.payment_session?.data.client_secret as string;
    const elements = stripe.value.elements({clientSecret: clientSecret.value});
    paymentElement.value = elements.create('card');
    if (!paymentElement.value) {
      return;
    }
    paymentElement.value.mount('#payment-element');

    // just add a sample customer REFACTOR NEEDED!!
    const thirdCart = await client.carts.update(backendData.cart.id, {email: '[email protected]'});
    console.log(thirdCart, 'cart when init');
  };

i get it in my stripe set up function

oak moat
#

Wow, why there are two, three carts

signal kelp
#

as i said really sorry for my coding style here ... but nevertheless this shouldn't be the problem

#

i just tried around a few things, that's why i have multiple variables for the cart

oak moat
#

How am I supposed to debug this? 🙂

#

How are you sure that backendData.cart.id === newCart.cart.id

signal kelp
#

yes that's completely stupid from my side an i really have to refactor it - but this i already have debugged it and it's the same cart.id

oak moat
#

I don't know, is there some strict mode like in React that runs code twice?

signal kelp
#

no not really

#

maybe i should first refactor it, right?

i always get 2 payments, one with the email and one with the customer id - this shouldn't be the case right?

oak moat
#

Create payment sessions after setting email