@funnelsgrove/payments 0.57.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.
@@ -1 +1 @@
1
- export declare const PAYMENTS_PACKAGE_VERSION = "0.57.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.57.0";
2
+ export const PAYMENTS_PACKAGE_VERSION = "0.58.0";
@@ -6,6 +6,7 @@ import { trackSolidgateCheckoutEvent } from '../services/solidgateCheckoutAnalyt
6
6
  import { pollSolidgateCheckoutStatus, prepareSolidgateCheckout, SolidgateExistingSubscriptionError, } from '../services/solidgate.service.js';
7
7
  import { trackCheckoutCanceled, trackCheckoutFailureShown, } from '../../../services/checkoutObservability.service.js';
8
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';
@@ -201,7 +202,7 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
201
202
  checkout: null, canResumeVerification: false, failureMessage,
202
203
  });
203
204
  const errorCode = error instanceof SolidgateExistingSubscriptionError ? error.code : undefined;
204
- trackFailure(failureMessage, 'checkout_session_creation', null, { errorCode });
205
+ trackFailure(failureMessage, 'checkout_session_creation', null, Object.assign(Object.assign({}, solidgateFailureDetails(error)), { errorCode }));
205
206
  (_a = onErrorRef.current) === null || _a === void 0 ? void 0 : _a.call(onErrorRef, failureMessage, errorCode);
206
207
  }
207
208
  });
@@ -397,10 +398,10 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
397
398
  void trackSolidgateCheckoutEvent('add_payment_info', ((_c = view.checkout) === null || _c === void 0 ? void 0 : _c.attemptId) || '', checkoutAnalyticsRef.current);
398
399
  }
399
400
  setState(Object.assign(Object.assign({}, view), { state: 'submitting' }));
400
- }, onVerify: () => void verifyCanonicalStatus(), onError: () => {
401
+ }, onVerify: () => void verifyCanonicalStatus(), onError: (error) => {
401
402
  var _a, _b;
402
403
  setState(Object.assign(Object.assign({}, view), { state: 'recoverable_error', canResumeVerification: false }));
403
- 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));
404
405
  (_b = onErrorRef.current) === null || _b === void 0 ? void 0 : _b.call(onErrorRef, copyRef.current.error);
405
406
  } }, view.checkout.attemptId)) : null;
406
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 Error('Solidgate checkout is temporarily unavailable');
85
+ throw new SolidgateCheckoutHttpError(response.status);
79
86
  }
80
87
  return response.json();
81
88
  };
@@ -0,0 +1,7 @@
1
+ export declare const solidgateFailureDetails: (error: unknown) => {
2
+ providerErrorType: string;
3
+ providerErrorCode?: undefined;
4
+ } | {
5
+ providerErrorType: string;
6
+ providerErrorCode: string | undefined;
7
+ };
@@ -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 : '')); };
@@ -45,7 +45,8 @@ 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') {
48
+ if (asNonEmptyString(input.errorCode) === 'already_subscribed_to_product'
49
+ || /payment has already been processed/i.test(input.errorMessage)) {
49
50
  return 'existing_subscription';
50
51
  }
51
52
  if (input.provider === 'stripe' && providerErrorCode
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/payments",
3
- "version": "0.57.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.40.0",
50
- "@funnelsgrove/analytics": "0.23.0"
49
+ "@funnelsgrove/runtime": "0.41.0",
50
+ "@funnelsgrove/analytics": "0.24.0"
51
51
  },
52
52
  "peerDependencies": {
53
- "@funnelsgrove/runtime": "^0.40.0",
54
- "@funnelsgrove/analytics": "^0.23.0"
53
+ "@funnelsgrove/runtime": "^0.41.0",
54
+ "@funnelsgrove/analytics": "^0.24.0"
55
55
  }
56
56
  }