2 minutes February 23, 2024

How can I integrate the Stripe Live Tax API in Shopware 6?

Live tax rate calculation is required for e-commerce websites. To ensure legal compliance with dynamic tax rates, enhance customer experience through accurate cost transparency, and automate processes for efficient global operations. 

This feature guarantees real-time, error-free tax calculations, facilitating seamless transactions and precise financial reporting.

Steps for live tax calculation using Stripe Live Tax API

  • Collect API key from Stripe developer account.
    • Login to the Stripe dashboard
    • Select the “Developer” menu in the header
    • Select “API Keys” tab and create a Key

https://tinyurl.com/yr377vh5

  • Create a new subscriber with the event CartChangedEventSubscriber

         Register the Subscriber in the services file

/custom/plugins/HatslogicLiveTax/src/Resources/config/services.xml

We need to do the same for the following subscribers also

  • CustomerAddressWrittenSubscriber
  • CustomerSetDefaultShippingAddressEventSubscriber
  • CustomerLoginEventSubscriber
Create the subscriber file in

/custom/plugins/HatslogicLiveTax/src/Subscriber/CartChangedEventSubscriber.php

  • Create a service class named CustomTax in the following path /custom/plugins/HatslogicLiveTax/src/Service/CustomTax.php
 We can write code for API call here and also we can add if we have any kind of additional logic.
We have configured the Stripe secret key in the plugin configuration.
We are fetching this value like this

$stripeSecretKey = $this->systemConfigService->get(‘HatslogicLiveTax.config.hatsStripeSecretKey’);

  • By calling the function getLineitemTax() we will get the latest tax amount by the cart.

Now we need to alter the tax calculations by this value.

For that, we need to use the cart processor and override the existing cart tax calculations

Register the cart processor in the services file

/custom/plugins/HatslogicLiveTax/src/Resources/config/services.xml

Create CustomCartProcessor file in the following path

/custom/plugins/HatslogicLiveTax/src/Core/Checkout/CustomCartProcessor.php

Here we are updating tax calculations. If the cart has any additional kind of taxes that also will add as a separate tax item.

We need to make changes to the invoice file and the order summary pages.
For the storefront changes, we need to upgrade the following twig templates.

/custom/plugins/HatslogicLiveTax/src/Resources/views/storefront/page/checkout/checkout-item.html.twig

/custom/plugins/HatslogicLiveTax/src/Resources/views/storefront/page/checkout/summary/summary-position.html.twig

These are the simple required steps to set up a Stripe live tax calculation with the Shopware 6 checkout.

blog
Greetings! I'm Aneesh Sreedharan, CEO of 2Hats Logic Solutions. At 2Hats Logic Solutions, we are dedicated to providing technical expertise and resolving your concerns in the world of technology. Our blog page serves as a resource where we share insights and experiences, offering valuable perspectives on your queries.
Aneesh ceo
Aneesh Sreedharan
Founder & CEO, 2Hats Logic Solutions
Subscribe to our Newsletter
Arsha Contact

    Stay In The Loop!

    Subscribe to our newsletter and learn about the latest digital trends.