#Min.K
1 messages ยท Page 1 of 1 (latest)
Hello! We'll be with you shortly. 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.
๐ happy to help
Hi
We know that we can't call the upcoming invoice API if the subscription's status is canceled.
However, if I schedule a cancel, I still get an error when I call the upcoming invoice API.
taking a look at the request please give me a minute, I'll get back to you
ok
you created a subscription sub_1OJuQlH7t32LLKQx7mJ2eYl7 for your customer cus_P8Amv2acwixgC2 and then you made a request (https://dashboard.stripe.com/test/logs/req_fzJn18v6honxo7) on the dashboard to cancel the subscription at_period_end meaning there's no upcoming invoices for this subscription
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
@ใ
@devout belfry
I know.
Background.
- I'm calling the Upcoming Invoice API when I get the Subscription Update Completed webhook to tell the user what the next payment will be.
Therefore, I would like to know under what circumstances in a subscription I should not call the Upcoming Invoice API.
yes
when these values are set
cancel_at: 1702371399,
cancel_at_period_end: true,
canceled_at: 1701770944,
cancellation_details: {
comment: null,
feedback: null,
reason: "cancellation_requested"
},
That's a lot, can I just check cancel_at?
Or should we check canceled_at as well?
the most important one is cancel_at
So, if i only need to check one, why not just check cancel_at?
if the cancel_at is not null and greater than current_period_end you could still have an upcoming invoice
So, if i only need to check one, why not just check cancel_at? Right?
you need to check cancel_at and compare it to current_period_end when it's not null
I want to make this clear.
Is that right ?
if (cancel_at != null && canceled_at <= current_period_end) {
// There are no upcoming invoices
} else {
// There are upcoming invoices exist
}
cancel_at not canceled_at
Sorry my mistake
no worries
I want to make this clear.
Is that right ?
if (cancel_at != null && cancel_at <= current_period_end) {
// There are no upcoming invoices
} else {
// There are upcoming invoices exist
}
Thank you!
Hi! I'm taking over this thread.
To achieve this I would recommend to rely on the Invoice Upcoming endpoind:
- If you call it and it returns an error, then you know there are no upcoming Invoices
- If you call it and it returns an Invoice, then you know there will be an upcoming invoice
This feels like the more robust solution
Hi
I use the Upcoming Invoice API. However, I am getting an error when calling the API, so I am asking how to avoid this error.
You can call the endpoint in a try/catch, and handle the case when there's an error.
to learn how to catch exceptions: https://stripe.com/docs/error-handling?lang=node#catch-exceptions
You can call the endpoint in a try/catch, and handle the case when there's an error.
But this is unclear.
If the error codes in the Stripe API were clearly defined so that it was clear that there were no upcoming invoices, it would be usable.
However, the Stripe API doesn't give a clear error code that there are no such upcoming invoices.
Oh, i find error code
{
"error": {
"code": "invoice_upcoming_none",
"doc_url": "https://stripe.com/docs/error-codes/invoice-upcoming-none",
"message": "No upcoming invoices for customer: cus_P8Amv2acwixgC2",
"request_log_url": "https://dashboard.stripe.com/test/logs/req_eNxGgh811IAMpJ?t=1701771026",
"type": "invalid_request_error"
}
}
invoice_upcoming_none
yes exactly, you can use that error code
Okay, I'll use this, but it's not very good.
@atomic agate
Hi, Would it be okay to use the method below?
if (cancel_at != null && cancel_at <= current_period_end) {
// There are no upcoming invoices
} else {
// There are upcoming invoices exist
}
I don't think this covers all possible cases. That's I recommend using the upcoming invoice endpoint. It will be more reliable.
Very good point.
Thank you!