@funnelsgrove/payments 0.44.0 → 0.45.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 +7 -0
- package/dist/generated/package-version.d.ts +1 -1
- package/dist/generated/package-version.js +1 -1
- package/dist/providers/solidgate/components/SolidgateCheckoutDialog.js +1 -29
- package/dist/providers/solidgate/services/solidgate.service.d.ts +43 -0
- package/dist/providers/solidgate/services/solidgate.service.js +61 -0
- package/dist/providers/solidgate/services/solidgateCheckoutAnalytics.service.d.ts +2 -0
- package/dist/providers/solidgate/services/solidgateCheckoutAnalytics.service.js +29 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,6 +85,13 @@ mounts one official Solidgate form per attempt, destroys the remote form on repl
|
|
|
85
85
|
and never treats iframe `success` as funnel completion. Its `onSuccess` callback runs only after the
|
|
86
86
|
provider-neutral status endpoint finds canonical shared-ledger payment evidence.
|
|
87
87
|
|
|
88
|
+
For a Solidgate one-click upsell, call `completeSolidgateOneClickPayment` with the paid checkout's
|
|
89
|
+
`attemptId` as `checkoutSessionId`, the external `userId`, the published selection and a stable
|
|
90
|
+
`idempotencyKey`. It charges the card, Apple Pay, Google Pay or PayPal instrument saved by that
|
|
91
|
+
payment without showing a wallet button again, polls the new attempt, and emits `checkout_completed`
|
|
92
|
+
only for `succeeded`. On `SolidgateSavedPaymentMethodUnavailableError` (no reusable instrument),
|
|
93
|
+
render `SolidgateCheckoutDialog` with `checkoutType: 'one_time'` instead.
|
|
94
|
+
|
|
88
95
|
## Localized funnel copy
|
|
89
96
|
|
|
90
97
|
Funnel content files own translated strings. Pass a complete `SharedStripeCheckoutV2Copy`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PAYMENTS_PACKAGE_VERSION = "0.
|
|
1
|
+
export declare const PAYMENTS_PACKAGE_VERSION = "0.45.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.45.0";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { completePaywallCheckout } from '@funnelsgrove/runtime';
|
|
4
|
-
import { publicAnalyticsSdk } from '@funnelsgrove/analytics';
|
|
5
4
|
import { useCallback, useEffect, useMemo, useRef, useState, } from 'react';
|
|
5
|
+
import { trackSolidgateCheckoutEvent } from '../services/solidgateCheckoutAnalytics.service.js';
|
|
6
6
|
import { pollSolidgateCheckoutStatus, prepareSolidgateCheckout, SolidgateExistingSubscriptionError, } from '../services/solidgate.service.js';
|
|
7
7
|
import { trackCheckoutCanceled, trackCheckoutFailureShown, } from '../../../services/checkoutObservability.service.js';
|
|
8
8
|
import { solidgateDeclineMessage } from '../services/solidgateDeclineMessage.js';
|
|
@@ -39,34 +39,6 @@ const initialView = {
|
|
|
39
39
|
checkout: null,
|
|
40
40
|
canResumeVerification: false,
|
|
41
41
|
};
|
|
42
|
-
const trackSolidgateCheckoutEvent = async (eventName, attemptId, context) => {
|
|
43
|
-
var _a;
|
|
44
|
-
if (!context) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const input = {
|
|
48
|
-
eventId: eventName === 'add_payment_info' ? `add_payment_info:${attemptId}` : attemptId,
|
|
49
|
-
featureFlags: context.featureFlags,
|
|
50
|
-
stepId: context.stepId,
|
|
51
|
-
stepName: context.stepName,
|
|
52
|
-
stepType: context.stepType,
|
|
53
|
-
stepContractVersion: context.stepContractVersion,
|
|
54
|
-
metadata: Object.assign(Object.assign({}, (context.metadata || {})), { checkoutSessionId: attemptId, checkout_session_id: attemptId, environment: context.environment || ((_a = context.metadata) === null || _a === void 0 ? void 0 : _a.environment), payment_provider: 'solidgate' }),
|
|
55
|
-
};
|
|
56
|
-
try {
|
|
57
|
-
const trackedEventId = eventName === 'checkout_started'
|
|
58
|
-
? publicAnalyticsSdk.trackCheckoutStarted(input)
|
|
59
|
-
: eventName === 'checkout_completed'
|
|
60
|
-
? publicAnalyticsSdk.trackCheckoutCompleted(input)
|
|
61
|
-
: publicAnalyticsSdk.trackPaymentInfoSubmitted(input);
|
|
62
|
-
if (trackedEventId) {
|
|
63
|
-
await publicAnalyticsSdk.flush().catch(() => 0);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
catch (_b) {
|
|
67
|
-
// Analytics must never prevent payment.
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
42
|
const isAbortError = (error) => (error instanceof DOMException && error.name === 'AbortError');
|
|
71
43
|
export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, customerEmail, checkoutAnalytics, content, presentation, onClose, onCustomerEmailCommit, onSuccess, onRetry, onError, onPreparationStart, onStateChange, onPaymentPendingChange, }) {
|
|
72
44
|
const copy = useMemo(() => (Object.assign(Object.assign({}, defaultContent), content)), [content]);
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { type FunnelSdkRuntimeConfigOverrides } from '@funnelsgrove/runtime';
|
|
2
|
+
import type { SolidgateCheckoutAnalyticsContext } from '../components/SolidgateCheckoutDialog.types.js';
|
|
2
3
|
export type SolidgateCheckoutStatus = 'preparing' | 'requires_payment' | 'verifying' | 'succeeded' | 'failed' | 'expired';
|
|
3
4
|
export declare class SolidgateExistingSubscriptionError extends Error {
|
|
4
5
|
readonly code: "already_subscribed_to_product";
|
|
5
6
|
constructor();
|
|
6
7
|
}
|
|
8
|
+
/** The user's paid checkout left no reusable payment instrument; offer a fresh checkout instead. */
|
|
9
|
+
export declare class SolidgateSavedPaymentMethodUnavailableError extends Error {
|
|
10
|
+
readonly code: "saved_payment_method_unavailable";
|
|
11
|
+
constructor();
|
|
12
|
+
}
|
|
7
13
|
export type SolidgateCheckoutPreparation = {
|
|
8
14
|
attemptId: string;
|
|
9
15
|
display: {
|
|
@@ -69,3 +75,40 @@ export declare const pollSolidgateCheckoutStatus: (input: RetrieveSolidgateCheck
|
|
|
69
75
|
delay?: (delayMs: number, signal?: AbortSignal) => Promise<void>;
|
|
70
76
|
retrieveStatus?: typeof retrieveSolidgateCheckoutStatus;
|
|
71
77
|
}) => Promise<PollSolidgateCheckoutStatusResult>;
|
|
78
|
+
export type ChargeSolidgateOneClickPaymentInput = {
|
|
79
|
+
funnelId?: string | null;
|
|
80
|
+
/** External or internal funnel user id that owns the paid checkout. */
|
|
81
|
+
userId: string;
|
|
82
|
+
/** Attempt id of the user's paid Solidgate checkout. */
|
|
83
|
+
checkoutSessionId: string;
|
|
84
|
+
offerSetId: string;
|
|
85
|
+
funnelPlanKey: string;
|
|
86
|
+
paymentProfileId: string;
|
|
87
|
+
providerPlanId: string;
|
|
88
|
+
environment: 'test' | 'live';
|
|
89
|
+
/** Stable for one logical purchase; use a new key only for an explicit retry after a decline. */
|
|
90
|
+
idempotencyKey: string;
|
|
91
|
+
runtimeConfig?: FunnelSdkRuntimeConfigOverrides;
|
|
92
|
+
signal?: AbortSignal;
|
|
93
|
+
};
|
|
94
|
+
export type ChargeSolidgateOneClickPaymentResponse = {
|
|
95
|
+
checkoutSessionId: string;
|
|
96
|
+
status: 'verifying' | 'succeeded' | 'failed';
|
|
97
|
+
};
|
|
98
|
+
/** Charges a one-time offer to the instrument saved by the user's paid Solidgate checkout. */
|
|
99
|
+
export declare const chargeSolidgateOneClickPayment: (input: ChargeSolidgateOneClickPaymentInput) => Promise<ChargeSolidgateOneClickPaymentResponse>;
|
|
100
|
+
export type CompleteSolidgateOneClickPaymentInput = ChargeSolidgateOneClickPaymentInput & {
|
|
101
|
+
checkoutAnalytics?: SolidgateCheckoutAnalyticsContext | null;
|
|
102
|
+
};
|
|
103
|
+
export type CompleteSolidgateOneClickPaymentResponse = {
|
|
104
|
+
checkoutSessionId: string;
|
|
105
|
+
/** `verifying` means the outcome is still pending after polling; do not treat it as paid. */
|
|
106
|
+
status: 'succeeded' | 'failed' | 'verifying';
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Charges the saved instrument and waits for the verified invoice outcome.
|
|
110
|
+
* Throws SolidgateSavedPaymentMethodUnavailableError when the user must pay through checkout instead.
|
|
111
|
+
*/
|
|
112
|
+
export declare const completeSolidgateOneClickPayment: (input: CompleteSolidgateOneClickPaymentInput, options?: {
|
|
113
|
+
poll?: typeof pollSolidgateCheckoutStatus;
|
|
114
|
+
}) => Promise<CompleteSolidgateOneClickPaymentResponse>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { paywallCheckoutReturnUrl, retainPaywallCheckout, FUNNEL_ID, FUNNEL_SDK_PUBLISHABLE_KEY, buildMainApiUrl, resolvePreviewPaymentPublishableKey, } from '@funnelsgrove/runtime';
|
|
2
|
+
import { trackSolidgateCheckoutEvent } from './solidgateCheckoutAnalytics.service.js';
|
|
2
3
|
export class SolidgateExistingSubscriptionError extends Error {
|
|
3
4
|
constructor() {
|
|
4
5
|
super('You already have an active subscription to this product.');
|
|
@@ -6,6 +7,14 @@ export class SolidgateExistingSubscriptionError extends Error {
|
|
|
6
7
|
this.name = 'SolidgateExistingSubscriptionError';
|
|
7
8
|
}
|
|
8
9
|
}
|
|
10
|
+
/** The user's paid checkout left no reusable payment instrument; offer a fresh checkout instead. */
|
|
11
|
+
export class SolidgateSavedPaymentMethodUnavailableError extends Error {
|
|
12
|
+
constructor() {
|
|
13
|
+
super('Saved payment method is unavailable; open checkout.');
|
|
14
|
+
this.code = 'saved_payment_method_unavailable';
|
|
15
|
+
this.name = 'SolidgateSavedPaymentMethodUnavailableError';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
9
18
|
const trimTrailingSlash = (value) => value.replace(/\/+$/, '');
|
|
10
19
|
const requiredString = (value, name) => {
|
|
11
20
|
const normalized = typeof value === 'string' ? value.trim() : '';
|
|
@@ -41,6 +50,10 @@ const postJson = async (path, body, runtimeConfig, signal) => {
|
|
|
41
50
|
&& payload.code === 'already_subscribed_to_product') {
|
|
42
51
|
throw new SolidgateExistingSubscriptionError();
|
|
43
52
|
}
|
|
53
|
+
if (payload && typeof payload === 'object' && 'code' in payload
|
|
54
|
+
&& payload.code === 'saved_payment_method_unavailable') {
|
|
55
|
+
throw new SolidgateSavedPaymentMethodUnavailableError();
|
|
56
|
+
}
|
|
44
57
|
}
|
|
45
58
|
throw new Error('Solidgate checkout is temporarily unavailable');
|
|
46
59
|
}
|
|
@@ -215,3 +228,51 @@ export const pollSolidgateCheckoutStatus = async (input, options = {}) => {
|
|
|
215
228
|
(_e = input.signal) === null || _e === void 0 ? void 0 : _e.removeEventListener('abort', forwardAbort);
|
|
216
229
|
}
|
|
217
230
|
};
|
|
231
|
+
const oneClickStatuses = new Set(['verifying', 'succeeded', 'failed']);
|
|
232
|
+
/** Charges a one-time offer to the instrument saved by the user's paid Solidgate checkout. */
|
|
233
|
+
export const chargeSolidgateOneClickPayment = async (input) => {
|
|
234
|
+
const value = await postJson('/sdk/public/v2/payments/one-click', {
|
|
235
|
+
provider: 'solidgate',
|
|
236
|
+
environment: input.environment,
|
|
237
|
+
funnelId: resolveFunnelId(input.funnelId, input.runtimeConfig),
|
|
238
|
+
offerSetId: requiredString(input.offerSetId, 'offerSetId'),
|
|
239
|
+
paymentProfileId: requiredString(input.paymentProfileId, 'paymentProfileId'),
|
|
240
|
+
providerPlanId: requiredString(input.providerPlanId, 'providerPlanId'),
|
|
241
|
+
planKey: requiredString(input.funnelPlanKey, 'funnelPlanKey'),
|
|
242
|
+
userId: requiredString(input.userId, 'userId'),
|
|
243
|
+
checkoutSessionId: requiredString(input.checkoutSessionId, 'checkoutSessionId'),
|
|
244
|
+
idempotencyKey: requiredString(input.idempotencyKey, 'idempotencyKey'),
|
|
245
|
+
}, input.runtimeConfig, input.signal);
|
|
246
|
+
if (!isRecord(value) || value.provider !== 'solidgate' || typeof value.status !== 'string'
|
|
247
|
+
|| !oneClickStatuses.has(value.status)) {
|
|
248
|
+
throw new Error('Solidgate one-click returned an invalid response');
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
checkoutSessionId: requiredString(value.checkoutSessionId, 'checkoutSessionId'),
|
|
252
|
+
status: value.status,
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Charges the saved instrument and waits for the verified invoice outcome.
|
|
257
|
+
* Throws SolidgateSavedPaymentMethodUnavailableError when the user must pay through checkout instead.
|
|
258
|
+
*/
|
|
259
|
+
export const completeSolidgateOneClickPayment = async (input, options = {}) => {
|
|
260
|
+
const charge = await chargeSolidgateOneClickPayment(input);
|
|
261
|
+
const status = charge.status === 'verifying'
|
|
262
|
+
? (await (options.poll || pollSolidgateCheckoutStatus)({
|
|
263
|
+
funnelId: input.funnelId,
|
|
264
|
+
funnelEndUserId: input.userId,
|
|
265
|
+
attemptId: charge.checkoutSessionId,
|
|
266
|
+
runtimeConfig: input.runtimeConfig,
|
|
267
|
+
signal: input.signal,
|
|
268
|
+
})).status
|
|
269
|
+
: charge.status;
|
|
270
|
+
const result = {
|
|
271
|
+
checkoutSessionId: charge.checkoutSessionId,
|
|
272
|
+
status: status === 'succeeded' || status === 'failed' ? status : 'verifying',
|
|
273
|
+
};
|
|
274
|
+
if (result.status === 'succeeded') {
|
|
275
|
+
await trackSolidgateCheckoutEvent('checkout_completed', result.checkoutSessionId, input.checkoutAnalytics);
|
|
276
|
+
}
|
|
277
|
+
return result;
|
|
278
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { SolidgateCheckoutAnalyticsContext } from '../components/SolidgateCheckoutDialog.types.js';
|
|
2
|
+
export declare const trackSolidgateCheckoutEvent: (eventName: "checkout_started" | "add_payment_info" | "checkout_completed", attemptId: string, context: SolidgateCheckoutAnalyticsContext | null | undefined) => Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { publicAnalyticsSdk } from '@funnelsgrove/analytics';
|
|
2
|
+
export const trackSolidgateCheckoutEvent = async (eventName, attemptId, context) => {
|
|
3
|
+
var _a;
|
|
4
|
+
if (!context) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const input = {
|
|
8
|
+
eventId: eventName === 'add_payment_info' ? `add_payment_info:${attemptId}` : attemptId,
|
|
9
|
+
featureFlags: context.featureFlags,
|
|
10
|
+
stepId: context.stepId,
|
|
11
|
+
stepName: context.stepName,
|
|
12
|
+
stepType: context.stepType,
|
|
13
|
+
stepContractVersion: context.stepContractVersion,
|
|
14
|
+
metadata: Object.assign(Object.assign({}, (context.metadata || {})), { checkoutSessionId: attemptId, checkout_session_id: attemptId, environment: context.environment || ((_a = context.metadata) === null || _a === void 0 ? void 0 : _a.environment), payment_provider: 'solidgate' }),
|
|
15
|
+
};
|
|
16
|
+
try {
|
|
17
|
+
const trackedEventId = eventName === 'checkout_started'
|
|
18
|
+
? publicAnalyticsSdk.trackCheckoutStarted(input)
|
|
19
|
+
: eventName === 'checkout_completed'
|
|
20
|
+
? publicAnalyticsSdk.trackCheckoutCompleted(input)
|
|
21
|
+
: publicAnalyticsSdk.trackPaymentInfoSubmitted(input);
|
|
22
|
+
if (trackedEventId) {
|
|
23
|
+
await publicAnalyticsSdk.flush().catch(() => 0);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (_b) {
|
|
27
|
+
// Analytics must never prevent payment.
|
|
28
|
+
}
|
|
29
|
+
};
|