@funnelsgrove/payments 0.44.0 → 0.46.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/config/billing.config.d.ts +2 -0
- package/dist/generated/package-version.d.ts +1 -1
- package/dist/generated/package-version.js +1 -1
- package/dist/providers/paypal/paypalCheckout.service.js +1 -7
- 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/dist/services/publishedBillingRuntime.service.d.ts +4 -0
- package/dist/services/publishedBillingRuntime.service.js +52 -14
- package/package.json +5 -5
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`
|
|
@@ -47,6 +47,7 @@ export type BillingPlanMappingCatalog = Record<string, BillingPlanMappingConfig>
|
|
|
47
47
|
export type BillingPlanInputCatalog = BillingPlanCatalog | BillingPlanMappingCatalog;
|
|
48
48
|
export type BillingFirstDiscountConfig = {
|
|
49
49
|
stage: 'first';
|
|
50
|
+
discountKey?: string;
|
|
50
51
|
couponId: string;
|
|
51
52
|
discountPercent: number;
|
|
52
53
|
amountOffMinor?: number;
|
|
@@ -56,6 +57,7 @@ export type BillingFirstDiscountConfig = {
|
|
|
56
57
|
};
|
|
57
58
|
export type BillingSecondDiscountConfig = {
|
|
58
59
|
stage: 'second';
|
|
60
|
+
discountKey?: string;
|
|
59
61
|
couponId: string;
|
|
60
62
|
discountPercent: number;
|
|
61
63
|
amountOffMinor?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PAYMENTS_PACKAGE_VERSION = "0.
|
|
1
|
+
export declare const PAYMENTS_PACKAGE_VERSION = "0.46.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.46.0";
|
|
@@ -32,13 +32,7 @@ async function request(input, path, signal, body) {
|
|
|
32
32
|
}
|
|
33
33
|
export async function preparePayPalCheckout(input, idempotencyKey, signal) {
|
|
34
34
|
var _a;
|
|
35
|
-
const result = await request(input, '/sdk/public/v2/payments/checkout-sessions', signal, {
|
|
36
|
-
provider: 'paypal', checkoutType: 'subscription', uiMode: 'custom', environment: input.environment,
|
|
37
|
-
paymentProfileId: input.option.paymentProfileId, providerPlanId: input.option.providerPlanId,
|
|
38
|
-
funnelId: ((_a = input.runtimeConfig) === null || _a === void 0 ? void 0 : _a.funnelId) || FUNNEL_ID, funnelEndUserId: input.funnelEndUserId,
|
|
39
|
-
offerSetId: input.offerSetId, planKey: input.funnelPlanKey, idempotencyKey,
|
|
40
|
-
returnUrl: window.location.href, successUrl: window.location.href, failUrl: window.location.href,
|
|
41
|
-
});
|
|
35
|
+
const result = await request(input, '/sdk/public/v2/payments/checkout-sessions', signal, Object.assign(Object.assign({ provider: 'paypal', checkoutType: 'subscription', uiMode: 'custom', environment: input.environment, paymentProfileId: input.option.paymentProfileId, providerPlanId: input.option.providerPlanId }, (input.option.discountKey ? { couponId: input.option.discountKey } : {})), { funnelId: ((_a = input.runtimeConfig) === null || _a === void 0 ? void 0 : _a.funnelId) || FUNNEL_ID, funnelEndUserId: input.funnelEndUserId, offerSetId: input.offerSetId, planKey: input.funnelPlanKey, idempotencyKey, returnUrl: window.location.href, successUrl: window.location.href, failUrl: window.location.href }));
|
|
42
36
|
const initialization = result.initialization;
|
|
43
37
|
if (typeof result.attemptId !== 'string' || !result.attemptId || !record(initialization)
|
|
44
38
|
|| initialization.kind !== 'paypal' || initialization.clientId !== input.option.clientId
|
|
@@ -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
|
+
};
|
|
@@ -9,6 +9,8 @@ export type PayPalBillingOption = {
|
|
|
9
9
|
amountMinor: number;
|
|
10
10
|
currency: string;
|
|
11
11
|
summary: string;
|
|
12
|
+
discountKey?: string;
|
|
13
|
+
discountOptionsByKey?: Readonly<Record<string, PayPalBillingOption>>;
|
|
12
14
|
};
|
|
13
15
|
export type ResolvedPublishedBillingRuntime = {
|
|
14
16
|
paypalOptionsByPlanKey?: Readonly<Record<string, PayPalBillingOption>>;
|
|
@@ -36,6 +38,8 @@ export type ResolvedPublishedBillingRuntime = {
|
|
|
36
38
|
unavailablePlanKeys: readonly string[];
|
|
37
39
|
};
|
|
38
40
|
export declare const EMPTY_PUBLISHED_BILLING_RUNTIME: ResolvedPublishedBillingRuntime;
|
|
41
|
+
/** Select native terms without applying another provider's percentage to PayPal. */
|
|
42
|
+
export declare const resolvePayPalBillingOption: (runtime: Pick<ResolvedPublishedBillingRuntime, "paypalOptionsByPlanKey" | "discounts">, funnelPlanKey: string, discountKeyOrCouponId?: string | null) => PayPalBillingOption | null;
|
|
39
43
|
export declare const resolvePublishedBillingRuntime: ({ config, featureFlags, mode, search, defaultOfferSetId, locale, baseCatalogsByMode, fallbackDiscounts, resolvedExperiments, }: {
|
|
40
44
|
config: ResolvedFunnelRuntimeConfig | null;
|
|
41
45
|
featureFlags: Readonly<Record<string, string | boolean>>;
|
|
@@ -9,8 +9,27 @@ export const EMPTY_PUBLISHED_BILLING_RUNTIME = Object.freeze({
|
|
|
9
9
|
plans: [], planCatalog: {}, defaultPlanKey: '', discounts: null, upsells: [], downsells: [],
|
|
10
10
|
unavailablePlanKeys: [],
|
|
11
11
|
});
|
|
12
|
+
/** Select native terms without applying another provider's percentage to PayPal. */
|
|
13
|
+
export const resolvePayPalBillingOption = (runtime, funnelPlanKey, discountKeyOrCouponId) => {
|
|
14
|
+
var _a, _b;
|
|
15
|
+
const option = (_a = runtime.paypalOptionsByPlanKey) === null || _a === void 0 ? void 0 : _a[funnelPlanKey];
|
|
16
|
+
if (!option)
|
|
17
|
+
return null;
|
|
18
|
+
if (!discountKeyOrCouponId)
|
|
19
|
+
return option;
|
|
20
|
+
const discountKey = ((_b = Object.values(runtime.discounts || {}).find(discount => (discount.couponId === discountKeyOrCouponId))) === null || _b === void 0 ? void 0 : _b.discountKey) || discountKeyOrCouponId;
|
|
21
|
+
return option.discountOptionsByKey && Object.hasOwn(option.discountOptionsByKey, discountKey)
|
|
22
|
+
? option.discountOptionsByKey[discountKey] : option;
|
|
23
|
+
};
|
|
24
|
+
const isRecord = (value) => (Boolean(value) && typeof value === 'object' && !Array.isArray(value));
|
|
25
|
+
const nativePayPalOption = (mapping, paymentProfileId, clientId) => {
|
|
26
|
+
if (!(mapping === null || mapping === void 0 ? void 0 : mapping.providerPlanId) || !mapping.checkoutSummaryLabel || mapping.amountCents == null || !mapping.currency)
|
|
27
|
+
return null;
|
|
28
|
+
return { paymentProfileId, clientId, providerPlanId: mapping.providerPlanId,
|
|
29
|
+
summary: mapping.checkoutSummaryLabel, amountMinor: mapping.amountCents, currency: mapping.currency };
|
|
30
|
+
};
|
|
12
31
|
export const resolvePublishedBillingRuntime = ({ config, featureFlags, mode, search = '', defaultOfferSetId, locale, baseCatalogsByMode, fallbackDiscounts, resolvedExperiments = resolvePublishedRuntimeExperiments(config), }) => {
|
|
13
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
32
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
14
33
|
const offerSets = (_a = config === null || config === void 0 ? void 0 : config.offerSets) !== null && _a !== void 0 ? _a : [];
|
|
15
34
|
const selection = resolvePublishedOfferSetSelection({
|
|
16
35
|
offerSets,
|
|
@@ -38,35 +57,54 @@ export const resolvePublishedBillingRuntime = ({ config, featureFlags, mode, sea
|
|
|
38
57
|
const provider = runtime.getPaymentProvider(mode);
|
|
39
58
|
const paymentProviderConfig = (_c = (_b = runtime.offerSet) === null || _b === void 0 ? void 0 : _b.paymentProviderConfigByMode) === null || _c === void 0 ? void 0 : _c[mode];
|
|
40
59
|
const paypalOptionsByPlanKey = {};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
60
|
+
const offerDiscounts = Array.isArray((_e = (_d = runtime.offerSet) === null || _d === void 0 ? void 0 : _d.metadata) === null || _e === void 0 ? void 0 : _e.discounts)
|
|
61
|
+
? runtime.offerSet.metadata.discounts.filter(isRecord) : [];
|
|
62
|
+
for (const item of ((_f = runtime.offerSet) === null || _f === void 0 ? void 0 : _f.items) || []) {
|
|
63
|
+
const binding = (_g = item.paymentProfileBindings) === null || _g === void 0 ? void 0 : _g.find(candidate => candidate.provider === 'paypal');
|
|
64
|
+
const profileId = (binding === null || binding === void 0 ? void 0 : binding.paymentProfileId) || (provider === 'paypal' ? (_h = runtime.offerSet) === null || _h === void 0 ? void 0 : _h.paymentProfileId : null);
|
|
44
65
|
if (!profileId)
|
|
45
66
|
continue;
|
|
46
|
-
const mapping = binding ? (
|
|
47
|
-
const profileConfig = ((
|
|
67
|
+
const mapping = binding ? (_j = binding.providerMappingsByMode) === null || _j === void 0 ? void 0 : _j[mode] : (_k = item.providerMappingsByMode) === null || _k === void 0 ? void 0 : _k[mode];
|
|
68
|
+
const profileConfig = ((_o = (_m = (_l = runtime.offerSet) === null || _l === void 0 ? void 0 : _l.paymentProviderConfigByProfileId) === null || _m === void 0 ? void 0 : _m[profileId]) === null || _o === void 0 ? void 0 : _o[mode])
|
|
48
69
|
|| (provider === 'paypal' ? paymentProviderConfig : null);
|
|
49
70
|
const clientId = (profileConfig === null || profileConfig === void 0 ? void 0 : profileConfig.provider) === 'paypal' ? profileConfig.paypalClientId : null;
|
|
50
|
-
if (!
|
|
71
|
+
if (!clientId)
|
|
72
|
+
continue;
|
|
73
|
+
const option = nativePayPalOption(mapping, profileId, clientId);
|
|
74
|
+
if (!option)
|
|
51
75
|
continue;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
76
|
+
const discountOptionsByKey = {};
|
|
77
|
+
for (const discount of offerDiscounts) {
|
|
78
|
+
if (!discount.key)
|
|
79
|
+
continue;
|
|
80
|
+
const variants = (_p = discount.metadata) === null || _p === void 0 ? void 0 : _p.paypalPlanMappings;
|
|
81
|
+
if (!Array.isArray(variants))
|
|
82
|
+
continue;
|
|
83
|
+
const variant = variants.filter(isRecord).find(candidate => (candidate.funnelPlanKey === item.funnelPlanKey && candidate.paymentProfileId === profileId));
|
|
84
|
+
const nativeMapping = (_q = variant === null || variant === void 0 ? void 0 : variant.providerMappingsByMode) === null || _q === void 0 ? void 0 : _q[mode];
|
|
85
|
+
const selectedPlanId = mode === 'test' ? variant === null || variant === void 0 ? void 0 : variant.testProviderPlanId : variant === null || variant === void 0 ? void 0 : variant.liveProviderPlanId;
|
|
86
|
+
if (!selectedPlanId || (nativeMapping === null || nativeMapping === void 0 ? void 0 : nativeMapping.providerPlanId) !== selectedPlanId)
|
|
87
|
+
continue;
|
|
88
|
+
const discountOption = nativePayPalOption(nativeMapping, profileId, clientId);
|
|
89
|
+
if (discountOption)
|
|
90
|
+
discountOptionsByKey[discount.key] = Object.assign(Object.assign({}, discountOption), { discountKey: discount.key });
|
|
91
|
+
}
|
|
92
|
+
paypalOptionsByPlanKey[item.funnelPlanKey] = Object.assign(Object.assign({}, option), (Object.keys(discountOptionsByKey).length ? { discountOptionsByKey } : {}));
|
|
55
93
|
}
|
|
56
94
|
const pinnedFeatureFlags = Object.assign(Object.assign({}, featureFlags), (selection.experimentId && selection.variantKey
|
|
57
95
|
? { [selection.experimentId]: selection.variantKey }
|
|
58
96
|
: {}));
|
|
59
97
|
return {
|
|
60
98
|
paypalOptionsByPlanKey,
|
|
61
|
-
revisionId: (
|
|
62
|
-
sourceVersionId: (
|
|
99
|
+
revisionId: (_r = config === null || config === void 0 ? void 0 : config.revisionId) !== null && _r !== void 0 ? _r : null,
|
|
100
|
+
sourceVersionId: (_s = config === null || config === void 0 ? void 0 : config.sourceVersionId) !== null && _s !== void 0 ? _s : null,
|
|
63
101
|
paymentsApiVersion: 'v2',
|
|
64
102
|
mode,
|
|
65
103
|
offerSetId: selection.offerSetId,
|
|
66
|
-
paymentProfileId: ((
|
|
104
|
+
paymentProfileId: ((_u = (_t = runtime.offerSet) === null || _t === void 0 ? void 0 : _t.paymentProfileId) === null || _u === void 0 ? void 0 : _u.trim()) || null,
|
|
67
105
|
provider,
|
|
68
106
|
stripePublishableKey: provider === 'stripe' && (paymentProviderConfig === null || paymentProviderConfig === void 0 ? void 0 : paymentProviderConfig.provider) === 'stripe'
|
|
69
|
-
? ((
|
|
107
|
+
? ((_v = paymentProviderConfig === null || paymentProviderConfig === void 0 ? void 0 : paymentProviderConfig.stripePublishableKey) === null || _v === void 0 ? void 0 : _v.trim()) || null
|
|
70
108
|
: null,
|
|
71
109
|
experimentId: selection.experimentId,
|
|
72
110
|
variantKey: selection.variantKey,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funnelsgrove/payments",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.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.35.0",
|
|
50
|
+
"@funnelsgrove/analytics": "0.17.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@funnelsgrove/runtime": "^0.
|
|
54
|
-
"@funnelsgrove/analytics": "^0.
|
|
53
|
+
"@funnelsgrove/runtime": "^0.35.0",
|
|
54
|
+
"@funnelsgrove/analytics": "^0.17.0"
|
|
55
55
|
}
|
|
56
56
|
}
|