#When i use the stripe payment element it automatically completes cart

6 messages · Page 1 of 1 (latest)

worthy sedge
#

Firstly, all works fine, but i want to use the payment element from stripe instead of the card element.
the payment element return to a page and does not run the script afterwards, which is fine for me. But there is the cartComplete function which then doesn't get called. But even when it's not called i see the payment in stripe and the order in the medusa backend - so all works perfectly fine.
Since there is no documentation for it, i am not sure if this is on purpose.
This is my code of the stripe element.

  paymentElement.value = elements.create('payment');
  paymentElement.value.mount('#payment-element');

  const {error} = await stripe.value.confirmPayment({
      elements,
      confirmParams: {
        return_url: `${window.location.origin}/payment-complete`
      }
  });

  // this is not needed and i don't know why
  // await client.carts.complete(cartId);
stuck spruce
#

When you're using external payment gateway then yes. But for card payments, even through Payment Element, it should not leave the page

#
  const {error} = await stripe.value.confirmPayment({
      elements,
      redirect: 'if_required',
#

Remeber to also use clientSecret in confirmPayment

worthy sedge
#

thank you so much! i really appriciate your help! redirect 'if_required' helped'

maybe it is possible to bring the medusa stripe docu to the newest stand, because there is the old card element.

maybe it helps someone else: https://docs.stripe.com/payments/payment-element/migration

 const {error: submitError} = await elements.submit();
    if (submitError) {
      alert('submitError');
      return;
    }
    const {error} = await stripe.value.confirmPayment({
      elements,
      clientSecret: clientSecret.value,
      confirmParams: {
        return_url: 'https://localhost:3000',
      },
      redirect: "if_required"
    });
    if (error) {
      alert('there is some stripe error');
    }

Learn how to migrate your existing integration with individual payment method Elements into a single Element.

runic swan
#

@worthy sedge do you have a repo or code sample of the payment element implementation u can share by chance? i'm still having a hard time implementing