@funnelsgrove/payments 0.62.0 → 0.64.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.
- package/README.md +5 -1
- package/dist/generated/package-version.d.ts +1 -1
- package/dist/generated/package-version.js +1 -1
- package/dist/providers/solidgate/services/solidgate.service.js +7 -5
- package/dist/providers/stripe/components/StripeCheckoutExpressCheckoutButton.js +5 -0
- package/dist/providers/stripe/components/StripeWalletFirstCheckout.d.ts +6 -1
- package/dist/providers/stripe/components/StripeWalletFirstCheckout.js +13 -8
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -40,7 +40,11 @@ elsewhere, preselected, with Stripe's own button, and the card form as the secon
|
|
|
40
40
|
the session before card confirmation, since the form has no email field), `returnUrl`,
|
|
41
41
|
`checkoutAnalytics`, a complete `StripeWalletFirstCheckoutCopy` from the funnel's
|
|
42
42
|
content, and `themeColor`/`buttonColor`.
|
|
43
|
-
- The card form has no
|
|
43
|
+
- The card form has no name, email or terms text. Stripe asks for the postal code only for
|
|
44
|
+
card countries that use it (US, Canada, UK), which helps US issuers approve the payment.
|
|
45
|
+
Pass `paymentElementOptions` to override the card form's Payment Element options. Keys of
|
|
46
|
+
`fields.billingDetails` merge one by one with the defaults, for example
|
|
47
|
+
`{ fields: { billingDetails: { address: { country: 'auto', postalCode: 'never' } } } }`.
|
|
44
48
|
- `onCancel` runs when the visitor closes the Apple Pay or Google Pay sheet without paying,
|
|
45
49
|
for example to show an extra discount. The form is unlocked again by then.
|
|
46
50
|
- `onError(message, details?)` preserves the existing message argument and adds exported
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PAYMENTS_PACKAGE_VERSION = "0.
|
|
1
|
+
export declare const PAYMENTS_PACKAGE_VERSION = "0.64.0";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by scripts/generate-package-version.mjs.
|
|
2
|
-
export const PAYMENTS_PACKAGE_VERSION = "0.
|
|
2
|
+
export const PAYMENTS_PACKAGE_VERSION = "0.64.0";
|
|
@@ -99,9 +99,11 @@ const getJson = async (path, headers, runtimeConfig, signal) => {
|
|
|
99
99
|
return response.json();
|
|
100
100
|
};
|
|
101
101
|
const isRecord = (value) => (Boolean(value) && typeof value === 'object' && !Array.isArray(value));
|
|
102
|
-
const refreshCheckoutIdentity = async (userId, idempotencyKey, runtimeConfig, signal) => {
|
|
102
|
+
const refreshCheckoutIdentity = async (userId, idempotencyKey, environment, runtimeConfig, signal) => {
|
|
103
|
+
// Declare the environment like the session bootstrap; production QA treats an
|
|
104
|
+
// undeclared bootstrap as "not explicitly live" (FUN-381).
|
|
103
105
|
const payload = await funnelSdkService.bootstrapUser({
|
|
104
|
-
userId, idempotencyKey, runtimeConfig, signal,
|
|
106
|
+
userId, idempotencyKey, metadata: { environment }, runtimeConfig, signal,
|
|
105
107
|
});
|
|
106
108
|
const token = typeof payload.checkoutIdentityToken === 'string' ? payload.checkoutIdentityToken.trim() : '';
|
|
107
109
|
if (!token) {
|
|
@@ -125,7 +127,7 @@ const postWithCheckoutIdentity = async (identity, send) => {
|
|
|
125
127
|
throw error;
|
|
126
128
|
}
|
|
127
129
|
}
|
|
128
|
-
const refreshed = await refreshCheckoutIdentity(identity.userId, identity.idempotencyKey, identity.runtimeConfig, identity.signal);
|
|
130
|
+
const refreshed = await refreshCheckoutIdentity(identity.userId, identity.idempotencyKey, identity.environment, identity.runtimeConfig, identity.signal);
|
|
129
131
|
try {
|
|
130
132
|
return await send({ checkoutIdentityToken: refreshed });
|
|
131
133
|
}
|
|
@@ -206,7 +208,7 @@ export const prepareSolidgateCheckout = async (input) => {
|
|
|
206
208
|
}
|
|
207
209
|
const funnelEndUserId = requiredString(input.funnelEndUserId, 'funnelEndUserId');
|
|
208
210
|
const idempotencyKey = requiredString(input.idempotencyKey, 'idempotencyKey');
|
|
209
|
-
const response = await postWithCheckoutIdentity({ userId: funnelEndUserId, idempotencyKey, runtimeConfig: input.runtimeConfig, signal: input.signal }, (proof) => {
|
|
211
|
+
const response = await postWithCheckoutIdentity({ userId: funnelEndUserId, idempotencyKey, environment, runtimeConfig: input.runtimeConfig, signal: input.signal }, (proof) => {
|
|
210
212
|
var _a;
|
|
211
213
|
return postJson('/sdk/public/v2/payments/checkout-sessions', Object.assign(Object.assign(Object.assign(Object.assign({ checkoutType, uiMode: 'custom', environment,
|
|
212
214
|
paymentProfileId, provider: 'solidgate', providerPlanId, planKey: requiredString(input.funnelPlanKey, 'funnelPlanKey'), funnelId: resolveFunnelId(input.funnelId, input.runtimeConfig), funnelEndUserId, offerSetId: requiredString(input.offerSetId, 'offerSetId'), idempotencyKey }, proof), (input.language != null ? { language: input.language } : {})), (input.retryAttemptId ? { retryAttemptId: input.retryAttemptId } : {})), { couponId: ((_a = input.discountKeyOrProviderId) === null || _a === void 0 ? void 0 : _a.trim()) || null, returnUrl: paywallCheckoutReturnUrl(requiredString(input.returnUrl, 'returnUrl'), 'solidgate'), successUrl: paywallCheckoutReturnUrl(requiredString(input.successUrl, 'successUrl'), 'solidgate'), failUrl: paywallCheckoutReturnUrl(requiredString(input.failUrl, 'failUrl'), 'solidgate', true) }), input.runtimeConfig, input.signal);
|
|
@@ -304,7 +306,7 @@ const oneClickStatuses = new Set(['verifying', 'succeeded', 'failed']);
|
|
|
304
306
|
export const chargeSolidgateOneClickPayment = async (input) => {
|
|
305
307
|
const userId = requiredString(input.userId, 'userId');
|
|
306
308
|
const idempotencyKey = requiredString(input.idempotencyKey, 'idempotencyKey');
|
|
307
|
-
const value = await postWithCheckoutIdentity({ userId, idempotencyKey, runtimeConfig: input.runtimeConfig, signal: input.signal }, (proof) => postJson('/sdk/public/v2/payments/one-click', Object.assign({ provider: 'solidgate', environment: input.environment, funnelId: resolveFunnelId(input.funnelId, input.runtimeConfig), offerSetId: requiredString(input.offerSetId, 'offerSetId'), paymentProfileId: requiredString(input.paymentProfileId, 'paymentProfileId'), providerPlanId: requiredString(input.providerPlanId, 'providerPlanId'), planKey: requiredString(input.funnelPlanKey, 'funnelPlanKey'), userId, checkoutSessionId: requiredString(input.checkoutSessionId, 'checkoutSessionId'), idempotencyKey }, proof), input.runtimeConfig, input.signal));
|
|
309
|
+
const value = await postWithCheckoutIdentity({ userId, idempotencyKey, environment: input.environment, runtimeConfig: input.runtimeConfig, signal: input.signal }, (proof) => postJson('/sdk/public/v2/payments/one-click', Object.assign({ provider: 'solidgate', environment: input.environment, funnelId: resolveFunnelId(input.funnelId, input.runtimeConfig), offerSetId: requiredString(input.offerSetId, 'offerSetId'), paymentProfileId: requiredString(input.paymentProfileId, 'paymentProfileId'), providerPlanId: requiredString(input.providerPlanId, 'providerPlanId'), planKey: requiredString(input.funnelPlanKey, 'funnelPlanKey'), userId, checkoutSessionId: requiredString(input.checkoutSessionId, 'checkoutSessionId'), idempotencyKey }, proof), input.runtimeConfig, input.signal));
|
|
308
310
|
if (!isRecord(value) || value.provider !== 'solidgate' || typeof value.status !== 'string'
|
|
309
311
|
|| !oneClickStatuses.has(value.status)) {
|
|
310
312
|
throw new Error('Solidgate one-click returned an invalid response');
|
|
@@ -10,6 +10,7 @@ import { getUnsupportedCheckoutCountryMessage, normalizeSupportedCheckoutCountri
|
|
|
10
10
|
import { trackCheckoutCanceled, trackCheckoutFailureShown, } from '../../../services/checkoutObservability.service.js';
|
|
11
11
|
import { isStripeCheckoutAlreadyPaidError, normalizeStripeCheckoutError } from '../services/stripeCheckoutError.js';
|
|
12
12
|
const ExpressCheckoutElementWithCancel = ExpressCheckoutElement;
|
|
13
|
+
const WALLET_DECLINE_SHEET_MESSAGE = 'Your bank declined this card. Choose another card or approve the payment in your bank app.';
|
|
13
14
|
const buildDefaultOptions = () => ({
|
|
14
15
|
buttonHeight: 55,
|
|
15
16
|
buttonTheme: {
|
|
@@ -278,6 +279,10 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
|
|
|
278
279
|
message,
|
|
279
280
|
paymentMethod: details.paymentMethod,
|
|
280
281
|
});
|
|
282
|
+
// Apple Pay shows a custom sheet message only for invalid_payment_data;
|
|
283
|
+
// with 'fail' it shows a generic error and customers retry the same card.
|
|
284
|
+
event.paymentFailed({ reason: 'invalid_payment_data', message: WALLET_DECLINE_SHEET_MESSAGE });
|
|
285
|
+
return;
|
|
281
286
|
}
|
|
282
287
|
event.paymentFailed({ reason: 'fail', message });
|
|
283
288
|
return;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Stripe } from '@stripe/stripe-js';
|
|
1
|
+
import type { Stripe, StripeCheckoutPaymentElementOptions } from '@stripe/stripe-js';
|
|
2
2
|
import { type PlatformWalletPaymentMethod } from './walletPlatform.js';
|
|
3
3
|
import { type StripeSubscriptionCheckoutAnalyticsContext } from '../services/checkoutCompletionAnalytics.service.js';
|
|
4
4
|
import { type StripeCheckoutErrorDetails } from '../services/stripeCheckoutError.js';
|
|
@@ -41,5 +41,10 @@ export type StripeWalletFirstCheckoutProps = {
|
|
|
41
41
|
themeColor: string;
|
|
42
42
|
/** The method selected on mount; defaults to the platform wallet. */
|
|
43
43
|
initialMethod?: 'wallet' | 'card';
|
|
44
|
+
/**
|
|
45
|
+
* Card form options merged over the defaults. Keys of `fields.billingDetails` merge one by one,
|
|
46
|
+
* e.g. `{ fields: { billingDetails: { address: { country: 'auto', postalCode: 'never' } } } }`.
|
|
47
|
+
*/
|
|
48
|
+
paymentElementOptions?: StripeCheckoutPaymentElementOptions;
|
|
44
49
|
};
|
|
45
50
|
export declare function StripeWalletFirstCheckout(props: StripeWalletFirstCheckoutProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -9,7 +9,9 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
9
9
|
* even before the checkout session exists; the wallet slot holds a progress
|
|
10
10
|
* bar at the exact button height until Stripe's button replaces it, so nothing
|
|
11
11
|
* moves. Where the wallet cannot pay, the same slot explains that. The card
|
|
12
|
-
* form has no email
|
|
12
|
+
* form has no email or terms text: the session carries the email. Stripe asks
|
|
13
|
+
* for the postal code only for card countries that use it (US, CA, UK).
|
|
14
|
+
* `paymentElementOptions` overrides these card form defaults.
|
|
13
15
|
* `initialMethod: 'card'` opens the card form first, e.g. for a bottom-of-page
|
|
14
16
|
* "complete your order" block; the wallet stays one tap away.
|
|
15
17
|
*
|
|
@@ -67,7 +69,7 @@ export function StripeWalletFirstCheckout(props) {
|
|
|
67
69
|
}, [checkoutAnalytics, checkoutSessionId, clientSecret, selected, cardEngaged]);
|
|
68
70
|
return (_jsxs(_Fragment, { children: [options && stripePromise ? (_jsx(CheckoutProvider, { stripe: stripePromise, options: options, children: _jsx(StripeWalletFirstCheckoutForm, Object.assign({}, props, { wallet: wallet, selected: selected, onSelect: select, onCardEngaged: engageCard, style: style })) }, options.clientSecret)) : (_jsx(CheckoutLayout, { copy: copy, wallet: wallet, selected: selected, onSelect: select, disabled: false, style: style, walletSlot: _jsx("span", { className: 'wfc-progress', role: 'status', "aria-label": copy.processingLabel }), cardBody: _jsx("span", { className: 'wfc-progress wfc-progress--form', "aria-hidden": 'true' }) })), _jsx("style", { children: stripeWalletFirstCheckoutStyles })] }));
|
|
69
71
|
}
|
|
70
|
-
function StripeWalletFirstCheckoutForm({ amountCents, checkoutAnalytics, checkoutSessionId, copy, customerEmail, customerName, onCancel, onError, onSuccess, returnUrl, summaryLabel, wallet, selected, onSelect, onCardEngaged, style, }) {
|
|
72
|
+
function StripeWalletFirstCheckoutForm({ amountCents, checkoutAnalytics, checkoutSessionId, copy, customerEmail, customerName, onCancel, onError, onSuccess, paymentElementOptions: paymentElementOverrides, returnUrl, summaryLabel, wallet, selected, onSelect, onCardEngaged, style, }) {
|
|
71
73
|
const checkoutState = useCheckout();
|
|
72
74
|
// null until Stripe answers; the slot shows progress at the button's height meanwhile.
|
|
73
75
|
const [walletAvailable, setWalletAvailable] = useState(null);
|
|
@@ -90,12 +92,15 @@ function StripeWalletFirstCheckoutForm({ amountCents, checkoutAnalytics, checkou
|
|
|
90
92
|
googlePay: wallet === 'googlePay' ? 'always' : 'never',
|
|
91
93
|
},
|
|
92
94
|
}), [wallet]);
|
|
93
|
-
const paymentElementOptions = useMemo(() =>
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
terms: { card: 'never' },
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
const paymentElementOptions = useMemo(() => {
|
|
96
|
+
var _a;
|
|
97
|
+
const billingDetails = (_a = paymentElementOverrides === null || paymentElementOverrides === void 0 ? void 0 : paymentElementOverrides.fields) === null || _a === void 0 ? void 0 : _a.billingDetails;
|
|
98
|
+
return Object.assign(Object.assign({ layout: 'tabs', terms: { card: 'never' }, wallets: { applePay: 'never', googlePay: 'never', link: 'never' } }, paymentElementOverrides), { fields: {
|
|
99
|
+
billingDetails: typeof billingDetails === 'string' ? billingDetails : Object.assign({ name: 'never', email: 'never',
|
|
100
|
+
// US banks match the postal code against the cardholder's; without it they decline more as fraud.
|
|
101
|
+
address: { country: 'auto', postalCode: 'auto' } }, billingDetails),
|
|
102
|
+
} });
|
|
103
|
+
}, [paymentElementOverrides]);
|
|
99
104
|
// A hidden Payment Element measures 0px wide; let Stripe re-layout when it opens.
|
|
100
105
|
useEffect(() => {
|
|
101
106
|
if (selected !== 'card')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funnelsgrove/payments",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.64.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.
|
|
50
|
-
"@funnelsgrove/analytics": "0.
|
|
49
|
+
"@funnelsgrove/runtime": "0.42.0",
|
|
50
|
+
"@funnelsgrove/analytics": "0.25.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@funnelsgrove/runtime": "^0.
|
|
54
|
-
"@funnelsgrove/analytics": "^0.
|
|
53
|
+
"@funnelsgrove/runtime": "^0.42.0",
|
|
54
|
+
"@funnelsgrove/analytics": "^0.25.0"
|
|
55
55
|
}
|
|
56
56
|
}
|