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.