#nt_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always 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/1285175040102367295
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
๐ happy to help
we don't store GET responses so I can't really see the response you got from this request
would you mind sharing the JSON?
Yes sure.
This is the payload I send:
customer: "cus_QrJ7raz6gTeqjN",
subscription_details: {
items: [{
price_data: {
product: "prod_MBN105BNaSFeHX",
recurring: {interval: "year"},
unit_amount: 142800, currency: "USD"
},
quantity: 1
}],
start_date: (Time.now.utc - 1.day).to_i,
default_tax_rates: ["txr_1PdgGxDgQLhhFEp9YtTvKSux"]
}
}
this is the response
Are you still here?
Where do you specify the proration exactly?
If I pass the start date in the past isn't that enough? I cannot set the proration_date attribute as I don't pass a subscription id ( due to the invoice being for an one off item)
I think this just specifies when you want the hypothetical Subscription to start, regardless of the current time: https://docs.stripe.com/api/invoices/upcoming#upcoming_invoice-subscription_details-start_date
Yes but that makes the upcoming invoice to include a prorated line item.with the correct unused time amount but the only issue is that it is not a negative line item
I see. This is expected because the billing_cycle_anchor is still at the time when you send the request.
Why do you expect it to be negative?
Because I retrieve an upcoming invoice for an item with annual billing period but the billing cycle start date is in the past. Is this possible to achieve somehow?
You would get the amount for a part of the last cycle + the full next cycle, and the cycle starts now. Not sure why would the proration be negative.
Can I pass the proration_date for an upcoming invoice without a subscription id maybe?
You can try this. But also try setting billing_cycle_anchor to the start of the Subscription: https://docs.stripe.com/api/invoices/upcoming#upcoming_invoice-subscription_details-billing_cycle_anchor
I am not exactly sure if this is what you're looking for, but the combination of these might get you what you need.
Sorry the link points to the billing cycle anchor. Should I also set something else? because already tried the billing cycle anchor and didn't work
You can try both proration_date and billing_cycle_anchor
Maybe you could share in a bit more detail what you're trying to achieve, on high-level? What's the information you're trying to get from the upcoming Invoice?
Yes of course. I am trying to preview the prorated amount for an one-off invoice if the customer purchases an item in the middle of the billing cycle.
The case is that we have customers with custome pricing and we do not store their subscriptions on Stripe but rather locally. So the stripe customer does not have an active subscription. Those customers can purchase some one-off items and if they are at any point of their billing cycle we need to prorate those amounts. For example let's say that the customer has a manual yearly subscription with start_date: 2024-01-01 and end_date: 2025-01-01
If this was a customr with an active stripe subscription and I wanted to preview an upcoming invoice with an added subscription item that costs 100 usd at 2024-06-01, the new added item would have 2 line items, the unused time from 2024-01-01 till 2024-06-01 and the remaining time from 2024-06-01 till 2025-01-01. The remaining time is prorated on the total list price of 100. This is what I would like but for one-off invoice items.
Also if I specify a proration_date I get this error: ```
Cannot specify proration date without specifying a subscription
Does the billing cycle renew on 2025-01-01?
Not for the one-off item no.
It is an one-off payment without recurring period.
Ideally, this payload suits my case but the line item is not a prorated one:
payload = {
customer: "cus_QrJ7raz6gTeqjN",
invoice_items:
[{
price_data: {
product: "prod_MBN105BNaSFeHX",
unit_amount: 142800, currency: "USD",
tax_behavior: "exclusive"
},
quantity: 1,
tax_rates: ["txr_1PdgGxDgQLhhFEp9YtTvKSux"],
period: {
start: (Time.now.utc - 1.day).to_i,
end: (Time.now.utc - 1.day + 1.year).to_i
}
}]
}