-
Notifications
You must be signed in to change notification settings - Fork 684
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[12.x] Implement invoice renderer (#1304)
* Implement invoice renderer * wip * wip * formatting * Add default renderer in service provider Co-authored-by: Taylor Otwell <taylor@laravel.com>
- Loading branch information
1 parent
2dbcf86
commit e0767e6
Showing
5 changed files
with
84 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Laravel\Cashier\Contracts; | ||
|
||
use Laravel\Cashier\Invoice; | ||
|
||
interface InvoiceRenderer | ||
{ | ||
/** | ||
* Render the invoice as a PDF and return the raw bytes. | ||
* | ||
* @param \Laravel\Cashier\Invoice $invoice | ||
* @param array $data | ||
* @param array $options | ||
* @return string | ||
*/ | ||
public function render(Invoice $invoice, array $data = [], array $options = []): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Laravel\Cashier\Invoices; | ||
|
||
use Dompdf\Dompdf; | ||
use Dompdf\Options; | ||
use Laravel\Cashier\Contracts\InvoiceRenderer; | ||
use Laravel\Cashier\Invoice; | ||
|
||
class DompdfInvoiceRenderer implements InvoiceRenderer | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function render(Invoice $invoice, array $data = [], array $options = []): string | ||
{ | ||
if (! defined('DOMPDF_ENABLE_AUTOLOAD')) { | ||
define('DOMPDF_ENABLE_AUTOLOAD', false); | ||
} | ||
|
||
$dompdfOptions = new Options; | ||
$dompdfOptions->setChroot(base_path()); | ||
|
||
$dompdf = new Dompdf($dompdfOptions); | ||
$dompdf->setPaper($options['paper'] ?? 'letter'); | ||
$dompdf->loadHtml($invoice->view($data)->render()); | ||
$dompdf->render(); | ||
|
||
return (string) $dompdf->output(); | ||
} | ||
} |