stripe-decline-codes 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,199 @@
1
+ import type { DeclineCategory, DeclineCode, DeclineCodeResult, Locale, StripeDeclineError } from './types.js';
2
+ /**
3
+ * Get decline code information with description and recommended actions
4
+ *
5
+ * @param declineCode - The Stripe decline code to look up
6
+ * @returns Object containing the decline code information and documentation version
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const result = getDeclineDescription('insufficient_funds');
11
+ * console.log(result.code.description);
12
+ * // => "The card has insufficient funds to complete the purchase."
13
+ * console.log(result.code.nextUserAction);
14
+ * // => "Please try again using an alternative payment method."
15
+ * ```
16
+ */
17
+ export declare function getDeclineDescription(declineCode?: string): DeclineCodeResult;
18
+ /**
19
+ * Get localized decline code message for end users
20
+ *
21
+ * @param declineCode - The Stripe decline code
22
+ * @param locale - The locale to use (default: 'en')
23
+ * @returns User-facing message in the specified locale, or undefined if not found
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const message = getDeclineMessage('insufficient_funds', 'ja');
28
+ * console.log(message);
29
+ * // => "別のお支払い方法を使用してもう一度お試しください。"
30
+ * ```
31
+ */
32
+ export declare function getDeclineMessage(declineCode: string, locale?: Locale): string | undefined;
33
+ /**
34
+ * Get all available decline codes
35
+ *
36
+ * @returns Array of all supported decline code strings
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const codes = getAllDeclineCodes();
41
+ * console.log(codes.length); // => 44
42
+ * console.log(codes.includes('insufficient_funds')); // => true
43
+ * ```
44
+ */
45
+ export declare function getAllDeclineCodes(): DeclineCode[];
46
+ /**
47
+ * Check if a decline code is valid
48
+ *
49
+ * @param code - The code to validate
50
+ * @returns True if the code exists in the database
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * isValidDeclineCode('insufficient_funds'); // => true
55
+ * isValidDeclineCode('invalid_code'); // => false
56
+ * ```
57
+ */
58
+ export declare function isValidDeclineCode(code: string): code is DeclineCode;
59
+ /**
60
+ * Get the documentation version for the decline codes data
61
+ *
62
+ * @returns The Stripe API documentation version string
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * const version = getDocVersion();
67
+ * console.log(version); // => "2024-12-18"
68
+ * ```
69
+ */
70
+ export declare function getDocVersion(): string;
71
+ /**
72
+ * Format a decline message with custom template variables
73
+ *
74
+ * @param declineCode - The Stripe decline code
75
+ * @param locale - The locale to use (default: 'en')
76
+ * @param variables - Optional variables to replace in the message template
77
+ * @returns Formatted user-facing message with variables replaced
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * const message = formatDeclineMessage('insufficient_funds', 'en', {
82
+ * merchantName: 'Acme Store',
83
+ * supportEmail: 'support@acme.com'
84
+ * });
85
+ * console.log(message);
86
+ * // => "Please try again using an alternative payment method."
87
+ * ```
88
+ */
89
+ export declare function formatDeclineMessage(declineCode: string, locale?: Locale, variables?: Record<string, string>): string | undefined;
90
+ /**
91
+ * Get the category of a decline code (SOFT_DECLINE or HARD_DECLINE)
92
+ *
93
+ * @param code - The decline code to categorize
94
+ * @returns The category of the decline code, or undefined if invalid
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * getDeclineCategory('insufficient_funds'); // => 'SOFT_DECLINE'
99
+ * getDeclineCategory('fraudulent'); // => 'HARD_DECLINE'
100
+ * ```
101
+ */
102
+ export declare function getDeclineCategory(code: string): DeclineCategory | undefined;
103
+ /**
104
+ * Check if a decline code is a hard decline (permanent, should not retry)
105
+ *
106
+ * @param code - The decline code to check
107
+ * @returns True if the code is a hard decline
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * isHardDecline('fraudulent'); // => true
112
+ * isHardDecline('insufficient_funds'); // => false
113
+ * ```
114
+ */
115
+ export declare function isHardDecline(code: string): boolean;
116
+ /**
117
+ * Check if a decline code is a soft decline (temporary, can retry)
118
+ *
119
+ * @param code - The decline code to check
120
+ * @returns True if the code is a soft decline
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * isSoftDecline('insufficient_funds'); // => true
125
+ * isSoftDecline('fraudulent'); // => false
126
+ * ```
127
+ */
128
+ export declare function isSoftDecline(code: string): boolean;
129
+ /**
130
+ * Extract localized message from a Stripe error object
131
+ *
132
+ * @param error - The Stripe error object (or any caught value)
133
+ * @param locale - The locale to use (default: 'en')
134
+ * @returns User-facing message in the specified locale, or undefined if not found
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * const stripeError = {
139
+ * type: 'StripeCardError',
140
+ * decline_code: 'insufficient_funds',
141
+ * message: 'Your card has insufficient funds.'
142
+ * };
143
+ * const message = getMessageFromStripeError(stripeError, 'ja');
144
+ * console.log(message);
145
+ * // => "別のお支払い方法を使用してもう一度お試しください。"
146
+ * ```
147
+ */
148
+ export declare function getMessageFromStripeError(error: unknown, locale?: Locale): string | undefined;
149
+ /**
150
+ * Type guard that narrows an unknown error to one carrying a known Stripe decline code
151
+ *
152
+ * Returns true when `error` is an object whose `decline_code` is a valid
153
+ * {@link DeclineCode}. Designed for `catch` blocks: a `StripeCardError` from
154
+ * stripe-node >= 18 (where `decline_code` is a required `string`) narrows
155
+ * straight to {@link StripeDeclineError}; errors from stripe-node <= 17 or
156
+ * plain objects fall back through the same runtime check.
157
+ *
158
+ * @param error - The value to check (e.g. a caught Stripe error)
159
+ * @returns True if the error carries a known decline code
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * try {
164
+ * await stripe.charges.create({ ... });
165
+ * } catch (err) {
166
+ * if (isStripeDeclineError(err)) {
167
+ * // err.decline_code is typed as DeclineCode here
168
+ * console.log(getDeclineMessage(err.decline_code, 'ja'));
169
+ * }
170
+ * }
171
+ * ```
172
+ */
173
+ export declare function isStripeDeclineError(error: unknown): error is StripeDeclineError;
174
+ /**
175
+ * Extract a validated decline code from a Stripe error object
176
+ *
177
+ * Unlike `getMessageFromStripeError`, this returns the decline code itself
178
+ * (typed as {@link DeclineCode}) so it can be passed to any other helper in
179
+ * this library. Accepts `unknown` so caught errors can be passed directly.
180
+ *
181
+ * @param error - The Stripe error object (or any caught value)
182
+ * @returns The decline code, or undefined if absent or unknown
183
+ *
184
+ * @example
185
+ * ```ts
186
+ * try {
187
+ * await stripe.charges.create({ ... });
188
+ * } catch (err) {
189
+ * const code = getDeclineCodeFromError(err);
190
+ * if (code && isSoftDecline(code)) {
191
+ * // safe to retry
192
+ * }
193
+ * }
194
+ * ```
195
+ */
196
+ export declare function getDeclineCodeFromError(error: unknown): DeclineCode | undefined;
197
+ export { DECLINE_CODES, DOC_VERSION } from './data/decline-codes.js';
198
+ export type { DeclineCategory, DeclineCode, DeclineCodeInfo, DeclineCodeResult, Locale, StripeDeclineError, StripeError, Translation, } from './types.js';
199
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,MAAM,EACN,kBAAkB,EAEnB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAa7E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,GAAE,MAAa,GAAG,MAAM,GAAG,SAAS,CAYhG;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,IAAI,WAAW,EAAE,CAElD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,WAAW,CAEpE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE,MAAa,EACrB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACjC,MAAM,GAAG,SAAS,CAqBpB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAM5E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,OAAO,EACd,MAAM,GAAE,MAAa,GACpB,MAAM,GAAG,SAAS,CAMpB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB,CAQhF;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,GAAG,SAAS,CAE/E;AAGD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAErE,YAAY,EACV,eAAe,EACf,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,MAAM,EACN,kBAAkB,EAClB,WAAW,EACX,WAAW,GACZ,MAAM,YAAY,CAAC"}
@@ -1,8 +1,9 @@
1
- const i = "2024-12-18", r = {
1
+ const a = "2024-12-18", r = {
2
2
  approve_with_id: {
3
3
  description: "The payment cannot be authorized.",
4
4
  nextSteps: "The payment should be attempted again. If it still cannot be processed, the customer needs to contact their card issuer.",
5
5
  nextUserAction: "Please try again. If it still cannot be processed, the please contact your card issuer.",
6
+ category: "SOFT_DECLINE",
6
7
  translations: {
7
8
  ja: {
8
9
  description: "支払いは承認できません。",
@@ -14,6 +15,7 @@ const i = "2024-12-18", r = {
14
15
  description: "The card has been declined for an unknown reason.",
15
16
  nextSteps: "The customer needs to contact their card issuer for more information.",
16
17
  nextUserAction: "Please contact your card issuer for more information.",
18
+ category: "SOFT_DECLINE",
17
19
  translations: {
18
20
  ja: {
19
21
  description: "カードは未知の理由で拒否されました。",
@@ -25,6 +27,7 @@ const i = "2024-12-18", r = {
25
27
  description: "The card does not support this type of purchase.",
26
28
  nextSteps: "The customer needs to contact their card issuer to make sure their card can be used to make this type of purchase.",
27
29
  nextUserAction: "Your card issuer may not support this type of purchase, please contact your card issuer for more information.",
30
+ category: "HARD_DECLINE",
28
31
  translations: {
29
32
  ja: {
30
33
  description: "カードはこのタイプの購入をサポートしません。",
@@ -36,6 +39,7 @@ const i = "2024-12-18", r = {
36
39
  description: "The customer has exceeded the balance or credit limit available on their card.",
37
40
  nextSteps: "The customer should contact their card issuer for more information.",
38
41
  nextUserAction: "Please contact your card issuer for more information.",
42
+ category: "SOFT_DECLINE",
39
43
  translations: {
40
44
  ja: {
41
45
  description: "このカードの残高またはクレジット制限を超えました。",
@@ -47,6 +51,7 @@ const i = "2024-12-18", r = {
47
51
  description: "The card does not support the specified currency.",
48
52
  nextSteps: "The customer needs to check with the issuer whether the card can be used for the type of currency specified.",
49
53
  nextUserAction: "Please contact your card issuer to verify this type of currency can be used for this payment.",
54
+ category: "HARD_DECLINE",
50
55
  translations: {
51
56
  ja: {
52
57
  description: "カードは指定された通貨をサポートしていません。",
@@ -58,6 +63,7 @@ const i = "2024-12-18", r = {
58
63
  description: "The card has been declined for an unknown reason.",
59
64
  nextSteps: "The customer needs to contact their card issuer for more information.",
60
65
  nextUserAction: "Please contact your card issuer for more information.",
66
+ category: "SOFT_DECLINE",
61
67
  translations: {
62
68
  ja: {
63
69
  description: "カードは未知の理由で拒否されました。",
@@ -69,6 +75,7 @@ const i = "2024-12-18", r = {
69
75
  description: "The card has been declined for an unknown reason.",
70
76
  nextSteps: "The customer should contact their card issuer for more information.",
71
77
  nextUserAction: "Please contact your card issuer for more information.",
78
+ category: "HARD_DECLINE",
72
79
  translations: {
73
80
  ja: {
74
81
  description: "カードは未知の理由で拒否されました。",
@@ -80,6 +87,7 @@ const i = "2024-12-18", r = {
80
87
  description: "A transaction with identical amount and credit card information was submitted very recently.",
81
88
  nextSteps: "Check to see if a recent payment already exists.",
82
89
  nextUserAction: "Check to see if a recent payment already exists.",
90
+ category: "SOFT_DECLINE",
83
91
  translations: {
84
92
  ja: {
85
93
  description: "ごく最近、同一の金額とクレジットカード情報を使用した取引が送信されました。",
@@ -91,6 +99,7 @@ const i = "2024-12-18", r = {
91
99
  description: "The card has expired.",
92
100
  nextSteps: "The customer should use another card.",
93
101
  nextUserAction: "Please use another card.",
102
+ category: "HARD_DECLINE",
94
103
  translations: {
95
104
  ja: {
96
105
  description: "カードは期限切れです。",
@@ -102,6 +111,7 @@ const i = "2024-12-18", r = {
102
111
  description: "The payment has been declined as Stripe suspects it is fraudulent.",
103
112
  nextSteps: "Do not report more detailed information to your customer. Instead, present as you would the generic_decline described below.",
104
113
  nextUserAction: "Please contact your card issuer for more information.",
114
+ category: "HARD_DECLINE",
105
115
  translations: {
106
116
  ja: {
107
117
  description: "不正と思われるため、支払いは拒否されました。",
@@ -113,6 +123,7 @@ const i = "2024-12-18", r = {
113
123
  description: "The card has been declined for an unknown reason.",
114
124
  nextSteps: "The customer needs to contact their card issuer for more information.",
115
125
  nextUserAction: "Please contact your card issuer for more information.",
126
+ category: "SOFT_DECLINE",
116
127
  translations: {
117
128
  ja: {
118
129
  description: "カードは未知の理由で拒否されました。",
@@ -124,6 +135,7 @@ const i = "2024-12-18", r = {
124
135
  description: "The card number is incorrect.",
125
136
  nextSteps: "The customer should try again using the correct card number.",
126
137
  nextUserAction: "Please check your card numbers and try again. If it still cannot be processed, the please contact your card issuer.",
138
+ category: "HARD_DECLINE",
127
139
  translations: {
128
140
  ja: {
129
141
  description: "カード番号が正しくありません。",
@@ -135,6 +147,7 @@ const i = "2024-12-18", r = {
135
147
  description: "The CVC number is incorrect.",
136
148
  nextSteps: "The customer should try again using the correct CVC.",
137
149
  nextUserAction: "Please check your card numbers and try again. If it still cannot be processed, the please contact your card issuer.",
150
+ category: "HARD_DECLINE",
138
151
  translations: {
139
152
  ja: {
140
153
  description: "CVC番号が正しくありません。",
@@ -146,6 +159,7 @@ const i = "2024-12-18", r = {
146
159
  description: "The PIN entered is incorrect. This decline code only applies to payments made with a card reader.",
147
160
  nextSteps: "The customer should try again using the correct PIN.",
148
161
  nextUserAction: "Please check your PIN and try again. If it still cannot be processed, the please contact your card issuer.",
162
+ category: "HARD_DECLINE",
149
163
  translations: {
150
164
  ja: {
151
165
  description: "PINコードが正しくありません。",
@@ -157,6 +171,7 @@ const i = "2024-12-18", r = {
157
171
  description: "The ZIP/postal code is incorrect.",
158
172
  nextSteps: "The customer should try again using the correct billing ZIP/postal code.",
159
173
  nextUserAction: "Please try again using the correct ZIP/postal code.",
174
+ category: "HARD_DECLINE",
160
175
  translations: {
161
176
  ja: {
162
177
  description: "郵便番号が正しくありません。",
@@ -168,6 +183,7 @@ const i = "2024-12-18", r = {
168
183
  description: "The card has insufficient funds to complete the purchase.",
169
184
  nextSteps: "The customer should use an alternative payment method.",
170
185
  nextUserAction: "Please try again using an alternative payment method.",
186
+ category: "SOFT_DECLINE",
171
187
  translations: {
172
188
  ja: {
173
189
  description: "カードの購入に必要な資金が不足しています。",
@@ -179,6 +195,7 @@ const i = "2024-12-18", r = {
179
195
  description: "The card, or account the card is connected to, is invalid.",
180
196
  nextSteps: "The customer needs to contact their card issuer to check that the card is working correctly.",
181
197
  nextUserAction: "Please contact your card issuer for more information.",
198
+ category: "HARD_DECLINE",
182
199
  translations: {
183
200
  ja: {
184
201
  description: "カード、またはカードが接続されているアカウントが無効です。",
@@ -190,6 +207,7 @@ const i = "2024-12-18", r = {
190
207
  description: "The payment amount is invalid, or exceeds the amount that is allowed.",
191
208
  nextSteps: "If the amount appears to be correct, the customer needs to check with their card issuer that they can make purchases of that amount.",
192
209
  nextUserAction: "Please contact your card issuer for more information.",
210
+ category: "SOFT_DECLINE",
193
211
  translations: {
194
212
  ja: {
195
213
  description: "支払い金額が無効であるか、許可されている金額を超えています。",
@@ -201,6 +219,7 @@ const i = "2024-12-18", r = {
201
219
  description: "The CVC number is incorrect.",
202
220
  nextSteps: "The customer should try again using the correct CVC.",
203
221
  nextUserAction: "Please try again using the correct CVC.",
222
+ category: "HARD_DECLINE",
204
223
  translations: {
205
224
  ja: {
206
225
  description: "CVC番号が正しくありません。",
@@ -212,6 +231,7 @@ const i = "2024-12-18", r = {
212
231
  description: "The expiration year invalid.",
213
232
  nextSteps: "The customer should try again using the correct expiration date.",
214
233
  nextUserAction: "Please try again using the correct expiration date.",
234
+ category: "HARD_DECLINE",
215
235
  translations: {
216
236
  ja: {
217
237
  description: "有効期限が無効です。",
@@ -223,6 +243,7 @@ const i = "2024-12-18", r = {
223
243
  description: "The card number is incorrect.",
224
244
  nextSteps: "The customer should try again using the correct card number.",
225
245
  nextUserAction: "Please try again using the correct card number.",
246
+ category: "HARD_DECLINE",
226
247
  translations: {
227
248
  ja: {
228
249
  description: "カード番号が正しくありません。",
@@ -234,6 +255,7 @@ const i = "2024-12-18", r = {
234
255
  description: "The PIN entered is incorrect. This decline code only applies to payments made with a card reader.",
235
256
  nextSteps: "The customer should try again using the correct PIN.",
236
257
  nextUserAction: "Please try again using the correct card PIN.",
258
+ category: "HARD_DECLINE",
237
259
  translations: {
238
260
  ja: {
239
261
  description: "PINコードが正しくありません。",
@@ -245,6 +267,7 @@ const i = "2024-12-18", r = {
245
267
  description: "The card issuer could not be reached, so the payment could not be authorized.",
246
268
  nextSteps: "The payment should be attempted again. If it still cannot be processed, the customer needs to contact their card issuer.",
247
269
  nextUserAction: "Please try again. If it still cannot be processed, the please contact your card issuer.",
270
+ category: "SOFT_DECLINE",
248
271
  translations: {
249
272
  ja: {
250
273
  description: "カード発行者に連絡できなかったため、支払いを承認できませんでした。",
@@ -256,6 +279,7 @@ const i = "2024-12-18", r = {
256
279
  description: "The payment has been declined because the card is reported lost.",
257
280
  nextSteps: "The specific reason for the decline should not be reported to the customer. Instead, it needs to be presented as a generic decline.",
258
281
  nextUserAction: "Please contact your card issuer for more information.",
282
+ category: "HARD_DECLINE",
259
283
  translations: {
260
284
  ja: {
261
285
  description: "カードは未知の理由で拒否されました。",
@@ -267,6 +291,7 @@ const i = "2024-12-18", r = {
267
291
  description: "The payment has been declined because it matches a value on the Stripe user's blocklist.",
268
292
  nextSteps: "Do not report more detailed information to your customer. Instead, present as you would the generic_decline described above.",
269
293
  nextUserAction: "Please contact your card issuer for more information.",
294
+ category: "HARD_DECLINE",
270
295
  translations: {
271
296
  ja: {
272
297
  description: "カードは未知の理由で拒否されました。",
@@ -278,6 +303,7 @@ const i = "2024-12-18", r = {
278
303
  description: "The card, or account the card is connected to, is invalid.",
279
304
  nextSteps: "The customer needs to contact their card issuer for more information.",
280
305
  nextUserAction: "Please contact your card issuer for more information.",
306
+ category: "SOFT_DECLINE",
281
307
  translations: {
282
308
  ja: {
283
309
  description: "カード、またはカードが接続されているアカウントが無効です。",
@@ -289,6 +315,7 @@ const i = "2024-12-18", r = {
289
315
  description: "The card has been declined for an unknown reason.",
290
316
  nextSteps: "The customer should contact their card issuer for more information.",
291
317
  nextUserAction: "Please contact your card issuer for more information.",
318
+ category: "SOFT_DECLINE",
292
319
  translations: {
293
320
  ja: {
294
321
  description: "カードは未知の理由で拒否されました。",
@@ -300,6 +327,7 @@ const i = "2024-12-18", r = {
300
327
  description: "The payment is not permitted.",
301
328
  nextSteps: "The customer needs to contact their card issuer for more information.",
302
329
  nextUserAction: "Please contact your card issuer for more information.",
330
+ category: "HARD_DECLINE",
303
331
  translations: {
304
332
  ja: {
305
333
  description: "支払いは許可されていません。",
@@ -311,6 +339,7 @@ const i = "2024-12-18", r = {
311
339
  description: "The card cannot be used to make this payment (it is possible it has been reported lost or stolen).",
312
340
  nextSteps: "The customer needs to contact their card issuer for more information.",
313
341
  nextUserAction: "Please contact your card issuer for more information.",
342
+ category: "HARD_DECLINE",
314
343
  translations: {
315
344
  ja: {
316
345
  description: "カードでこの支払いを行うことはできません(紛失または盗難にあったと報告されている可能性があります)。",
@@ -322,6 +351,7 @@ const i = "2024-12-18", r = {
322
351
  description: "The allowable number of PIN tries has been exceeded.",
323
352
  nextSteps: "The customer must use another card or method of payment.",
324
353
  nextUserAction: "Please use another card or method of payment.",
354
+ category: "SOFT_DECLINE",
325
355
  translations: {
326
356
  ja: {
327
357
  description: "PIN試行回数の上限を超えました。",
@@ -333,6 +363,7 @@ const i = "2024-12-18", r = {
333
363
  description: "An error occurred while processing the card.",
334
364
  nextSteps: "The payment should be attempted again. If it still cannot be processed, try again later.",
335
365
  nextUserAction: "Please try again. If it still cannot be processed, the please contact your card issuer.",
366
+ category: "SOFT_DECLINE",
336
367
  translations: {
337
368
  ja: {
338
369
  description: "カードの処理中にエラーが発生しました。",
@@ -344,6 +375,7 @@ const i = "2024-12-18", r = {
344
375
  description: "The payment could not be processed by the issuer for an unknown reason.",
345
376
  nextSteps: "The payment should be attempted again. If it still cannot be processed, the customer needs to contact their card issuer.",
346
377
  nextUserAction: "Please try again. If it still cannot be processed, the please contact your card issuer.",
378
+ category: "SOFT_DECLINE",
347
379
  translations: {
348
380
  ja: {
349
381
  description: "原因不明のため、発行者が支払いを処理できませんでした。",
@@ -355,6 +387,7 @@ const i = "2024-12-18", r = {
355
387
  description: "The card cannot be used to make this payment (it is possible it has been reported lost or stolen).",
356
388
  nextSteps: "The customer needs to contact their card issuer for more information.",
357
389
  nextUserAction: "Please contact your card issuer for more information.",
390
+ category: "HARD_DECLINE",
358
391
  translations: {
359
392
  ja: {
360
393
  description: "カードでこの支払いを行うことはできません(紛失または盗難にあったと報告されている可能性があります)。",
@@ -366,6 +399,7 @@ const i = "2024-12-18", r = {
366
399
  description: "The card has been declined for an unknown reason.",
367
400
  nextSteps: "The customer should contact their card issuer for more information.",
368
401
  nextUserAction: "Please contact your card issuer for more information.",
402
+ category: "HARD_DECLINE",
369
403
  translations: {
370
404
  ja: {
371
405
  description: "カードは未知の理由で拒否されました。",
@@ -377,6 +411,7 @@ const i = "2024-12-18", r = {
377
411
  description: "The card has been declined for an unknown reason.",
378
412
  nextSteps: "The customer should contact their card issuer for more information.",
379
413
  nextUserAction: "Please contact your card issuer for more information.",
414
+ category: "HARD_DECLINE",
380
415
  translations: {
381
416
  ja: {
382
417
  description: "カードは未知の理由で拒否されました。",
@@ -388,6 +423,7 @@ const i = "2024-12-18", r = {
388
423
  description: "The card has been declined for an unknown reason.",
389
424
  nextSteps: "The customer needs to contact their card issuer for more information.",
390
425
  nextUserAction: "Please contact your card issuer for more information.",
426
+ category: "HARD_DECLINE",
391
427
  translations: {
392
428
  ja: {
393
429
  description: "カードは未知の理由で拒否されました。",
@@ -399,6 +435,7 @@ const i = "2024-12-18", r = {
399
435
  description: "The card has been declined for an unknown reason.",
400
436
  nextSteps: "The customer should contact their card issuer for more information.",
401
437
  nextUserAction: "Please contact your card issuer for more information.",
438
+ category: "HARD_DECLINE",
402
439
  translations: {
403
440
  ja: {
404
441
  description: "カードは未知の理由で拒否されました。",
@@ -410,6 +447,7 @@ const i = "2024-12-18", r = {
410
447
  description: "The payment has been declined because the card is reported stolen.",
411
448
  nextSteps: "The specific reason for the decline should not be reported to the customer. Instead, it needs to be presented as a generic decline.",
412
449
  nextUserAction: "Please contact your card issuer for more information.",
450
+ category: "HARD_DECLINE",
413
451
  translations: {
414
452
  ja: {
415
453
  description: "カードは未知の理由で拒否されました。",
@@ -421,6 +459,7 @@ const i = "2024-12-18", r = {
421
459
  description: "The card has been declined for an unknown reason.",
422
460
  nextSteps: "The customer should contact their card issuer for more information.",
423
461
  nextUserAction: "Please contact your card issuer for more information.",
462
+ category: "HARD_DECLINE",
424
463
  translations: {
425
464
  ja: {
426
465
  description: "カードは未知の理由で拒否されました。",
@@ -432,6 +471,7 @@ const i = "2024-12-18", r = {
432
471
  description: "A Stripe test card number was used.",
433
472
  nextSteps: "A genuine card must be used to make a payment.",
434
473
  nextUserAction: "A genuine card must be used to make a payment.",
474
+ category: "HARD_DECLINE",
435
475
  translations: {
436
476
  ja: {
437
477
  description: "Stripeテストカード番号を使用しました。",
@@ -443,6 +483,7 @@ const i = "2024-12-18", r = {
443
483
  description: "The card has been declined for an unknown reason.",
444
484
  nextSteps: "The customer needs to contact their card issuer for more information.",
445
485
  nextUserAction: "Please contact your card issuer for more information.",
486
+ category: "HARD_DECLINE",
446
487
  translations: {
447
488
  ja: {
448
489
  description: "カードは未知の理由で拒否されました。",
@@ -454,6 +495,7 @@ const i = "2024-12-18", r = {
454
495
  description: "The card has been declined for an unknown reason.",
455
496
  nextSteps: "Ask the customer to attempt the payment again. If subsequent payments are declined, the customer should contact their card issuer for more information.",
456
497
  nextUserAction: "Please try again. If it still cannot be processed, the please contact your card issuer.",
498
+ category: "SOFT_DECLINE",
457
499
  translations: {
458
500
  ja: {
459
501
  description: "カードは未知の理由で拒否されました。",
@@ -465,6 +507,7 @@ const i = "2024-12-18", r = {
465
507
  description: "The customer has exceeded the balance or credit limit available on their card.",
466
508
  nextSteps: "The customer should use an alternative payment method.",
467
509
  nextUserAction: "Please use another card or contact your card issuer for more information.",
510
+ category: "SOFT_DECLINE",
468
511
  translations: {
469
512
  ja: {
470
513
  description: "このカードの残高またはクレジット制限を超えました。",
@@ -473,54 +516,80 @@ const i = "2024-12-18", r = {
473
516
  }
474
517
  }
475
518
  };
476
- function l(e) {
477
- if (!e || !a(e))
519
+ function y(e) {
520
+ if (!e || !o(e))
478
521
  return {
479
- docVersion: i,
522
+ docVersion: a,
480
523
  code: {}
481
524
  };
482
525
  const t = r[e];
483
526
  return {
484
- docVersion: i,
527
+ docVersion: a,
485
528
  code: t
486
529
  };
487
530
  }
488
- function p(e, t = "en") {
489
- if (!a(e))
531
+ function c(e, t = "en") {
532
+ if (!o(e))
490
533
  return;
491
534
  const n = r[e];
492
535
  return t === "en" ? n.nextUserAction : n.translations?.[t]?.nextUserAction;
493
536
  }
494
- function h() {
537
+ function f() {
495
538
  return Object.keys(r);
496
539
  }
497
- function a(e) {
498
- return e in r;
540
+ function o(e) {
541
+ return Object.hasOwn(r, e);
499
542
  }
500
- function m() {
501
- return i;
543
+ function x() {
544
+ return a;
502
545
  }
503
- function f(e, t = "en", n) {
504
- const o = p(e, t);
505
- if (!o)
546
+ function A(e, t = "en", n) {
547
+ const s = c(e, t);
548
+ if (!s)
506
549
  return;
507
- if (!n)
508
- return o;
509
- let s = o;
510
- for (const [c, d] of Object.entries(n)) {
511
- const u = new RegExp(`\\{\\{${c}\\}\\}`, "g");
512
- s = s.replace(u, d);
550
+ if (!n || Object.keys(n).length === 0)
551
+ return s;
552
+ let i = s;
553
+ for (const [l, p] of Object.entries(n)) {
554
+ const h = l.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), m = new RegExp(`\\{\\{${h}\\}\\}`, "g");
555
+ i = i.replace(m, p);
513
556
  }
514
- return s;
557
+ return i;
558
+ }
559
+ function d(e) {
560
+ if (o(e))
561
+ return r[e].category;
562
+ }
563
+ function _(e) {
564
+ return d(e) === "HARD_DECLINE";
565
+ }
566
+ function g(e) {
567
+ return d(e) === "SOFT_DECLINE";
568
+ }
569
+ function E(e, t = "en") {
570
+ if (u(e))
571
+ return c(e.decline_code, t);
572
+ }
573
+ function u(e) {
574
+ return typeof e == "object" && e !== null && "decline_code" in e && typeof e.decline_code == "string" && o(e.decline_code);
575
+ }
576
+ function T(e) {
577
+ return u(e) ? e.decline_code : void 0;
515
578
  }
516
579
  export {
517
580
  r as DECLINE_CODES,
518
- i as DOC_VERSION,
519
- f as formatDeclineMessage,
520
- h as getAllDeclineCodes,
521
- l as getDeclineDescription,
522
- p as getDeclineMessage,
523
- m as getDocVersion,
524
- a as isValidDeclineCode
581
+ a as DOC_VERSION,
582
+ A as formatDeclineMessage,
583
+ f as getAllDeclineCodes,
584
+ d as getDeclineCategory,
585
+ T as getDeclineCodeFromError,
586
+ y as getDeclineDescription,
587
+ c as getDeclineMessage,
588
+ x as getDocVersion,
589
+ E as getMessageFromStripeError,
590
+ _ as isHardDecline,
591
+ g as isSoftDecline,
592
+ u as isStripeDeclineError,
593
+ o as isValidDeclineCode
525
594
  };
526
- //# sourceMappingURL=index.es.js.map
595
+ //# sourceMappingURL=index.mjs.map