Skip to content

Commit 50f2f08

Browse files
[8.x] Document invoice renderer (laravel#7639)
* Update billing.md * Update billing.md * Update billing.md Co-authored-by: Taylor Otwell <[email protected]>
1 parent ff7f2bf commit 50f2f08

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

billing.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,35 @@ The `downloadInvoice` method also allows for a custom filename via its third arg
15861586

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

1589+
<a name="custom-invoice-render"></a>
1590+
#### Custom Invoice Renderer
1591+
1592+
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:
1593+
1594+
use Illuminate\Support\Facades\Http;
1595+
use Laravel\Cashier\Contracts\InvoiceRenderer;
1596+
use Laravel\Cashier\Invoice;
1597+
1598+
class ApiInvoiceRenderer implements InvoiceRenderer
1599+
{
1600+
/**
1601+
* Render the given invoice and return the raw PDF bytes.
1602+
*
1603+
* @param \Laravel\Cashier\Invoice. $invoice
1604+
* @param array $data
1605+
* @param array $options
1606+
* @return string
1607+
*/
1608+
public function render(Invoice $invoice, array $data = [], array $options = []): string
1609+
{
1610+
$html = $invoice->view($data)->render();
1611+
1612+
return Http::get('https://example.com/html-to-pdf', ['html' => $html])->get()->body();
1613+
}
1614+
}
1615+
1616+
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.
1617+
15891618
<a name="checkout"></a>
15901619
## Checkout
15911620

0 commit comments

Comments
 (0)