An Interest In:
Web News this Week
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
- April 18, 2024
Getting started with Stripe Tax via the Orders API
What youll learn
In this episode youll learn how to modify your integration to leverage Stripe Tax. This is enabled through the new Orders API which is now in public beta.
If you have a direct (a.k.a. custom) integration with Stripe using Payment Intents to accept payments, until now you will not have been able to take advantage of Stripe Tax to automate tax calculation and collection. As Kelly Moriarty noted in her recent blog post on building Stripe Tax, a gingerbread man wearing chocolate pants is taxed at a different rate in the UK as one that isnt. Tax calculation is difficult and thats where Stripe Tax can help with just some simple configuration and integration with the new Orders API.
Prerequisites
If youd like to follow along, youll need a Stripe account which you can sign up for here, and access to the public beta. You can sign up for the Orders public beta here.
Enabling Stripe Tax on an Order
An Order describes a purchase being made by a customer, including the products and quantities being purchased, the order status, the payment information, the amount of tax owed, and the billing and shipping details. An Order is underpinned by a Payment Intent, and by using Orders you can unlock many advanced commerce features like tax collection, inventory management, discounts, product catalog usage, line items, and much more. There are two steps to enabling Stripe Tax with Orders:
- Configure Stripe Tax in your account settings
- Set an origin address. This is the address where your business is located or your goods ship from.
- Optionally set a default product category. This is the default type of goods or services you sell, like coffee or a SaaS product. This is optional as it can be set on a per-product basis but will make your product configuration simpler if you sell products of a specific product category.
- Declare where you are registered to collect taxes. In this step you set tax registrations for the countries and states (for example in the US each state sets its own sales tax) where you are registered to collect taxes. This is so that Stripe Tax can automatically calculate VAT, GST, and sales tax owed in the locations that you have tax obligations.
- Enable Stripe Tax when creating an Order.
order = Stripe::Order.create({ ip_address: request.ip, automatic_tax: { enabled: true, }, currency: 'eur', line_items: [{ price: 'price_1KtuODAk55zJ6rm2QoQCeFGX', }], payment: { settings: { payment_method_types: ['card'] }, }, })
Comparing the Payment Intent integration with an Orders integration
- Instead of creating a Payment Intent on the backend, create an Order passing Product or Price information instead of a pre-calculated amount in cents.
order = Stripe::Order.create({ ip_address: request.ip, automatic_tax: { enabled: true, }, currency: 'eur', line_items: [{ price: 'price_1KtuODAk55zJ6rm2QoQCeFGX', }], payment: { settings: { payment_method_types: ['card'] }, }, })
- Pass the client secret from the Order to the frontend, just as you would with a Payment Intent.
{ clientSecret: order.client_secret }.to_json
- Instead of mounting a card (or other element) and using
confirmCardPayment()
(or the corresponding confirm function call) to confirm, use the Payment Element, and useprocessOrder()
to submit and process the order.
const { error } = await stripe.processOrder({ elements, confirmParams: { return_url: window.location.href + '/success.html', } });
Try Stripe Tax via Orders now
To get early access to the Orders public beta, sign up here.
What to watch next
To fulfill orders we highly recommend creating and using a webhook endpoint to listen for important events on your account like successful payments. You can watch videos on our StripeDevelopers channel on webhooks here. If youd like to learn more about getting started with Stripe Tax you can watch this short introduction here.
Stay connected
In addition, you can stay up to date with Stripe in a few ways:
Follow us on Twitter
Join the official Discord server
Subscribe to our Youtube channel
Sign up for the Dev Digest
Original Link: https://dev.to/stripe/getting-started-with-stripe-tax-via-the-orders-api-5ci3
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To