#ZakMcKraken
1 messages · Page 1 of 1 (latest)
Hello 👋
I'm not sure as I haven't tested this flow personally.
An alternative in this case would be using Customer Credit Balance
https://stripe.com/docs/invoicing/customer/balance#working-with-credit-balances
It applies to the next finalized invoice on to a customer
does that help @spring field ?
If I try to do that using price_data and the add_invoice_items param described on https://stripe.com/docs/billing/invoices/subscription#first-invoice-extra, it doesn't let me create a negative amount (and also, sadly, requires a product to be created ahead).
Also, How exactly are you doing this? Can you share an example?
You likely want to create a negative invoice item as shown in the example here
https://stripe.com/docs/api/invoiceitems/create
by specifying a negative amount, customer and subscription ID
so I'm actually trying to get away from using a credit balance because that doesn't work as it should in a tax context (aka tax gets applied to the full amount and then the credit is deducted, instead of deducting the credit and then calculating the taxes)
as I said invoice items works but I was trying to use add_invoice_items to reduce the calls
[
'price_data' => [
'currency' => 'USD',
'tax_behavior' => 'exclusive',
'unit_amount_decimal' => -100,
]
]
]```
It's missing the product param but this will still return
Stripe\Exception\InvalidRequestException with message 'This value must be greater than or equal to 0 (it currently is '-0.1e3').
which doesnt make any sense since according to the documentation we should be able to use this for discounts
this feels like a bug
You can exclude the product if you are using a Price ID but not if you are using price_data
(also maybe credit balance does work for the purpose if I use type "applied_to_invoice" I have to try that)
That sounds like it would be closer to what you are trying to achieve
@rich nimbus I know, just omitted the product to show you an example
I don't think the behavior you are seeing is a bug, just maybe not as useful as it could be
Since our docs for add_invoice_item state that, for unit_amount must be a positive integer in cents and unit_amount_decimal is the same as unit amount but accepts decimal values
I'll give you that
but one would expect it to behave the same as adding an invoice item
and also the fact that https://stripe.com/docs/billing/invoices/subscription#first-invoice-extra
the title is "Add an extra charge or discount on a subscription’s first invoice" but if it doesn't accept negative value, how do you add a discount?
I'm guessing you'd have to go ahead and create a product with a negative price?
Well you don't have to create a Product record, just a Price record
so like a price with a non-active product beforehand
Or you could use product_data when creating the Price to avoid a new Product record: https://stripe.com/docs/api/prices/create#create_price-product_data
Then you could provide as little as a name to indicate what the product/price is for
yeah that's what I meant
I was assuming product_data.active would have to be set to false so it doesn't show up in the UI
Yes that would be a good approach
I think so
the reason I don't like credit balance and pending invoice items is that we could run into race conditions
aka the discount is applied to the wrong invoice
I can understand that, since credit balances don't discriminate which invoice they are applied to
TY for the help, I'll try what we discussed