@funnelsgrove/payments 0.58.0 → 0.60.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.58.0";
1
+ export declare const PAYMENTS_PACKAGE_VERSION = "0.60.0";
@@ -1,2 +1,2 @@
1
1
  // Generated by scripts/generate-package-version.mjs.
2
- export const PAYMENTS_PACKAGE_VERSION = "0.58.0";
2
+ export const PAYMENTS_PACKAGE_VERSION = "0.60.0";
@@ -212,6 +212,8 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
212
212
  const showPreparingLoader = view.state === 'loading'
213
213
  || (view.state === 'ready' && !paymentFormMounted);
214
214
  const hasExistingSubscription = view.state === 'existing_subscription';
215
+ const paymentPending = view.state === 'submitting' || view.state === 'verifying'
216
+ || view.state === 'success' || view.canResumeVerification;
215
217
  useEffect(() => {
216
218
  var _a;
217
219
  if (!open || (layout === 'wallet' && !hasExistingSubscription)) {
@@ -222,7 +224,7 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
222
224
  : null;
223
225
  const handleKeyDown = (event) => {
224
226
  var _a;
225
- if (event.key === 'Escape') {
227
+ if (event.key === 'Escape' && !paymentPending) {
226
228
  const analytics = checkoutAnalyticsRef.current;
227
229
  if (analytics) {
228
230
  trackCheckoutCanceled({
@@ -244,13 +246,13 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
244
246
  window.removeEventListener('keydown', handleKeyDown);
245
247
  previouslyFocused === null || previouslyFocused === void 0 ? void 0 : previouslyFocused.focus();
246
248
  };
247
- }, [hasExistingSubscription, layout, open, showPreparingLoader, view.checkout]);
249
+ }, [hasExistingSubscription, layout, open, paymentPending, showPreparingLoader, view.checkout]);
248
250
  useEffect(() => () => {
249
251
  var _a, _b;
250
252
  (_a = prepareAbortRef.current) === null || _a === void 0 ? void 0 : _a.abort();
251
253
  (_b = statusAbortRef.current) === null || _b === void 0 ? void 0 : _b.abort();
252
254
  }, []);
253
- const verifyCanonicalStatus = useCallback(async () => {
255
+ const verifyCanonicalStatus = useCallback(async (challengeActive = view.challengeActive) => {
254
256
  var _a, _b, _c, _d;
255
257
  const checkout = view.checkout;
256
258
  if (!checkout || view.state === 'success') {
@@ -259,7 +261,7 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
259
261
  (_a = statusAbortRef.current) === null || _a === void 0 ? void 0 : _a.abort();
260
262
  const controller = new AbortController();
261
263
  statusAbortRef.current = controller;
262
- setState({ state: 'verifying', checkout, canResumeVerification: false });
264
+ setState({ state: 'verifying', checkout, canResumeVerification: false, challengeActive });
263
265
  try {
264
266
  const result = await pollSolidgateCheckoutStatus({
265
267
  attemptId: checkout.attemptId,
@@ -293,16 +295,17 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
293
295
  trackFailure(failureMessage, 'payment_failed', checkout.attemptId, Object.assign(Object.assign({}, (isSolidgateCustomerDecline(result.failureCode) ? { providerDeclineCode: result.failureCode } : {})), { providerErrorCode: result.failureCode }));
294
296
  (_c = onErrorRef.current) === null || _c === void 0 ? void 0 : _c.call(onErrorRef, failureMessage);
295
297
  }
296
- else if (result.status === 'requires_payment') {
298
+ else if (result.status === 'requires_payment' && !challengeActive) {
297
299
  setState({ state: 'ready', checkout, canResumeVerification: false });
298
300
  }
299
301
  else {
300
- setState({ state: 'verifying', checkout, canResumeVerification: result.timedOut });
302
+ setState({ state: 'verifying', checkout, challengeActive,
303
+ canResumeVerification: result.timedOut || result.status === 'requires_payment' });
301
304
  }
302
305
  }
303
306
  catch (_e) {
304
307
  if (!controller.signal.aborted) {
305
- setState({ state: 'recoverable_error', checkout, canResumeVerification: true });
308
+ setState({ state: 'recoverable_error', checkout, canResumeVerification: true, challengeActive });
306
309
  trackFailure(copyRef.current.error, 'payment_verification', checkout.attemptId);
307
310
  (_d = onErrorRef.current) === null || _d === void 0 ? void 0 : _d.call(onErrorRef, copyRef.current.error);
308
311
  }
@@ -337,6 +340,8 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
337
340
  }, [copy.customerEmailInvalid, copy.customerEmailUnavailable, emailInput, onCustomerEmailCommit, trackFailure, view.checkout]);
338
341
  const handleClose = () => {
339
342
  var _a;
343
+ if (paymentPending)
344
+ return;
340
345
  const analytics = checkoutAnalyticsRef.current;
341
346
  if (analytics) {
342
347
  trackCheckoutCanceled({
@@ -353,7 +358,7 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
353
358
  return null;
354
359
  }
355
360
  const showForm = view.state === 'ready'
356
- || view.state === 'submitting';
361
+ || view.state === 'submitting' || view.challengeActive;
357
362
  const statusMessage = view.state === 'loading'
358
363
  ? copy.loading
359
364
  : view.state === 'submitting'
@@ -388,7 +393,7 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
388
393
  attemptId: source,
389
394
  });
390
395
  }, className: 'solidgate-checkout-action solidgate-checkout-action--spaced', children: copy.retry })) : null] }));
391
- const paymentForm = view.checkout ? (_jsx(SolidgatePaymentForm, { walletOnly: layout === 'wallet', secureLabel: presentation === null || presentation === void 0 ? void 0 : presentation.secureLabel, cardLabel: presentation === null || presentation === void 0 ? void 0 : presentation.cardLabel, paymentMethodLabel: presentation === null || presentation === void 0 ? void 0 : presentation.paymentMethodLabel, buttonColor: (presentation === null || presentation === void 0 ? void 0 : presentation.buttonColor) || '#3f51b5', cardSubmitLabel: (presentation === null || presentation === void 0 ? void 0 : presentation.cardSubmitLabel) || 'Pay securely', checkout: view.checkout, hidden: !showForm, loadingLabel: copy.loading, onMounted: () => {
396
+ const paymentForm = view.checkout ? (_jsx(SolidgatePaymentForm, { walletOnly: layout === 'wallet', secureLabel: presentation === null || presentation === void 0 ? void 0 : presentation.secureLabel, cardLabel: presentation === null || presentation === void 0 ? void 0 : presentation.cardLabel, paymentMethodLabel: presentation === null || presentation === void 0 ? void 0 : presentation.paymentMethodLabel, buttonColor: (presentation === null || presentation === void 0 ? void 0 : presentation.buttonColor) || '#3f51b5', cardSubmitLabel: (presentation === null || presentation === void 0 ? void 0 : presentation.cardSubmitLabel) || 'Pay securely', checkout: view.checkout, hidden: !showForm, challengeActive: view.challengeActive, paymentPending: paymentPending, loadingLabel: copy.loading, onMounted: () => {
392
397
  var _a;
393
398
  setMountedPaymentAttemptId(((_a = view.checkout) === null || _a === void 0 ? void 0 : _a.attemptId) || null);
394
399
  }, onSubmit: () => {
@@ -398,7 +403,7 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
398
403
  void trackSolidgateCheckoutEvent('add_payment_info', ((_c = view.checkout) === null || _c === void 0 ? void 0 : _c.attemptId) || '', checkoutAnalyticsRef.current);
399
404
  }
400
405
  setState(Object.assign(Object.assign({}, view), { state: 'submitting' }));
401
- }, onVerify: () => void verifyCanonicalStatus(), onError: (error) => {
406
+ }, onVerify: () => void verifyCanonicalStatus(true), onPaymentResult: () => void verifyCanonicalStatus(false), onError: (error) => {
402
407
  var _a, _b;
403
408
  setState(Object.assign(Object.assign({}, view), { state: 'recoverable_error', canResumeVerification: false }));
404
409
  trackFailure(copyRef.current.error, 'payment_form', (_a = view.checkout) === null || _a === void 0 ? void 0 : _a.attemptId, solidgateFailureDetails(error));
@@ -419,7 +424,7 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
419
424
  'solidgate-checkout-dialog',
420
425
  showPreparingLoader ? 'is-preparing' : '',
421
426
  presentation && !hasExistingSubscription ? 'is-branded' : '',
422
- ].filter(Boolean).join(' '), children: [_jsxs("div", { className: 'solidgate-checkout-header', children: [_jsx("button", { ref: closeButtonRef, type: 'button', onClick: handleClose, "aria-label": copy.closeAriaLabel, className: 'solidgate-checkout-close', children: _jsx("span", { "aria-hidden": 'true' }) }), _jsx("h2", { id: 'solidgate-checkout-title', className: 'solidgate-checkout-title', children: hasExistingSubscription ? copy.existingSubscriptionTitle : (presentation === null || presentation === void 0 ? void 0 : presentation.title) || copy.title })] }), presentation && !hasExistingSubscription ? _jsx(SolidgateCheckoutSummary, { presentation: presentation }) : null, view.state === 'collecting_email' ? (_jsxs("form", { className: 'solidgate-checkout-email-form', onSubmit: (event) => void commitCustomerEmail(event), children: [_jsxs("label", { className: 'solidgate-checkout-email-label', children: [copy.customerEmailLabel, _jsx("input", { type: 'email', autoComplete: 'email', inputMode: 'email', maxLength: 320, required: true, value: emailInput, onChange: (event) => {
427
+ ].filter(Boolean).join(' '), children: [_jsxs("div", { className: 'solidgate-checkout-header', children: [_jsx("button", { ref: closeButtonRef, type: 'button', onClick: handleClose, disabled: paymentPending, "aria-label": copy.closeAriaLabel, className: 'solidgate-checkout-close', children: _jsx("span", { "aria-hidden": 'true' }) }), _jsx("h2", { id: 'solidgate-checkout-title', className: 'solidgate-checkout-title', children: hasExistingSubscription ? copy.existingSubscriptionTitle : (presentation === null || presentation === void 0 ? void 0 : presentation.title) || copy.title })] }), presentation && !hasExistingSubscription ? _jsx(SolidgateCheckoutSummary, { presentation: presentation }) : null, view.state === 'collecting_email' ? (_jsxs("form", { className: 'solidgate-checkout-email-form', onSubmit: (event) => void commitCustomerEmail(event), children: [_jsxs("label", { className: 'solidgate-checkout-email-label', children: [copy.customerEmailLabel, _jsx("input", { type: 'email', autoComplete: 'email', inputMode: 'email', maxLength: 320, required: true, value: emailInput, onChange: (event) => {
423
428
  setEmailInput(event.target.value);
424
429
  setEmailError(null);
425
430
  }, placeholder: copy.customerEmailPlaceholder, "aria-invalid": Boolean(emailError), className: 'solidgate-checkout-email-input' })] }), emailError ? (_jsx("p", { role: 'alert', className: 'solidgate-checkout-alert', children: emailError })) : null, _jsx("button", { type: 'submit', disabled: emailSubmitting, className: 'solidgate-checkout-action', children: copy.customerEmailContinue })] })) : null, paymentForm, statusMessage && view.state !== 'ready' ? (_jsx("div", { className: 'solidgate-checkout-status', children: _jsx("p", { role: 'status', "aria-live": 'polite', children: statusMessage }) })) : null, recoveryActions] })) : null] }), _jsx("style", { children: solidgateCheckoutDialogStyles })] }));
@@ -1,5 +1,5 @@
1
1
  import type { SolidgateCheckoutPreparation } from '../services/solidgate.service.js';
2
- export declare function SolidgatePaymentForm({ buttonColor, walletOnly, cardSubmitLabel, secureLabel, cardLabel, paymentMethodLabel, checkout, hidden, onError, onMounted, onSubmit, onVerify, }: {
2
+ export declare function SolidgatePaymentForm({ buttonColor, walletOnly, cardSubmitLabel, secureLabel, cardLabel, paymentMethodLabel, checkout, hidden, challengeActive, paymentPending, onError, onMounted, onSubmit, onVerify, onPaymentResult, }: {
3
3
  buttonColor: string;
4
4
  walletOnly?: boolean;
5
5
  cardSubmitLabel: string;
@@ -8,9 +8,12 @@ export declare function SolidgatePaymentForm({ buttonColor, walletOnly, cardSubm
8
8
  paymentMethodLabel?: string;
9
9
  checkout: SolidgateCheckoutPreparation;
10
10
  hidden: boolean;
11
+ challengeActive?: boolean;
12
+ paymentPending?: boolean;
11
13
  loadingLabel: string;
12
14
  onError: (error?: unknown) => void;
13
15
  onMounted: () => void;
14
16
  onSubmit: () => void;
15
17
  onVerify: () => void;
18
+ onPaymentResult: () => void;
16
19
  }): import("react/jsx-runtime").JSX.Element;
@@ -3,13 +3,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useId, useRef, useState } from 'react';
4
4
  import { PaymentBrandMark, SecurityLockIcon } from '../../stripe/components/CheckoutBrandAssets.js';
5
5
  import { SolidgateSdkPayment } from './SolidgateSdkPayment.js';
6
- export function SolidgatePaymentForm({ buttonColor, walletOnly = false, cardSubmitLabel, secureLabel, cardLabel = 'Credit card', paymentMethodLabel = 'Payment method', checkout, hidden, onError, onMounted, onSubmit, onVerify, }) {
6
+ export function SolidgatePaymentForm({ buttonColor, walletOnly = false, cardSubmitLabel, secureLabel, cardLabel = 'Credit card', paymentMethodLabel = 'Payment method', checkout, hidden, challengeActive = false, paymentPending = false, onError, onMounted, onSubmit, onVerify, onPaymentResult, }) {
7
7
  const panelId = useId();
8
8
  const [wallets, setWallets] = useState([]);
9
9
  const [selectedMethod, setSelectedMethod] = useState('wallet');
10
10
  const showTabs = !walletOnly && Boolean(secureLabel) && wallets.length > 0;
11
- const showWallet = walletOnly || !showTabs || selectedMethod === 'wallet';
12
- const showCard = !walletOnly && (!showTabs || selectedMethod === 'card');
11
+ const showWallet = !challengeActive && (walletOnly || !showTabs || selectedMethod === 'wallet');
12
+ const showCard = challengeActive || (!walletOnly && (!showTabs || selectedMethod === 'card'));
13
13
  const submittedRef = useRef(false);
14
14
  const paymentBoundaryRef = useRef(null);
15
15
  const mountedReportedRef = useRef(false);
@@ -44,7 +44,7 @@ export function SolidgatePaymentForm({ buttonColor, walletOnly = false, cardSubm
44
44
  return () => observer.disconnect();
45
45
  }, [checkout.attemptId]);
46
46
  const walletButtonType = checkout.display.billingInterval ? 'subscribe' : 'buy';
47
- return (_jsxs("div", { ref: paymentBoundaryRef, className: `solidgate-checkout-payment${secureLabel && !walletOnly ? ' is-branded' : ''}`, "data-solidgate-attempt-id": checkout.attemptId, hidden: hidden, "aria-hidden": hidden || undefined, children: [showTabs ? (_jsxs("div", { className: 'solidgate-checkout-methods', role: 'tablist', "aria-label": paymentMethodLabel, children: [_jsx("button", { type: 'button', role: 'tab', id: `${panelId}-wallet-tab`, "aria-label": wallets.join(' / '), "aria-selected": selectedMethod === 'wallet', "aria-controls": `${panelId}-wallet`, className: 'solidgate-checkout-method', onClick: () => setSelectedMethod('wallet'), children: wallets.map((label) => _jsx(PaymentBrandMark, { label: label, className: 'solidgate-checkout-tab-wallet' }, label)) }), _jsxs("button", { type: 'button', role: 'tab', id: `${panelId}-card-tab`, "aria-selected": selectedMethod === 'card', "aria-controls": `${panelId}-card`, className: 'solidgate-checkout-method', onClick: () => setSelectedMethod('card'), children: [_jsx("strong", { children: cardLabel }), _jsx("span", { className: 'solidgate-checkout-tab-brands', "aria-hidden": 'true', children: ['Visa', 'Mastercard', 'Maestro', 'Discover'].map((label) => (_jsx(PaymentBrandMark, { label: label, className: 'solidgate-checkout-tab-brand' }, label))) })] })] })) : null, !walletOnly && secureLabel && wallets.length > 0 && showWallet ? (_jsxs("p", { className: 'solidgate-checkout-secure', children: [_jsx(SecurityLockIcon, {}), secureLabel] })) : null, _jsxs("div", { className: 'solidgate-checkout-wallets', id: `${panelId}-wallet`, role: showTabs ? 'tabpanel' : undefined, "aria-labelledby": showTabs ? `${panelId}-wallet-tab` : undefined, hidden: !showWallet, children: [_jsx("div", { ref: applePayContainerRef, "data-solidgate-wallet": 'apple-pay' }), _jsx("div", { ref: googlePayContainerRef, "data-solidgate-wallet": 'google-pay' })] }), _jsx("div", { className: 'solidgate-checkout-card', id: `${panelId}-card`, role: showTabs ? 'tabpanel' : undefined, "aria-labelledby": showTabs ? `${panelId}-card-tab` : undefined, hidden: !showCard, children: _jsx(SolidgateSdkPayment, { onInitializationError: onError, merchantData: checkout.initialization.merchantData, width: '100%', formParams: Object.assign({ autoFocus: false, enabled: !walletOnly, isSolidLogoVisible: false, submitButtonText: cardSubmitLabel }, (secureLabel ? { cardNumberLabel: 'Card number', cardExpiryDateLabel: 'Expiration date', cardCvvLabel: 'Security code' } : {})), styles: {
47
+ return (_jsxs("div", { ref: paymentBoundaryRef, className: `solidgate-checkout-payment${secureLabel && !walletOnly ? ' is-branded' : ''}`, "data-solidgate-attempt-id": checkout.attemptId, hidden: hidden, "aria-hidden": hidden || undefined, children: [showTabs ? (_jsxs("div", { className: 'solidgate-checkout-methods', role: 'tablist', "aria-label": paymentMethodLabel, children: [_jsx("button", { type: 'button', role: 'tab', id: `${panelId}-wallet-tab`, "aria-label": wallets.join(' / '), disabled: paymentPending, "aria-selected": selectedMethod === 'wallet', "aria-controls": `${panelId}-wallet`, className: 'solidgate-checkout-method', onClick: () => setSelectedMethod('wallet'), children: wallets.map((label) => _jsx(PaymentBrandMark, { label: label, className: 'solidgate-checkout-tab-wallet' }, label)) }), _jsxs("button", { type: 'button', role: 'tab', id: `${panelId}-card-tab`, disabled: paymentPending, "aria-selected": selectedMethod === 'card', "aria-controls": `${panelId}-card`, className: 'solidgate-checkout-method', onClick: () => setSelectedMethod('card'), children: [_jsx("strong", { children: cardLabel }), _jsx("span", { className: 'solidgate-checkout-tab-brands', "aria-hidden": 'true', children: ['Visa', 'Mastercard', 'Maestro', 'Discover'].map((label) => (_jsx(PaymentBrandMark, { label: label, className: 'solidgate-checkout-tab-brand' }, label))) })] })] })) : null, !walletOnly && secureLabel && wallets.length > 0 && showWallet ? (_jsxs("p", { className: 'solidgate-checkout-secure', children: [_jsx(SecurityLockIcon, {}), secureLabel] })) : null, _jsxs("div", { className: 'solidgate-checkout-wallets', id: `${panelId}-wallet`, role: showTabs ? 'tabpanel' : undefined, "aria-labelledby": showTabs ? `${panelId}-wallet-tab` : undefined, hidden: !showWallet, inert: paymentPending, children: [_jsx("div", { ref: applePayContainerRef, "data-solidgate-wallet": 'apple-pay' }), _jsx("div", { ref: googlePayContainerRef, "data-solidgate-wallet": 'google-pay' })] }), _jsx("div", { className: 'solidgate-checkout-card', id: `${panelId}-card`, role: showTabs ? 'tabpanel' : undefined, "aria-labelledby": showTabs ? `${panelId}-card-tab` : undefined, hidden: !showCard, children: _jsx(SolidgateSdkPayment, { onInitializationError: onError, merchantData: checkout.initialization.merchantData, width: '100%', formParams: Object.assign({ autoFocus: false, enabled: !walletOnly, isSolidLogoVisible: false, submitButtonText: cardSubmitLabel }, (secureLabel ? { cardNumberLabel: 'Card number', cardExpiryDateLabel: 'Expiration date', cardCvvLabel: 'Security code' } : {})), styles: {
48
48
  form_body: {
49
49
  'font-family': 'Inter, Arial, sans-serif',
50
50
  },
@@ -74,9 +74,9 @@ 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: (error) => {
77
+ }, onVerify: onVerify, onSuccess: onPaymentResult, onFail: onPaymentResult, onError: (error) => {
78
78
  if (submittedRef.current) {
79
- onVerify();
79
+ onPaymentResult();
80
80
  return;
81
81
  }
82
82
  onError(error);
@@ -1,4 +1,6 @@
1
1
  import { FunnelSdkHttpError } from '@funnelsgrove/runtime';
2
+ // Network rejection text from Chrome, Safari and Firefox.
3
+ const BROWSER_TRANSPORT_FAILURE = /^(?:Failed to fetch|Load failed|NetworkError when attempting to fetch resource\.?)$/i;
2
4
  const readRetryAfterMs = (retryAfter) => {
3
5
  const value = retryAfter === null || retryAfter === void 0 ? void 0 : retryAfter.trim();
4
6
  if (!value) {
@@ -24,7 +26,9 @@ export const describeStripeCheckoutFailure = (error) => {
24
26
  ? 'Enter a valid email address to continue.'
25
27
  : rawMessage === 'Internal server error'
26
28
  ? 'Unable to initialize checkout. Stripe settings may be missing for this funnel.'
27
- : rawMessage;
29
+ : error instanceof TypeError && BROWSER_TRANSPORT_FAILURE.test(rawMessage)
30
+ ? "We couldn't reach checkout. Check your network connection and try again."
31
+ : rawMessage;
28
32
  const retryAfterMs = error instanceof FunnelSdkHttpError
29
33
  ? readRetryAfterMs(error.retryAfter)
30
34
  : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/payments",
3
- "version": "0.58.0",
3
+ "version": "0.60.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",