#ben-clum_api

1 messages ยท Page 1 of 1 (latest)

trim joltBOT
#

๐Ÿ‘‹ 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.

civic pier
#

Hi, let me help you with this.

hallow needle
#

gotcha, yeah I need an exact amount

civic pier
#

Yeah, I don't see an easy workaround unfortunately.

trim joltBOT
civic pier
#

Why do you need an exact amount? How are you planning to use this value?

sweet wren
#

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.

hallow needle
#

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.