#arvindkgs

1 messages ยท Page 1 of 1 (latest)

low socketBOT
hybrid hazel
#

no there isn't. You'd create the items one by one with an API call to the Invoie Item create endpoint

glossy ivy
#

So first create invoice and then pass along that invoice id next when calling create invoice item api?

#

@hybrid hazel ๐Ÿ‘†

#

@hybrid hazel Also when does from_invoice work? Is it only on one-off invoices?

hybrid hazel
hybrid hazel
glossy ivy
hybrid hazel
#

it links to some documentation, it's some feature for copying an existing invoice to a new one, did you have a specific question?

glossy ivy
#

Yes, I tried to use it, but it does not work for invoices generated from subscriptions. Is this expected behavior?

hybrid hazel
#

did you read the docs linked from the API reference?

glossy ivy
#

I am not revising a invoices after finalization. This is while creating a new invoice via api

#

Ohh does from_invoice become a revision of earlier invoice

#

I thought it just copies the values

hybrid hazel
#

I don't really know or understand that invoice revision feature, I've never used it or spoke to a user who was using it

glossy ivy
#

Also I just tried the api to create invoice first and I am getting error


An invoice cannot be generated for the specified customer as there are no pending invoice items. Check that the correct customer is being specified or create any necessary invoice items first.```
#

This is request body

{
  "collection_method": "send_invoice",
  "due_date": "1695895200",
  "auto_advance": "false",
  "customer": "cus_OL86sE8CaHbzmt"
}```
#

This is response

{
  "error": {
    "code": "invoice_no_customer_line_items",
    "doc_url": "https://stripe.com/docs/error-codes/invoice-no-customer-line-items",
    "message": "Nothing to invoice for customer",
    "param": "customer",
    "request_log_url": "https://dashboard.stripe.com/test/logs/req_0KaV5o81cHlC5j?t=1690455620",
    "type": "invalid_request_error"
  }
}```
#

This is the request id - req_0KaV5o81cHlC5j

hybrid hazel
#

it's because you're using an old API version where Invoices worked differently

#

it used to be that you had to create the items first ,and then create the Invoice to "pull them in"

#

relates to https://stripe.com/docs/upgrades#2022-08-01

The pending_invoice_items_behavior parameter on create Invoice no longer supports the include_and_require value. When the parameter is omitted the default value of pending_invoice_items_behavior is now exclude.

glossy ivy
#

How do I use new api version ? Update stripe jar? I am using java

hybrid hazel
#

you'd have to update the version of stripe-java yes(note of course that will involve various breaking changes so you need to read the Changelog carefully and test existing code)

#

or as I mentioned you can pass an API parameter to opt in to the current Invoice item behaviour

glossy ivy
#

okay I will try it thank you

hybrid hazel
#

note that you'll probably have to use .putExtraParam("pending_invoice_items_behavior", "exclude") directly on a InvoiceCreateParams in order to pass the parameter, since I assume the old library version doesn't expose that argument

glossy ivy
#

Isn't exclude the default behaviour ? Below is from the stripe api docs
```How to handle pending invoice items on invoice creation. One of include or exclude. include will include any pending invoice items, and will create an empty draft invoice if no pending invoice items exist. exclude will always create an empty invoice draft regardless if there are pending invoice items or not. Defaults to exclude if the parameter is omitted.``

hybrid hazel
#

Isn't exclude the default behaviour ?
on the current API version it is

#

you're not on the current API version. The docs are all written from the perspective of what the latest API version does

#

on the old version the default behaviour is "include_and_require" , which is the idea that we can't create the Invoice unless you create the items first ,and then create the Invoice to "pull them in"

glossy ivy
#

The stripe java library I am using has invoiceCreateParams.setPendingInvoiceItemsBehavior() , does this mean I am using new api? How can we check what version api I am on?

hybrid hazel
#

no it just means it has that parameter, we added it at some point to help with the migration and I was over-zealous in assuming you were an older version of the library that didn't have it yet

glossy ivy
#

I see from the stripe logs API version 2020-08-27

hybrid hazel
#

you're on a 2020 API version

#

yes

glossy ivy
#

So I can use invoiceCreateParams.setPendingInvoiceItemsBehavior() or I have to use .putExtraParam("pending_invoice_items_behavior", "exclude")

hybrid hazel
#

the former should work

#

you can just try it without asking me

glossy ivy
#

Sure thanks