Currency conversion API
Use the Currency API to handle multi-currency Stripe Checkout conversions.
Shoppers hesitate when a price is shown in a currency they do not think in. Converting it before checkout removes that pause. This guide wires the currency API endpoint into Stripe Checkout so prices render in the customer’s local currency.
Why implement currency conversion?
Research shows that displaying prices in local currencies can significantly increase checkout conversions. It helps:
- Build Trust: Familiarity breeds trust. Customers are more likely to complete a purchase if they see prices in their own currency.
- Reduce Cart Abandonment: Unexpected costs related to currency conversion can cause customers to abandon their carts.
- Streamline Experience: A frictionless experience from browsing to purchasing enhances user satisfaction and loyalty.
Setting up the currency API
Step 1: get API access
First, sign up for an account and add credits to use our currency conversion API key Spider Credits. Obtain your API key upon registration.
Step 2: integrate API with Stripe
Stripe supports dynamic currency conversion through its API. You will get the unit in the currency local in your webhooks. When you are using unit based measurements you need to convert that local currency back to the unit base you need like USD. Below is a basic integration example using Node.js.
Install required packages
npm install stripe axiosCode example
const stripe = require('stripe')('your-stripe-secret-key');
const axios = require('axios');
// Function to get exchange rates from the API. This will allow easy conversions to units.
async function getExchangeRates(baseCurrency = 'USD') {
const response = await axios.get(
`https://spider.cloud/data/exchange-rates`, { headers: { Authorization: `Bearer $REPLACE_WITH_SPIDER_API_KEY` } }
);
return response.data.rates;
}
// Create a checkout session with dynamic pricing
async function createCheckoutSession() {
const rates = await getExchangeRates();
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [
{
price_data: {
currency: 'usd', // Change based on customer's location
product_data: {
name: 'T-shirt',
},
unit_amount: 2000, // e.g., price in USD
},
quantity: 1,
},
],
mode: 'payment',
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
});
return session.url;
}
createCheckoutSession()
.then((url) => console.log('Checkout URL:', url))
.catch((error) => console.error('Error:', error));Step 3: update frontend
Modify your frontend to display prices in the local currency using the exchange rates obtained from the currency API.
async function displayPrices() {
const rates = await getExchangeRates();
const userCurrency = 'EUR'; // This can be determined by user location
// Assuming product price in USD
const productPriceUSD = 20.0;
const productPriceLocal = productPriceUSD * rates[userCurrency];
document.getElementById('price').innerText = `${productPriceLocal} ${userCurrency}`;
}
displayPrices();Conclusion
That is local-currency pricing end to end: fetch the rate, convert the amount, hand the converted figure to Stripe Checkout.
For the rest of the Checkout options, see the Stripe API reference.
*note: this is no longer required as Stripe has this built in.
Run this on a page you care about
The playground sends the request this page describes and shows you the response. Keyless runs work without an account, capped at 25 a day.