#peepeepoopoo_code

1 messages ยท Page 1 of 1 (latest)

compact nexusBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1354564462065225958

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

lost wigeon
#

Here is the rest of my code, I followed the documentation here (https://docs.stripe.com/elements/express-checkout-element/accept-a-payment#additional-options) :

This is in my API server:

app.post('/create-intent', async (req, res) => {
  console.log('Received request body:', req.body); // Debugging
    try {
      const { mode, amount, currency } = req.body._commonOptions

      if (!amount || !currency || !mode) {
        return res.status(400).json({ error: 'Missing required fields' });
      }
      const intent = await stripe.paymentIntents.create({
        // To allow saving and retrieving payment methods, provide the Customer ID.
      //  customer: customer.id,
        // mode: mode,
        amount: amount, // Ensure `amount` is in the smallest currency unit
        currency: currency,
        // In the latest version of the API, specifying the `automatic_payment_methods` parameter is optional because Stripe enables its functionality by default.
        automatic_payment_methods: {enabled: true},
      });
      console.log("success!", {client_secret: intent.client_secret})
      res.json({client_secret: intent.client_secret});
  } catch (error) {
    console.error('Error creating payment intent:', error);
    res.status(500).json({ error: error.message });
  }
});
#

This is in my frontend:



// Create the PaymentIntent and obtain clientSecret
    const res = await fetch('https://blabla.com/create-intent', {
      method: 'POST',
      headers: {
          'Content-Type': 'application/json',
      },
      body: JSON.stringify(elements),
    });
    const {client_secret: clientSecret} = await res.json();
  
    const {error} = await stripe.confirmPayment({
      // `elements` instance used to create the Express Checkout Element
      elements,
      // `clientSecret` from the created PaymentIntent
      clientSecret,
      confirmParams: {
        return_url: '[https...](https://blabla.com/)/completed'
      },
    });
  
    if (error) {

       console.log('coolStory', error);
      // This point is only reached if there's an immediate error when
      // confirming the payment. Show the error to your customer (for example, payment details incomplete)
      handleError(error);
    } else {
      // The payment UI automatically closes with a success animation.
      // Your customer is redirected to your `return_url`.
    }
  });

#

The error in coolStory gives me the log of

"The provided setup_future_usage (null) does not match the expected setup_future_usage (off_session). Try confirming with a Payment Intent that is configured to use the same parameters as Stripe Elements."

#

When I try to pay with subscription, it gives me this:

visual dome
#

Hi there!

#

Could you provide a sample PaymentIntent?

lost wigeon
#

Hello!

lost wigeon
visual dome
#

I'm asking for a specific PaymentIntent id, which will look like pi_abc123

lost wigeon
#

Got it! where can I find this?

#

In the create-intent?

visual dome
lost wigeon
#

Oh I see it! its showing the errors

#

Does this help?

visual dome
#

Yes, could you copy and paste that id starting with pi_

lost wigeon
#

Yup!

visual dome
#

Sorry for the wait there. Are you using our React components or creating the Elements manually with elements.create()?

lost wigeon
#

Wait I did it!!

#

I added setup_future_usage: 'off_session', to /create-intent and in

    const elements = stripe.elements({
        mode: mode,
        amount: amount * 100, // Convert to smallest currency unit
        currency: currency,
     setup_future_usage: 'off_session',
        appearance,
    });
visual dome
#

Yeah, that's the reason

lost wigeon
#

Yay awesome, thank you very much! I was using elements.create() I did not expect that

visual dome
#

If you pass setup_future_usage or payment_method_types to Elements, we expect those to match on the PaymentIntent

lost wigeon
#

Noted. thanks very much!! we can close this ๐Ÿ˜„
have a great day!