Facing issue with increasing the quantity in existing with prorated charges

34 views
Skip to first unread message

Gopi Vetrivel

unread,
Feb 24, 2025, 1:20:26 PMFeb 24
to Stripe API Discussion
We have two products in Stripe:

1. **Product One** (e.g., $2)
2. **Product two** (e.g., $6)

We're developing in Java Spring boot with Thymeleaf.

Initially, a user can select the quantity of the Product 1, and the Product 2 is optional. For example, a client might purchase 30 product one with 10 product two. When this happens, we create a subscription in Stripe and map the subscription ID to our database for future reference.

If the same customer wants to add more quantity to either or both products later, we need to retrieve the existing subscription using the stored subscription ID. Then, we must calculate the prorated charges for the new additions and display this amount in our application's embedded UI.

The first time a subscription is created, it handles recurring payments. For subsequent additions, we use the subscription ID to create a payment session. However, we're facing challenges in accurately calculating and displaying the prorated amount for the new quantities, considering the remaining time and unused portion of the existing subscription.

Our goal is to calculate the prorated charges for the new quantities (for the current month) and ensure the recurring payments are handled correctly by the subscription. How can we achieve this calculation and display the correct prorated amount for the additional quantities?

Thanks
Gopi V

Remi J.

unread,
Feb 24, 2025, 1:29:18 PMFeb 24
to api-d...@lists.stripe.com
Hey Gopi,

Our Subscriptions API supports calculating proration automatically for quantity changes like the ones you described. I recommend referring to the following documentation page [1]. It covers how to use our Retrieve Upcoming Invoice API [2] to "preview" the calculation and display it to the end customer in this section [3].

In your example, you have a Subscription (sub_A) to 2 separate Products/Prices so each one is represented by a SubscriptionItem (si_123 and si_456) each with their current recurring quantity. If your customer wants to buy say 10 more of Product B then you are going to want to update the quantity of sub_456 from 10 to 20 to reflect that change. When you call the Retrieve Upcoming Invoice API, you are going to explicitly pass the new quantity for that SubscriptionItem in the `subscription_items` parameter [4] and we will automatically calculate the proration for you.

If you want your customer to pay you for the difference immediately instead of on the next Invoice at the end of the current period, you can use the `subscription_proration_behavior: 'always_invoice'` parameter [5]. In that case the Invoice returned would only contain the proration we calculated.

If you have any follow up questions about this, I recommend using our Discord server [6] where you can talk to Stripe developers in real time and they can help you make this work quickly!

Best,
Remi


To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss...@lists.stripe.com.
Reply all
Reply to author
Forward
0 new messages