#ben-clum_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1318222499636576348
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi, let me help you with this.
It doesn't seem like the method has any parameters to specify the upcoming invoice that's not the next one: https://docs.stripe.com/api/invoices/upcoming
You could potentially approximate the amount by specifying the cancel_at to the same day the the upcoming month, but this might not work if you need the exact amount: https://docs.stripe.com/api/invoices/upcoming#upcoming_invoice-subscription_cancel_at
gotcha, yeah I need an exact amount
Yeah, I don't see an easy workaround unfortunately.
Why do you need an exact amount? How are you planning to use this value?
Hi there ๐ jumping in as my teammate needs to step away. I'm fairly certain this isn't supported, unless the last Invoice that you're referring to is also the next one that the Subscription will generate when you retrieve the upcoming Invoice. We don't currently have a mechanism that allows you to retrieve an Invoice beyond the next upcoming one.
I think this might work as a workaround, see any issues with this?
upcoming_invoice_params = {
subscription_details: {
items: [{
price: subscription.plan.id
}],
start_date: last_billing_cycle_end_date_before_cancel_date.to_i,
billing_cycle_anchor: cancel_on.to_i,
proration_behavior: 'create_prorations'
}
}
if subscription.details['default_tax_rates'].present?
upcoming_invoice_params[:subscription_details][:default_tax_rates] = subscription.details['default_tax_rates'].map { |rate| rate['id'] }
end
if subscription.details['discounts'].present?
upcoming_invoice_params[:discounts] = subscription.details['discounts'].map { |discount| { discount: discount['id'] } }
end
Stripe::Invoice.upcoming(upcoming_invoice_params)
basically treat the last "period end" date before the cancellation date as the start of a new "fake" subscription, and the anchor date would be the cancellation date.