vincent15000's avatar

Cashier / Stripe / How to calculate automatically taxes ?

Hello,

I have added Cashier::calculateTaxes(); in the AppServiceProvider.

But sure it's not sufficient.

I had a look at the documentation and it seems to be necessary to configure something. But it's quite difficult for me, because I don't know so much about taxes and it's the first time I really use Stripe and Cashier.

The idea is : a french company will sell subscriptions to clients in Canada and the US.

What do I have to configure in Stripe ?

Thanks for your help.

V

0 likes
3 replies
LaryAI's avatar
Level 58

To automatically calculate taxes using Laravel Cashier and Stripe, you need to configure a few things both in your Laravel application and in your Stripe account. Here's a step-by-step guide to help you set it up:

  1. Enable Tax Calculation in Stripe:

    • Log in to your Stripe Dashboard.
    • Navigate to the "Tax" section and enable automatic tax calculation. This will allow Stripe to calculate taxes based on the customer's location.
  2. Configure Tax Rates in Stripe:

    • In the Stripe Dashboard, set up the tax rates for the regions you are selling to (Canada and the US in your case). Stripe provides a way to automatically calculate these based on the customer's address.
  3. Update Your Laravel Application:

    • Ensure you have the latest version of Laravel Cashier installed. You can update it via Composer:

      composer require laravel/cashier
      
    • In your AppServiceProvider, you can use the Cashier::calculateTaxes() method to enable tax calculation. However, you also need to ensure that your application is providing the necessary customer information to Stripe.

  4. Set Up Customer Information:

    • When creating or updating a customer in Stripe, make sure to include their address information. This is crucial for Stripe to determine the correct tax rate.
    $user = User::find(1);
    
    $user->createOrGetStripeCustomer([
        'address' => [
            'line1' => '123 Main Street',
            'city' => 'Anytown',
            'state' => 'CA',
            'country' => 'US',
            'postal_code' => '12345',
        ],
    ]);
    
  5. Create Subscriptions with Tax Calculation:

    • When creating a subscription, ensure that you pass the tax_behavior parameter to let Stripe know how to handle taxes. This can be set to inclusive, exclusive, or unspecified.
    $user->newSubscription('default', 'price_id')
         ->taxBehavior('exclusive') // or 'inclusive'
         ->create();
    
  6. Testing:

    • Test your setup thoroughly to ensure that taxes are being calculated and applied correctly. You can use Stripe's test mode to simulate transactions.

By following these steps, you should be able to set up automatic tax calculation for your subscriptions using Laravel Cashier and Stripe. Make sure to consult Stripe's documentation for any region-specific tax rules and configurations.

vincent15000's avatar

What's the difference between exclusive, inclusive and unspecified ?

vincent15000's avatar
vincent15000
OP
Best Answer
Level 63

I have found : on stripe, it's necessary to create a tax for the countries where clients are.

Then the tax is automatically applied.

Please or to participate in this conversation.