#aayush

1 messages · Page 1 of 1 (latest)

humble zephyrBOT
nocturne idol
#

Hi there!

#

I'm guessing you want the first payment of the subscription to succeeded, and then a following payment to fail?

full maple
#

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?

nocturne idol
#

For the first payment it depends. How are you creating your subscriptions?

full maple
#

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,
},
});
}
});

full maple
nocturne idol
#

You are using Checkout Session, so the first payment will be handled by Stripe, you have nothing to do.

full maple
nocturne idol
#

is there any api which can handle this?
What exactly do you mean by "this"? What exactly are you trying to do?

full maple
#

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.

nocturne idol
full maple
#

Is there a example code available for it?How to integrate it with /webhooks

nocturne idol
full maple
#

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.