@funnelsgrove/payments 0.1.47 → 0.1.48
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 +2 -2
- package/dist/services/stripe.service.d.ts +2 -7
- package/dist/services/stripe.service.js +72 -218
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Shared billing and checkout helpers for funnels.
|
|
|
5
5
|
Read this file before editing checkout code. Deeper implementation docs:
|
|
6
6
|
|
|
7
7
|
- [Shared Payments](../../docs/funnel-sdk/shared-payments.md)
|
|
8
|
-
- [Funnel
|
|
8
|
+
- [Funnel SDK runtime service](../../docs/funnel-sdk/funnel-api.md)
|
|
9
9
|
|
|
10
10
|
## Owns provider-backed checkout primitives
|
|
11
11
|
|
|
@@ -22,7 +22,7 @@ Use these for new subscription paywalls:
|
|
|
22
22
|
- `WalletSubscriptionCheckoutSlot`
|
|
23
23
|
- `trackPaidStripeSubscriptionCheckoutCompleted`
|
|
24
24
|
|
|
25
|
-
Use `chargeStripeOneClickPayment` for post-checkout one-click upsells when the shared client helper fits the funnel.
|
|
25
|
+
Use `chargeStripeOneClickPayment` for post-checkout one-click upsells when the shared client helper fits the funnel. It delegates to `funnelSdkService.chargeOneClickPayment`.
|
|
26
26
|
|
|
27
27
|
## Compatibility-Only Surfaces
|
|
28
28
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Stripe } from '@stripe/stripe-js';
|
|
2
2
|
import { type BillingFallbackPlanConfig, type BillingPlanCatalog, type BillingPlanInterval, type BillingPlanInputCatalog } from '../config/billing.config.js';
|
|
3
|
-
import { type ResolvedCountryPricing } from '@funnelsgrove/runtime';
|
|
3
|
+
import { type FunnelSdkRuntimeConfigOverrides, type ResolvedCountryPricing } from '@funnelsgrove/runtime';
|
|
4
4
|
import type { RuntimeMode } from '@funnelsgrove/runtime';
|
|
5
5
|
import { type RemoteProjectBillingPlan } from './planCatalog.service.js';
|
|
6
6
|
export type PaywallPlan = {
|
|
@@ -22,12 +22,7 @@ export type PaywallPlan = {
|
|
|
22
22
|
billingIntervalCount?: number;
|
|
23
23
|
source: 'stripe' | 'config';
|
|
24
24
|
};
|
|
25
|
-
export type StripeRuntimeConfigOverrides =
|
|
26
|
-
apiBaseUrl?: string | null;
|
|
27
|
-
funnelId?: string | null;
|
|
28
|
-
funnelVersionId?: string | null;
|
|
29
|
-
funnelSdkPublishableKey?: string | null;
|
|
30
|
-
};
|
|
25
|
+
export type StripeRuntimeConfigOverrides = FunnelSdkRuntimeConfigOverrides;
|
|
31
26
|
export type PaywallPlanResolutionOptions = {
|
|
32
27
|
locale?: string | null;
|
|
33
28
|
pricing?: ResolvedCountryPricing<string> | null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var _a, _b, _c, _d;
|
|
2
2
|
import { loadStripe } from '@stripe/stripe-js';
|
|
3
3
|
import { billingPlanList, } from '../config/billing.config.js';
|
|
4
|
-
import {
|
|
4
|
+
import { FUNNEL_ID, FUNNEL_SDK_PUBLISHABLE_KEY, funnelSdkService, runtimeEnvConfig, } from '@funnelsgrove/runtime';
|
|
5
5
|
import { isBillingPlanMappingCatalog, resolveMappedProjectPlans, } from './planCatalog.service.js';
|
|
6
6
|
const STRIPE_TEST_PUBLISHABLE_KEY = ((_b = (_a = runtimeEnvConfig.stripeTestPublishableKey) !== null && _a !== void 0 ? _a : runtimeEnvConfig.stripePublishableKey) !== null && _b !== void 0 ? _b : '').trim();
|
|
7
7
|
const STRIPE_LIVE_PUBLISHABLE_KEY = ((_d = (_c = runtimeEnvConfig.stripeLivePublishableKey) !== null && _c !== void 0 ? _c : runtimeEnvConfig.stripePublishableKey) !== null && _d !== void 0 ? _d : '').trim();
|
|
@@ -26,35 +26,6 @@ const asTrimmedStringOrNull = (value) => {
|
|
|
26
26
|
const trimmed = value.trim();
|
|
27
27
|
return trimmed || null;
|
|
28
28
|
};
|
|
29
|
-
const trimTrailingSlash = (value) => {
|
|
30
|
-
return value.replace(/\/+$/, '');
|
|
31
|
-
};
|
|
32
|
-
const toNormalizedPath = (path) => {
|
|
33
|
-
return path.startsWith('/') ? path : `/${path}`;
|
|
34
|
-
};
|
|
35
|
-
const resolveStripeRuntimeConfig = (runtimeConfig) => {
|
|
36
|
-
var _a, _b, _c;
|
|
37
|
-
return {
|
|
38
|
-
apiBaseUrl: asTrimmedStringOrNull(runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.apiBaseUrl),
|
|
39
|
-
funnelId: (_a = asTrimmedStringOrNull(runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.funnelId)) !== null && _a !== void 0 ? _a : asTrimmedStringOrNull(FUNNEL_ID),
|
|
40
|
-
funnelVersionId: (_b = asTrimmedStringOrNull(runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.funnelVersionId)) !== null && _b !== void 0 ? _b : asTrimmedStringOrNull(runtimeEnvConfig.funnelVersionId),
|
|
41
|
-
funnelSdkPublishableKey: resolvePreviewPaymentPublishableKey((_c = asTrimmedStringOrNull(runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.funnelSdkPublishableKey)) !== null && _c !== void 0 ? _c : asTrimmedStringOrNull(FUNNEL_SDK_PUBLISHABLE_KEY)) || null,
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
const buildStripeRuntimeApiUrl = (path, runtimeConfig) => {
|
|
45
|
-
const { apiBaseUrl } = resolveStripeRuntimeConfig(runtimeConfig);
|
|
46
|
-
if (!apiBaseUrl) {
|
|
47
|
-
return buildMainApiUrl(path);
|
|
48
|
-
}
|
|
49
|
-
return `${trimTrailingSlash(apiBaseUrl)}${toNormalizedPath(path)}`;
|
|
50
|
-
};
|
|
51
|
-
const buildStripeRuntimeHeaders = (runtimeConfig, headers) => {
|
|
52
|
-
const { funnelSdkPublishableKey } = resolveStripeRuntimeConfig(runtimeConfig);
|
|
53
|
-
if (!funnelSdkPublishableKey) {
|
|
54
|
-
return Object.assign({}, (headers !== null && headers !== void 0 ? headers : {}));
|
|
55
|
-
}
|
|
56
|
-
return Object.assign({ 'x-sdk-publishable-key': funnelSdkPublishableKey }, (headers !== null && headers !== void 0 ? headers : {}));
|
|
57
|
-
};
|
|
58
29
|
const asFiniteNumberOrNull = (value) => {
|
|
59
30
|
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
60
31
|
return null;
|
|
@@ -329,28 +300,6 @@ const toFallbackPaywallPlans = (planCatalog, options) => {
|
|
|
329
300
|
const isFallbackBillingPlanCatalog = (planCatalog) => {
|
|
330
301
|
return Array.isArray(planCatalog) || !isBillingPlanMappingCatalog(planCatalog);
|
|
331
302
|
};
|
|
332
|
-
const parseErrorMessage = async (response, fallbackMessage) => {
|
|
333
|
-
try {
|
|
334
|
-
const payload = (await response.json());
|
|
335
|
-
const apiError = asTrimmedStringOrNull(payload.error);
|
|
336
|
-
if (apiError) {
|
|
337
|
-
return apiError;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
catch (_a) {
|
|
341
|
-
// ignore JSON parsing errors
|
|
342
|
-
}
|
|
343
|
-
try {
|
|
344
|
-
const errorText = await response.text();
|
|
345
|
-
if (errorText.trim()) {
|
|
346
|
-
return errorText;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
catch (_b) {
|
|
350
|
-
// ignore text parsing errors
|
|
351
|
-
}
|
|
352
|
-
return fallbackMessage;
|
|
353
|
-
};
|
|
354
303
|
export function getFallbackPlans(planCatalog, options) {
|
|
355
304
|
if (!planCatalog) {
|
|
356
305
|
return reorderPlans(fallbackPaywallPlans, options === null || options === void 0 ? void 0 : options.pricing);
|
|
@@ -431,20 +380,9 @@ const getStripeSyncedPlanRecords = async (mode) => {
|
|
|
431
380
|
return cachedPromise;
|
|
432
381
|
}
|
|
433
382
|
const nextPromise = (async () => {
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
if (FUNNEL_ID) {
|
|
437
|
-
url.searchParams.set('funnelId', FUNNEL_ID);
|
|
438
|
-
}
|
|
439
|
-
const response = await fetch(url.toString(), {
|
|
440
|
-
method: 'GET',
|
|
441
|
-
headers: buildSdkHeaders(),
|
|
383
|
+
const payload = await funnelSdkService.listPaymentPlans({
|
|
384
|
+
environment: mode,
|
|
442
385
|
});
|
|
443
|
-
if (!response.ok) {
|
|
444
|
-
const errorMessage = await parseErrorMessage(response, 'Unable to load Stripe plans');
|
|
445
|
-
throw new Error(errorMessage);
|
|
446
|
-
}
|
|
447
|
-
const payload = (await response.json());
|
|
448
386
|
const rawPlans = Array.isArray(payload.plans) ? payload.plans : [];
|
|
449
387
|
return rawPlans
|
|
450
388
|
.filter((rawPlan) => isRecord(rawPlan))
|
|
@@ -595,58 +533,30 @@ const normalizeCheckoutAnalyticsMetadata = (metadata, plan) => {
|
|
|
595
533
|
};
|
|
596
534
|
export async function createStripePaymentIntent(input) {
|
|
597
535
|
var _a, _b;
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
funnelId: runtimeConfig.funnelId || undefined,
|
|
607
|
-
funnelVersionId: runtimeConfig.funnelVersionId || undefined,
|
|
608
|
-
planId: input.planId,
|
|
609
|
-
amountCents: input.amountCents,
|
|
610
|
-
couponId: ((_a = input.couponId) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
|
|
611
|
-
analyticsMetadata: normalizeAnalyticsMetadata(input.analyticsMetadata),
|
|
612
|
-
user_id: ((_b = input.user_id) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
|
|
613
|
-
environment: input.environment || undefined,
|
|
614
|
-
}),
|
|
536
|
+
return funnelSdkService.createOneTimePaymentIntent({
|
|
537
|
+
planId: input.planId,
|
|
538
|
+
amountCents: input.amountCents,
|
|
539
|
+
couponId: ((_a = input.couponId) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
|
|
540
|
+
analyticsMetadata: normalizeAnalyticsMetadata(input.analyticsMetadata),
|
|
541
|
+
userId: ((_b = input.user_id) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
|
|
542
|
+
environment: input.environment,
|
|
543
|
+
runtimeConfig: input.runtimeConfig,
|
|
615
544
|
});
|
|
616
|
-
if (!response.ok) {
|
|
617
|
-
const errorMessage = await parseErrorMessage(response, 'Unable to create payment intent');
|
|
618
|
-
throw new Error(errorMessage);
|
|
619
|
-
}
|
|
620
|
-
return (await response.json());
|
|
621
545
|
}
|
|
622
546
|
export async function chargeStripeOneClickPayment(input) {
|
|
623
547
|
var _a, _b, _c, _d, _e;
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
amountCents: input.amountCents,
|
|
636
|
-
currency: ((_a = input.currency) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
|
|
637
|
-
analyticsMetadata: normalizeAnalyticsMetadata(input.analyticsMetadata),
|
|
638
|
-
user_id: ((_b = input.user_id) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
|
|
639
|
-
stripe_customer_id: ((_c = input.stripe_customer_id) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
|
|
640
|
-
checkoutSessionId: ((_d = input.checkoutSessionId) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
|
|
641
|
-
idempotencyKey: ((_e = input.idempotencyKey) === null || _e === void 0 ? void 0 : _e.trim()) || undefined,
|
|
642
|
-
environment: input.environment || undefined,
|
|
643
|
-
}),
|
|
548
|
+
return funnelSdkService.chargeOneClickPayment({
|
|
549
|
+
planId: input.planId,
|
|
550
|
+
amountCents: input.amountCents,
|
|
551
|
+
currency: ((_a = input.currency) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
|
|
552
|
+
analyticsMetadata: normalizeAnalyticsMetadata(input.analyticsMetadata),
|
|
553
|
+
userId: ((_b = input.user_id) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
|
|
554
|
+
stripeCustomerId: ((_c = input.stripe_customer_id) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
|
|
555
|
+
checkoutSessionId: ((_d = input.checkoutSessionId) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
|
|
556
|
+
idempotencyKey: ((_e = input.idempotencyKey) === null || _e === void 0 ? void 0 : _e.trim()) || undefined,
|
|
557
|
+
environment: input.environment,
|
|
558
|
+
runtimeConfig: input.runtimeConfig,
|
|
644
559
|
});
|
|
645
|
-
if (!response.ok) {
|
|
646
|
-
const errorMessage = await parseErrorMessage(response, 'Unable to charge one-click payment');
|
|
647
|
-
throw new Error(errorMessage);
|
|
648
|
-
}
|
|
649
|
-
return (await response.json());
|
|
650
560
|
}
|
|
651
561
|
export async function createStripeSubscriptionCheckout(input) {
|
|
652
562
|
var _a, _b, _c, _d, _e;
|
|
@@ -654,36 +564,22 @@ export async function createStripeSubscriptionCheckout(input) {
|
|
|
654
564
|
if (!recurring) {
|
|
655
565
|
throw new Error('Unable to resolve the recurring interval for the selected plan');
|
|
656
566
|
}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
billingInterval: recurring.interval,
|
|
673
|
-
billingIntervalCount: recurring.intervalCount,
|
|
674
|
-
couponId: ((_c = input.couponId) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
|
|
675
|
-
analyticsMetadata: normalizeCheckoutAnalyticsMetadata(input.analyticsMetadata, input.plan),
|
|
676
|
-
customerEmail: ((_d = input.customerEmail) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
|
|
677
|
-
returnUrl: input.returnUrl,
|
|
678
|
-
user_id: ((_e = input.user_id) === null || _e === void 0 ? void 0 : _e.trim()) || undefined,
|
|
679
|
-
environment: input.environment || undefined,
|
|
680
|
-
}),
|
|
567
|
+
return funnelSdkService.createSubscriptionCheckout({
|
|
568
|
+
planId: getPaywallPlanSelectionValue(input.plan),
|
|
569
|
+
providerPlanId: ((_a = input.plan.providerPlanId) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
|
|
570
|
+
title: input.plan.title,
|
|
571
|
+
description: ((_b = input.plan.description) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
|
|
572
|
+
amountCents: input.plan.amountCents,
|
|
573
|
+
billingInterval: recurring.interval,
|
|
574
|
+
billingIntervalCount: recurring.intervalCount,
|
|
575
|
+
couponId: ((_c = input.couponId) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
|
|
576
|
+
analyticsMetadata: normalizeCheckoutAnalyticsMetadata(input.analyticsMetadata, input.plan),
|
|
577
|
+
customerEmail: ((_d = input.customerEmail) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
|
|
578
|
+
returnUrl: input.returnUrl,
|
|
579
|
+
userId: ((_e = input.user_id) === null || _e === void 0 ? void 0 : _e.trim()) || undefined,
|
|
580
|
+
environment: input.environment,
|
|
581
|
+
runtimeConfig: input.runtimeConfig,
|
|
681
582
|
});
|
|
682
|
-
if (!response.ok) {
|
|
683
|
-
const errorMessage = await parseErrorMessage(response, 'Unable to create subscription checkout');
|
|
684
|
-
throw new Error(errorMessage);
|
|
685
|
-
}
|
|
686
|
-
return (await response.json());
|
|
687
583
|
}
|
|
688
584
|
export async function updateStripeSubscriptionCheckoutPlan(input) {
|
|
689
585
|
var _a, _b, _c, _d, _e;
|
|
@@ -691,61 +587,33 @@ export async function updateStripeSubscriptionCheckoutPlan(input) {
|
|
|
691
587
|
if (!recurring) {
|
|
692
588
|
throw new Error('Unable to resolve the recurring interval for the selected plan');
|
|
693
589
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
amountCents: input.plan.amountCents,
|
|
710
|
-
billingInterval: recurring.interval,
|
|
711
|
-
billingIntervalCount: recurring.intervalCount,
|
|
712
|
-
couponId: ((_c = input.couponId) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
|
|
713
|
-
analyticsMetadata: normalizeCheckoutAnalyticsMetadata(input.analyticsMetadata, input.plan),
|
|
714
|
-
customerEmail: ((_d = input.customerEmail) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
|
|
715
|
-
user_id: ((_e = input.user_id) === null || _e === void 0 ? void 0 : _e.trim()) || undefined,
|
|
716
|
-
environment: input.environment || undefined,
|
|
717
|
-
}),
|
|
590
|
+
return funnelSdkService.updateSubscriptionCheckoutPlan({
|
|
591
|
+
checkoutSessionId: input.checkoutSessionId.trim(),
|
|
592
|
+
planId: getPaywallPlanSelectionValue(input.plan),
|
|
593
|
+
providerPlanId: ((_a = input.plan.providerPlanId) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
|
|
594
|
+
title: input.plan.title,
|
|
595
|
+
description: ((_b = input.plan.description) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
|
|
596
|
+
amountCents: input.plan.amountCents,
|
|
597
|
+
billingInterval: recurring.interval,
|
|
598
|
+
billingIntervalCount: recurring.intervalCount,
|
|
599
|
+
couponId: ((_c = input.couponId) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
|
|
600
|
+
analyticsMetadata: normalizeCheckoutAnalyticsMetadata(input.analyticsMetadata, input.plan),
|
|
601
|
+
customerEmail: ((_d = input.customerEmail) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
|
|
602
|
+
userId: ((_e = input.user_id) === null || _e === void 0 ? void 0 : _e.trim()) || undefined,
|
|
603
|
+
environment: input.environment,
|
|
604
|
+
runtimeConfig: input.runtimeConfig,
|
|
718
605
|
});
|
|
719
|
-
if (!response.ok) {
|
|
720
|
-
const errorMessage = await parseErrorMessage(response, 'Unable to update subscription checkout');
|
|
721
|
-
throw new Error(errorMessage);
|
|
722
|
-
}
|
|
723
|
-
return (await response.json());
|
|
724
606
|
}
|
|
725
607
|
export async function verifyStripeSubscriptionCheckoutPayment(input) {
|
|
726
608
|
const checkoutSessionId = input.checkoutSessionId.trim();
|
|
727
609
|
if (!checkoutSessionId) {
|
|
728
610
|
throw new Error('checkoutSessionId is required');
|
|
729
611
|
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
'Content-Type': 'application/json',
|
|
735
|
-
}),
|
|
736
|
-
body: JSON.stringify({
|
|
737
|
-
publishableKey: runtimeConfig.funnelSdkPublishableKey || undefined,
|
|
738
|
-
funnelId: runtimeConfig.funnelId || undefined,
|
|
739
|
-
funnelVersionId: runtimeConfig.funnelVersionId || undefined,
|
|
740
|
-
checkoutSessionId,
|
|
741
|
-
environment: input.environment || undefined,
|
|
742
|
-
}),
|
|
612
|
+
return funnelSdkService.verifySubscriptionCheckout({
|
|
613
|
+
checkoutSessionId,
|
|
614
|
+
environment: input.environment,
|
|
615
|
+
runtimeConfig: input.runtimeConfig,
|
|
743
616
|
});
|
|
744
|
-
if (!response.ok) {
|
|
745
|
-
const errorMessage = await parseErrorMessage(response, 'Unable to verify subscription checkout');
|
|
746
|
-
throw new Error(errorMessage);
|
|
747
|
-
}
|
|
748
|
-
return (await response.json());
|
|
749
617
|
}
|
|
750
618
|
export async function createStripeCheckoutSession(input) {
|
|
751
619
|
var _a, _b, _c, _d, _e;
|
|
@@ -753,37 +621,23 @@ export async function createStripeCheckoutSession(input) {
|
|
|
753
621
|
if (!recurring) {
|
|
754
622
|
throw new Error('Unable to resolve the recurring interval for the selected plan');
|
|
755
623
|
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
billingIntervalCount: recurring.intervalCount,
|
|
773
|
-
couponId: ((_c = input.couponId) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
|
|
774
|
-
analyticsMetadata: normalizeCheckoutAnalyticsMetadata(input.analyticsMetadata, input.plan),
|
|
775
|
-
successUrl: input.successUrl,
|
|
776
|
-
cancelUrl: input.cancelUrl,
|
|
777
|
-
customerEmail: ((_d = input.customerEmail) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
|
|
778
|
-
user_id: ((_e = input.user_id) === null || _e === void 0 ? void 0 : _e.trim()) || undefined,
|
|
779
|
-
environment: input.environment || undefined,
|
|
780
|
-
}),
|
|
624
|
+
return funnelSdkService.createHostedCheckoutSession({
|
|
625
|
+
planId: getPaywallPlanSelectionValue(input.plan),
|
|
626
|
+
providerPlanId: ((_a = input.plan.providerPlanId) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
|
|
627
|
+
title: input.plan.title,
|
|
628
|
+
description: ((_b = input.plan.description) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
|
|
629
|
+
amountCents: input.plan.amountCents,
|
|
630
|
+
billingInterval: recurring.interval,
|
|
631
|
+
billingIntervalCount: recurring.intervalCount,
|
|
632
|
+
couponId: ((_c = input.couponId) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
|
|
633
|
+
analyticsMetadata: normalizeCheckoutAnalyticsMetadata(input.analyticsMetadata, input.plan),
|
|
634
|
+
successUrl: input.successUrl,
|
|
635
|
+
cancelUrl: input.cancelUrl,
|
|
636
|
+
customerEmail: ((_d = input.customerEmail) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
|
|
637
|
+
userId: ((_e = input.user_id) === null || _e === void 0 ? void 0 : _e.trim()) || undefined,
|
|
638
|
+
environment: input.environment,
|
|
639
|
+
runtimeConfig: input.runtimeConfig,
|
|
781
640
|
});
|
|
782
|
-
if (!response.ok) {
|
|
783
|
-
const errorMessage = await parseErrorMessage(response, 'Unable to create checkout session');
|
|
784
|
-
throw new Error(errorMessage);
|
|
785
|
-
}
|
|
786
|
-
return (await response.json());
|
|
787
641
|
}
|
|
788
642
|
export async function redirectToStripeCheckout(input) {
|
|
789
643
|
var _a;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funnelsgrove/payments",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.48",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@funnelsgrove/analytics": "^0.1.28",
|
|
31
|
-
"@funnelsgrove/runtime": "^0.1.
|
|
31
|
+
"@funnelsgrove/runtime": "^0.1.46",
|
|
32
32
|
"@stripe/react-stripe-js": "^5.6.0",
|
|
33
33
|
"@stripe/stripe-js": "^8.7.0",
|
|
34
34
|
"react": "19.2.3",
|