Issue
I'm trying to implement stripe payment on my web app, Node and react is the stack.
- creating a stripe subscription in backend
newSubscription = await stripe.subscriptions.create({
customer: {{customerid},
items: [
{
price: {{price}},
},
],
payment_behavior: 'default_incomplete',
expand: ['pending_setup_intent'],
trial_period_days: 7,
off_session: true,
});
- when i add trail period i'm getting client secrete something like 'seti_XXXXX'.
- when there is no trail i'm getting client secrete as 'pi_XXX'.
- when i'm using payment intent secrete key stripe element is working and transaction is happening.
- when i i use setup intent client secrete, that si'm getting when trial active is not working with stripe element. it show some error saying payment intent not found.
i tried to pass both client secretes to element, but when trail is active. In that case i'm getting the setup intent client secrete so that the element throughs some error. `
{
"error": {
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such payment_intent: 'seti_XXXXXXXXXXXXX'",
"param": "intent",
"request_log_url": "https://dashboard.stripe.com/test/logs/req_XXXXXXXXXXX",
"type": "invalid_request_error"
}
}
` how to solve this issue, i want trail activated subscription, when trails ends the user must be credited with that amount.
Solution
When you include a trial period in your subscription, a $0 invoice is generated initially, which doesn't require payment. This way you are creating a SetupIntent, instead of PaymentIntent. You can see it in the ID prefix: seti_…
. Since there is no payment happening right away, SetupIntent allows you to store the payment details, which, in turn, the subscription can use for recurring payments.
Therefore, you should use the confirmSetup method, when the user submits the form.
Answered By - vanya
Answer Checked By - - Mary Flores (ReactFix Volunteer)