#tcg_api

1 messages ¡ Page 1 of 1 (latest)

icy elkBOT
thorny gullBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

icy elkBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1252730879931977833

📝 Have more to share? Add details, code, screenshots, videos, etc. below.

dense glen
#

Hi there

#

Could you try setting a value for this (should be a timestamp in unix time that corresponds to day 15, down to the second, to see the expected proration amount)

autumn geode
#

i have tried that param but i am receiving wrong values, suposing current period 11 jul. 2025 to 11 ago. 2025

#

i have to pass timestamp for 26-july-2025 wright?

#

now i am receiving it

Request req_EwBjYagN2Ypwhu: Recurring estimates do not support the following features: subscription prorations, trials, cancellations, prebilling, schedules, and invoice item additions.
#

using preview_mode='next' i am received negative amount

dense glen
#

We're expecting the unix time stamp

#

So for July 26, 2025, it should be something like 1753564581 but that's for July 26, 2025, 9:16:21pm GMT

autumn geode
#

My current code

stripe.Invoice.create_preview(
                customer=customer_id,
                preview_mode="next",
                subscription=subscription_data["id"],
                subscription_details={
                    "items": [
                        {
                            "id": current_subscription_item_data["id"],
                            "quantity": quantity - current_quantity,
                        }
                    ],
                    "proration_date": 1753573760
                },
            )
dense glen
#

Okay, looking at the request you shared above

autumn geode
#

FYI quantity = 12 and current_quantity = 11

dense glen
#

Looking at req_EwBjYagN2Ypwhu, you're passing subscription_details.items[0].quantity of 1

#

but more importantly, in order to calculate proration, you need to pass preview_mode: next. In req_EwBjYagN2Ypwhu, you passed recurring

autumn geode
#

ok, i will change preview_mode

#

let me try

#

my use case is

#

during current period 11 jul. 2025 to 11 ago. 2025 having an active subcription with quantity=10 I need to preview next invoice amount with quantity=11 (i have it ok) and in the other side I need to preview prorated amount ok the quantity difference on day 26 like before. Do you undestand?

dense glen
#

Not sure I follow the second piece

autumn geode
#

ok, let me try againg (sorry about my english)

dense glen
#

So given a billing period from July 11 - August 11, you want to preview the next invoice if you change the quantity to 11 midway through the cycle. I understand that piece

autumn geode
#

yes

#

the second piece. I want to show my customer how much cost the extra prorated (from July 26 - August 11) payment amount increase

dense glen
#

Okay, got it

autumn geode
#

Assuming a cost per unit per month of 3 euros. The final result would be to inform the customer that with a quantity of 11, the next invoice (starting from August 11) will be 33 euros, and they now have to make an extra payment of 1.5 euros.

dense glen
#

Hold on

#

Let's talk about proration

#

So you have a customer who is moving from a quantity of 12 to a quantity of 11?

autumn geode
#

it's an example. Supposing moving from 10 to 11

dense glen
#

Okay, got it

autumn geode
#

my customer should pay half month (1.5 euros) and the next full month payment should be 33 euros

dense glen
#

If you make an update from a quantity of 10 to a quantity of 11 partway through the billing cycle, they'll see two items on their next invoice:

  • A credit for the "unused" 15 days at a quantity of 10
  • A charge for the remaining 15 days at a quantity of 11

for the sake of simplicity, let's say it's a 15 Euro credit and a 16.50 Euro charge for a net of 1.50

#

You can preview this amount by using create_preview with the following params:
stripe.Invoice.create_preview(
customer=customer_id,
preview_mode="next",
subscription=subscription_data["id"],
subscription_details={
"items": [
{
"id": current_subscription_item_data["id"],
"quantity": 11,
}
],
"proration_date": 1753573760
},
)

#

You would have to make a second call to see the next recurring invoice (which is separate from the prorated invoice):

stripe.Invoice.create_preview(
customer=customer_id,
preview_mode="recurring",
subscription=subscription_data["id"],
subscription_details={
"items": [
{
"id": current_subscription_item_data["id"],
"quantity": 11
}
],
},
)

#

Note that preview_mode is recurring and I've omitted the proration_date. This will return to you what the full invoice amount will be during the first full billing cycle at a quantity of 11

autumn geode
#

to the second one i have to pass the final quantity

dense glen
#

correct

autumn geode
#

the last one should get an amount of 1.5?

dense glen
#

No, that last one will show you 33 euros

autumn geode
#

oo ok

dense glen
#

The preview where preview_mode: next and with the proration date will give you the 1.5 amount

autumn geode
#

mm ok

#

let me try

#

both cases with final quantity

dense glen
#

correct

autumn geode
#

mm it doesn't return 1.5

#

but i think I can calculate the difference between both calcs

dense glen
#

It should return something very close for amount_due