#Yaziit-paymentintents
1 messages · Page 1 of 1 (latest)
You can learn more about the PaymentIntents lifecycle here as well: https://dev.to/stripe/the-paymentintents-lifecycle-4f5o
ok thanks so
const handleConfirmCard = async (clientSecret, customerId, cbName) => {
const result = await stripe.confirmCardPayment(clientSecret, {
payment_method: {
card: await elements?.getElement(CardElement),
//card: cardElement,
billing_details: {
name: cbName,
},
// setup_future_usage: 'off_session'
}
});
if (result.error) {
await Router.push('/paymentFailed')
setLoader(false)
throw (result.error);
}
if (result.paymentIntent.status === 'succeeded') {
await handleSubscription(customerId)
}
}
after the succeeded i can work like the payment is ok ?
and i have a question, why here the setup_futur_usage doesnt work ?
thanks for links i will check this 🙂
after the succeeded i can work like the payment is ok ?
you can, but do note that code might not get called(the user might close their browser) so usually you use webhooks for backend reconciliation, but you can certainly use that code to handle frontend actions after the payment.
why here the setup_futur_usage doesnt work ?
can you elaborate on that a little? I assume you tried it, got an error and then commented it out? What was the error?
in any case you can't pass setup_future_usage on the frontend so you'd get an error, it's something you pass on the backend when creating the PaymentIntent
it does not recognize the parameter
yep, it's a backend-only parameter (there's only a subset of things you can pass on the frontend since the customer could technically edit them and cause unexpected things) so that's expected
i have another question :
In my business, client pay for 14 days, then a subscription start after 14 days.
First i create a payment intent, if the payment intent is ok i create my database subscription, then i create the stripe subscription.
What is the best way for doing this ?
I would create the Subscription object immediately after the PaymentIntent succeeds and set it to use a trial period of 14 days(that way the first payment of the subscription is skipped so you are not double-charging the customer today and the next one is in 14 days), I think.
if (result.paymentIntent.status === 'succeeded') {
await handleSubscription(customerId) ===> HERE
}
i call it here ?
i cant work with webhook beacause, i wont execute the proccess for exsisting recurrent payment intent
i dont know i you know what i mean
well this is all on the frontend so you can't create the Subscription directly here. If your handleSubscription function calls your backend then it could call the API to create the subscription. But then it won't work if the the customer closes the browser part-way through, as I referenced
not sure what that means, but in theory you should be able to listen for payment_intent.payment_succeeded and handle the outcome
yes i can, but the probleme is :
user pay -> payment succeeded (webhook) -> create stripe subscription
but i have many customer atm. with subscription
lets imagine a user subscription is invoiced today
invoice subscription -> payment succeded (webhook) -> create subscription
In this case i wont create a subscription
beacuse the last customer already have a subscription
i dont know how i can go out this case
you can check various fields to differentiate the events though so you don't use the same logic for both.
for example, if the event is about a recurring payment, the invoice field on the PaymentIntent is set, but if it's a one-off PaymentIntent you created, it won't be
https://stripe.com/docs/api/payment_intents/object#payment_intent_object-invoice
so you can inspect fields like that and branch the code in your webhook handler
ok thanks i will check