#Wik

1 messages ยท Page 1 of 1 (latest)

flat viperBOT
simple whale
#

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.

wraith thicket
#

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?

simple whale
#

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

wraith thicket
#

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!

flat viperBOT
simple whale
# wraith thicket 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.

wraith thicket
#

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"}
]
})

queen perch
#

๐Ÿ‘‹ stepping in

#

Can you share the payload that you get back from your upcoming invoice request?

wraith thicket
queen perch
#

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

wraith thicket
#

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

queen perch
#

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', }]

wraith thicket
#

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

#

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

queen perch
#

Sorry server is busy, coming back around to this

wraith thicket
#

no worries ๐Ÿ™Œ

queen perch
#

So wait you do want to add an item or you want to replace the current one?

wraith thicket
#

I'll need to jump to a call in 10 so will be inactive for 30 minutes

queen perch
#

Maybe I misunderstood

wraith thicket
#

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

queen perch
#

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

wraith thicket
#

yay, it worked! just one more question, sorry ๐Ÿ˜…

queen perch
#

Glad it worked!

#

And no worries -- we are here to help!

flat viperBOT
wraith thicket
#

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,