@funnelsgrove/payments 0.59.0 → 0.61.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.59.0";
1
+ export declare const PAYMENTS_PACKAGE_VERSION = "0.61.0";
@@ -1,2 +1,2 @@
1
1
  // Generated by scripts/generate-package-version.mjs.
2
- export const PAYMENTS_PACKAGE_VERSION = "0.59.0";
2
+ export const PAYMENTS_PACKAGE_VERSION = "0.61.0";
@@ -9,6 +9,7 @@ import { isSolidgateCustomerDecline, solidgateDeclineMessage } from '../services
9
9
  import { solidgateFailureDetails } from '../services/solidgateFailureDetails.js';
10
10
  import { SolidgateCheckoutSummary } from './SolidgateCheckoutSummary.js';
11
11
  import { SolidgatePaymentForm } from './SolidgatePaymentForm.js';
12
+ import { useSolidgateWalletReadiness } from './useSolidgateWalletReadiness.js';
12
13
  import { solidgateCheckoutDialogStyles } from './SolidgateCheckoutDialog.styles.js';
13
14
  const defaultContent = {
14
15
  title: 'Secure checkout',
@@ -42,6 +43,7 @@ const initialView = {
42
43
  };
43
44
  const isAbortError = (error) => (error instanceof DOMException && error.name === 'AbortError');
44
45
  export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, customerEmail, checkoutAnalytics, content, presentation, onClose, onCustomerEmailCommit, onSuccess, onRetry, onError, onPreparationStart, onStateChange, onPaymentPendingChange, }) {
46
+ var _a;
45
47
  const copy = useMemo(() => (Object.assign(Object.assign({}, defaultContent), content)), [content]);
46
48
  const [view, setView] = useState(initialView);
47
49
  const [retryRequest, setRetryRequest] = useState(null);
@@ -149,6 +151,8 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
149
151
  }, []);
150
152
  const requiresEmailCommit = Boolean(onCustomerEmailCommit);
151
153
  const startedAttemptRef = useRef(null);
154
+ const walletReadiness = useSolidgateWalletReadiness(checkoutAnalyticsRef, layout === 'wallet' && view.state === 'ready' ? (_a = view.checkout) === null || _a === void 0 ? void 0 : _a.attemptId : undefined);
155
+ const { startPreparation: startWalletPreparation, finishPreparation: finishWalletPreparation } = walletReadiness;
152
156
  const active = open && (layout !== 'wallet' || Boolean(normalizedCustomerEmail));
153
157
  useEffect(() => {
154
158
  var _a, _b, _c, _d, _e, _f, _g;
@@ -182,10 +186,13 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
182
186
  setState(initialView);
183
187
  }
184
188
  });
189
+ const walletPreparation = layout === 'wallet' ? startWalletPreparation() : null;
185
190
  void prepareSolidgateCheckout(Object.assign(Object.assign({}, preparedRequest), { signal: controller.signal }))
186
191
  .then((checkout) => {
187
192
  if (!controller.signal.aborted) {
188
193
  declinedAttemptRef.current = null;
194
+ if (walletPreparation)
195
+ finishWalletPreparation(walletPreparation, checkout.attemptId);
189
196
  setState({ state: 'ready', checkout, canResumeVerification: false });
190
197
  if (layout !== 'wallet') {
191
198
  void trackSolidgateCheckoutEvent('checkout_started', checkout.attemptId, checkoutAnalyticsRef.current);
@@ -207,11 +214,14 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
207
214
  }
208
215
  });
209
216
  return () => controller.abort();
210
- }, [checkoutKey, committedEmail, layout, onPreparationStart, active, requiresEmailCommit, setState, trackFailure]);
217
+ }, [checkoutKey, committedEmail, layout, onPreparationStart, active, requiresEmailCommit, setState, trackFailure,
218
+ startWalletPreparation, finishWalletPreparation]);
211
219
  const paymentFormMounted = Boolean(view.checkout && mountedPaymentAttemptId === view.checkout.attemptId);
212
220
  const showPreparingLoader = view.state === 'loading'
213
221
  || (view.state === 'ready' && !paymentFormMounted);
214
222
  const hasExistingSubscription = view.state === 'existing_subscription';
223
+ const paymentPending = view.state === 'submitting' || view.state === 'verifying'
224
+ || view.state === 'success' || view.canResumeVerification;
215
225
  useEffect(() => {
216
226
  var _a;
217
227
  if (!open || (layout === 'wallet' && !hasExistingSubscription)) {
@@ -222,7 +232,7 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
222
232
  : null;
223
233
  const handleKeyDown = (event) => {
224
234
  var _a;
225
- if (event.key === 'Escape') {
235
+ if (event.key === 'Escape' && !paymentPending) {
226
236
  const analytics = checkoutAnalyticsRef.current;
227
237
  if (analytics) {
228
238
  trackCheckoutCanceled({
@@ -244,13 +254,13 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
244
254
  window.removeEventListener('keydown', handleKeyDown);
245
255
  previouslyFocused === null || previouslyFocused === void 0 ? void 0 : previouslyFocused.focus();
246
256
  };
247
- }, [hasExistingSubscription, layout, open, showPreparingLoader, view.checkout]);
257
+ }, [hasExistingSubscription, layout, open, paymentPending, showPreparingLoader, view.checkout]);
248
258
  useEffect(() => () => {
249
259
  var _a, _b;
250
260
  (_a = prepareAbortRef.current) === null || _a === void 0 ? void 0 : _a.abort();
251
261
  (_b = statusAbortRef.current) === null || _b === void 0 ? void 0 : _b.abort();
252
262
  }, []);
253
- const verifyCanonicalStatus = useCallback(async () => {
263
+ const verifyCanonicalStatus = useCallback(async (challengeActive = view.challengeActive) => {
254
264
  var _a, _b, _c, _d;
255
265
  const checkout = view.checkout;
256
266
  if (!checkout || view.state === 'success') {
@@ -259,7 +269,7 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
259
269
  (_a = statusAbortRef.current) === null || _a === void 0 ? void 0 : _a.abort();
260
270
  const controller = new AbortController();
261
271
  statusAbortRef.current = controller;
262
- setState({ state: 'verifying', checkout, canResumeVerification: false });
272
+ setState({ state: 'verifying', checkout, canResumeVerification: false, challengeActive });
263
273
  try {
264
274
  const result = await pollSolidgateCheckoutStatus({
265
275
  attemptId: checkout.attemptId,
@@ -293,16 +303,17 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
293
303
  trackFailure(failureMessage, 'payment_failed', checkout.attemptId, Object.assign(Object.assign({}, (isSolidgateCustomerDecline(result.failureCode) ? { providerDeclineCode: result.failureCode } : {})), { providerErrorCode: result.failureCode }));
294
304
  (_c = onErrorRef.current) === null || _c === void 0 ? void 0 : _c.call(onErrorRef, failureMessage);
295
305
  }
296
- else if (result.status === 'requires_payment') {
306
+ else if (result.status === 'requires_payment' && !challengeActive) {
297
307
  setState({ state: 'ready', checkout, canResumeVerification: false });
298
308
  }
299
309
  else {
300
- setState({ state: 'verifying', checkout, canResumeVerification: result.timedOut });
310
+ setState({ state: 'verifying', checkout, challengeActive,
311
+ canResumeVerification: result.timedOut || result.status === 'requires_payment' });
301
312
  }
302
313
  }
303
314
  catch (_e) {
304
315
  if (!controller.signal.aborted) {
305
- setState({ state: 'recoverable_error', checkout, canResumeVerification: true });
316
+ setState({ state: 'recoverable_error', checkout, canResumeVerification: true, challengeActive });
306
317
  trackFailure(copyRef.current.error, 'payment_verification', checkout.attemptId);
307
318
  (_d = onErrorRef.current) === null || _d === void 0 ? void 0 : _d.call(onErrorRef, copyRef.current.error);
308
319
  }
@@ -337,6 +348,8 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
337
348
  }, [copy.customerEmailInvalid, copy.customerEmailUnavailable, emailInput, onCustomerEmailCommit, trackFailure, view.checkout]);
338
349
  const handleClose = () => {
339
350
  var _a;
351
+ if (paymentPending)
352
+ return;
340
353
  const analytics = checkoutAnalyticsRef.current;
341
354
  if (analytics) {
342
355
  trackCheckoutCanceled({
@@ -353,7 +366,7 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
353
366
  return null;
354
367
  }
355
368
  const showForm = view.state === 'ready'
356
- || view.state === 'submitting';
369
+ || view.state === 'submitting' || view.challengeActive;
357
370
  const statusMessage = view.state === 'loading'
358
371
  ? copy.loading
359
372
  : view.state === 'submitting'
@@ -388,7 +401,7 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
388
401
  attemptId: source,
389
402
  });
390
403
  }, 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: () => {
404
+ 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
405
  var _a;
393
406
  setMountedPaymentAttemptId(((_a = view.checkout) === null || _a === void 0 ? void 0 : _a.attemptId) || null);
394
407
  }, onSubmit: () => {
@@ -398,7 +411,7 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
398
411
  void trackSolidgateCheckoutEvent('add_payment_info', ((_c = view.checkout) === null || _c === void 0 ? void 0 : _c.attemptId) || '', checkoutAnalyticsRef.current);
399
412
  }
400
413
  setState(Object.assign(Object.assign({}, view), { state: 'submitting' }));
401
- }, onVerify: () => void verifyCanonicalStatus(), onError: (error) => {
414
+ }, onVerify: () => void verifyCanonicalStatus(true), onPaymentResult: () => void verifyCanonicalStatus(false), onWalletsChange: layout === 'wallet' ? walletReadiness.reportWalletsReady : undefined, onError: (error) => {
402
415
  var _a, _b;
403
416
  setState(Object.assign(Object.assign({}, view), { state: 'recoverable_error', canResumeVerification: false }));
404
417
  trackFailure(copyRef.current.error, 'payment_form', (_a = view.checkout) === null || _a === void 0 ? void 0 : _a.attemptId, solidgateFailureDetails(error));
@@ -419,7 +432,7 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
419
432
  'solidgate-checkout-dialog',
420
433
  showPreparingLoader ? 'is-preparing' : '',
421
434
  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) => {
435
+ ].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
436
  setEmailInput(event.target.value);
424
437
  setEmailError(null);
425
438
  }, 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,6 @@
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
+ import type { SolidgateWalletPaymentMethod } from './useSolidgateWalletReadiness.js';
3
+ export declare function SolidgatePaymentForm({ buttonColor, walletOnly, cardSubmitLabel, secureLabel, cardLabel, paymentMethodLabel, checkout, hidden, challengeActive, paymentPending, onError, onMounted, onSubmit, onVerify, onPaymentResult, onWalletsChange, }: {
3
4
  buttonColor: string;
4
5
  walletOnly?: boolean;
5
6
  cardSubmitLabel: string;
@@ -8,9 +9,13 @@ export declare function SolidgatePaymentForm({ buttonColor, walletOnly, cardSubm
8
9
  paymentMethodLabel?: string;
9
10
  checkout: SolidgateCheckoutPreparation;
10
11
  hidden: boolean;
12
+ challengeActive?: boolean;
13
+ paymentPending?: boolean;
11
14
  loadingLabel: string;
12
15
  onError: (error?: unknown) => void;
13
16
  onMounted: () => void;
14
17
  onSubmit: () => void;
15
18
  onVerify: () => void;
19
+ onPaymentResult: () => void;
20
+ onWalletsChange?: (methods: readonly SolidgateWalletPaymentMethod[]) => void;
16
21
  }): 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, onWalletsChange, }) {
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);
@@ -19,6 +19,9 @@ export function SolidgatePaymentForm({ buttonColor, walletOnly = false, cardSubm
19
19
  useEffect(() => {
20
20
  onMountedRef.current = onMounted;
21
21
  }, [onMounted]);
22
+ useEffect(() => {
23
+ onWalletsChange === null || onWalletsChange === void 0 ? void 0 : onWalletsChange(wallets.map((label) => label === 'Apple Pay' ? 'apple_pay' : 'google_pay'));
24
+ }, [onWalletsChange, wallets]);
22
25
  useEffect(() => {
23
26
  mountedReportedRef.current = false;
24
27
  const boundary = paymentBoundaryRef.current;
@@ -44,7 +47,9 @@ export function SolidgatePaymentForm({ buttonColor, walletOnly = false, cardSubm
44
47
  return () => observer.disconnect();
45
48
  }, [checkout.attemptId]);
46
49
  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: {
50
+ 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,
51
+ // Wallet buttons wait for this iframe; iOS Safari throttles it under display:none. The SDK keeps a disabled form invisible.
52
+ hidden: !showCard && !walletOnly, 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
53
  form_body: {
49
54
  'font-family': 'Inter, Arial, sans-serif',
50
55
  },
@@ -74,9 +79,9 @@ export function SolidgatePaymentForm({ buttonColor, walletOnly = false, cardSubm
74
79
  }, onSubmit: () => {
75
80
  submittedRef.current = true;
76
81
  onSubmit();
77
- }, onVerify: onVerify, onSuccess: onVerify, onFail: onVerify, onError: (error) => {
82
+ }, onVerify: onVerify, onSuccess: onPaymentResult, onFail: onPaymentResult, onError: (error) => {
78
83
  if (submittedRef.current) {
79
- onVerify();
84
+ onPaymentResult();
80
85
  return;
81
86
  }
82
87
  onError(error);
@@ -0,0 +1,16 @@
1
+ import { type RefObject } from 'react';
2
+ import type { SolidgateCheckoutAnalyticsContext } from './SolidgateCheckoutDialog.types.js';
3
+ export type SolidgateWalletPaymentMethod = 'apple_pay' | 'google_pay';
4
+ type WalletPreparation = {
5
+ attemptId: string | null;
6
+ mountedAtMs: number;
7
+ requestStartedAtMs: number;
8
+ preparedAtMs: number | null;
9
+ };
10
+ /** Reports when Solidgate inserts inline wallet buttons, or that the platform wallet is still missing after 15 seconds. */
11
+ export declare function useSolidgateWalletReadiness(analyticsRef: RefObject<SolidgateCheckoutAnalyticsContext | null | undefined>, readyAttemptId: string | undefined): {
12
+ startPreparation: () => WalletPreparation;
13
+ finishPreparation: (preparation: WalletPreparation, attemptId: string) => void;
14
+ reportWalletsReady: (methods: readonly SolidgateWalletPaymentMethod[]) => void;
15
+ };
16
+ export {};
@@ -0,0 +1,87 @@
1
+ 'use client';
2
+ import { useCallback, useEffect, useRef } from 'react';
3
+ import { trackCheckoutWalletReady, trackCheckoutWalletSlow } from '../../../services/checkoutObservability.service.js';
4
+ import { getPlatformWalletPaymentMethods, resolveWalletPlatform } from '../../stripe/components/walletPlatform.js';
5
+ const WALLET_SLOW_THRESHOLD_MS = 15000;
6
+ /** Reports when Solidgate inserts inline wallet buttons, or that the platform wallet is still missing after 15 seconds. */
7
+ export function useSolidgateWalletReadiness(analyticsRef, readyAttemptId) {
8
+ const mountedAtRef = useRef(null);
9
+ const preparationRef = useRef(null);
10
+ // Keyed by `${attemptId}:${method}` so a re-prepared attempt is never reported twice.
11
+ const readyRef = useRef(new Set());
12
+ const slowRef = useRef(new Set());
13
+ const startPreparation = useCallback(() => {
14
+ var _a;
15
+ const requestStartedAtMs = performance.now();
16
+ const preparation = {
17
+ attemptId: null,
18
+ mountedAtMs: (_a = mountedAtRef.current) !== null && _a !== void 0 ? _a : (mountedAtRef.current = requestStartedAtMs),
19
+ requestStartedAtMs,
20
+ preparedAtMs: null,
21
+ };
22
+ preparationRef.current = preparation;
23
+ return preparation;
24
+ }, []);
25
+ const finishPreparation = useCallback((preparation, attemptId) => {
26
+ preparation.attemptId = attemptId;
27
+ preparation.preparedAtMs = performance.now();
28
+ }, []);
29
+ const reportWalletsReady = useCallback((methods) => {
30
+ const preparation = preparationRef.current;
31
+ const analytics = analyticsRef.current;
32
+ if (!analytics || !(preparation === null || preparation === void 0 ? void 0 : preparation.attemptId) || preparation.preparedAtMs === null) {
33
+ return;
34
+ }
35
+ const readyAtMs = performance.now();
36
+ for (const paymentMethod of methods) {
37
+ const key = `${preparation.attemptId}:${paymentMethod}`;
38
+ if (readyRef.current.has(key))
39
+ continue;
40
+ readyRef.current.add(key);
41
+ trackCheckoutWalletReady({
42
+ analytics,
43
+ checkoutSessionId: preparation.attemptId,
44
+ paymentMethod,
45
+ provider: 'solidgate',
46
+ walletTimingOrigin: 'prepared_here',
47
+ walletClientSecretToReadyMs: Math.max(0, readyAtMs - preparation.preparedAtMs),
48
+ walletMountToReadyMs: Math.max(0, readyAtMs - preparation.mountedAtMs),
49
+ walletMountToRequestMs: Math.max(0, preparation.requestStartedAtMs - preparation.mountedAtMs),
50
+ walletRequestMs: Math.max(0, preparation.preparedAtMs - preparation.requestStartedAtMs),
51
+ });
52
+ }
53
+ }, [analyticsRef]);
54
+ useEffect(() => {
55
+ if (!readyAttemptId) {
56
+ return;
57
+ }
58
+ const timer = setTimeout(() => {
59
+ const preparation = preparationRef.current;
60
+ const analytics = analyticsRef.current;
61
+ if (!analytics || (preparation === null || preparation === void 0 ? void 0 : preparation.attemptId) !== readyAttemptId || preparation.preparedAtMs === null) {
62
+ return;
63
+ }
64
+ const platform = resolveWalletPlatform({
65
+ maxTouchPoints: navigator.maxTouchPoints,
66
+ userAgent: navigator.userAgent,
67
+ });
68
+ for (const method of getPlatformWalletPaymentMethods(platform)) {
69
+ const paymentMethod = method === 'applePay' ? 'apple_pay' : 'google_pay';
70
+ const key = `${readyAttemptId}:${paymentMethod}`;
71
+ if (readyRef.current.has(key) || slowRef.current.has(key))
72
+ continue;
73
+ slowRef.current.add(key);
74
+ trackCheckoutWalletSlow({
75
+ analytics,
76
+ checkoutSessionId: readyAttemptId,
77
+ paymentMethod,
78
+ provider: 'solidgate',
79
+ walletTimingOrigin: 'prepared_here',
80
+ walletClientSecretToSlowMs: Math.max(0, performance.now() - preparation.preparedAtMs),
81
+ });
82
+ }
83
+ }, WALLET_SLOW_THRESHOLD_MS);
84
+ return () => clearTimeout(timer);
85
+ }, [analyticsRef, readyAttemptId]);
86
+ return { startPreparation, finishPreparation, reportWalletsReady };
87
+ }
@@ -4,6 +4,7 @@ import { completePaywallCheckout } from '@funnelsgrove/runtime';
4
4
  import { useEffect, useMemo, useRef, useState } from 'react';
5
5
  import { PaymentElement, useCheckout } from '@stripe/react-stripe-js/checkout';
6
6
  import { isValidCheckoutEmail as isValidEmail, isCheckoutEmailError } from '../../../services/checkoutEmail.js';
7
+ import { resolveCheckoutReturnUrl } from '../services/checkout/checkoutReturnUrl.js';
7
8
  import { PaymentBrandMark, SecurityLockIcon } from './CheckoutBrandAssets.js';
8
9
  import { StripeCheckoutExpressCheckoutButton } from './StripeCheckoutExpressCheckoutButton.js';
9
10
  import { getUnsupportedCheckoutCountryMessage, normalizeSupportedCheckoutCountries } from './checkoutCountries.js';
@@ -251,7 +252,7 @@ export function SharedStripeCheckoutV2CheckoutSessionForm({ copy = defaultChecko
251
252
  return;
252
253
  }
253
254
  await trackCheckoutSuccess();
254
- window.location.assign(returnUrl);
255
+ window.location.assign(resolveCheckoutReturnUrl(returnUrl, checkoutSessionId));
255
256
  return;
256
257
  }
257
258
  finishSubmitting();
@@ -2,6 +2,7 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { completePaywallCheckout } from '@funnelsgrove/runtime';
4
4
  import { isValidCheckoutEmail, isCheckoutEmailError } from '../../../services/checkoutEmail.js';
5
+ import { resolveCheckoutReturnUrl } from '../services/checkout/checkoutReturnUrl.js';
5
6
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
6
7
  import { ExpressCheckoutElement, useCheckout, } from '@stripe/react-stripe-js/checkout';
7
8
  import { queueStripeSubscriptionCheckoutStarted, trackPaidStripeSubscriptionCheckoutCompleted, trackStripeSubscriptionPaymentInfoSubmitted, } from '../services/checkoutCompletionAnalytics.service.js';
@@ -286,7 +287,7 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
286
287
  if (await verifyPaywall(event.expressPaymentType))
287
288
  return;
288
289
  await trackCheckoutSuccess();
289
- window.location.assign(returnUrl);
290
+ window.location.assign(resolveCheckoutReturnUrl(returnUrl, checkoutSessionId));
290
291
  }
291
292
  };
292
293
  const handleClick = async (event) => {
@@ -2,6 +2,7 @@
2
2
  import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
3
3
  import { queueStripeSubscriptionCheckoutStarted, trackStripeSubscriptionPaymentInfoSubmitted, trackPaidStripeSubscriptionCheckoutCompleted, } from '../services/checkoutCompletionAnalytics.service.js';
4
4
  import { isValidCheckoutEmail, isCheckoutEmailError } from '../../../services/checkoutEmail.js';
5
+ import { resolveCheckoutReturnUrl } from '../services/checkout/checkoutReturnUrl.js';
5
6
  const normalizeCurrency = (currency) => currency.trim().toLowerCase() || 'usd';
6
7
  export function useStripeSubscriptionWalletFirstRequest({ amountCents, checkoutAnalytics, currency = 'usd', merchantCountry = 'US', onError, onCancel, onSuccess, onPayerEmail, onPaymentInfoSubmitted, paymentMethod, returnUrl, session, summaryLabel, }) {
7
8
  const requestKey = [session.planKey, paymentMethod, currency, merchantCountry, amountCents].join('|');
@@ -111,7 +112,7 @@ export function useStripeSubscriptionWalletFirstRequest({ amountCents, checkoutA
111
112
  await trackPaidStripeSubscriptionCheckoutCompleted(Object.assign(Object.assign({}, callbacks.checkoutAnalytics), { checkoutSessionId })).catch(() => 'analytics_rejected');
112
113
  }
113
114
  await callbacks.onSuccess({ checkoutSessionId });
114
- window.location.assign(callbacks.returnUrl);
115
+ window.location.assign(resolveCheckoutReturnUrl(callbacks.returnUrl, checkoutSessionId));
115
116
  }
116
117
  catch (error) {
117
118
  completeWallet('fail');
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Fills Stripe's `{CHECKOUT_SESSION_ID}` return-URL template before a client-side redirect.
3
+ * Stripe fills it only on its own redirects; funnels build the template URL-encoded via URLSearchParams.
4
+ */
5
+ export declare const resolveCheckoutReturnUrl: (returnUrl: string, checkoutSessionId: string | null | undefined) => string;
@@ -0,0 +1,14 @@
1
+ const CHECKOUT_SESSION_TEMPLATE = '{CHECKOUT_SESSION_ID}';
2
+ /**
3
+ * Fills Stripe's `{CHECKOUT_SESSION_ID}` return-URL template before a client-side redirect.
4
+ * Stripe fills it only on its own redirects; funnels build the template URL-encoded via URLSearchParams.
5
+ */
6
+ export const resolveCheckoutReturnUrl = (returnUrl, checkoutSessionId) => {
7
+ const sessionId = checkoutSessionId === null || checkoutSessionId === void 0 ? void 0 : checkoutSessionId.trim();
8
+ if (!sessionId)
9
+ return returnUrl;
10
+ const encodedSessionId = encodeURIComponent(sessionId);
11
+ return returnUrl
12
+ .replaceAll(CHECKOUT_SESSION_TEMPLATE, encodedSessionId)
13
+ .replaceAll(encodeURIComponent(CHECKOUT_SESSION_TEMPLATE), encodedSessionId);
14
+ };
@@ -40,7 +40,7 @@ export type CheckoutWalletReadyInput = {
40
40
  analytics: CheckoutObservabilityAnalyticsContext;
41
41
  checkoutSessionId: string;
42
42
  paymentMethod: unknown;
43
- provider: 'stripe';
43
+ provider: 'solidgate' | 'stripe';
44
44
  walletTimingOrigin?: 'prepared_here' | 'already_active';
45
45
  walletClientSecretToReadyMs?: number;
46
46
  walletClientSecretToElementMountMs?: number;
@@ -58,7 +58,7 @@ export declare const trackCheckoutWalletSlow: (input: {
58
58
  analytics: CheckoutObservabilityAnalyticsContext;
59
59
  checkoutSessionId: string;
60
60
  paymentMethod: unknown;
61
- provider: "stripe";
61
+ provider: "solidgate" | "stripe";
62
62
  walletTimingOrigin: "prepared_here" | "already_active";
63
63
  walletClientSecretToSlowMs: number;
64
64
  }) => string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/payments",
3
- "version": "0.59.0",
3
+ "version": "0.61.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",