#skdzines_invoice-preview-api

1 messages ยท Page 1 of 1 (latest)

earnest elmBOT
#

๐Ÿ‘‹ 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.

queen loom
haughty prism
#

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'
]
}

#
#

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'
]
}

#

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

queen loom
haughty prism
#

here's the subscrtion id where the 10% discount is applied sub_1RyZ5nDjdxJUaev1vqT7jXCP

queen loom
#

What is the response from the request to get the upcoming invoice?

haughty prism
#

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?

queen loom
#

We do not log the response from a GET request hence I'm asking the response to be shared here

haughty prism
#

I shared the response above

queen loom
#

Yes, looking at that

haughty prism
#

okay, sorry, I thought you were saying something else

queen loom
#

I see the discount is there, can you share what the total amount expect vs. what you see here?

haughty prism
#

yeah, let me send it again without the subscription items as part of the request because that seems to respond correctly.

#

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

queen loom
#

I see that 90 is included in the discount_amounts. Are you taking taxes into account? What amount did you expect?

haughty prism
#

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

queen loom
haughty prism
#

should it be the "discounts: [ { coupon: "P5EwBtfH" } ] per line item?

queen loom
#

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

earnest elmBOT
haughty prism
#

okay, that's what I figured. Plus I had tried passing it at the line item level as shown above previously to no avail

queen loom
#

Did that work?

haughty prism
#

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

frail kernel
#

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

#
haughty prism
#

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?

earnest elmBOT