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.
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 ^^
No problem Ahmed, happy this package helps you out!
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 ?
Hi Robby,
Please open an issue for this in the github repo:
https://github.com/sandervanhooft/laravel-invoicable
Make sure to include any additional code necessary for others to reproduce the problem.
Sander
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
Hi Sven,
Take a look at this issue.
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
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
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?
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.
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.
Hi, thanks for writing this article. After trying laraveldailys invoice package which didn’t work out for me, I am eager to try yours.