@funnelsgrove/payments 0.1.5 → 0.1.7

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,5 +1,5 @@
1
1
  import { type WalletSubscriptionCheckoutSlotProps } from './WalletSubscriptionCheckoutSlot.js';
2
- export type ApplePaySubscriptionCheckoutSlotProps = Omit<WalletSubscriptionCheckoutSlotProps, 'availabilityPaymentMethod' | 'expressCheckoutAllowed' | 'placeholderLabel' | 'renderPlaceholder'> & {
2
+ export type ApplePaySubscriptionCheckoutSlotProps = Omit<WalletSubscriptionCheckoutSlotProps, 'availabilityPaymentMethod' | 'expressCheckoutAllowed' | 'placeholderLabel' | 'renderPlaceholder' | 'renderPreparingPlaceholder'> & {
3
3
  placeholderLabel?: string;
4
4
  };
5
5
  export declare function ApplePaySubscriptionCheckoutSlot({ placeholderLabel, ...slotProps }: ApplePaySubscriptionCheckoutSlotProps): import("react/jsx-runtime").JSX.Element;
@@ -13,9 +13,9 @@ var __rest = (this && this.__rest) || function (s, e) {
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { ApplePaySubscribeButton } from '../../components/shared/ApplePaySubscribeButton.js';
15
15
  import { useApplePayExpressCheckoutAllowed } from '../../components/shared/SharedStripeCheckoutDialog.js';
16
- import { WalletSubscriptionCheckoutSlot, } from './WalletSubscriptionCheckoutSlot.js';
16
+ import { WalletSubscriptionCheckoutLoadingPlaceholder, WalletSubscriptionCheckoutSlot, } from './WalletSubscriptionCheckoutSlot.js';
17
17
  export function ApplePaySubscriptionCheckoutSlot(_a) {
18
18
  var { placeholderLabel = 'Subscribe with Apple Pay' } = _a, slotProps = __rest(_a, ["placeholderLabel"]);
19
19
  const allowApplePayExpressCheckout = useApplePayExpressCheckoutAllowed();
20
- return (_jsx(WalletSubscriptionCheckoutSlot, Object.assign({}, slotProps, { availabilityPaymentMethod: 'applePay', expressCheckoutAllowed: allowApplePayExpressCheckout, placeholderLabel: placeholderLabel, renderPlaceholder: (placeholderProps) => (_jsx(ApplePaySubscribeButton, Object.assign({}, placeholderProps))) })));
20
+ return (_jsx(WalletSubscriptionCheckoutSlot, Object.assign({}, slotProps, { availabilityPaymentMethod: 'applePay', expressCheckoutAllowed: allowApplePayExpressCheckout, placeholderLabel: placeholderLabel, renderPreparingPlaceholder: (placeholderProps) => (_jsx(WalletSubscriptionCheckoutLoadingPlaceholder, Object.assign({}, placeholderProps, { label: 'Loading Apple Pay' }))), renderPlaceholder: (placeholderProps) => (_jsx(ApplePaySubscribeButton, Object.assign({}, placeholderProps))) })));
21
21
  }
@@ -1,6 +1,6 @@
1
1
  import type { StripeExpressCheckoutElementOptions } from '@stripe/stripe-js';
2
2
  import { type WalletSubscriptionCheckoutSlotProps } from './WalletSubscriptionCheckoutSlot.js';
3
- export type GooglePaySubscriptionCheckoutSlotProps = Omit<WalletSubscriptionCheckoutSlotProps, 'availabilityPaymentMethod' | 'options' | 'placeholderLabel' | 'renderPlaceholder'> & {
3
+ export type GooglePaySubscriptionCheckoutSlotProps = Omit<WalletSubscriptionCheckoutSlotProps, 'availabilityPaymentMethod' | 'options' | 'placeholderLabel' | 'renderPlaceholder' | 'renderPreparingPlaceholder'> & {
4
4
  options?: StripeExpressCheckoutElementOptions;
5
5
  placeholderLabel?: string;
6
6
  };
@@ -12,7 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  };
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { GooglePaySubscribeButton } from '../../components/shared/GooglePaySubscribeButton.js';
15
- import { WalletSubscriptionCheckoutSlot, } from './WalletSubscriptionCheckoutSlot.js';
15
+ import { WalletSubscriptionCheckoutLoadingPlaceholder, WalletSubscriptionCheckoutSlot, } from './WalletSubscriptionCheckoutSlot.js';
16
16
  const googlePayExpressCheckoutOptions = {
17
17
  buttonHeight: 55,
18
18
  buttonTheme: {
@@ -40,5 +40,5 @@ const googlePayExpressCheckoutOptions = {
40
40
  export function GooglePaySubscriptionCheckoutSlot(_a) {
41
41
  var _b, _c, _d, _e, _f, _g, _h, _j, _k;
42
42
  var { options, placeholderLabel = 'Subscribe with Google Pay' } = _a, slotProps = __rest(_a, ["options", "placeholderLabel"]);
43
- return (_jsx(WalletSubscriptionCheckoutSlot, Object.assign({}, slotProps, { availabilityPaymentMethod: 'googlePay', options: Object.assign(Object.assign(Object.assign({}, googlePayExpressCheckoutOptions), (options !== null && options !== void 0 ? options : {})), { buttonTheme: Object.assign(Object.assign({}, ((_b = googlePayExpressCheckoutOptions.buttonTheme) !== null && _b !== void 0 ? _b : {})), ((_c = options === null || options === void 0 ? void 0 : options.buttonTheme) !== null && _c !== void 0 ? _c : {})), buttonType: Object.assign(Object.assign({}, ((_d = googlePayExpressCheckoutOptions.buttonType) !== null && _d !== void 0 ? _d : {})), ((_e = options === null || options === void 0 ? void 0 : options.buttonType) !== null && _e !== void 0 ? _e : {})), layout: Object.assign(Object.assign({}, ((_f = googlePayExpressCheckoutOptions.layout) !== null && _f !== void 0 ? _f : {})), ((_g = options === null || options === void 0 ? void 0 : options.layout) !== null && _g !== void 0 ? _g : {})), paymentMethods: Object.assign(Object.assign({}, ((_h = googlePayExpressCheckoutOptions.paymentMethods) !== null && _h !== void 0 ? _h : {})), ((_j = options === null || options === void 0 ? void 0 : options.paymentMethods) !== null && _j !== void 0 ? _j : {})), paymentMethodOrder: (_k = options === null || options === void 0 ? void 0 : options.paymentMethodOrder) !== null && _k !== void 0 ? _k : googlePayExpressCheckoutOptions.paymentMethodOrder }), placeholderLabel: placeholderLabel, renderPlaceholder: (placeholderProps) => (_jsx(GooglePaySubscribeButton, Object.assign({}, placeholderProps))) })));
43
+ return (_jsx(WalletSubscriptionCheckoutSlot, Object.assign({}, slotProps, { availabilityPaymentMethod: 'googlePay', options: Object.assign(Object.assign(Object.assign({}, googlePayExpressCheckoutOptions), (options !== null && options !== void 0 ? options : {})), { buttonTheme: Object.assign(Object.assign({}, ((_b = googlePayExpressCheckoutOptions.buttonTheme) !== null && _b !== void 0 ? _b : {})), ((_c = options === null || options === void 0 ? void 0 : options.buttonTheme) !== null && _c !== void 0 ? _c : {})), buttonType: Object.assign(Object.assign({}, ((_d = googlePayExpressCheckoutOptions.buttonType) !== null && _d !== void 0 ? _d : {})), ((_e = options === null || options === void 0 ? void 0 : options.buttonType) !== null && _e !== void 0 ? _e : {})), layout: Object.assign(Object.assign({}, ((_f = googlePayExpressCheckoutOptions.layout) !== null && _f !== void 0 ? _f : {})), ((_g = options === null || options === void 0 ? void 0 : options.layout) !== null && _g !== void 0 ? _g : {})), paymentMethods: Object.assign(Object.assign({}, ((_h = googlePayExpressCheckoutOptions.paymentMethods) !== null && _h !== void 0 ? _h : {})), ((_j = options === null || options === void 0 ? void 0 : options.paymentMethods) !== null && _j !== void 0 ? _j : {})), paymentMethodOrder: (_k = options === null || options === void 0 ? void 0 : options.paymentMethodOrder) !== null && _k !== void 0 ? _k : googlePayExpressCheckoutOptions.paymentMethodOrder }), placeholderLabel: placeholderLabel, renderPreparingPlaceholder: (placeholderProps) => (_jsx(WalletSubscriptionCheckoutLoadingPlaceholder, Object.assign({}, placeholderProps, { label: 'Loading Google Pay' }))), renderPlaceholder: (placeholderProps) => (_jsx(GooglePaySubscribeButton, Object.assign({}, placeholderProps))) })));
44
44
  }
@@ -22,11 +22,13 @@ export type WalletSubscriptionCheckoutSlotProps = {
22
22
  onUnavailableClick?: () => Promise<void> | void;
23
23
  options?: StripeExpressCheckoutElementOptions;
24
24
  placeholderLabel: string;
25
+ renderPreparingPlaceholder?: (props: WalletPlaceholderButtonProps) => ReactNode;
25
26
  renderPlaceholder: (props: WalletPlaceholderButtonProps) => ReactNode;
26
27
  returnUrl: string;
27
28
  session: StripeSubscriptionCheckoutSession;
28
29
  summaryLabel: string;
29
30
  suspended?: boolean;
30
31
  };
31
- export declare function WalletSubscriptionCheckoutSlot({ amountCents, availabilityPaymentMethod, beforeConfirm, className, customerEmail, customerName, disabled, expressCheckoutAllowed, onAvailabilityChange, onError, onSuccess, onUnavailableClick, options, placeholderLabel, renderPlaceholder, returnUrl, session, summaryLabel, suspended, }: WalletSubscriptionCheckoutSlotProps): import("react/jsx-runtime").JSX.Element;
32
+ export declare function WalletSubscriptionCheckoutLoadingPlaceholder({ className, label, }: Pick<WalletPlaceholderButtonProps, 'className' | 'label'>): import("react/jsx-runtime").JSX.Element;
33
+ export declare function WalletSubscriptionCheckoutSlot({ amountCents, availabilityPaymentMethod, beforeConfirm, className, customerEmail, customerName, disabled, expressCheckoutAllowed, onAvailabilityChange, onError, onSuccess, onUnavailableClick, options, placeholderLabel, renderPreparingPlaceholder, renderPlaceholder, returnUrl, session, summaryLabel, suspended, }: WalletSubscriptionCheckoutSlotProps): import("react/jsx-runtime").JSX.Element;
32
34
  export {};
@@ -2,7 +2,15 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { useCallback, useEffect, useRef, useState } from 'react';
4
4
  import { StripeExpressCheckoutElement } from '../../components/shared/StripeExpressCheckoutElement.js';
5
- export function WalletSubscriptionCheckoutSlot({ amountCents, availabilityPaymentMethod, beforeConfirm, className, customerEmail, customerName, disabled = false, expressCheckoutAllowed = true, onAvailabilityChange, onError, onSuccess, onUnavailableClick, options, placeholderLabel, renderPlaceholder, returnUrl, session, summaryLabel, suspended = false, }) {
5
+ export function WalletSubscriptionCheckoutLoadingPlaceholder({ className, label, }) {
6
+ return (_jsxs("div", { className: [
7
+ 'wallet-subscription-checkout-slot__loading',
8
+ className !== null && className !== void 0 ? className : '',
9
+ ]
10
+ .filter(Boolean)
11
+ .join(' '), "aria-label": label, role: 'status', children: [_jsx("span", { className: 'wallet-subscription-checkout-slot__loading-bar' }), _jsx("style", { children: walletSubscriptionCheckoutLoadingPlaceholderStyles })] }));
12
+ }
13
+ export function WalletSubscriptionCheckoutSlot({ amountCents, availabilityPaymentMethod, beforeConfirm, className, customerEmail, customerName, disabled = false, expressCheckoutAllowed = true, onAvailabilityChange, onError, onSuccess, onUnavailableClick, options, placeholderLabel, renderPreparingPlaceholder, renderPlaceholder, returnUrl, session, summaryLabel, suspended = false, }) {
6
14
  const [walletAvailability, setWalletAvailability] = useState({
7
15
  available: null,
8
16
  intentKey: session.intentKey,
@@ -12,14 +20,16 @@ export function WalletSubscriptionCheckoutSlot({ amountCents, availabilityPaymen
12
20
  const walletAvailable = walletAvailability.intentKey === session.intentKey
13
21
  ? walletAvailability.available
14
22
  : null;
15
- const shouldRenderPlaceholder = !suspended && expressCheckoutAllowed && walletAvailable === null;
16
23
  const shouldRenderExpressCheckout = !suspended &&
17
24
  expressCheckoutAllowed &&
18
25
  walletAvailable !== false &&
19
26
  Boolean(session.activeClientSecret) &&
20
27
  Boolean(session.stripePromise);
21
- const placeholderBehindExpressCheckout = shouldRenderPlaceholder && shouldRenderExpressCheckout;
22
- const placeholderIsPreparing = shouldRenderPlaceholder && !shouldRenderExpressCheckout;
28
+ const shouldRenderPlaceholder = !shouldRenderExpressCheckout &&
29
+ !suspended &&
30
+ expressCheckoutAllowed &&
31
+ walletAvailable === null;
32
+ const placeholderIsPreparing = shouldRenderPlaceholder;
23
33
  const markWalletUnavailable = useCallback((intentKey) => {
24
34
  setWalletAvailability({
25
35
  available: false,
@@ -86,12 +96,7 @@ export function WalletSubscriptionCheckoutSlot({ amountCents, availabilityPaymen
86
96
  .filter(Boolean)
87
97
  .join(' '), "aria-busy": placeholderIsPreparing || undefined, children: [shouldRenderExpressCheckout &&
88
98
  session.activeClientSecret &&
89
- session.stripePromise ? (_jsx(StripeExpressCheckoutElement, { amountCents: amountCents, availabilityPaymentMethods: [availabilityPaymentMethod], beforeConfirm: beforeConfirm, className: className, clientSecret: session.activeClientSecret, customerEmail: customerEmail, customerName: customerName, onAvailabilityChange: handleAvailabilityChange, onError: handleError, onSuccess: onSuccess, options: options, returnUrl: returnUrl, stripePromise: session.stripePromise, summaryLabel: summaryLabel })) : null, shouldRenderPlaceholder ? (_jsx("div", { className: [
90
- 'wallet-subscription-checkout-slot__placeholder',
91
- placeholderBehindExpressCheckout ? 'is-behind-express-checkout' : '',
92
- ]
93
- .filter(Boolean)
94
- .join(' '), children: renderPlaceholder({
99
+ session.stripePromise ? (_jsx(StripeExpressCheckoutElement, { amountCents: amountCents, availabilityPaymentMethods: [availabilityPaymentMethod], beforeConfirm: beforeConfirm, className: className, clientSecret: session.activeClientSecret, customerEmail: customerEmail, customerName: customerName, onAvailabilityChange: handleAvailabilityChange, onError: handleError, onSuccess: onSuccess, options: options, returnUrl: returnUrl, stripePromise: session.stripePromise, summaryLabel: summaryLabel })) : null, shouldRenderPlaceholder ? (_jsx("div", { className: 'wallet-subscription-checkout-slot__placeholder', children: (renderPreparingPlaceholder !== null && renderPreparingPlaceholder !== void 0 ? renderPreparingPlaceholder : renderPlaceholder)({
95
100
  className,
96
101
  disabled: slotDisabled,
97
102
  label: placeholderLabel,
@@ -115,8 +120,48 @@ const walletSubscriptionCheckoutSlotStyles = `
115
120
  inset: 0;
116
121
  z-index: 1;
117
122
  }
123
+ `;
124
+ const walletSubscriptionCheckoutLoadingPlaceholderStyles = `
125
+ .wallet-subscription-checkout-slot__loading {
126
+ position: relative;
127
+ display: flex;
128
+ width: 100%;
129
+ min-height: var(--wallet-subscription-checkout-slot-min-height, 64px);
130
+ box-sizing: border-box;
131
+ align-items: center;
132
+ overflow: hidden;
133
+ border: 1px solid rgb(63 81 181 / 14%);
134
+ border-radius: 16px;
135
+ background: rgb(255 255 255 / 74%);
136
+ }
137
+
138
+ .wallet-subscription-checkout-slot__loading-bar {
139
+ position: absolute;
140
+ inset: 0;
141
+ background:
142
+ linear-gradient(
143
+ 90deg,
144
+ rgb(255 255 255 / 0%) 0%,
145
+ rgb(255 255 255 / 68%) 42%,
146
+ rgb(255 255 255 / 0%) 82%
147
+ ),
148
+ linear-gradient(90deg, #e6f3fb 0%, #f6fbff 100%);
149
+ animation: wallet-subscription-checkout-slot-loading 1200ms ease-in-out infinite;
150
+ }
151
+
152
+ @keyframes wallet-subscription-checkout-slot-loading {
153
+ 0% {
154
+ transform: translateX(-60%);
155
+ }
156
+
157
+ 100% {
158
+ transform: translateX(60%);
159
+ }
160
+ }
118
161
 
119
- .wallet-subscription-checkout-slot__placeholder.is-behind-express-checkout {
120
- pointer-events: none;
162
+ @media (prefers-reduced-motion: reduce) {
163
+ .wallet-subscription-checkout-slot__loading-bar {
164
+ animation: none;
165
+ }
121
166
  }
122
167
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/payments",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",