stripe-decline-codes

A TypeScript library providing human-readable descriptions and localized user messages for all 44 Stripe payment decline codes. Zero dependencies, fully typed, and supports English and Japanese translations to improve payment error user experience.

Key Features

Installation

npm install stripe-decline-codes

Primary Functions

getDeclineDescription()

Returns detailed information about a specific decline code, including descriptions, next steps, and translations.

import { getDeclineDescription } from 'stripe-decline-codes';

const info = getDeclineDescription('card_declined');
console.log(info.description);
console.log(info.nextSteps);
console.log(info.translations.en);

getDeclineMessage()

Delivers localized user-facing messages. Users can specify language preference ('en' or 'ja').

import { getDeclineMessage } from 'stripe-decline-codes';

const message = getDeclineMessage('insufficient_funds', 'en');
console.log(message); // "The card was declined due to insufficient funds."

formatDeclineMessage()

Enables custom message formatting with variable substitution for merchant names or support details.

import { formatDeclineMessage } from 'stripe-decline-codes';

const message = formatDeclineMessage('card_declined', 'en', {
  merchantName: 'Example Store',
  supportEmail: 'support@example.com'
});

Benefits

When handling Stripe payment errors, converting technical decline codes into customer-friendly explanations is essential. This library simplifies the translation workflow and provides consistent user experience across multilingual applications.

Tags

TypeScriptStripenpmi18nPayments

License

MIT