Question

I'm using the following code to get the invoices created by the specified customer:

customer.invoices.all

But it retrieves all the invoices regardless of which customer created them. I also tried the following:

Stripe::Invoice.all(customer: CUSTOMER_ID)

And it behaves the same way. Am I doing something wrong or is this a bug?

Was it helpful?

Solution 2

Update 10/23/2020

The new Stripe API requires the following:

Stripe::Invoice.list(customer: CUSTOMER_ID)

Original Answer

It looks like like calling all on invoices overrides the previous query where it retrieves the invoices for the customer.

The following retrieves all invoices:

customer.invoices.all

The following retrieves all invoices for the customer only:

customer.invoices

OTHER TIPS

Try this:

Stripe::Invoice.all(:customer => "CUSTOMER_ID")

From the API: https://stripe.com/docs/api?lang=ruby#list_customer_invoices

You can try to do something like

  customer = Stripe::Customer.retrieve("cus_6C09m0rCIx3Ld8")
  invoices = Stripe::Invoice.all(:customer => customer.id)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top