#Wik
1 messages ยท Page 1 of 1 (latest)
Hi ๐ yes, you can use the upcoming invoice API to preview the next Invoice for a Subscription, and provide adjustments in that request to simulate changes being made to the Subscription.
This document goes into a bit more detail about that and shows an example of retrieving an upcoming Invoice for a Subscription using a new Price:
https://stripe.com/docs/billing/subscriptions/prorations#preview-proration
Yes, but this doc mentions only changing subscription, not adding to it
I tried creating an invoice item to preview how it'll change the price, but I am getting an error
Stripe::InvoiceItem.create({
customer: 'cus_NejoWOf0IUwOmM',
price: 'price_1Mqc27JA8pMPzFjlM40EXYmT',
})
Stripe::InvalidRequestError: The price specified is set to type=recurring but this field only accepts prices with type=one_time.
So I wonder - how can I preview how the price will change if I add a second product to my current subscription?
To add an additional subscription item to the preview, you'll provide the details for the new item in the subscription_items hash. When doing so you'll omit the id parameter in that hash as you want to simulate a new subscription item rather than simulate changing an existing one.
https://stripe.com/docs/api/invoices/upcoming#upcoming_invoice-subscription_items
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Great, thank you! One more question
Can I use the upcoming invoice to see how much I'd have to pay if I were to change the subscription today, not at the end of the period and taking into consideration what I paid for my current subscription (subscription_proration_behavior: "create_prorations" I think, I'm not sure how to change billing date though)
oh, I see proration date!
Exactly, the subscription_proration_date field allows you to simulate making the update at a specific time. I believe that field defaults to the current time if the parameter is not provided.
I have a user on $199/month plan (subscribed today). I want to see what Stripe will return for changing them to $19/month plan + $100/month seat. They'd be charged $0 for the next few payments as that $199 would cover the next few month, but upcoming invoice has total: 43662. Why is that?
Stripe:: Invoice.upcoming({
customer: 'cus_NejoWOf0IUwOmM',
subscription: "sub_1MtQKQJA8pMPzFjlFSgOxKiI",
subscription_proration_behavior: "create_prorations",
subscription_proration_date: proration_date,
subscription_items: [
{plan: "monthly-19usd-plus-20201101"},
{price: "price_1MoiQiJA8pMPzFjla4njMBh1"}
]
})
๐ stepping in
Can you share the payload that you get back from your upcoming invoice request?
Can you pull out just the lines data and format it?
That is what you want to look at specifically for why the total is the amount it is
sure
Oh, so it looks like instead of changing $199 => $19 + $100, I did ($199 + $19 + $100) + ($19 + $100)?
How can I fix the request then? When I tried removing subscription, I got an error saying that it's mandatory
Ah you added an item
Instead of replacing
You need to pass the Subscription Item ID
Should look like items: [{ id: subscription.items.data[0].id, price: 'price_CBb6IXqvTLXp3f', }]
trying
hm, still seems wrong
I did
customer: 'cus_NejoWOf0IUwOmM',
subscription_proration_behavior: "create_prorations",
subscription_proration_date: proration_date,
subscription: "sub_1MtQKQJA8pMPzFjlFSgOxKiI",
subscription_items: [
id: subscription.items.data[0].id,
price: "monthly-19usd-plus-20201101",
price: "price_1MoiQiJA8pMPzFjla4njMBh1"
]
})```
hoping to see $199 => $19 + $100 change
but lines suggest it only calculated for $100 seat, ignoring the $19 bit?
I tried modelling items differently but still not luck ```items = [{
id: subscription.items.data[0].id,
price: 'monthly-19usd-plus-20201101',
},
{
id: subscription.items.data[0].id,
price: 'price_1MoiQiJA8pMPzFjla4njMBh1'
}]
Stripe::InvalidRequestError: The array you specified contains a duplicate entry: 'si_NejoWvQcxIXbxX'
any idea how to do this call to see how adding a product to an existing subscription will change it? I do not want to remove the original product though
Sorry server is busy, coming back around to this
no worries ๐
So wait you do want to add an item or you want to replace the current one?
I'll need to jump to a call in 10 so will be inactive for 30 minutes
Maybe I misunderstood
let me rephrase ๐
GIVEN I'm on $199 plan/month that started on 1st April
WHEN I add $100/month seat on 5th April
THEN I want to be able to preview how much I'll be charged with proration
And I am trying to figure out how to ask your API about this using the upcoming invoice mechanism
Ah okay
Thanks for clarifying
Then you want ```Stripe:: Invoice.upcoming({
customer: 'cus_NejoWOf0IUwOmM',
subscription: "sub_1MtQKQJA8pMPzFjlFSgOxKiI",
subscription_proration_behavior: "create_prorations",
subscription_proration_date: proration_date,
subscription_items: [
{price: "price_1MoiQiJA8pMPzFjla4njMBh1"}
]
})
By passing plan and price you were adding two items
plan is our legacy API
price is our newer API
You will still see references to plan as we still support the legacy API
But you don't want to pass both here
yay, it worked! just one more question, sorry ๐
my one more question
is about coupons
I added a 10% off forever coupon
but lines show as if it was only applied to the remaining time
even though total seems correct?
customer: 'cus_NejoWOf0IUwOmM',
subscription: "sub_1MtQKQJA8pMPzFjlFSgOxKiI",
coupon: "wik-all-forever",
subscription_items: [
{price: "price_1MoiQiJA8pMPzFjla4njMBh1", quantity: 2}
]
})```
"total": 53813,