@funnelsgrove/payments 0.56.0 → 0.57.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.
@@ -1 +1 @@
1
- export declare const PAYMENTS_PACKAGE_VERSION = "0.56.0";
1
+ export declare const PAYMENTS_PACKAGE_VERSION = "0.57.0";
@@ -1,2 +1,2 @@
1
1
  // Generated by scripts/generate-package-version.mjs.
2
- export const PAYMENTS_PACKAGE_VERSION = "0.56.0";
2
+ export const PAYMENTS_PACKAGE_VERSION = "0.57.0";
@@ -5,7 +5,7 @@ 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
9
  import { SolidgateCheckoutSummary } from './SolidgateCheckoutSummary.js';
10
10
  import { SolidgatePaymentForm } from './SolidgatePaymentForm.js';
11
11
  import { solidgateCheckoutDialogStyles } from './SolidgateCheckoutDialog.styles.js';
@@ -139,19 +139,12 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
139
139
  (_b = onPaymentPendingChangeRef.current) === null || _b === void 0 ? void 0 : _b.call(onPaymentPendingChangeRef, nextView.state === 'submitting'
140
140
  || nextView.state === 'verifying' || nextView.state === 'success' || nextView.canResumeVerification);
141
141
  }, []);
142
- const trackFailure = useCallback((message, failureStage, attemptId) => {
142
+ const trackFailure = useCallback((message, failureStage, attemptId, details) => {
143
143
  const analytics = checkoutAnalyticsRef.current;
144
144
  if (!analytics) {
145
145
  return;
146
146
  }
147
- trackCheckoutFailureShown({
148
- analytics,
149
- checkoutSessionId: attemptId,
150
- errorMessage: message,
151
- failureStage,
152
- paymentMethod: 'card',
153
- provider: 'solidgate',
154
- });
147
+ trackCheckoutFailureShown(Object.assign({ analytics, checkoutSessionId: attemptId, errorMessage: message, failureStage, paymentMethod: 'card', provider: 'solidgate' }, details));
155
148
  }, []);
156
149
  const requiresEmailCommit = Boolean(onCustomerEmailCommit);
157
150
  const startedAttemptRef = useRef(null);
@@ -207,8 +200,9 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
207
200
  state: error instanceof SolidgateExistingSubscriptionError ? 'existing_subscription' : 'recoverable_error',
208
201
  checkout: null, canResumeVerification: false, failureMessage,
209
202
  });
210
- trackFailure(failureMessage, 'checkout_session_creation');
211
- (_a = onErrorRef.current) === null || _a === void 0 ? void 0 : _a.call(onErrorRef, failureMessage, error instanceof SolidgateExistingSubscriptionError ? error.code : undefined);
203
+ const errorCode = error instanceof SolidgateExistingSubscriptionError ? error.code : undefined;
204
+ trackFailure(failureMessage, 'checkout_session_creation', null, { errorCode });
205
+ (_a = onErrorRef.current) === null || _a === void 0 ? void 0 : _a.call(onErrorRef, failureMessage, errorCode);
212
206
  }
213
207
  });
214
208
  return () => controller.abort();
@@ -295,7 +289,7 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
295
289
  declinedAttemptRef.current = checkout.attemptId;
296
290
  const failureMessage = solidgateDeclineMessage(result.failureCode);
297
291
  setState({ state: 'recoverable_error', checkout, canResumeVerification: false, failureMessage });
298
- trackFailure(failureMessage, 'payment_failed', checkout.attemptId);
292
+ trackFailure(failureMessage, 'payment_failed', checkout.attemptId, Object.assign(Object.assign({}, (isSolidgateCustomerDecline(result.failureCode) ? { providerDeclineCode: result.failureCode } : {})), { providerErrorCode: result.failureCode }));
299
293
  (_c = onErrorRef.current) === null || _c === void 0 ? void 0 : _c.call(onErrorRef, failureMessage);
300
294
  }
301
295
  else if (result.status === 'requires_payment') {
@@ -1 +1,2 @@
1
1
  export declare const solidgateDeclineMessage: (code?: string) => string;
2
+ export declare const isSolidgateCustomerDecline: (code?: string) => boolean;
@@ -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)));
@@ -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,17 @@ 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
+ return 'existing_subscription';
50
+ }
48
51
  if (input.provider === 'stripe' && providerErrorCode
49
52
  && STRIPE_VALIDATION_ERROR_CODES.has(providerErrorCode)) {
50
53
  return 'validation_failure';
51
54
  }
52
- if (input.provider === 'stripe' && (Boolean(providerDeclineCode)
53
- || providerErrorType === 'card_error'
54
- || (providerErrorCode ? STRIPE_PAYMENT_REJECTION_CODES.has(providerErrorCode) : false)
55
- || /card has insufficient funds|unable to authenticate your payment method|card(?: was| is)? declined|security code is incorrect/i.test(input.errorMessage))) {
55
+ if (Boolean(providerDeclineCode)
56
+ || (input.provider === 'stripe' && (providerErrorType === 'card_error'
57
+ || (providerErrorCode ? STRIPE_PAYMENT_REJECTION_CODES.has(providerErrorCode) : false)))
58
+ || /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
59
  return 'payment_rejection';
57
60
  }
58
61
  const message = input.errorMessage.trim();
@@ -192,6 +195,7 @@ export const trackCheckoutFailureShown = (input) => {
192
195
  const providerErrorCode = (_b = asNonEmptyString(input.providerErrorCode)) === null || _b === void 0 ? void 0 : _b.slice(0, 120);
193
196
  const providerErrorType = (_c = asNonEmptyString(input.providerErrorType)) === null || _c === void 0 ? void 0 : _c.slice(0, 120);
194
197
  const failureCategory = classifyCheckoutFailure({
198
+ errorCode: input.errorCode,
195
199
  errorMessage,
196
200
  provider: input.provider,
197
201
  providerDeclineCode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/payments",
3
- "version": "0.56.0",
3
+ "version": "0.57.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",