Laravel Cashier list all user invoices

826 views Asked by At

How to display all user invoices for referencing in the admin section of the application.

I can get a user invoices by

$userinvoices = $user->invoices();

Or I can get all invoice by stripe API:

$invoices = \Stripe\Invoice::all(array("limit" => 30));

in the second case, I can't get the details of the user the invoice belongs to.

Or is there any way to save invoice data to database on every creation of the invoice in stripe.

1

There are 1 answers

0
AfikDeri On

Your first option is the better way to go since you have all the information on the invoice and also the user info on the object.

If you want, you can go to your stripe dashboard -> Your account -> account settings -> webhooks -> add endpoint -> select events and select the invoiceitem.created event. setup your endpoint in the application and do whatever you need with it.

Example:

public function invoiceCreated(Request $request){

    $payload = $request->all();

    if($payload['type'] == 'invoiceitem.created'){

        // do whatever you want with the $payload["data"]...

    }

}

Good Luck :)