Learn how to fix the Stripe currency mismatch error by ensuring consistent currency settings for Customers, Products, Prices, and payments in your Stripe integration.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
How to Fix Currency Mismatch Error in Stripe
Introduction
The currency mismatch error in Stripe occurs when you attempt to process a payment with a currency that doesn't match the currency of another related object, such as a Customer, Subscription, or Product. This tutorial will guide you through identifying and resolving currency mismatch errors in various Stripe implementation scenarios.
Step 1: Understanding the Currency Mismatch Error
Currency mismatch errors typically appear with messages like:
This PaymentIntent's currency (usd) does not match the Customer's default currency (eur)
or
Currency mismatch: expected 'usd', received 'eur'
These errors occur when Stripe objects with fixed currencies (like Products or Subscriptions) are used with payments in different currencies.
Step 2: Checking Your Stripe Dashboard Configuration
First, verify your currency settings in the Stripe Dashboard:
Step 3: Fixing Currency Mismatch in PaymentIntent Creation
When creating a PaymentIntent, ensure it uses the same currency as the Customer's default currency:
// JavaScript example
// INCORRECT - might cause currency mismatch
const paymentIntent = await stripe.paymentIntents.create({
amount: 2000,
currency: 'usd',
customer: 'cus\_123456789',
});
// CORRECT - fetch customer first and use their currency
const customer = await stripe.customers.retrieve('cus\_123456789');
const paymentIntent = await stripe.paymentIntents.create({
amount: 2000,
currency: customer.currency || 'usd', // Use customer currency or default
customer: 'cus\_123456789',
});
Step 4: Fixing Currency Mismatch in Subscriptions
For subscriptions, ensure that the Price, Product, and Customer all use the same currency:
// JavaScript example
// Create a Price in the correct currency
const price = await stripe.prices.create({
unit\_amount: 2000,
currency: 'usd',
product: 'prod\_123456789',
recurring: {
interval: 'month',
},
});
// Create a subscription with matching currency
const subscription = await stripe.subscriptions.create({
customer: 'cus\_123456789',
items: [
{ price: price.id },
],
currency: 'usd', // Must match the Price currency
});
Step 5: Updating Customer Default Currency
If needed, update a customer's default currency to match your product pricing:
// JavaScript example
const updatedCustomer = await stripe.customers.update(
'cus\_123456789',
{
currency: 'usd',
}
);
Step 6: Handling Multi-Currency Support
If your application needs to support multiple currencies:
// JavaScript example
// Function to create a payment intent with proper currency handling
async function createPaymentWithCurrencyCheck(amount, currencyCode, customerId) {
try {
// Retrieve the customer
const customer = await stripe.customers.retrieve(customerId);
// Check if customer has a different currency than requested
if (customer.currency && customer.currency !== currencyCode) {
// Option 1: Use the customer's currency
currencyCode = customer.currency;
// Recalculate amount based on exchange rate if needed
// Option 2: Update the customer's currency to match
await stripe.customers.update(customerId, { currency: currencyCode });
}
// Create the payment intent with the appropriate currency
const paymentIntent = await stripe.paymentIntents.create({
amount: amount,
currency: currencyCode,
customer: customerId,
});
return paymentIntent;
} catch (error) {
console.error('Error handling currency:', error);
throw error;
}
}
Step 7: Setting Default Currency for New Customers
When creating new customers, explicitly set the currency to avoid mismatches:
// JavaScript example
const customer = await stripe.customers.create({
email: '[email protected]',
name: 'Jenny Rosen',
currency: 'usd', // Set default currency
});
Step 8: Fixing Currency Mismatch in Checkout Sessions
For Stripe Checkout, ensure the currency matches any associated customers or products:
// JavaScript example
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line\_items: [
{
price\_data: {
currency: 'usd',
product\_data: {
name: 'Product Name',
},
unit\_amount: 2000,
},
quantity: 1,
},
],
mode: 'payment',
customer: 'cus\_123456789', // Make sure this customer's currency matches
success\_url: 'https://example.com/success',
cancel\_url: 'https://example.com/cancel',
});
Step 9: Handling Payment Methods with Currency Restrictions
Some payment methods only work with specific currencies. Ensure compatibility:
// JavaScript example
// Function to get available payment methods based on currency
function getAvailablePaymentMethods(currency) {
const allPaymentMethods = ['card', 'sepa\_debit', 'ideal', 'bancontact', 'giropay'];
// Example currency restrictions
const restrictions = {
'eur': ['card', 'sepa\_debit', 'ideal', 'bancontact', 'giropay'],
'usd': ['card'],
'gbp': ['card', 'bacs\_debit'],
// Add more as needed
};
return restrictions[currency] || ['card']; // Default to card if currency not in list
}
// Create payment intent with appropriate payment methods
const paymentIntent = await stripe.paymentIntents.create({
amount: 2000,
currency: 'eur',
payment_method_types: getAvailablePaymentMethods('eur'),
});
Step 10: Debugging Currency Mismatch Issues
If you continue to experience issues, use Stripe's logging capabilities to identify the mismatch source:
// JavaScript example
// Helper function to debug currency mismatches
async function debugCurrencyMismatch(customerId, productId, priceId) {
const results = {
customer: null,
product: null,
price: null,
};
try {
if (customerId) {
results.customer = await stripe.customers.retrieve(customerId);
console.log(`Customer ${customerId} currency: ${results.customer.currency}`);
}
if (productId) {
results.product = await stripe.products.retrieve(productId);
console.log(`Product ${productId} details:`, results.product);
}
if (priceId) {
results.price = await stripe.prices.retrieve(priceId);
console.log(`Price ${priceId} currency: ${results.price.currency}`);
}
return results;
} catch (error) {
console.error('Error debugging currency mismatch:', error);
throw error;
}
}
Conclusion
Currency mismatch errors in Stripe can be resolved by ensuring consistent currency usage across all related objects in your payment flow. Always check the currency settings for Customers, Products, Prices, and payment operations to maintain compatibility. For multi-currency applications, implement proper currency handling logic that respects Stripe's constraints while providing flexibility for your users.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.