@funnelsgrove/payments 0.1.57 → 0.1.59
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.
|
@@ -5,6 +5,7 @@ import type { RuntimeMode } from '@funnelsgrove/runtime';
|
|
|
5
5
|
import { type RemoteProjectBillingPlan } from './planCatalog.service.js';
|
|
6
6
|
export type PaywallPlan = {
|
|
7
7
|
id: string;
|
|
8
|
+
offerSetKey?: string;
|
|
8
9
|
title: string;
|
|
9
10
|
description?: string;
|
|
10
11
|
providerPlanId?: string;
|
|
@@ -45,7 +46,7 @@ export declare function resolvePaywallPlansFromProjectPlans(projectPlans: readon
|
|
|
45
46
|
export declare function getPaywallPlans(mode: RuntimeMode, planCatalog?: BillingPlanInputCatalog | readonly BillingFallbackPlanConfig[], options?: PaywallPlanResolutionOptions): Promise<readonly PaywallPlan[]>;
|
|
46
47
|
export declare function isStripeConfigured(mode: RuntimeMode): boolean;
|
|
47
48
|
export declare function getStripePromise(_mode: RuntimeMode, runtimePublishableKey?: string | null): Promise<Stripe | null> | null;
|
|
48
|
-
type CheckoutSessionPlanInput = Pick<PaywallPlan, 'amountCents' | 'analyticsPurchaseValue' | 'billingInterval' | 'billingIntervalCount' | 'description' | 'id' | 'providerPlanId' | 'title' | 'followUpProviderPlanId' | 'followUpPlanTitle' | 'followUpBillingInterval' | 'followUpBillingIntervalCount' | 'introIterations'>;
|
|
49
|
+
type CheckoutSessionPlanInput = Pick<PaywallPlan, 'amountCents' | 'analyticsPurchaseValue' | 'billingInterval' | 'billingIntervalCount' | 'description' | 'id' | 'providerPlanId' | 'title' | 'followUpProviderPlanId' | 'followUpPlanTitle' | 'followUpBillingInterval' | 'followUpBillingIntervalCount' | 'introIterations' | 'offerSetKey'>;
|
|
49
50
|
type CheckoutPlanRecurringConfig = {
|
|
50
51
|
interval: BillingPlanInterval;
|
|
51
52
|
intervalCount: number;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
var _a, _b, _c, _d;
|
|
2
1
|
import { loadStripe } from '@stripe/stripe-js';
|
|
3
2
|
import { billingPlanList, } from '../config/billing.config.js';
|
|
4
|
-
import { FUNNEL_ID, FUNNEL_SDK_PUBLISHABLE_KEY, funnelSdkService,
|
|
3
|
+
import { FUNNEL_ID, FUNNEL_SDK_PUBLISHABLE_KEY, funnelSdkService, } from '@funnelsgrove/runtime';
|
|
5
4
|
import { isBillingPlanMappingCatalog, resolveMappedProjectPlans, } from './planCatalog.service.js';
|
|
6
|
-
const STRIPE_TEST_PUBLISHABLE_KEY = ((_b = (_a = runtimeEnvConfig.stripeTestPublishableKey) !== null && _a !== void 0 ? _a : runtimeEnvConfig.stripePublishableKey) !== null && _b !== void 0 ? _b : '').trim();
|
|
7
|
-
const STRIPE_LIVE_PUBLISHABLE_KEY = ((_d = (_c = runtimeEnvConfig.stripeLivePublishableKey) !== null && _c !== void 0 ? _c : runtimeEnvConfig.stripePublishableKey) !== null && _d !== void 0 ? _d : '').trim();
|
|
8
5
|
const stripePromiseByKey = new Map();
|
|
9
6
|
const syncedPlansPromiseByMode = new Map();
|
|
10
7
|
export const buildPaywallPlanResolutionSignature = (options) => {
|
|
@@ -292,12 +289,6 @@ export function buildConfigPaywallPlans(planCatalog, orderedPlanIds = []) {
|
|
|
292
289
|
: Object.entries(planCatalog !== null && planCatalog !== void 0 ? planCatalog : {}).map(([key, plan]) => toConfigPaywallPlan(key, plan));
|
|
293
290
|
return getOrderedPaywallPlans(plans, orderedPlanIds);
|
|
294
291
|
}
|
|
295
|
-
const getStripePublishableKeyFromEnv = (mode) => {
|
|
296
|
-
if (mode === 'live') {
|
|
297
|
-
return STRIPE_LIVE_PUBLISHABLE_KEY || STRIPE_TEST_PUBLISHABLE_KEY;
|
|
298
|
-
}
|
|
299
|
-
return STRIPE_TEST_PUBLISHABLE_KEY || STRIPE_LIVE_PUBLISHABLE_KEY;
|
|
300
|
-
};
|
|
301
292
|
const toFallbackPaywallPlans = (planCatalog, options) => {
|
|
302
293
|
const sourcePlans = buildConfigPaywallPlans(planCatalog);
|
|
303
294
|
return reorderPlans(sourcePlans.length > 0 ? sourcePlans : fallbackPaywallPlans, options === null || options === void 0 ? void 0 : options.pricing);
|
|
@@ -430,7 +421,8 @@ export async function getPaywallPlans(mode, planCatalog, options) {
|
|
|
430
421
|
return getFallbackPlans(planCatalog, options);
|
|
431
422
|
}
|
|
432
423
|
export function isStripeConfigured(mode) {
|
|
433
|
-
|
|
424
|
+
void mode;
|
|
425
|
+
return FUNNEL_SDK_PUBLISHABLE_KEY.length > 0;
|
|
434
426
|
}
|
|
435
427
|
export function getStripePromise(_mode, runtimePublishableKey) {
|
|
436
428
|
const resolvedPublishableKey = (runtimePublishableKey === null || runtimePublishableKey === void 0 ? void 0 : runtimePublishableKey.trim()) || '';
|
|
@@ -537,18 +529,19 @@ const normalizeCheckoutAnalyticsMetadata = (metadata, plan) => {
|
|
|
537
529
|
return Object.assign(Object.assign({}, (normalized !== null && normalized !== void 0 ? normalized : {})), { analyticsPurchaseValue });
|
|
538
530
|
};
|
|
539
531
|
export async function createStripeOneTimeCheckout(input) {
|
|
540
|
-
var _a, _b, _c, _d, _e;
|
|
532
|
+
var _a, _b, _c, _d, _e, _f;
|
|
541
533
|
return funnelSdkService.createOneTimeCheckout({
|
|
534
|
+
offerSetKey: ((_a = input.plan.offerSetKey) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
|
|
542
535
|
planId: getPaywallPlanSelectionValue(input.plan),
|
|
543
|
-
providerPlanId: ((
|
|
536
|
+
providerPlanId: ((_b = input.plan.providerPlanId) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
|
|
544
537
|
title: input.plan.title,
|
|
545
|
-
description: ((
|
|
538
|
+
description: ((_c = input.plan.description) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
|
|
546
539
|
amountCents: input.plan.amountCents,
|
|
547
|
-
couponId: ((
|
|
540
|
+
couponId: ((_d = input.couponId) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
|
|
548
541
|
analyticsMetadata: normalizeCheckoutAnalyticsMetadata(input.analyticsMetadata, input.plan),
|
|
549
|
-
customerEmail: ((
|
|
542
|
+
customerEmail: ((_e = input.customerEmail) === null || _e === void 0 ? void 0 : _e.trim()) || undefined,
|
|
550
543
|
returnUrl: input.returnUrl,
|
|
551
|
-
userId: ((
|
|
544
|
+
userId: ((_f = input.user_id) === null || _f === void 0 ? void 0 : _f.trim()) || undefined,
|
|
552
545
|
environment: input.environment,
|
|
553
546
|
runtimeConfig: input.runtimeConfig,
|
|
554
547
|
});
|
|
@@ -584,57 +577,59 @@ export async function chargeStripeOneClickPayment(input) {
|
|
|
584
577
|
});
|
|
585
578
|
}
|
|
586
579
|
export async function createStripeSubscriptionCheckout(input) {
|
|
587
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
580
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
588
581
|
const recurring = resolveCheckoutPlanRecurringConfig(input.plan);
|
|
589
582
|
if (!recurring) {
|
|
590
583
|
throw new Error('Unable to resolve the recurring interval for the selected plan');
|
|
591
584
|
}
|
|
592
585
|
return funnelSdkService.createSubscriptionCheckout({
|
|
586
|
+
offerSetKey: ((_a = input.plan.offerSetKey) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
|
|
593
587
|
planId: getPaywallPlanSelectionValue(input.plan),
|
|
594
|
-
providerPlanId: ((
|
|
588
|
+
providerPlanId: ((_b = input.plan.providerPlanId) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
|
|
595
589
|
title: input.plan.title,
|
|
596
|
-
description: ((
|
|
590
|
+
description: ((_c = input.plan.description) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
|
|
597
591
|
amountCents: input.plan.amountCents,
|
|
598
592
|
billingInterval: recurring.interval,
|
|
599
593
|
billingIntervalCount: recurring.intervalCount,
|
|
600
|
-
followUpProviderPlanId: ((
|
|
601
|
-
followUpPlanTitle: ((
|
|
594
|
+
followUpProviderPlanId: ((_d = input.plan.followUpProviderPlanId) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
|
|
595
|
+
followUpPlanTitle: ((_e = input.plan.followUpPlanTitle) === null || _e === void 0 ? void 0 : _e.trim()) || undefined,
|
|
602
596
|
followUpBillingInterval: input.plan.followUpBillingInterval,
|
|
603
597
|
followUpBillingIntervalCount: input.plan.followUpBillingIntervalCount,
|
|
604
598
|
introIterations: input.plan.introIterations,
|
|
605
|
-
couponId: ((
|
|
599
|
+
couponId: ((_f = input.couponId) === null || _f === void 0 ? void 0 : _f.trim()) || undefined,
|
|
606
600
|
analyticsMetadata: normalizeCheckoutAnalyticsMetadata(input.analyticsMetadata, input.plan),
|
|
607
|
-
customerEmail: ((
|
|
601
|
+
customerEmail: ((_g = input.customerEmail) === null || _g === void 0 ? void 0 : _g.trim()) || undefined,
|
|
608
602
|
returnUrl: input.returnUrl,
|
|
609
|
-
userId: ((
|
|
603
|
+
userId: ((_h = input.user_id) === null || _h === void 0 ? void 0 : _h.trim()) || undefined,
|
|
610
604
|
environment: input.environment,
|
|
611
605
|
runtimeConfig: input.runtimeConfig,
|
|
612
606
|
});
|
|
613
607
|
}
|
|
614
608
|
export async function updateStripeSubscriptionCheckoutPlan(input) {
|
|
615
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
609
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
616
610
|
const recurring = resolveCheckoutPlanRecurringConfig(input.plan);
|
|
617
611
|
if (!recurring) {
|
|
618
612
|
throw new Error('Unable to resolve the recurring interval for the selected plan');
|
|
619
613
|
}
|
|
620
614
|
return funnelSdkService.updateSubscriptionCheckoutPlan({
|
|
621
615
|
checkoutSessionId: input.checkoutSessionId.trim(),
|
|
616
|
+
offerSetKey: ((_a = input.plan.offerSetKey) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
|
|
622
617
|
planId: getPaywallPlanSelectionValue(input.plan),
|
|
623
|
-
providerPlanId: ((
|
|
618
|
+
providerPlanId: ((_b = input.plan.providerPlanId) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
|
|
624
619
|
title: input.plan.title,
|
|
625
|
-
description: ((
|
|
620
|
+
description: ((_c = input.plan.description) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
|
|
626
621
|
amountCents: input.plan.amountCents,
|
|
627
622
|
billingInterval: recurring.interval,
|
|
628
623
|
billingIntervalCount: recurring.intervalCount,
|
|
629
|
-
followUpProviderPlanId: ((
|
|
630
|
-
followUpPlanTitle: ((
|
|
624
|
+
followUpProviderPlanId: ((_d = input.plan.followUpProviderPlanId) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
|
|
625
|
+
followUpPlanTitle: ((_e = input.plan.followUpPlanTitle) === null || _e === void 0 ? void 0 : _e.trim()) || undefined,
|
|
631
626
|
followUpBillingInterval: input.plan.followUpBillingInterval,
|
|
632
627
|
followUpBillingIntervalCount: input.plan.followUpBillingIntervalCount,
|
|
633
628
|
introIterations: input.plan.introIterations,
|
|
634
|
-
couponId: ((
|
|
629
|
+
couponId: ((_f = input.couponId) === null || _f === void 0 ? void 0 : _f.trim()) || undefined,
|
|
635
630
|
analyticsMetadata: normalizeCheckoutAnalyticsMetadata(input.analyticsMetadata, input.plan),
|
|
636
|
-
customerEmail: ((
|
|
637
|
-
userId: ((
|
|
631
|
+
customerEmail: ((_g = input.customerEmail) === null || _g === void 0 ? void 0 : _g.trim()) || undefined,
|
|
632
|
+
userId: ((_h = input.user_id) === null || _h === void 0 ? void 0 : _h.trim()) || undefined,
|
|
638
633
|
environment: input.environment,
|
|
639
634
|
runtimeConfig: input.runtimeConfig,
|
|
640
635
|
});
|
|
@@ -651,25 +646,26 @@ export async function verifyStripeSubscriptionCheckoutPayment(input) {
|
|
|
651
646
|
});
|
|
652
647
|
}
|
|
653
648
|
export async function createStripeCheckoutSession(input) {
|
|
654
|
-
var _a, _b, _c, _d, _e;
|
|
649
|
+
var _a, _b, _c, _d, _e, _f;
|
|
655
650
|
const recurring = resolveCheckoutPlanRecurringConfig(input.plan);
|
|
656
651
|
if (!recurring) {
|
|
657
652
|
throw new Error('Unable to resolve the recurring interval for the selected plan');
|
|
658
653
|
}
|
|
659
654
|
return funnelSdkService.createHostedCheckoutSession({
|
|
655
|
+
offerSetKey: ((_a = input.plan.offerSetKey) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
|
|
660
656
|
planId: getPaywallPlanSelectionValue(input.plan),
|
|
661
|
-
providerPlanId: ((
|
|
657
|
+
providerPlanId: ((_b = input.plan.providerPlanId) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
|
|
662
658
|
title: input.plan.title,
|
|
663
|
-
description: ((
|
|
659
|
+
description: ((_c = input.plan.description) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
|
|
664
660
|
amountCents: input.plan.amountCents,
|
|
665
661
|
billingInterval: recurring.interval,
|
|
666
662
|
billingIntervalCount: recurring.intervalCount,
|
|
667
|
-
couponId: ((
|
|
663
|
+
couponId: ((_d = input.couponId) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
|
|
668
664
|
analyticsMetadata: normalizeCheckoutAnalyticsMetadata(input.analyticsMetadata, input.plan),
|
|
669
665
|
successUrl: input.successUrl,
|
|
670
666
|
cancelUrl: input.cancelUrl,
|
|
671
|
-
customerEmail: ((
|
|
672
|
-
userId: ((
|
|
667
|
+
customerEmail: ((_e = input.customerEmail) === null || _e === void 0 ? void 0 : _e.trim()) || undefined,
|
|
668
|
+
userId: ((_f = input.user_id) === null || _f === void 0 ? void 0 : _f.trim()) || undefined,
|
|
673
669
|
environment: input.environment,
|
|
674
670
|
runtimeConfig: input.runtimeConfig,
|
|
675
671
|
});
|