#devangbhuva97-invoices
1 messages · Page 1 of 1 (latest)
@waxen siren you can delete the items before they're attached to a finalized invoice (https://stripe.com/docs/api/invoiceitems/delete)
can you say more about what "something [going] wrong" means exactly?
"something [going] wrong" means got any error in create invoice due to pass some bad data
We are creating multiple invoice items. So there are also chances that getting error while create any 1 invoice item
Yes we can delete items but we need to store in local variable after creating item. Is there any better way? Similar like DB transaction commit & rollback
hmm if you pass invalid parameters you just get an error back, no item gets created and no action happens
so I don't understand the concern
you also wouldn't pass invalid parameters since you'd test all this code in test mode during development to iron out problems!
Suppose I want to create 5 invoice items. 2 items created & on 3rd item, I got some error
Yes.. we try to test all the things. But there will be couple for user inputs we need to use there. So due to that inputs, stripe throw error in create invoice item
then 2 items are created.
you get an exception from our library when creating the third one so your code either crashes or you catch it and try again
Yes.. but I want - either all 5 items should create or 0.
then if you catch an exception then you could call some other code you have to delete the existing invoice items(the API I linked above) and rollback that way, sure.
Ok.. so there is not direct any way to handle like db transaction. Need to handle manually on catch by storing created items data
yes
Is there any API to create bulk invoice items?
no
😃
well, kind of, there's add_invoice_items when creating a subscription https://stripe.com/docs/api/subscriptions/create#create_subscription-add_invoice_items
but not for one-off invoices, it's a separate API call for each item
but it's not fit in our usecase
It'll create price inside given product if we pass price_data
Our usecase:
We have list of products in page. Where customer will be able to choose multiple products. Products will be either recurring or onetime.
We are only creating recurring products in stripe & onetime products maintain in our system
Here tricky part is we are also giving to support to add setup fee with recurring - That's not support in stripe
So now if we'll use add invoice items to charge setup fee, stripe will create new price under that product
sorry I'm a bit lost, this is a brand new question? Not sure where price_data came from..
we are also giving to support to add setup fee with recurring - That's not support in stripe
hmm it is? https://stripe.com/docs/billing/invoices/subscription#first-invoice-extra
So now if we'll use add invoice items to charge setup fee, stripe will create new price under that product
if you useprice_datayes, but that's just how it works. You should use a separate product I'd suggest
yeah but suddenly we're talking about subscriptions when before I thought it was one off invoices. but ok
so what's the problem? it will generate a new Price yes, that's intentional, as it makes reporting/analysis easier when specific Prices are used for all the line items rather than being ad-hoc
Problem is we don't want to create onetime price in stripe.
ok then don't, you can technically just call https://stripe.com/docs/api/invoiceitems/create#create_invoiceitem-amount directly(one by one) instead of add_invoice_items then
but add_invoice_items creates Prices yes, it's intentional as I said, to make reporting more rich, so all the newer parts of the API will work this way
That's great but if there will be millions of purchase for same product with setup fee, it'll create too many onetime price for setup fee
yep that's fair feedback! The team is aware of that.
Then why use price_data?
if you're going to have same setup fee of e.g. $100 each time, just pass the price_xxx of the one you created?
you don't have to create a new one every single time with price_data!
Yes.. currently we are trying build this flow.. but edge case is handling error. Because stripe will automatically fetch all the pending items in create invoice. We are not able to track how many items added
Yes.. it's possible but can not do in our current system. Because we are also supporting other payment providers. So it's overhead to maintain onetime products with payment providers. So it's easy to charge directly runtime