#kratos6753
1 messages · Page 1 of 1 (latest)
Hello 👋
Can you try setting pending_invoice_item_behavior to include when creating the invoice?
https://stripe.com/docs/api/invoices/create#create_invoice-pending_invoice_items_behavior
we are not using this option, but still were able to add pending invoiceitems implicitly, how come this instance (req_uYt95sF4JIcw3R) we were not able to do that implicitly?
I think the default behavior on the pending_invoice_item is exclude. Can you share an example request where this worked automatically?
stripe.InvoiceItem.create(customer='xxxx', currency='eur', amount=1800, description='invoice 1234xxx')
stripe.Invoice.create(**{
"description": "xxxxxx1234",
"application_fee_amount": "12",
"auto_advance": "True",
"statement_descriptor": "xxxxx12",
"default_payment_method": "pm_1MZpqxA7BWdKIiAU2fg6Wbyf",
"customer": "cus_NKUqcGyttAQU8n",
"transfer_data": {
"destination": "acct_16nyiVHY17xxxxx"
}
})
I understand that as per documentation, the default behavior is exclude, but we got it to work without explicitly using that option. we are using the below API version - 2020-08-27
does this version make any difference, may be the documentation is not applicable for this api version
I think the issue here was a race condition between the creation request for the invoice item and invoice
Looking at the invoice item creation timestamp, it
was created on 2023-04-12 11:44:11 UTC
The invoice creation request came in at the same time
https://dashboard.stripe.com/test/logs/req_uYt95sF4JIcw3R
2023-04-12 11:44:11 UTC
Assuming the invoice create request landed first, there were no invoice items at that point to invoice the customer for
but we are running this code in sequence, how come it will be asynchronous? if it can be asynchronous - is there some guideline to write code handling the race condition?
I think the stripe-python library does support automatic retries for failed requests.
https://github.com/stripe/stripe-python#configuring-automatic-retries
If that doesn't work, you'd likely want to wait for invoiceitem creation request to come back with a response and then try to create an invoice
if two pending invoice items are of different currency and we create invoice without passing currency param, would this cause any issue? for example - one item is in usd & other one in eur
I think it would only pick up one of those types of items, likely the one for the customer's default currency. But I don't have time to test this at the moment. Would you be able to try that in test mode to see what happens?
ok, will check. Thanks for the help.