@funnelsgrove/payments 0.56.0 → 0.58.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.
- package/dist/generated/package-version.d.ts +1 -1
- package/dist/generated/package-version.js +1 -1
- package/dist/providers/solidgate/components/SolidgateCheckoutDialog.js +10 -15
- package/dist/providers/solidgate/components/SolidgatePaymentForm.d.ts +1 -1
- package/dist/providers/solidgate/components/SolidgatePaymentForm.js +2 -2
- package/dist/providers/solidgate/components/SolidgateSdkPayment.d.ts +1 -1
- package/dist/providers/solidgate/components/SolidgateSdkPayment.js +2 -2
- package/dist/providers/solidgate/services/solidgate.service.d.ts +4 -0
- package/dist/providers/solidgate/services/solidgate.service.js +8 -1
- package/dist/providers/solidgate/services/solidgateDeclineMessage.d.ts +1 -0
- package/dist/providers/solidgate/services/solidgateDeclineMessage.js +7 -0
- package/dist/providers/solidgate/services/solidgateFailureDetails.d.ts +7 -0
- package/dist/providers/solidgate/services/solidgateFailureDetails.js +27 -0
- package/dist/providers/stripe/components/SharedStripeCheckoutV2Form.internal.js +2 -2
- package/dist/providers/stripe/components/StripeCheckoutExpressCheckoutButton.js +2 -2
- package/dist/providers/stripe/components/StripeWalletFirstCheckout.js +2 -2
- package/dist/providers/stripe/services/stripeCheckoutError.d.ts +1 -0
- package/dist/providers/stripe/services/stripeCheckoutError.js +2 -0
- package/dist/services/checkoutObservability.service.d.ts +2 -2
- package/dist/services/checkoutObservability.service.js +9 -4
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PAYMENTS_PACKAGE_VERSION = "0.
|
|
1
|
+
export declare const PAYMENTS_PACKAGE_VERSION = "0.58.0";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by scripts/generate-package-version.mjs.
|
|
2
|
-
export const PAYMENTS_PACKAGE_VERSION = "0.
|
|
2
|
+
export const PAYMENTS_PACKAGE_VERSION = "0.58.0";
|
|
@@ -5,7 +5,8 @@ import { useCallback, useEffect, useMemo, useRef, useState, } from 'react';
|
|
|
5
5
|
import { trackSolidgateCheckoutEvent } from '../services/solidgateCheckoutAnalytics.service.js';
|
|
6
6
|
import { pollSolidgateCheckoutStatus, prepareSolidgateCheckout, SolidgateExistingSubscriptionError, } from '../services/solidgate.service.js';
|
|
7
7
|
import { trackCheckoutCanceled, trackCheckoutFailureShown, } from '../../../services/checkoutObservability.service.js';
|
|
8
|
-
import { solidgateDeclineMessage } from '../services/solidgateDeclineMessage.js';
|
|
8
|
+
import { isSolidgateCustomerDecline, solidgateDeclineMessage } from '../services/solidgateDeclineMessage.js';
|
|
9
|
+
import { solidgateFailureDetails } from '../services/solidgateFailureDetails.js';
|
|
9
10
|
import { SolidgateCheckoutSummary } from './SolidgateCheckoutSummary.js';
|
|
10
11
|
import { SolidgatePaymentForm } from './SolidgatePaymentForm.js';
|
|
11
12
|
import { solidgateCheckoutDialogStyles } from './SolidgateCheckoutDialog.styles.js';
|
|
@@ -139,19 +140,12 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
|
|
|
139
140
|
(_b = onPaymentPendingChangeRef.current) === null || _b === void 0 ? void 0 : _b.call(onPaymentPendingChangeRef, nextView.state === 'submitting'
|
|
140
141
|
|| nextView.state === 'verifying' || nextView.state === 'success' || nextView.canResumeVerification);
|
|
141
142
|
}, []);
|
|
142
|
-
const trackFailure = useCallback((message, failureStage, attemptId) => {
|
|
143
|
+
const trackFailure = useCallback((message, failureStage, attemptId, details) => {
|
|
143
144
|
const analytics = checkoutAnalyticsRef.current;
|
|
144
145
|
if (!analytics) {
|
|
145
146
|
return;
|
|
146
147
|
}
|
|
147
|
-
trackCheckoutFailureShown({
|
|
148
|
-
analytics,
|
|
149
|
-
checkoutSessionId: attemptId,
|
|
150
|
-
errorMessage: message,
|
|
151
|
-
failureStage,
|
|
152
|
-
paymentMethod: 'card',
|
|
153
|
-
provider: 'solidgate',
|
|
154
|
-
});
|
|
148
|
+
trackCheckoutFailureShown(Object.assign({ analytics, checkoutSessionId: attemptId, errorMessage: message, failureStage, paymentMethod: 'card', provider: 'solidgate' }, details));
|
|
155
149
|
}, []);
|
|
156
150
|
const requiresEmailCommit = Boolean(onCustomerEmailCommit);
|
|
157
151
|
const startedAttemptRef = useRef(null);
|
|
@@ -207,8 +201,9 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
|
|
|
207
201
|
state: error instanceof SolidgateExistingSubscriptionError ? 'existing_subscription' : 'recoverable_error',
|
|
208
202
|
checkout: null, canResumeVerification: false, failureMessage,
|
|
209
203
|
});
|
|
210
|
-
|
|
211
|
-
(
|
|
204
|
+
const errorCode = error instanceof SolidgateExistingSubscriptionError ? error.code : undefined;
|
|
205
|
+
trackFailure(failureMessage, 'checkout_session_creation', null, Object.assign(Object.assign({}, solidgateFailureDetails(error)), { errorCode }));
|
|
206
|
+
(_a = onErrorRef.current) === null || _a === void 0 ? void 0 : _a.call(onErrorRef, failureMessage, errorCode);
|
|
212
207
|
}
|
|
213
208
|
});
|
|
214
209
|
return () => controller.abort();
|
|
@@ -295,7 +290,7 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
|
|
|
295
290
|
declinedAttemptRef.current = checkout.attemptId;
|
|
296
291
|
const failureMessage = solidgateDeclineMessage(result.failureCode);
|
|
297
292
|
setState({ state: 'recoverable_error', checkout, canResumeVerification: false, failureMessage });
|
|
298
|
-
trackFailure(failureMessage, 'payment_failed', checkout.attemptId);
|
|
293
|
+
trackFailure(failureMessage, 'payment_failed', checkout.attemptId, Object.assign(Object.assign({}, (isSolidgateCustomerDecline(result.failureCode) ? { providerDeclineCode: result.failureCode } : {})), { providerErrorCode: result.failureCode }));
|
|
299
294
|
(_c = onErrorRef.current) === null || _c === void 0 ? void 0 : _c.call(onErrorRef, failureMessage);
|
|
300
295
|
}
|
|
301
296
|
else if (result.status === 'requires_payment') {
|
|
@@ -403,10 +398,10 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
|
|
|
403
398
|
void trackSolidgateCheckoutEvent('add_payment_info', ((_c = view.checkout) === null || _c === void 0 ? void 0 : _c.attemptId) || '', checkoutAnalyticsRef.current);
|
|
404
399
|
}
|
|
405
400
|
setState(Object.assign(Object.assign({}, view), { state: 'submitting' }));
|
|
406
|
-
}, onVerify: () => void verifyCanonicalStatus(), onError: () => {
|
|
401
|
+
}, onVerify: () => void verifyCanonicalStatus(), onError: (error) => {
|
|
407
402
|
var _a, _b;
|
|
408
403
|
setState(Object.assign(Object.assign({}, view), { state: 'recoverable_error', canResumeVerification: false }));
|
|
409
|
-
trackFailure(copyRef.current.error, 'payment_form', (_a = view.checkout) === null || _a === void 0 ? void 0 : _a.attemptId);
|
|
404
|
+
trackFailure(copyRef.current.error, 'payment_form', (_a = view.checkout) === null || _a === void 0 ? void 0 : _a.attemptId, solidgateFailureDetails(error));
|
|
410
405
|
(_b = onErrorRef.current) === null || _b === void 0 ? void 0 : _b.call(onErrorRef, copyRef.current.error);
|
|
411
406
|
} }, view.checkout.attemptId)) : null;
|
|
412
407
|
if (layout === 'wallet' && !hasExistingSubscription) {
|
|
@@ -9,7 +9,7 @@ export declare function SolidgatePaymentForm({ buttonColor, walletOnly, cardSubm
|
|
|
9
9
|
checkout: SolidgateCheckoutPreparation;
|
|
10
10
|
hidden: boolean;
|
|
11
11
|
loadingLabel: string;
|
|
12
|
-
onError: () => void;
|
|
12
|
+
onError: (error?: unknown) => void;
|
|
13
13
|
onMounted: () => void;
|
|
14
14
|
onSubmit: () => void;
|
|
15
15
|
onVerify: () => void;
|
|
@@ -74,11 +74,11 @@ export function SolidgatePaymentForm({ buttonColor, walletOnly = false, cardSubm
|
|
|
74
74
|
}, onSubmit: () => {
|
|
75
75
|
submittedRef.current = true;
|
|
76
76
|
onSubmit();
|
|
77
|
-
}, onVerify: onVerify, onSuccess: onVerify, onFail: onVerify, onError: () => {
|
|
77
|
+
}, onVerify: onVerify, onSuccess: onVerify, onFail: onVerify, onError: (error) => {
|
|
78
78
|
if (submittedRef.current) {
|
|
79
79
|
onVerify();
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
|
-
onError();
|
|
82
|
+
onError(error);
|
|
83
83
|
} }, checkout.attemptId) }), !walletOnly && secureLabel && (wallets.length === 0 || !showWallet) ? (_jsxs("p", { className: 'solidgate-checkout-secure is-card', children: [_jsx(SecurityLockIcon, {}), secureLabel] })) : null] }));
|
|
84
84
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type Payment from '@solidgate/react-sdk';
|
|
2
2
|
import { type ComponentProps } from 'react';
|
|
3
3
|
type Props = ComponentProps<typeof Payment> & {
|
|
4
|
-
onInitializationError: () => void;
|
|
4
|
+
onInitializationError: (error: unknown) => void;
|
|
5
5
|
};
|
|
6
6
|
/** Own container IDs and cancel pending initialization when a placement goes away. */
|
|
7
7
|
export declare function SolidgateSdkPayment(props: Props): import("react/jsx-runtime").JSX.Element;
|
|
@@ -43,9 +43,9 @@ export function SolidgateSdkPayment(props) {
|
|
|
43
43
|
instance.on(sdk.MessageType.Fail, (event) => { var _a, _b; return (_b = (_a = callbacks.current).onFail) === null || _b === void 0 ? void 0 : _b.call(_a, event.data); });
|
|
44
44
|
instance.on(sdk.MessageType.Error, (event) => { var _a, _b; return (_b = (_a = callbacks.current).onError) === null || _b === void 0 ? void 0 : _b.call(_a, event.data); });
|
|
45
45
|
(_b = (_a = callbacks.current).onReadyPaymentInstance) === null || _b === void 0 ? void 0 : _b.call(_a, instance);
|
|
46
|
-
}).catch(() => {
|
|
46
|
+
}).catch((error) => {
|
|
47
47
|
if (active)
|
|
48
|
-
callbacks.current.onInitializationError();
|
|
48
|
+
callbacks.current.onInitializationError(error);
|
|
49
49
|
});
|
|
50
50
|
return () => {
|
|
51
51
|
active = false;
|
|
@@ -5,6 +5,10 @@ export declare class SolidgateExistingSubscriptionError extends Error {
|
|
|
5
5
|
readonly code: "already_subscribed_to_product";
|
|
6
6
|
constructor();
|
|
7
7
|
}
|
|
8
|
+
export declare class SolidgateCheckoutHttpError extends Error {
|
|
9
|
+
readonly status: number;
|
|
10
|
+
constructor(status: number);
|
|
11
|
+
}
|
|
8
12
|
/** The user's paid checkout left no reusable payment instrument; offer a fresh checkout instead. */
|
|
9
13
|
export declare class SolidgateSavedPaymentMethodUnavailableError extends Error {
|
|
10
14
|
readonly code: "saved_payment_method_unavailable";
|
|
@@ -7,6 +7,13 @@ export class SolidgateExistingSubscriptionError extends Error {
|
|
|
7
7
|
this.name = 'SolidgateExistingSubscriptionError';
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
+
export class SolidgateCheckoutHttpError extends Error {
|
|
11
|
+
constructor(status) {
|
|
12
|
+
super('Solidgate checkout is temporarily unavailable');
|
|
13
|
+
this.status = status;
|
|
14
|
+
this.name = 'SolidgateCheckoutHttpError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
10
17
|
/** The user's paid checkout left no reusable payment instrument; offer a fresh checkout instead. */
|
|
11
18
|
export class SolidgateSavedPaymentMethodUnavailableError extends Error {
|
|
12
19
|
constructor() {
|
|
@@ -75,7 +82,7 @@ const postJson = async (path, body, runtimeConfig, signal) => {
|
|
|
75
82
|
throw new SolidgateCheckoutIdentityExpiredError();
|
|
76
83
|
}
|
|
77
84
|
}
|
|
78
|
-
throw new
|
|
85
|
+
throw new SolidgateCheckoutHttpError(response.status);
|
|
79
86
|
}
|
|
80
87
|
return response.json();
|
|
81
88
|
};
|
|
@@ -22,3 +22,10 @@ const messages = {
|
|
|
22
22
|
};
|
|
23
23
|
export const solidgateDeclineMessage = (code) => ((code && Object.hasOwn(messages, code) ? messages[code] : undefined)
|
|
24
24
|
|| 'Your payment was declined. Use another payment method or contact your bank.');
|
|
25
|
+
// Issuer, card-data and bank-verification refusals; other codes stay platform failures.
|
|
26
|
+
const customerDeclineCodes = new Set([
|
|
27
|
+
'2.04', '2.06', '2.08', '2.09', '2.15',
|
|
28
|
+
'3.01', '3.02', '3.03', '3.04', '3.05', '3.06', '3.07', '3.09', '3.11', '3.13',
|
|
29
|
+
'4.08',
|
|
30
|
+
]);
|
|
31
|
+
export const isSolidgateCustomerDecline = (code) => (Boolean(code && customerDeclineCodes.has(code)));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SolidgateCheckoutHttpError, SolidgateExistingSubscriptionError, SolidgateSavedPaymentMethodUnavailableError, } from './solidgate.service.js';
|
|
2
|
+
const browserErrorNames = new Set([
|
|
3
|
+
'Error', 'TypeError', 'SyntaxError', 'RangeError', 'ReferenceError', 'URIError',
|
|
4
|
+
'EvalError', 'NetworkError', 'TimeoutError', 'AbortError',
|
|
5
|
+
]);
|
|
6
|
+
export const solidgateFailureDetails = (error) => {
|
|
7
|
+
if (error instanceof SolidgateCheckoutHttpError) {
|
|
8
|
+
return { providerErrorType: error.name, providerErrorCode: String(error.status) };
|
|
9
|
+
}
|
|
10
|
+
if (error instanceof SolidgateExistingSubscriptionError || error instanceof SolidgateSavedPaymentMethodUnavailableError) {
|
|
11
|
+
return { providerErrorType: error.name, providerErrorCode: error.code };
|
|
12
|
+
}
|
|
13
|
+
if (error instanceof Error) {
|
|
14
|
+
return { providerErrorType: browserErrorNames.has(error.name) ? error.name : 'Error' };
|
|
15
|
+
}
|
|
16
|
+
const payload = error && typeof error === 'object' ? error : null;
|
|
17
|
+
const value = payload && 'value' in payload ? payload.value : null;
|
|
18
|
+
const name = value && typeof value === 'object' && 'name' in value ? value.name : null;
|
|
19
|
+
const details = payload && 'details' in payload ? payload.details : null;
|
|
20
|
+
const code = details && typeof details === 'object' && 'code' in details ? details.code : null;
|
|
21
|
+
// Fixed values from @solidgate/client-sdk-loader's ErrorMessage; omit arbitrary payload fields.
|
|
22
|
+
return {
|
|
23
|
+
providerErrorType: typeof name === 'string' && ['ConnectionError', 'InitPaymentError', 'GatewayError'].includes(name)
|
|
24
|
+
? name : 'Error',
|
|
25
|
+
providerErrorCode: typeof code === 'string' && ['1.01', '6.01', '2.01'].includes(code) ? code : undefined,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -11,7 +11,7 @@ import { isInactiveCheckoutSessionError } from '../hooks/useStripeSubscriptionCh
|
|
|
11
11
|
import { getStripeWalletPaymentMethodOrder, usePlatformWalletPaymentMethods } from './walletPlatform.js';
|
|
12
12
|
import { trackPaidStripeSubscriptionCheckoutCompleted, trackStripeSubscriptionPaymentInfoSubmitted } from '../services/checkoutCompletionAnalytics.service.js';
|
|
13
13
|
import { trackCheckoutFailureShown } from '../../../services/checkoutObservability.service.js';
|
|
14
|
-
import { normalizeStripeCheckoutError } from '../services/stripeCheckoutError.js';
|
|
14
|
+
import { isStripeCheckoutAlreadyPaidError, normalizeStripeCheckoutError } from '../services/stripeCheckoutError.js';
|
|
15
15
|
import { SharedCheckoutPaymentMethods } from './SharedCheckoutPaymentMethods.internal.js';
|
|
16
16
|
import { SharedStripeCheckoutV2Summary } from './SharedStripeCheckoutV2Summary.internal.js';
|
|
17
17
|
import { useCheckoutEmail } from './useCheckoutEmail.internal.js';
|
|
@@ -234,7 +234,7 @@ export function SharedStripeCheckoutV2CheckoutSessionForm({ copy = defaultChecko
|
|
|
234
234
|
const result = await checkoutState.checkout.confirm({
|
|
235
235
|
redirect: 'if_required',
|
|
236
236
|
});
|
|
237
|
-
if (result.type === 'error') {
|
|
237
|
+
if (result.type === 'error' && !isStripeCheckoutAlreadyPaidError(result.error)) {
|
|
238
238
|
const message = result.error.message || copy.paymentFailed;
|
|
239
239
|
setSharedError(message, false, normalizeStripeCheckoutError(message, result.error, 'card'));
|
|
240
240
|
finishSubmitting();
|
|
@@ -7,7 +7,7 @@ import { ExpressCheckoutElement, useCheckout, } from '@stripe/react-stripe-js/ch
|
|
|
7
7
|
import { queueStripeSubscriptionCheckoutStarted, trackPaidStripeSubscriptionCheckoutCompleted, trackStripeSubscriptionPaymentInfoSubmitted, } from '../services/checkoutCompletionAnalytics.service.js';
|
|
8
8
|
import { getUnsupportedCheckoutCountryMessage, normalizeSupportedCheckoutCountries, } from './checkoutCountries.js';
|
|
9
9
|
import { trackCheckoutCanceled, trackCheckoutFailureShown, } from '../../../services/checkoutObservability.service.js';
|
|
10
|
-
import { normalizeStripeCheckoutError } from '../services/stripeCheckoutError.js';
|
|
10
|
+
import { isStripeCheckoutAlreadyPaidError, normalizeStripeCheckoutError } from '../services/stripeCheckoutError.js';
|
|
11
11
|
const ExpressCheckoutElementWithCancel = ExpressCheckoutElement;
|
|
12
12
|
const buildDefaultOptions = () => ({
|
|
13
13
|
buttonHeight: 55,
|
|
@@ -268,7 +268,7 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
|
|
|
268
268
|
const result = await checkoutState.checkout.confirm(Object.assign(Object.assign({}, (confirmEmail
|
|
269
269
|
? { email: preparedCustomerEmail || (customerEmail === null || customerEmail === void 0 ? void 0 : customerEmail.trim()) || undefined }
|
|
270
270
|
: {})), { expressCheckoutConfirmEvent: event, redirect: 'if_required' }));
|
|
271
|
-
if (result.type === 'error') {
|
|
271
|
+
if (result.type === 'error' && !isStripeCheckoutAlreadyPaidError(result.error)) {
|
|
272
272
|
const message = result.error.message || 'Wallet checkout failed.';
|
|
273
273
|
const details = reportFailure(message, 'wallet_confirmation', event.expressPaymentType, result.error);
|
|
274
274
|
if (details.category === 'payment_rejection') {
|
|
@@ -25,7 +25,7 @@ import { stripeWalletFirstCheckoutStyles } from './StripeWalletFirstCheckout.sty
|
|
|
25
25
|
import { queueStripeSubscriptionCheckoutStarted, trackPaidStripeSubscriptionCheckoutCompleted, trackStripeCheckoutShown, trackStripeSubscriptionPaymentInfoSubmitted, } from '../services/checkoutCompletionAnalytics.service.js';
|
|
26
26
|
import { trackCheckoutFailureShown } from '../../../services/checkoutObservability.service.js';
|
|
27
27
|
import { useCheckoutShownOnce } from '../hooks/useCheckoutShownOnce.js';
|
|
28
|
-
import { normalizeStripeCheckoutError } from '../services/stripeCheckoutError.js';
|
|
28
|
+
import { isStripeCheckoutAlreadyPaidError, normalizeStripeCheckoutError } from '../services/stripeCheckoutError.js';
|
|
29
29
|
const appearance = {
|
|
30
30
|
labels: 'above',
|
|
31
31
|
variables: {
|
|
@@ -161,7 +161,7 @@ function StripeWalletFirstCheckoutForm({ amountCents, checkoutAnalytics, checkou
|
|
|
161
161
|
await trackStripeSubscriptionPaymentInfoSubmitted(Object.assign(Object.assign({}, checkoutAnalytics), { checkoutSessionId })).catch(() => 'analytics_rejected');
|
|
162
162
|
}
|
|
163
163
|
const result = await checkout.confirm({ redirect: 'if_required' });
|
|
164
|
-
if (result.type === 'error') {
|
|
164
|
+
if (result.type === 'error' && !isStripeCheckoutAlreadyPaidError(result.error)) {
|
|
165
165
|
const message = result.error.message || copy.paymentFailed;
|
|
166
166
|
showError(message, normalizeStripeCheckoutError(message, result.error, 'card'));
|
|
167
167
|
submitInFlight.current = false;
|
|
@@ -8,3 +8,4 @@ export type StripeCheckoutErrorDetails = {
|
|
|
8
8
|
providerErrorType?: string;
|
|
9
9
|
};
|
|
10
10
|
export declare function normalizeStripeCheckoutError(message: string, error?: unknown, paymentMethod?: unknown): StripeCheckoutErrorDetails;
|
|
11
|
+
export declare const isStripeCheckoutAlreadyPaidError: (error: unknown) => boolean;
|
|
@@ -12,3 +12,5 @@ export function normalizeStripeCheckoutError(message, error, paymentMethod) {
|
|
|
12
12
|
};
|
|
13
13
|
return Object.assign(Object.assign({}, providerFields), { category: classifyCheckoutFailure(Object.assign({ errorMessage: message, provider: 'stripe' }, providerFields)), paymentMethod: toAnalyticsPaymentMethod(paymentMethod) });
|
|
14
14
|
}
|
|
15
|
+
// Stripe rejects a repeated confirmation of a Checkout Session that is already paid.
|
|
16
|
+
export const isStripeCheckoutAlreadyPaidError = (error) => { var _a; return /payment has already been processed/i.test(String((_a = asRecord(error).message) !== null && _a !== void 0 ? _a : '')); };
|
|
@@ -31,8 +31,8 @@ type CheckoutFailureShownInput = CheckoutObservabilityInput & {
|
|
|
31
31
|
providerErrorCode?: string | null;
|
|
32
32
|
providerErrorType?: string | null;
|
|
33
33
|
};
|
|
34
|
-
export type CheckoutFailureCategory = 'network_failure' | 'payment_rejection' | 'platform_failure' | 'session_failure' | 'validation_failure';
|
|
35
|
-
export type CheckoutFailureClassificationInput = Pick<CheckoutFailureShownInput, 'errorMessage' | 'provider' | 'providerDeclineCode' | 'providerErrorCode' | 'providerErrorType'>;
|
|
34
|
+
export type CheckoutFailureCategory = 'existing_subscription' | 'network_failure' | 'payment_rejection' | 'platform_failure' | 'session_failure' | 'validation_failure';
|
|
35
|
+
export type CheckoutFailureClassificationInput = Pick<CheckoutFailureShownInput, 'errorCode' | 'errorMessage' | 'provider' | 'providerDeclineCode' | 'providerErrorCode' | 'providerErrorType'>;
|
|
36
36
|
export declare const classifyCheckoutFailure: (input: CheckoutFailureClassificationInput) => CheckoutFailureCategory;
|
|
37
37
|
export declare const trackCheckoutFailureShown: (input: CheckoutFailureShownInput) => string | null;
|
|
38
38
|
export declare const trackCheckoutCanceled: (input: CheckoutObservabilityInput) => string | null;
|
|
@@ -45,14 +45,18 @@ export const classifyCheckoutFailure = (input) => {
|
|
|
45
45
|
const providerDeclineCode = asNonEmptyString(input.providerDeclineCode);
|
|
46
46
|
const providerErrorCode = asNonEmptyString(input.providerErrorCode);
|
|
47
47
|
const providerErrorType = asNonEmptyString(input.providerErrorType);
|
|
48
|
+
if (asNonEmptyString(input.errorCode) === 'already_subscribed_to_product'
|
|
49
|
+
|| /payment has already been processed/i.test(input.errorMessage)) {
|
|
50
|
+
return 'existing_subscription';
|
|
51
|
+
}
|
|
48
52
|
if (input.provider === 'stripe' && providerErrorCode
|
|
49
53
|
&& STRIPE_VALIDATION_ERROR_CODES.has(providerErrorCode)) {
|
|
50
54
|
return 'validation_failure';
|
|
51
55
|
}
|
|
52
|
-
if (
|
|
53
|
-
|| providerErrorType === 'card_error'
|
|
54
|
-
|
|
55
|
-
|| /card has insufficient funds|unable to authenticate your payment method|card(?: was| is)? declined|security code is incorrect/i.test(input.errorMessage))
|
|
56
|
+
if (Boolean(providerDeclineCode)
|
|
57
|
+
|| (input.provider === 'stripe' && (providerErrorType === 'card_error'
|
|
58
|
+
|| (providerErrorCode ? STRIPE_PAYMENT_REJECTION_CODES.has(providerErrorCode) : false)))
|
|
59
|
+
|| /card has insufficient funds|unable to authenticate your payment method|card(?: was| is)? declined|security code is incorrect|card has expired|card type isn[’']t accepted/i.test(input.errorMessage)) {
|
|
56
60
|
return 'payment_rejection';
|
|
57
61
|
}
|
|
58
62
|
const message = input.errorMessage.trim();
|
|
@@ -192,6 +196,7 @@ export const trackCheckoutFailureShown = (input) => {
|
|
|
192
196
|
const providerErrorCode = (_b = asNonEmptyString(input.providerErrorCode)) === null || _b === void 0 ? void 0 : _b.slice(0, 120);
|
|
193
197
|
const providerErrorType = (_c = asNonEmptyString(input.providerErrorType)) === null || _c === void 0 ? void 0 : _c.slice(0, 120);
|
|
194
198
|
const failureCategory = classifyCheckoutFailure({
|
|
199
|
+
errorCode: input.errorCode,
|
|
195
200
|
errorMessage,
|
|
196
201
|
provider: input.provider,
|
|
197
202
|
providerDeclineCode,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funnelsgrove/payments",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.58.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",
|
|
@@ -46,11 +46,11 @@
|
|
|
46
46
|
"jsdom": "20.0.3",
|
|
47
47
|
"typescript": "^5",
|
|
48
48
|
"vitest": "^3.2.4",
|
|
49
|
-
"@funnelsgrove/runtime": "0.
|
|
50
|
-
"@funnelsgrove/analytics": "0.
|
|
49
|
+
"@funnelsgrove/runtime": "0.41.0",
|
|
50
|
+
"@funnelsgrove/analytics": "0.24.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@funnelsgrove/runtime": "^0.
|
|
54
|
-
"@funnelsgrove/analytics": "^0.
|
|
53
|
+
"@funnelsgrove/runtime": "^0.41.0",
|
|
54
|
+
"@funnelsgrove/analytics": "^0.24.0"
|
|
55
55
|
}
|
|
56
56
|
}
|