#skdzines_invoice-preview-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/1409526220525146122
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi, can you share the request id and the response you get from both instances please? Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
Request without discounts applied: req_bmE4sK6JMyflKP
actually I don't think that's the correct request. I'm not seeing the /preview or upcoming invoice endpoint to find the correct request id
here is a request I'm making locally to the stripe.Invoice.upcoming endpoing with the subscription_items that is not returning the discounts amounts:
Request body:
{
'customer': 'cus_SuNrMiTtXt0hyE',
'subscription': 'sub_1RyZ5nDjdxJUaev1vqT7jXCP',
'stripe_account': 'acct_1L08CfDjdxJUaev1',
'subscription_items': [
{
'quantity': 1,
'price_data': {
'currency': 'USD',
'product': 'prod_M9Ad8EmDbyskDh',
'recurring': {
'interval': 'year',
'interval_count': 1
},
'tax_behavior': 'exclusive',
'unit_amount': 36000
}
},
{
'quantity': 2,
'price_data': {
'currency': 'USD',
'product': 'prod_M9AdtdQ7MbcnZr',
'recurring': {
'interval': 'year',
'interval_count': 1
},
'tax_behavior': 'exclusive',
'unit_amount': 21600
}
}
],
'subscription_proration_date': 1755802079,
'subscription_billing_cycle_anchor': 'unchanged',
'subscription_proration_behavior': 'always_invoice',
'expand': [
'lines.data.plan.product'
]
}
INFO [stripe:log_info:128] [cluster=dev] [] [pid=140][tname=MainThread][request=293dc348-9b33-478e-a644-d1155ef215d7]: message='Stripe API response' path=https://api.stripe.com/v1/invoices/upcoming?customer=cus_SuNrMiTtXt0hyE&subscription=sub_1RyZ5nDjdxJUaev1vqT7jXCP&subscription_items[0][quantity]=1&subscription_items[0][price_data][currency]=USD&subscription_items[0][price_data][product]=prod_M9Ad8EmDbyskDh&subscription_items[0][price_data][recurring][interval]=year&subscription_items[0][price_data][recurring][interval_count]=1&subscription_items[0][price_data][tax_behavior]=exclusive&subscription_items[0][price_data][unit_amount]=36000&subscription_items[1][quantity]=2&subscription_items[1][price_data][currency]=USD&subscription_items[1][price_data][product]=prod_M9AdtdQ7MbcnZr&subscription_items[1][price_data][recurring][interval]=year&subscription_items[1][price_data][recurring][interval_count]=1&subscription_items[1][price_data][tax_behavior]=exclusive&subscription_items[1][price_data][unit_amount]=21600&subscription_proration_date=1755802079&subscription_billing_cycle_anchor=unchanged&subscription_proration_behavior=always_invoice&expand[0]=lines.data.plan.product response_code=200
Response:
"lines": {
[billingstripesvc] "data": [
[billingstripesvc] {
[billingstripesvc] "amount": 32382,
[billingstripesvc] "amount_excluding_tax": 32382,
[billingstripesvc] "currency": "usd",
[billingstripesvc] "description": "Remaining time on Team Advantage Admin Seat (with 10.0% off) after 21 Aug 2025",
[billingstripesvc] "discount_amounts": [
[billingstripesvc] {
[billingstripesvc] "amount": 0,
[billingstripesvc] "discount": "di_1RyblrDjdxJUaev190NFfSFZ"
[billingstripesvc] }
[billingstripesvc] ],
[billingstripesvc] "discountable": false,
[billingstripesvc] "discounts": [],
[billingstripesvc] "id": "il_tmp_1a0629DjdxJUaev1cb3513dc",
[billingstripesvc] "invoice": null,
[billingstripesvc] "invoice_item": "ii_1S00PsDjdxJUaev1wOQNuV3Q",
[billingstripesvc] "livemode": false,
[billingstripesvc] "metadata": {},
[billingstripesvc] "object": "line_item",
[billingstripesvc] "parent": {
Here's a successful one with an empty subscription_items being sent as part of the rquest:
Request:
{
'customer': 'cus_SuNrMiTtXt0hyE',
'subscription': 'sub_1RyZ5nDjdxJUaev1vqT7jXCP',
'stripe_account': 'acct_1L08CfDjdxJUaev1',
'subscription_items': [
],
'subscription_proration_date': 1755802079,
'subscription_billing_cycle_anchor': 'unchanged',
'subscription_proration_behavior': 'always_invoice',
'expand': [
'lines.data.plan.product'
]
}
INFO [stripe:log_info:128] [cluster=dev] [] [pid=140][tname=MainThread][request=f1db6542-8d7f-43a8-aad1-f6a32db272ab]: message='Stripe API response' path=https://api.stripe.com/v1/invoices/upcoming?customer=cus_SuNrMiTtXt0hyE&subscription=sub_1RyZ5nDjdxJUaev1vqT7jXCP&subscription_proration_date=1755802079&subscription_billing_cycle_anchor=unchanged&subscription_proration_behavior=always_invoice&expand[0]=lines.data.plan.product response_code=200
Response:
"lines": {
[billingstripesvc] "data": [
[billingstripesvc] {
[billingstripesvc] "amount": 90000,
[billingstripesvc] "amount_excluding_tax": 90000,
[billingstripesvc] "currency": "usd",
[billingstripesvc] "description": "3 seats \u00d7 Team Advantage Admin Seat (at $300.00 / year)",
[billingstripesvc] "discount_amounts": [
[billingstripesvc] {
[billingstripesvc] "amount": 9000,
[billingstripesvc] "discount": "di_1RyblrDjdxJUaev190NFfSFZ"
[billingstripesvc] }
[billingstripesvc] ],
[billingstripesvc] "discountable": true,
[billingstripesvc] "discounts": [],
[billingstripesvc] "id": "il_tmp_1b0804DjdxJUaev10fcb4217",
[billingstripesvc] "invoice": null,
[billingstripesvc] "livemode": false,
[billingstripesvc] "metadata": {
[billingstripesvc] "action": "new_subscription",
[billingstripesvc] "group_id": "2822279",
[billingstripesvc] "local_subscription_id": "16365",
[billingstripesvc] "package_id": "134",
it does not look like you're passing a discount, and that subscription does not look like it has discounts already: https://dashboard.stripe.com/test/logs/req_BMVQDXDFBVXy6k
Are you able to pass that coupon id, https://docs.stripe.com/api/invoices/upcoming?api-version=2024-12-18.acacia#upcoming_invoice-coupon
here's the subscrtion id where the 10% discount is applied sub_1RyZ5nDjdxJUaev1vqT7jXCP
What is the response from the request to get the upcoming invoice?
I can paste what the full response is from my local console for the upcoming invoice. For some reason I can only see the actual invoice in the logs, not the preview invoice.
ah, I didn't realize the filter was there to see the GET requests. One sec
request id for the upcoming invoice req_MSfragnqsqE3O9
but where is the response for that GET request in the dashboard?
We do not log the response from a GET request hence I'm asking the response to be shared here
I shared the response above
Yes, looking at that
okay, sorry, I thought you were saying something else
I see the discount is there, can you share what the total amount expect vs. what you see here?
yeah, let me send it again without the subscription items as part of the request because that seems to respond correctly.
new request id: req_Jag2LTolRYyZw0
I believe the problem is we want to send a preview request with a new set of line items that aren't part of the actual invoice yet for users to be able to preview their total amount with discounts before committing to the upgrade with addtional seats
hence, we need to send the full list of existing line items plus the new as the subscription_items[]
Example line item:
3 seats x $300 = $900
$900 * .10 = $90 discount amount
I see that 90 is included in the discount_amounts. Are you taking taxes into account? What amount did you expect?
We expect the $90 discount amount. The calculations are correct when not passing the list of subscription_items as part of the request. The problem is we need to pass the array of subscription_items but when we provide them, the discounts are not being applied to each line item
as shown in the first example of response data
Ok, so on this request, https://dashboard.stripe.com/test/logs/req_Jag2LTolRYyZw0 you're not changing anything.
However, on this request, you're passing the subscription items: https://dashboard.stripe.com/test/logs/req_MSfragnqsqE3O9
When you pass the subscription items, the discount is not applicable. When you pass the subscription items, can you pass the discount, https://docs.stripe.com/api/invoices/upcoming?api-version=2024-12-18.acacia#upcoming_invoice-discounts please?
should it be the "discounts: [ { coupon: "P5EwBtfH" } ] per line item?
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
The discount was inherited from the subscription but I see discount was not applicable. I'm trying to debug why so passing outside of the line items is what we'd want
okay, that's what I figured. Plus I had tried passing it at the line item level as shown above previously to no avail
Did that work?
No, here's the new request id req_ER1LwoYsmK60cz
response
also tried using "discounts: [ { discount: "di_1RyblrDjdxJUaev190NFfSFZ" } ]" per line item with the same result on this request: req_yMqU6oeRVVuSIY
Hmm it does seem odd that the discount is represented there but doesnt reflect in discounted amounts
However, the line items also are not the full value from the price data you sent, by more than what the small hours of proration would suggest
Are you trying to update the existing items with new pricing in this preview? If so, i noticed you're not specifying the item id of the existing items
Other thoughts:
1/ Trying the top level coupon parameter: https://docs.stripe.com/api/invoices/upcoming?lang=curl&api-version=2024-06-20#upcoming_invoice-coupon
2/ Using the Preview Invoice api instead of Upcoming Invoice: https://docs.stripe.com/api/invoices/create_preview?lang=curl&api-version=2024-06-20
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
what do you mean by "the line items also are not the full value from the price data"?
I believe the problem is we want to send a preview request with a new set of line items that aren't part of the actual invoice yet for users to be able to preview their total amount with discounts before committing to the upgrade with addtional seats
hence, we need to send the full list of existing line items plus the new as the subscription_items[]
is the create_preview a replacement for upcoming?
I can give it a try but will take me a little bit of time
I need to run to other meetings, can I refer back to this thread later?