#aayush
1 messages · Page 1 of 1 (latest)
Hi there!
I'm guessing you want the first payment of the subscription to succeeded, and then a following payment to fail?
I want this scenario: that due to any reason if a payments fail while subscribing for the first time or for the next billing date in any case if payments fail how can i handle that is there any api or anything related to it?
For recurring payments this is handled by your dashboard settings: https://dashboard.stripe.com/settings/billing/automatic
For the first payment it depends. How are you creating your subscriptions?
im creating the subscription using this api
app.post("/create-checkout-session", async (req, res) => {
const domainURL = process.env.DOMAIN;
const testClock = await stripe.testHelpers.testClocks.create({
frozen_time: parseInt(new Date().getTime() / 1000),
});
const customer = await stripe.customers.create({
test_clock: testClock.id,
});
try {
const session = await stripe.checkout.sessions.create({
mode: "subscription",
customer: customer.id,
line_items: [
{
price: "price.id",
quantity: 1,
},
],
// ?session_id={CHECKOUT_SESSION_ID} means the redirect will have the session ID set as a query param
success_url: ${domainURL}/success.html?session_id={CHECKOUT_SESSION_ID},
cancel_url: ${domainURL}/canceled.html,
// automatic_tax: { enabled: true }
});
return res.redirect(303, session.url);
} catch (e) {
res.status(400);
return res.send({
error: {
message: e.message,
},
});
}
});
is there any api which can handle this?
You are using Checkout Session, so the first payment will be handled by Stripe, you have nothing to do.
is there any api which can handle this?
What exactly do you mean by "this"? What exactly are you trying to do?
basically i want to see if the payments fail for the subscription, is there any way to handle it in api.For ex. the webhook api gives diff events but there is no case for a failure payment.
but there is no case for a failure payment.
There is! This is covered here: https://stripe.com/docs/billing/subscriptions/webhooks#payment-failures
Is there a example code available for it?How to integrate it with /webhooks
Yes we have guides on webooks, like this one: https://stripe.com/docs/webhooks/quickstart
also is there anyhow i can control billing cycle of subscriptions for users.
for instance i want their billing cycle to be billed on 1st of every month.