#Rohit89
1 messages · Page 1 of 1 (latest)
For any recurring type, the Checkout Session should be created subscription mode. payment mode is for one-time payment. Is there any reason why payment mode is set?
When user first time signup to our platform.. we have mode:subscription. Hence subscription is created when checkout is done
When inside the app, user click on buy more seats... we want to open up stripe checkout page// if we use mode: subscription, it will create new subscription. We want to create the items to the existing monthly subscription
We dont want to create two subscriptions for a user. It should be one subscription with multiple subscription items. Checkout with mode: subscription will always create new subscription
Thanks for sharing the details. payment mode is for one-time payment and it won't add items to existing subscription. Unfortunately, Checkout Session is not designed for updating existing subscription.
If you wish to add items on existing subscription, you can do so with Update Subscription API directly with adding new items.price and its quantity: https://stripe.com/docs/api/subscriptions/update
I was using this api
Stripe::SubscriptionItem.create({
subscription: 'xx',
price: 'xx',
quantity: 5,
proration_behavior: 'always_invoice'
})
That should work too! Do you face any error with this request?
I can hit this API in backend, but how user do the payment.. ? I want to open a payment page so that user select a quantity and do the payment
So I was thinking if any way I can use checkout page, receive the payment, and on webhook call the above api
The card saved on the subscription will be charged immediately with proration_behaviour to always_invoice
It may be possible that user subscribed to monthly plan on jan 1.. and buy the seats on jan 20. So when click on buy seats .. we want to receive the payment for period 20 jan to billing cycle of monthly subscription
If we just make custom form to input the quantity. And initiate the above api to create items. User wont able to know how much he will be paid
It's not possible to have multiple billing cycle date on a single subscription. If the monthly is subscribed to Jan 1 and seats are added on Jan 20, there will be a invoice for prorated seats adding on Jan 20. However, the billing cycle will always be on first of the month afterwards.
You can use upcoming invoice API to preview the amount to be paid if the customer decides to add seats: https://stripe.com/docs/billing/subscriptions/prorations#preview-proration
that is sent in email ?
sub_1MIEjyLv5rdhLZWUW2tTn5BO this subscription started on 23 dec, next billing will be on 2 feb.
This is monthly seat price - price_1LUYZpLv5rdhLZWUxenJy1U1
How can I see the preview. If user want to buy 5 seats today
You can use the Upcoming Invoice API and set the timestamp which you intend to update the seats to get a preview on the prorated amount to be paid in the response of the API: https://stripe.com/docs/billing/subscriptions/prorations#preview-proration
The subscription I have sent you wont have any items added yet. I want to see how much user will pay today to 2 feb. Next billing will start on 2 feb. Correct?
Where I can mention the quantity 5
proration_date = Time.now.to_i
subscription = Stripe::Subscription.retrieve('sub_1MIEjyLv5rdhLZWUW2tTn5BO')
items = [{
id: subscription.items.data[0].id,
quantity: 5,
price: 'price_1LUYZpLv5rdhLZWUxenJy1U1'
}]
invoice = Stripe::Invoice.upcoming({
customer: 'cus_N2JMf9FO6u6M3u',
subscription: 'sub_1MIEjyLv5rdhLZWUW2tTn5BO',
subscription_items: items,
subscription_proration_date: proration_date,
})
Is it this way????
Yes! Upcoming invoice API is before making changes to the subscription and gives you a preview on the prorated amount from the intended changed timestamp to next billing cycle.
Since you're going to add items instead of modifying the current one, the items should be:
items = [{
quantity: 5,
price: 'price_1LUYZpLv5rdhLZWUxenJy1U1'
}]
If you set id, it will try to compute the prorated by modifying the existing plan instead of adding the new one.
The proration_date will be the epoch timestamp in UTC that you intend to update such as current timestamp.
how it should be?
I have a check on your request https://dashboard.stripe.com/test/logs/req_6AlSz3sIMpAnej and the API parameters are correct. The quantity is also set correctly as well.
Let me check how 74553 is computed
there?
Yes! I'm still checking how this is computed
ok
Could you share the full response (instead of screenshot), so that we can have more information to investigate?
sure
@dull yarrow to clarify, do you want to invoice the customer immediately after you add the additional quantity?
yes... adding items to existing monthly subscription
if that's the case, then you need to pass in subscription_proration_behavior=always_invoice when creating the upcoming invoice
if you don't, then the upcoming invoice generated for that subscription is on the usual renewal date : which would also include the monthly renewal subscription items of :
- 1 × Flex Test | Starter (at $165.00 / month)
- 5 Flex seat × Flex Test | Starter User Seat (at $79.00 / month)
let me try
I want to check how much user pay
sub_1MIEjyLv5rdhLZWUW2tTn5BO this subscription started on 23 dec, next billing will be on 2 feb.
This is monthly seat price - price_1LUYZpLv5rdhLZWUxenJy1U1
subscription = Stripe::Subscription.retrieve('sub_1MIEjyLv5rdhLZWUW2tTn5BO')
items = [{
quantity: 5,
price: 'price_1LUYZpLv5rdhLZWUxenJy1U1'
}]
invoice = Stripe::Invoice.upcoming({
customer: 'cus_N2JMf9FO6u6M3u',
subscription: 'sub_1MIEjyLv5rdhLZWUW2tTn5BO',
subscription_items: items,
subscription_proration_behavior: "always_invoice",
})
is it ?
i'm sorry, but your answer seems a bit contradictory. I asked if you want to invoice the customer immediately after including the additional seats -> your answer is yes. However, you're mentioning that you want to see how much is the next billing on 2 feb.
can you clarify which is it?
No no..
- I want to see how much user pay. If buy 5 seats today.
- How much user pay on 2 feb on next billing cycle ?
is this what you're looking for?
- how much if the customer buys and pays for 5 seats today
- after 1. (i.e. that additional 5 seats is already paid for), how much will the customer pay on 2 feb
- Yeah, if I already subscribed to monthly plan on 23 dec. Now today I want to purchase 5 seats.
- The monthly plan will renew on 2 feb. So much I have to pay on 2 feb for month plan + 5 seats.
for 1. yes, your code looks correct, but please run it and check if the amount matches what you're expecting
invoice = Stripe::Invoice.upcoming({
customer: 'cus_N2JMf9FO6u6M3u',
subscription: 'sub_1MIEjyLv5rdhLZWUW2tTn5BO',
subscription_items: items,
subscription_proration_behavior: "always_invoice",
})
please don't provide a screenshot. If you want to share, pasting the full response would be more helpful
ok
have you validated it yourself? i.e. check the start and end period of the line item in the invoice, you would be able to see the period of that line item that it's charged for
does it match the amount you're expecting?
Let me check
it says "amount_due": 18493,
"period_end": 1674103763,
"period_start": 1672679342,
period_start - 2 jan
period end - 19 January
Isn't it should calculate from 19 jan to 2 feb
can you paste the full invoice here again
sure
items = [{
quantity: 5,
price: 'price_1LUYZpLv5rdhLZWUxenJy1U1'
}]
invoice = Stripe::Invoice.upcoming({
customer: 'cus_N2JMf9FO6u6M3u',
subscription: 'sub_1MIEjyLv5rdhLZWUW2tTn5BO',
subscription_items: items,
subscription_proration_behavior: "always_invoice",
})
"lines": {
"object": "list",
"data": [
{
"id": "il_tmp_1MRq40Lv5rdhLZWU26FtWpgZ",
"object": "line_item",
"amount": 18493,
"amount_excluding_tax": 18493,
"currency": "usd",
"description": "Remaining time on 5 × Flex Test | Starter User Seat after 19 Jan 2023",
"discount_amounts": [],
"discountable": false,
"discounts": [],
"invoice_item": "ii_1MRq40Lv5rdhLZWU26FtWpgZ",
"livemode": false,
"metadata": {},
"period": {
"end": 1675357742, -> Thu Feb 02 2023 17:09:02 GMT
"start": 1674103763 -> Thu Jan 19 2023 04:49:23 GMT
},
you get above from response I sent?
Got it
And now on feb 2 I will pay
monthly price + 79 X 5
correcT?
as the billing cycle renew
To summarize again :
- how much if the customer buys and pays for 5 seats today
- after 1. (i.e. that additional 5 seats is already paid for), how much will the customer pay on 2 feb
there isn't a straightforward way to retrieve the upcoming invoice for 2. that i can think of
I guess on feb 2 when plan renews.. it charges for monthly plan + 79 X 5
165$ of monthly plan + 79$ per seat X 5
when the plan renews it should charge for the 79 x 5 + 165
yeah, that would happen on feb 2
for that subscription
https://stripe.com/docs/billing/subscriptions/prorations#preview-proration
What is the purpose of using id ?
id: subscription.items.data[0].id
if you pass in a subscription item id, this means you want to replace that item
Let me check
If you check this subscription sub_1MIEjyLv5rdhLZWUW2tTn5BO
Stripe::SubscriptionItem.create({
subscription: 'sub_1MIEjyLv5rdhLZWUW2tTn5BO',
price: 'price_1LUYZpLv5rdhLZWUxenJy1U1',
quantity: 5,
proration_behavior: 'always_invoice'
})
It updates my subscription
charge 184.57$
next invoice is 560.00$
it looks good!!
I can not upgrade this subscription from portal as portal has limitations to upgrade subscription with multiple items .. it shows only cancel button.
I want to upgrade this subscription to another monthly plan which is power plan.
power plan price per month: 600$ per month
price_1LUXefLv5rdhLZWUfaiQ9ZYW
power seat plan: 99$ per month
price_1LUYbnLv5rdhLZWUNhRwU77E
how I can do that?
you can take a look at this section : https://stripe.com/docs/billing/subscriptions/upgrade-downgrade#changing
I checked that , my subscription has now two items. One is monthly subscription and other is monthly seat plan with 5 quantity
When I want to upgrade I want to update both --
monthly plan 165$ to mothly 600$
monthly seat plan 79$ to monthly 99$
subscription = Stripe::Subscription.retrieve('sub_1MIEjyLv5rdhLZWUW2tTn5BO')
Stripe::Subscription.update(
subscription.id,
{
proration_behavior: 'always_invoice'
items: [
{
id: subscription.items.data[0].id,
price: 'price_1LUXefLv5rdhLZWUfaiQ9ZYW'
},
{
id: subscription.items.data[1].id,
price: 'price_1LUYbnLv5rdhLZWUNhRwU77E'
}
]
}
)
Am i correct?
you can run it and try
It works but for second item quantity changes to 1 it was 5.
Stripe::Subscription.update(
subscription.id,
{
proration_behavior: 'always_invoice',
items: [
{
id: subscription.items.data[0].id,
price: 'price_1LUXefLv5rdhLZWUfaiQ9ZYW'
},
{
id: subscription.items.data[1].id,
price: 'price_1LUYbnLv5rdhLZWUNhRwU77E'
}
]
}
)
Since that item has 5 quantity. Isn't it should consider that
Hi @dull yarrow I'm taking over. It's a long thread, do you mind to give me a summary?
I have this subscription sub_1MIEjyLv5rdhLZWUW2tTn5BO
It has two items.
- Monthly plan of 165$
- 5 seats. 79$ per seat monthly
If you see above I upgrade the plan to power plan.. that plan has different price for monthly and seat plan.
It updated the plan on both items.. but for second item quantity changes to 1 from 5.
Hmm, but the quantity of the 2nd subscription item is already 5 before the update, am I right?
yes
you can check logs
This is when I buy 5 seats using 79$ plan
quantity is 5
Do I need to pass quantity again when upgrading subscription? I don't think so//
Do you want to keep the quantity as 5 or change it to 1 after the update?
5 because my plan has that I just want to move to bigger plan
but it reduces the quantity from 5 to 1
But just now you said
It updated the plan on both items.. but for second item quantity changes to 1 from 5.
yes... why it changes the quantity
Stripe::Subscription.update(
subscription.id,
{
proration_behavior: 'always_invoice',
items: [
{
id: subscription.items.data[0].id,
price: 'price_1LUXefLv5rdhLZWUfaiQ9ZYW'
},
{
id: subscription.items.data[1].id,
price: 'price_1LUYbnLv5rdhLZWUNhRwU77E'
}
]
}
)
it should keep 5 for item 2...
5 X 99$
When I upgrade plan. I don't want the quantity will change automatically!
Thanks for waiting, discord is busy today
No issues
I'd suggest you to specify the quantity when updating the subscription.
Ok. The APIs I shared is to upgrade plan. As it can't be done from billing portal since it has limitation not to have update option for subscription with multiple items.
Is there way that we can show user the payment page? Can't use checkout as it create new subscription again!
Hmm, I remember customer can adjust the quantity when upgrading the subscription through customer billing portal https://stripe.com/docs/customer-management
We can not use billing portal. It has limitations with subscriptions with multiple items
Oh right, you have multiple proudcts
In this case, rather than doing it programmatically through API, I don't have any other solutions.
And we need some input form to get the quantity from user