Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

CrastyCrap's avatar

Customize laravel cashier stripe invoice

Hello, How can i customize (appearnecre ) laravel cashier invoice that was downloaded when i call the following function

$company->generateInvoice($inoviceID);
0 likes
3 replies
LaryAI's avatar
Level 58

To customize the appearance of the invoice generated by Laravel Cashier Stripe, you can modify the invoice template provided by Stripe.

First, you need to retrieve the invoice object from Stripe using the invoice ID. Then, you can update the invoice template by modifying the HTML and CSS.

Here's an example code snippet:

use Stripe\Invoice;

$invoice = Invoice::retrieve($invoiceID, ['expand' => ['charge']]);
$invoicePdf = $invoice->pdf(['footer' => '<p>Your custom footer</p>']);

// Modify the appearance of the invoicePdf here

// Download the modified invoice
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="invoice.pdf"');
echo $invoicePdf;

In this example, we retrieve the invoice object from Stripe and generate the PDF version of the invoice. Then, we can modify the appearance of the invoicePdf by updating the HTML and CSS. Finally, we download the modified invoice as a PDF file.

Note that this is just an example and you can customize the appearance of the invoice as per your requirements.

Hassankhan's avatar
Level 1

To customize the Laravel Cashier Stripe invoice in Laravel, you can use the built-in Laravel Cashier event system to listen for specific events and modify the invoice before it is sent to Stripe. Here's a step-by-step guide to customizing the invoice:

Step 1: Create an Event Listener Create an event listener that will be responsible for modifying the invoice. You can generate the listener using the Artisan command:

php artisan make:listener CustomizeInvoice

This command will generate a new listener file in the app/Listeners directory.

Step 2: Implement the Listener
Open the generated listener file (app/Listeners/CustomizeInvoice.php) and modify the handle method. This method will receive the InvoiceCreated event, which contains the invoice object. You can customize the invoice in this method. Here's an example:

use Laravel\Cashier\Events\InvoiceCreated;

class CustomizeInvoice { public function handle(InvoiceCreated $event) { $invoice = $event->invoice;

    // Perform your customization here
    $invoice->description = 'Custom Invoice Description';

    // Save the modified invoice
    $invoice->save();
}

}

In this example, we update the invoice's description to a custom value. You can modify other invoice properties as needed.

Step 3: Register the Event Listener Next, you need to register your event listener in Laravel's event service provider. Open the app/Providers/EventServiceProvider.php file and add the following code inside the listen property:

protected $listen = [
    InvoiceCreated::class => [
        CustomizeInvoice::class,
    ],
];


protected $listen = [ InvoiceCreated::class => [ CustomizeInvoice::class, ], ]; Step 4: Run Migrations If you haven't already done so, run the migrations to ensure the necessary tables are created in your database: php artisan migrate

Step 5: Clear Configuration Cache If your Laravel application is in production or you have a configuration cache enabled, you need to clear the cache so that the event listener is registered:

php artisan config:clear


1 like

Please or to participate in this conversation.