@funnelsgrove/payments 0.43.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 +21 -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 +4 -30
- package/dist/providers/solidgate/services/solidgate.service.d.ts +45 -0
- package/dist/providers/solidgate/services/solidgate.service.js +63 -2
- package/dist/providers/solidgate/services/solidgateCheckoutAnalytics.service.d.ts +2 -0
- package/dist/providers/solidgate/services/solidgateCheckoutAnalytics.service.js +29 -0
- package/dist/services/paywallOffer.service.js +1 -1
- package/dist/services/paywallPlans/types.d.ts +0 -2
- 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`
|
|
@@ -95,6 +102,20 @@ hooks; wallet surfaces accept it through their `checkout` input. Stripe clients
|
|
|
95
102
|
cached by publishable key and locale so changing language cannot reuse another
|
|
96
103
|
language's client. Locale does not change a plan, currency or billing interval.
|
|
97
104
|
|
|
105
|
+
For Solidgate, pass `language: 'es'` to `prepareSolidgateCheckout`, or inside
|
|
106
|
+
`SolidgateCheckoutDialog.request`, to use Spanish for the provider form:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
const checkout = await prepareSolidgateCheckout({ ...checkoutRequest, language: 'es' });
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Use a [supported Solidgate language tag](https://docs.solidgate.com/payments/integrate/payment-form/form-insights/implementation-tips/#supported-translations).
|
|
113
|
+
Map regional funnel locales explicitly (for example, `es-ES` to `es`); the API rejects
|
|
114
|
+
unsupported tags. Omitted/null language preserves browser selection. The dialog
|
|
115
|
+
captures language when preparing the attempt; close and reopen it to adopt a change.
|
|
116
|
+
Funnel-owned dialog text still comes from `content` and `presentation`.
|
|
117
|
+
See the [checkout language contract](../../docs/product-specs/billing.md#solidgate-checkout-language).
|
|
118
|
+
|
|
98
119
|
`ManageSubscriptionContent` exported by this package extends the runtime content
|
|
99
120
|
with optional `labels: ManageSubscriptionLabels`. A localized funnel should make
|
|
100
121
|
`labels` required in its own content type and provide the complete English and
|
|
@@ -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]);
|
|
@@ -106,7 +78,7 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
|
|
|
106
78
|
setCommittedEmail(normalizedCustomerEmail);
|
|
107
79
|
setEmailError(null);
|
|
108
80
|
}, [customerEmail, normalizedCustomerEmail]);
|
|
109
|
-
const { discountKeyOrProviderId, failUrl, funnelPlanKey, paymentProfileId, providerPlanId, checkoutType, environment, funnelEndUserId, funnelId, idempotencyKey, offerSetId, returnUrl, runtimeConfig, successUrl, } = request;
|
|
81
|
+
const { discountKeyOrProviderId, failUrl, funnelPlanKey, paymentProfileId, providerPlanId, checkoutType, environment, language, funnelEndUserId, funnelId, idempotencyKey, offerSetId, returnUrl, runtimeConfig, successUrl, } = request;
|
|
110
82
|
const checkoutKey = (retryRequest === null || retryRequest === void 0 ? void 0 : retryRequest.originalKey) === idempotencyKey
|
|
111
83
|
? retryRequest.key : idempotencyKey;
|
|
112
84
|
const retryAttemptId = (retryRequest === null || retryRequest === void 0 ? void 0 : retryRequest.originalKey) === idempotencyKey ? retryRequest.attemptId : request.retryAttemptId;
|
|
@@ -121,6 +93,7 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
|
|
|
121
93
|
providerPlanId: (providerPlanId === null || providerPlanId === void 0 ? void 0 : providerPlanId.trim()) || null,
|
|
122
94
|
checkoutType: checkoutType || null,
|
|
123
95
|
environment: environment || null,
|
|
96
|
+
language,
|
|
124
97
|
idempotencyKey: checkoutKey.trim(),
|
|
125
98
|
retryAttemptId,
|
|
126
99
|
discountKeyOrProviderId: (discountKeyOrProviderId === null || discountKeyOrProviderId === void 0 ? void 0 : discountKeyOrProviderId.trim()) || null,
|
|
@@ -143,6 +116,7 @@ export function SolidgateCheckoutDialog({ open, layout = 'dialog', request, cust
|
|
|
143
116
|
providerPlanId,
|
|
144
117
|
checkoutType,
|
|
145
118
|
environment,
|
|
119
|
+
language,
|
|
146
120
|
funnelEndUserId,
|
|
147
121
|
funnelId,
|
|
148
122
|
funnelSdkPublishableKey,
|
|
@@ -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: {
|
|
@@ -34,6 +40,8 @@ export type PrepareSolidgateCheckoutInput = {
|
|
|
34
40
|
providerPlanId?: string | null;
|
|
35
41
|
checkoutType?: 'subscription' | 'one_time' | null;
|
|
36
42
|
environment?: 'test' | 'live' | null;
|
|
43
|
+
/** Solidgate form language tag (for example, 'es'); omitted/null uses browser language. */
|
|
44
|
+
language?: string | null;
|
|
37
45
|
idempotencyKey: string;
|
|
38
46
|
retryAttemptId?: string | null;
|
|
39
47
|
discountKeyOrProviderId?: string | null;
|
|
@@ -67,3 +75,40 @@ export declare const pollSolidgateCheckoutStatus: (input: RetrieveSolidgateCheck
|
|
|
67
75
|
delay?: (delayMs: number, signal?: AbortSignal) => Promise<void>;
|
|
68
76
|
retrieveStatus?: typeof retrieveSolidgateCheckoutStatus;
|
|
69
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
|
}
|
|
@@ -129,8 +142,8 @@ export const prepareSolidgateCheckout = async (input) => {
|
|
|
129
142
|
if (!paymentProfileId || !providerPlanId || !checkoutType || !environment) {
|
|
130
143
|
throw new Error('Solidgate V2 checkout selection is incomplete');
|
|
131
144
|
}
|
|
132
|
-
const result = parsePreparation(await postJson('/sdk/public/v2/payments/checkout-sessions', Object.assign(Object.assign({ checkoutType, uiMode: 'custom', environment,
|
|
133
|
-
paymentProfileId, provider: 'solidgate', providerPlanId, planKey: requiredString(input.funnelPlanKey, 'funnelPlanKey'), funnelId: resolveFunnelId(input.funnelId, input.runtimeConfig), funnelEndUserId: requiredString(input.funnelEndUserId, 'funnelEndUserId'), offerSetId: requiredString(input.offerSetId, 'offerSetId'), idempotencyKey: requiredString(input.idempotencyKey, 'idempotencyKey') }, (input.retryAttemptId ? { retryAttemptId: input.retryAttemptId } : {})), { couponId: ((_c = input.discountKeyOrProviderId) === null || _c === void 0 ? void 0 : _c.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));
|
|
145
|
+
const result = parsePreparation(await postJson('/sdk/public/v2/payments/checkout-sessions', Object.assign(Object.assign(Object.assign({ checkoutType, uiMode: 'custom', environment,
|
|
146
|
+
paymentProfileId, provider: 'solidgate', providerPlanId, planKey: requiredString(input.funnelPlanKey, 'funnelPlanKey'), funnelId: resolveFunnelId(input.funnelId, input.runtimeConfig), funnelEndUserId: requiredString(input.funnelEndUserId, 'funnelEndUserId'), offerSetId: requiredString(input.offerSetId, 'offerSetId'), idempotencyKey: requiredString(input.idempotencyKey, 'idempotencyKey') }, (input.language != null ? { language: input.language } : {})), (input.retryAttemptId ? { retryAttemptId: input.retryAttemptId } : {})), { couponId: ((_c = input.discountKeyOrProviderId) === null || _c === void 0 ? void 0 : _c.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));
|
|
134
147
|
retainPaywallCheckout('solidgate', result.attemptId);
|
|
135
148
|
return result;
|
|
136
149
|
};
|
|
@@ -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
|
+
};
|
|
@@ -285,7 +285,7 @@ export const buildDiscountedPaywallPlans = (input) => {
|
|
|
285
285
|
? discountedMoney
|
|
286
286
|
? formatProviderMoney(discountedMoney, locale)
|
|
287
287
|
: formatMoneyFromCents(discountedAmountCents, planCurrency, locale)
|
|
288
|
-
: plan.priceLabel, oldPriceLabel: hasActiveDiscount ? plan.priceLabel :
|
|
288
|
+
: plan.priceLabel, oldPriceLabel: hasActiveDiscount ? plan.priceLabel : undefined, perDayAmount: hasActiveDiscount ? discountedPerDayAmount : plan.perDayAmount, baseAmountCents: plan.amountCents, basePriceLabel: plan.priceLabel, basePerDayAmount: plan.perDayAmount, oldPerDayAmount: hasActiveDiscount ? plan.perDayAmount : null, couponId: hasActiveDiscount ? input.couponId : null, hasActiveDiscount });
|
|
289
289
|
});
|
|
290
290
|
};
|
|
291
291
|
export const getPaywallPromoDisplayName = (referenceMs) => {
|
|
@@ -11,8 +11,6 @@ export type PaywallPlan = {
|
|
|
11
11
|
providerPlanId?: string;
|
|
12
12
|
priceLabel: string;
|
|
13
13
|
oldPriceLabel?: string;
|
|
14
|
-
/** Display-only price shown crossed out when no coupon discount is active. */
|
|
15
|
-
priceBeforeDiscount?: string;
|
|
16
14
|
featuredTag?: string;
|
|
17
15
|
perDayAmount: string;
|
|
18
16
|
perDayLabel: string;
|