Skip to content

Commit

Permalink
[8.x] Document invoice renderer (#7639)
Browse files Browse the repository at this point in the history
* Update billing.md

* Update billing.md

* Update billing.md

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
driesvints and taylorotwell authored Jan 31, 2022
1 parent ff7f2bf commit 50f2f08
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions billing.md
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,35 @@ The `downloadInvoice` method also allows for a custom filename via its third arg

return $request->user()->downloadInvoice($invoiceId, [], 'my-invoice');

<a name="custom-invoice-render"></a>
#### Custom Invoice Renderer

Cashier also makes it possible to use a custom invoice renderer. By default, Cashier uses the `DompdfInvoiceRenderer` implementation, which utilizes the [dompdf](https://github.com/dompdf/dompdf) PHP library to generate Cashier's invoices. However, you may use any renderer you wish by implementing the `Laravel\Cashier\Contracts\InvoiceRenderer` interface. For example, you may wish to render an invoice PDF using an API call to a third-party PDF rendering service:

use Illuminate\Support\Facades\Http;
use Laravel\Cashier\Contracts\InvoiceRenderer;
use Laravel\Cashier\Invoice;

class ApiInvoiceRenderer implements InvoiceRenderer
{
/**
* Render the given invoice and return the raw PDF bytes.
*
* @param \Laravel\Cashier\Invoice. $invoice
* @param array $data
* @param array $options
* @return string
*/
public function render(Invoice $invoice, array $data = [], array $options = []): string
{
$html = $invoice->view($data)->render();

return Http::get('https://example.com/html-to-pdf', ['html' => $html])->get()->body();
}
}

Once you have implemented the invoice renderer contract, you should update the `cashier.invoices.renderer` configuration value in your application's `config/cashier.php` configuration file. This configuration value should be set to the class name of your custom renderer implementation.

<a name="checkout"></a>
## Checkout

Expand Down

0 comments on commit 50f2f08

Please sign in to comment.