#peepeepoopoo_code
1 messages ยท Page 1 of 1 (latest)
๐ 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.
- peepeepoopoo_code, 5 hours ago, 25 messages
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:
Hello!
Yes, I provided the code above the picture : const res = await fetch('https://blabla.com/create-intent'
I'm asking for a specific PaymentIntent id, which will look like pi_abc123
You could log it from there, or else you can just look at the API responses in your request logs: https://dashboard.stripe.com/logs?method[0]=post&method[1]=delete&direction[0]=connect_in&direction[1]=self
Yes, could you copy and paste that id starting with pi_
Sorry for the wait there. Are you using our React components or creating the Elements manually with elements.create()?
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,
});
Yeah, that's the reason
Yay awesome, thank you very much! I was using elements.create() I did not expect that
If you pass setup_future_usage or payment_method_types to Elements, we expect those to match on the PaymentIntent
Noted. thanks very much!! we can close this ๐
have a great day!