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

ianmcqueen's avatar

Adding Tax Amount to Transaction Metadata with Laravel Cashier

Hi there,

I have a platform utilizing Laravel Cashier and I noticed that when I export my Stripe transactions in a CSV file that no tax amount is specified under the Stripe-specific tax field for each transaction (it's showing 0.00).

Sure taxPercentage() calculates the correct tax to charge a user and does so accordingly, but this itemized amount of what the tax amount actually was is not available in Stripe reporting.

How are other users handling this? Are you adding metadata to each transaction via a webhook when a transaction is successful?

Thanks in advanced. Searching for solutions!

0 likes
1 reply
ianmcqueen's avatar
ianmcqueen
OP
Best Answer
Level 8

I've developed my own solution. You have to override the default StripeWebhookController that ships with Laravel Cashier. Then, handle the invoice.payment_succeeded event like this:

public function handleWebhook(Request $request)
{
    $payload = json_decode($request->getContent(), true);

    if (! $this->isInTestingEnvironment() && ! $this->eventExistsOnStripe($payload['id'])) {
        return;
    }

    /*
     * Handle a successful invoice payment
     */

    if ($payload['type'] == 'invoice.payment_succeeded') {
        return $this->addTaxToInvoice($payload);
    }

    /*
     * Use Laravel Cashier's default functionality
     */

    return parent::handleWebhook($request);
}

addTaxToInvoice goes something like:

private function addTaxToInvoice($payload)
{
    $taxAmt = $payload['data']['object']['tax'];

    if ( ! is_null($taxAmt))
    {
        Stripe::setApiKey(env('STRIPE_SECRET'));

        try {
            $charge = Charge::retrieve($payload['data']['object']['charge']);
            $charge->metadata = ['tax_amount' => ($taxAmt / 100)];
            $charge->save();
        } catch (\Exception $e) {
            // Do nothing, charge doesn't exist
        }
    }
}

This will add the tax amount of the invoice to the charge, so that when you export the CSV file, you'll have a column of these amounts. We require this for tax reporting purposes.

Please or to participate in this conversation.