Stop creating your Laravel invoices manually

Every Laravel E-commerce project requires processing payments and generating invoices. Yet for the best experience this flow needs to be tailored for each project.

Just to give you a few use cases:

Sometimes a successful payment is confirmed with an invoice receipt. That’s the simple use case.

And sometimes there is no payment (yet) but there still is an invoice. In this case the customer pays some time after receiving the service/product. Or it’s a correcting invoice accompanied by an outbound payment.

There are probably other use cases.

And what’s common for all of these?

All these use cases require an invoice generator.

So that’s why I have created laravel-invoicable. You can use it to create your tailored payment process. Together with laravel-payable-redirect-mollie for example (see previous post).

Using this package, you can:

  • create an invoice
  • add lines (items) to the invoice
  • add seller info to the invoice
  • add customer info to the invoice
  • add payment info to the invoice
  • calculate taxes and totals
  • generate a pdf of the invoice
  • handle discounts*
  • set the currency
  • set invoice status

* You can handle discounts by adding a line with a negative amount, or describe it in the line description field (“product x incl 30% discount”) and subtract the discount manually.

Ready to stop creating your Laravel invoices manually? Check out the github page for more information and code examples.

Create your first Laravel package

Laravel package development from scratch

Learning Laravel package development doesn't have to be hard. If you know how to create a basic Laravel app, you can write packages as well.

I've opened this course up for free to the first 100 subscribers only.

Join now and get the first lesson in your inbox right away.

We won't send you spam. Unsubscribe at any time. Powered by ConvertKit

12 Replies to “Stop creating your Laravel invoices manually”

  1. Thanks for this package as i am suffering from same issue =(

    as i need an invoice to be like receipt voucher which is really a big headache when i implement it .

    thanks for your effort and time

    thanks again brother ^^

  2. Hey there, I’m getting this error:

    Column ‘invoicable_id’ cannot be null (SQL: insert into `invoices` (`invoicable_id` …)

    I’ve set the Invoice to an order like this:
    $invoice = $order->invoices()->create([]);
    $invoice->invoicable_id = SOME_ID;
    $invoice = $invoice->addAmountInclTax(AMOUNT, ‘Some description’, 0);

    Any ideas? Do I have to define $invoice->invoicable_id ?

  3. Hi Sander,

    In need of an invoice PDF, I decided to use this package as well (next to your laravel-payable-redirect-mollie package) and encounter the same problem as Robby here above mentions.

    Is there a solution for this? Right now, the package is not working…

    Cheers, Sven

      1. Hi Sander,

        Thank you! That is the solution for this problem. 🙂
        Apparently I didn’t found it while looking further into this…. Excuse me for that.

        Cheers, Sven

  4. Hi Sander,

    I’m back again…probably with a ‘noob’ question. Again…
    How to store or download the generated PDF?

    The mentioned methods ($invoice->download(); & $invoice->pdf();) don’t do anything.
    When I dd() them I see something which looks like a PDF, but saving this from the browser results in a corrupt PDF file.

    Do I need a Dompdf method here?
    I really appreciate your example code, but again it’s not working in my code. Maybe a more Laravel-like approach might help newbies?

    Kind regards, Sven

    1. I’m still struggling with this. I want to create the invoice in an event which is fired after the order is placed. I supply the $order data to the event handler, but the invoice is still not being created.

      I will try to put all the invoice generation code in the controller method, but this is not best practice… The method will be long AND it is not possible to use a queue for the invoice generation, which might be a good idea.

      Can you please provide any help about this?

      1. It works right away when placed in the controller method… 🙂
        So…1 day spoilt on trying to get this in an event.

        Maybe, when you have time, you can supply an example using the Laravel Event system with this package?
        Again, for noobs some things are not always clear…

        I hope somebody else can use my use-case.

  5. Hi Sven,

    Glad to hear it worked out.

    My best guess is that the issue when using events is because the invoice pdf/download response is actually a byte stream (so it supports larger pdfs).

    You’d need something to process this stream in the event listener. When you are processing this stream in your browser, your browser is handling it for you.

Leave a Reply

Your email address will not be published. Required fields are marked *