Complete database of Stripe decline codes with descriptions and localized messages
A lightweight, zero-dependency TypeScript library providing human-readable descriptions and localized user messages for all Stripe payment decline codes.
- 🎯 Complete Coverage - All 44 Stripe decline codes included
- 🌐 Localization - Built-in English and Japanese translations
- 📘 TypeScript Support - Full type definitions included
- 🪶 Zero Dependencies - Lightweight and fast
- 🔄 Up-to-date - Based on Stripe API documentation (2024-12-18)
- ✅ Well Tested - Comprehensive test coverage
- 🎨 Message Formatting - Customizable message templates with variable substitution
This library is a complete TypeScript rewrite and continuation of the original stripe-utils package. The project has been:
- Renamed from
stripe-utilstostripe-decline-codesto better reflect its focused scope - Rewritten entirely in modern TypeScript with full type safety
- Modernized with current tooling (Vite, Biome, Vitest)
- Focused exclusively on Stripe decline code handling (subscription utilities removed)
- Updated with the latest Stripe decline codes (2024-12-18)
Credit to the original stripe-utils project for the initial implementation.
npm install stripe-decline-codesimport { getDeclineDescription } from 'stripe-decline-codes';
const result = getDeclineDescription('insufficient_funds');
console.log(result.code.description);
// => "The card has insufficient funds to complete the purchase."
console.log(result.code.nextUserAction);
// => "Please try again using an alternative payment method."
console.log(result.docVersion);
// => "2024-12-18"Get user-facing messages in different languages:
import { getDeclineMessage } from 'stripe-decline-codes';
// English (default)
const enMessage = getDeclineMessage('insufficient_funds');
console.log(enMessage);
// => "Please try again using an alternative payment method."
// Japanese
const jaMessage = getDeclineMessage('insufficient_funds', 'ja');
console.log(jaMessage);
// => "別のお支払い方法を使用してもう一度お試しください。"import { isValidDeclineCode } from 'stripe-decline-codes';
isValidDeclineCode('insufficient_funds'); // => true
isValidDeclineCode('invalid_code'); // => falseimport { getAllDeclineCodes } from 'stripe-decline-codes';
const codes = getAllDeclineCodes();
console.log(codes.length); // => 44
console.log(codes);
// => ['approve_with_id', 'call_issuer', 'card_not_supported', ...]Perfect for error handling in your Stripe integration:
import Stripe from 'stripe';
import { getDeclineMessage } from 'stripe-decline-codes';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
try {
const charge = await stripe.charges.create({
amount: 2000,
currency: 'usd',
source: 'tok_chargeDeclined',
});
} catch (error) {
if (error.type === 'StripeCardError') {
const declineCode = error.decline_code;
const userMessage = getDeclineMessage(declineCode, 'en');
console.log(userMessage);
// Display this message to your user
}
}Returns detailed information about a decline code.
Returns:
{
docVersion: string;
code: {
description: string;
nextSteps: string;
nextUserAction: string;
translations?: {
ja?: {
description: string;
nextUserAction: string;
};
};
} | {};
}Returns a localized user-facing message for a decline code.
Parameters:
declineCode- The Stripe decline codelocale- The locale to use ('en'or'ja', default:'en')
Returns an array of all supported decline code strings.
Type guard to check if a string is a valid decline code.
Returns the Stripe API documentation version that this library is based on.
formatDeclineMessage(declineCode: string, locale?: Locale, variables?: Record<string, string>): string | undefined
Returns a formatted message with optional variable substitution.
Example:
import { formatDeclineMessage } from 'stripe-decline-codes';
const message = formatDeclineMessage('insufficient_funds', 'en', {
merchantName: 'Acme Store',
supportEmail: 'support@acme.com'
});This library includes all 44 Stripe decline codes:
approve_with_id- Payment cannot be authorizedcall_issuer- Card declined for unknown reasoncard_not_supported- Card doesn't support this purchase typecard_velocity_exceeded- Balance or credit limit exceededcurrency_not_supported- Card doesn't support the currencydo_not_honor- Card declined for unknown reasondo_not_try_again- Card declined for unknown reasonduplicate_transaction- Identical transaction submitted recentlyexpired_card- Card has expiredfraudulent- Payment suspected to be fraudulentgeneric_decline- Card declined for unknown reasonincorrect_number- Card number is incorrectincorrect_cvc- CVC number is incorrectincorrect_pin- PIN is incorrectincorrect_zip- ZIP/postal code is incorrectinsufficient_funds- Insufficient fundsinvalid_account- Card or account is invalidinvalid_amount- Payment amount is invalid or too largeinvalid_cvc- CVC number is incorrectinvalid_expiry_year- Expiration year is invalidinvalid_number- Card number is incorrectinvalid_pin- PIN is incorrectissuer_not_available- Card issuer could not be reachedlost_card- Card reported lostmerchant_blacklist- Payment matches merchant blocklistnew_account_information_available- Card or account is invalidno_action_taken- Card declined for unknown reasonnot_permitted- Payment is not permittedpickup_card- Card cannot be used for this paymentpin_try_exceeded- PIN attempts exceededprocessing_error- Error processing the cardreenter_transaction- Payment could not be processedrestricted_card- Card cannot be used for this paymentrevocation_of_all_authorizations- Card declinedrevocation_of_authorization- Card declinedsecurity_violation- Card declinedservice_not_allowed- Card declinedstolen_card- Card reported stolenstop_payment_order- Card declinedtestmode_decline- Stripe test card usedtransaction_not_allowed- Card declinedtry_again_later- Card declined, try again laterwithdrawal_count_limit_exceeded- Credit limit exceeded
This library is written in TypeScript and includes full type definitions:
import type {
DeclineCode,
DeclineCodeInfo,
DeclineCodeResult,
Locale,
Translation,
} from 'stripe-decline-codes';# Install dependencies
npm install
# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Build
npm run build
# Lint
npm run lint
# Format code
npm run format
# Type check
npm run typecheckThis package uses np for releases:
npm run releaseContributions are welcome! Please feel free to submit a Pull Request.
MIT © Hidetaka Okamoto
- Forked and renewed from stripe-utils
- Complete rewrite in TypeScript
- Modern build system with Vite + Biome
- Added comprehensive type definitions
- Updated to latest Stripe decline codes (2024-12-18)
- Zero dependencies
- Enhanced API with new utility functions
- Improved documentation