#Rohit89

1 messages · Page 1 of 1 (latest)

terse thistleBOT
raven nova
#

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?

dull yarrow
#

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

raven nova
#

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

dull yarrow
#

I was using this api

Stripe::SubscriptionItem.create({
subscription: 'xx',
price: 'xx',
quantity: 5,
proration_behavior: 'always_invoice'
})

raven nova
#

That should work too! Do you face any error with this request?

dull yarrow
#

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

raven nova
#

The card saved on the subscription will be charged immediately with proration_behaviour to always_invoice

dull yarrow
#

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

raven nova
#

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.

dull yarrow
#

that is fine

#

concern is no way to show user the amount he is going to pay

raven nova
dull yarrow
#

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

raven nova
dull yarrow
#

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????

raven nova
#

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.

dull yarrow
#

"amount_remaining": 74553,

#

price of seat is 79$ per month

raven nova
#

Oh sorry my bad

#

Quantity field is incorrect

dull yarrow
#

how it should be?

raven nova
#

Let me check how 74553 is computed

dull yarrow
#

yes

#

price of seat is 79$ per month

dull yarrow
#

there?

raven nova
#

Yes! I'm still checking how this is computed

dull yarrow
#

ok

raven nova
#

Could you share the full response (instead of screenshot), so that we can have more information to investigate?

dull yarrow
#

sure

gleaming sigil
#

@dull yarrow to clarify, do you want to invoice the customer immediately after you add the additional quantity?

dull yarrow
#

yes... adding items to existing monthly subscription

gleaming sigil
#

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)
dull yarrow
#

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 ?

gleaming sigil
#

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?

dull yarrow
#

No no..

  1. I want to see how much user pay. If buy 5 seats today.
  2. How much user pay on 2 feb on next billing cycle ?
gleaming sigil
#

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
dull yarrow
#
  1. Yeah, if I already subscribed to monthly plan on 23 dec. Now today I want to purchase 5 seats.
  2. The monthly plan will renew on 2 feb. So much I have to pay on 2 feb for month plan + 5 seats.
gleaming sigil
#

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",
})
dull yarrow
#

"amount_due": 18493,

#

Is this amount of buying 5 seats

from today to 2 feb ?

gleaming sigil
#

please don't provide a screenshot. If you want to share, pasting the full response would be more helpful

dull yarrow
#

ok

gleaming sigil
#

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?

dull yarrow
#

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

gleaming sigil
#

can you paste the full invoice here again

dull yarrow
#

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

gleaming sigil
#
 "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
        },
dull yarrow
#

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

gleaming sigil
#

To summarize again :

  1. how much if the customer buys and pays for 5 seats today
  2. 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

dull yarrow
#

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

gleaming sigil
#

when the plan renews it should charge for the 79 x 5 + 165

dull yarrow
#

yeah, that would happen on feb 2

#

for that subscription

gleaming sigil
#

if you pass in a subscription item id, this means you want to replace that item

dull yarrow
#

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?

gleaming sigil
dull yarrow
#

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?

gleaming sigil
#

you can run it and try

dull yarrow
#

sure

#

Whats the purpose of

cancel_at_period_end: false

dull yarrow
#

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

dense dust
#

Hi @dull yarrow I'm taking over. It's a long thread, do you mind to give me a summary?

dull yarrow
#

I have this subscription sub_1MIEjyLv5rdhLZWUW2tTn5BO

It has two items.

  1. Monthly plan of 165$
  2. 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.

dense dust
#

Hmm, but the quantity of the 2nd subscription item is already 5 before the update, am I right?

dull yarrow
#

yes

#

you can check logs

#

quantity is 5

#

Do I need to pass quantity again when upgrading subscription? I don't think so//

dense dust
#

Do you want to keep the quantity as 5 or change it to 1 after the update?

dull yarrow
#

5 because my plan has that I just want to move to bigger plan

#

but it reduces the quantity from 5 to 1

dense dust
#

But just now you said
It updated the plan on both items.. but for second item quantity changes to 1 from 5.

dull yarrow
#

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!

dense dust
#

Thanks for waiting, discord is busy today

dull yarrow
#

No issues

dense dust
#

I'd suggest you to specify the quantity when updating the subscription.

dull yarrow
#

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!

dense dust
dull yarrow
#

We can not use billing portal. It has limitations with subscriptions with multiple items

dense dust
#

Oh right, you have multiple proudcts

#

In this case, rather than doing it programmatically through API, I don't have any other solutions.

dull yarrow
#

And we need some input form to get the quantity from user