#thefron_
1 messages · Page 1 of 1 (latest)
I'm not sure I follow. Can you give me an example of the params you're passing to retrieve an upcoming invoice and a subscription ID?
Sure, this is how I'm creating invoice preview
const isTrialing = subscription.status === "trialing"
const isDowngrade = !isAtLeastPlan(newPlan, subscriptionPlan)
const prorationDate = Math.floor(Date.now() / 1000)
const items = [
{
id: subscription.items.data[0].id,
price: (isAnnual
? newPlan.annualStripePriceId
: newPlan.monthlyStripePriceId) as string,
},
]
const invoice = await stripe.invoices.retrieveUpcoming({
customer: subscriptionPlan.stripeCustomerId,
subscription: subscriptionPlan.stripeSubscriptionId,
subscription_items: items,
...(!isDowngrade
? {
// If the new plan is an upgrade, we update immediately and prorate the difference.
subscription_proration_date: prorationDate,
subscription_proration_behavior: "always_invoice",
}
: isTrialing
? { subscription_trial_end: subscription.trial_end! }
: {}),
})
Sub Id: sub_1OgyvLInhc70Zj3fiuRdJ2Gr
that seems like expected behaviour to me, you're generating an invoice for switching to a new plan, but your subscription is still under a trial - so there's nothing to pay for
That's true, but I want to show user's upcoming invoice and amount due on trial end. i.e. If user is trialing on $30 plan and downgrade to $10, I want to show my own UI that the user will be charged $10 at the end of trial period using invoice preview.
maybe try passing in the trial_end set to the current timestamp?
Setting subscription_trial_end to now seems to show the charged price properly, but it is prompted that the user will immediately be charged?
btw this is what I was expecting
you'll probably need to build your own logic to ignore the immediately charged portion, but really though, that's how the upcoming invoice works right now i.e. if you set the trial end to a future date, you're generating an invoice for switching to a new plan, but your subscription is still under a trial - so there's nothing to pay for. If you set the trial_end to now, then you likely have to implement some logic to ignore the dates that the customer is going to be charged for
That makes sense. I can ignore the invoice preview's date and implement my own logic since the actual server logic will be scheduling the plan downgrade. I was wondering because when I match the billing period (monthly or annual) of the trial subscription with the new price ID, it correctly showed the amount due with the future date (trial end) as shown in the second screenshot. However, when the billing periods mismatched, it always showed the amount due as 0.
hrm, that's interesting. My guess as to why this is happening is because when you switch billing periods e.g. monthly -> annual, it'll invoice immediately : https://stripe.com/docs/billing/subscriptions/upgrade-downgrade#immediate-payment
whereas if you keep the same billing period, there's nothing to invoice so it displays the upcoming invoice as what will be invoiced after the trial ends