@stigg/react-sdk 4.5.3 → 4.5.5
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/components/checkout/CheckoutContainer.d.ts +4 -2
- package/dist/components/checkout/hooks/useSubscriptionState.d.ts +2 -2
- package/dist/components/checkout/steps/payment/stripe/stripe.utils.d.ts +9 -13
- package/dist/components/checkout/steps/payment/stripe/useSubmit.d.ts +2 -1
- package/dist/components/customerPortal/paywall/CustomerPortalPaywall.d.ts +0 -1
- package/dist/components/customerPortal/paywall/CustomerPortalPaywall.style.d.ts +0 -1
- package/dist/components/paywall/Paywall.d.ts +0 -1
- package/dist/components/paywall/PlanOffering.d.ts +2 -1
- package/dist/components/paywall/PlanOfferingButton.d.ts +1 -2
- package/dist/react-sdk.cjs.development.js +287 -260
- package/dist/react-sdk.cjs.development.js.map +1 -1
- package/dist/react-sdk.cjs.production.min.js +1 -1
- package/dist/react-sdk.cjs.production.min.js.map +1 -1
- package/dist/react-sdk.esm.js +288 -261
- package/dist/react-sdk.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/components/checkout/CheckoutContainer.tsx +13 -3
- package/src/components/checkout/hooks/useSubscriptionState.ts +2 -3
- package/src/components/checkout/steps/payment/stripe/stripe.utils.ts +31 -22
- package/src/components/checkout/steps/payment/stripe/useSubmit.ts +63 -46
- package/src/components/checkout/summary/CheckoutSummary.tsx +1 -0
- package/src/components/customerPortal/CustomerPortalContainer.tsx +5 -8
- package/src/components/customerPortal/paywall/CustomerPortalPaywall.style.ts +0 -10
- package/src/components/customerPortal/paywall/CustomerPortalPaywall.tsx +2 -5
- package/src/components/paywall/Paywall.tsx +36 -20
- package/src/components/paywall/PaywallContainer.tsx +2 -2
- package/src/components/paywall/PlanOffering.tsx +32 -17
- package/src/components/paywall/PlanOfferingButton.tsx +1 -3
- package/src/components/paywall/utils/mapPaywallData.ts +13 -11
- package/src/stories/Checkout.stories.tsx +2 -2
|
@@ -16,7 +16,8 @@ import { mapPaywallConfiguration } from '../../common/mapExternalTheme';
|
|
|
16
16
|
|
|
17
17
|
function getCustomerSubscriptionDetails(activeSubscriptions?: Subscription[] | null) {
|
|
18
18
|
let isCustomerOnTrial = true;
|
|
19
|
-
let currentSubscription: Subscription | null =
|
|
19
|
+
let currentSubscription: Subscription | null =
|
|
20
|
+
activeSubscriptions?.find((s) => s.status === SubscriptionStatus.InTrial) || null;
|
|
20
21
|
let currentPlan = currentSubscription?.plan;
|
|
21
22
|
const trialDaysLeft = currentSubscription?.trialEndDate
|
|
22
23
|
? calculateTrialDaysLeft(currentSubscription.trialEndDate)
|
|
@@ -45,9 +46,8 @@ type PaywallData = {
|
|
|
45
46
|
|
|
46
47
|
export function mapPaywallData(paywall: Paywall | null, showOnlyEligiblePlans?: boolean): PaywallData {
|
|
47
48
|
const { plans, currency, configuration, customer, activeSubscriptions, paywallCalculatedPricePoints } = paywall || {};
|
|
48
|
-
const { currentSubscription, currentPlan, isCustomerOnTrial, trialDaysLeft } =
|
|
49
|
-
activeSubscriptions
|
|
50
|
-
);
|
|
49
|
+
const { currentSubscription, currentPlan, isCustomerOnTrial, trialDaysLeft } =
|
|
50
|
+
getCustomerSubscriptionDetails(activeSubscriptions);
|
|
51
51
|
|
|
52
52
|
const scheduledUpdates = currentSubscription?.scheduledUpdates || [];
|
|
53
53
|
const currentCustomerPlanBillingPeriod = currentSubscription?.price?.billingPeriod;
|
|
@@ -58,16 +58,18 @@ export function mapPaywallData(paywall: Paywall | null, showOnlyEligiblePlans?:
|
|
|
58
58
|
({ subscriptionScheduleType }) => subscriptionScheduleType === SubscriptionScheduleType.BillingPeriod,
|
|
59
59
|
);
|
|
60
60
|
|
|
61
|
-
let paywallPlans: PaywallPlan[] = sortBy(plans, plan => plan.order).map(plan => {
|
|
61
|
+
let paywallPlans: PaywallPlan[] = sortBy(plans, (plan) => plan.order).map((plan) => {
|
|
62
62
|
const eligibleForProductTrial = customer?.eligibleForTrial?.find(
|
|
63
|
-
productTrial => productTrial.productId === plan.product.id,
|
|
63
|
+
(productTrial) => productTrial.productId === plan.product.id,
|
|
64
64
|
);
|
|
65
65
|
const isCurrentCustomerPlan = plan.id === currentPlan?.id;
|
|
66
66
|
|
|
67
67
|
const isNextPlan = (currentBillingPeriod: BillingPeriod) => {
|
|
68
68
|
const downgradeVariables = downgradeSchedule?.scheduleVariables as DowngradeChangeVariables;
|
|
69
69
|
const billingChangedVariables = billingChangedSchedule?.scheduleVariables as BillingPeriodChangeVariables;
|
|
70
|
-
const isPlanHasBillingPeriodPrice = plan.pricePoints.some(
|
|
70
|
+
const isPlanHasBillingPeriodPrice = plan.pricePoints.some(
|
|
71
|
+
(price) => price.billingPeriod === currentBillingPeriod,
|
|
72
|
+
);
|
|
71
73
|
|
|
72
74
|
return downgradeSchedule
|
|
73
75
|
? downgradeSchedule.targetPackage?.refId === plan.id &&
|
|
@@ -79,7 +81,7 @@ export function mapPaywallData(paywall: Paywall | null, showOnlyEligiblePlans?:
|
|
|
79
81
|
|
|
80
82
|
return {
|
|
81
83
|
...plan,
|
|
82
|
-
paywallCalculatedPricePoints: paywallCalculatedPricePoints?.filter(pricePoint => pricePoint.planId === plan.id),
|
|
84
|
+
paywallCalculatedPricePoints: paywallCalculatedPricePoints?.filter((pricePoint) => pricePoint.planId === plan.id),
|
|
83
85
|
isTriable: !isNil(plan.defaultTrialConfig) && (!eligibleForProductTrial || eligibleForProductTrial.eligible),
|
|
84
86
|
isCurrentCustomerPlan,
|
|
85
87
|
currentCustomerPlanBillingPeriod,
|
|
@@ -91,14 +93,14 @@ export function mapPaywallData(paywall: Paywall | null, showOnlyEligiblePlans?:
|
|
|
91
93
|
};
|
|
92
94
|
});
|
|
93
95
|
if (plans && currentPlan) {
|
|
94
|
-
const currentPlanOrder = currentPlan && plans?.find(x => x.id === currentPlan?.id)?.order;
|
|
96
|
+
const currentPlanOrder = currentPlan && plans?.find((x) => x.id === currentPlan?.id)?.order;
|
|
95
97
|
if (!isNil(currentPlanOrder)) {
|
|
96
|
-
paywallPlans = paywallPlans.map<PaywallPlan>(plan => ({
|
|
98
|
+
paywallPlans = paywallPlans.map<PaywallPlan>((plan) => ({
|
|
97
99
|
...plan,
|
|
98
100
|
isLowerThanCurrentPlan: currentPlanOrder > plan.order,
|
|
99
101
|
}));
|
|
100
102
|
if (showOnlyEligiblePlans) {
|
|
101
|
-
paywallPlans = paywallPlans.filter(plan => plan.order
|
|
103
|
+
paywallPlans = paywallPlans.filter((plan) => plan.order >= currentPlanOrder);
|
|
102
104
|
}
|
|
103
105
|
}
|
|
104
106
|
}
|
|
@@ -59,8 +59,8 @@ const Template: ComponentStory<any> = (args) => (
|
|
|
59
59
|
return { success: true };
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
const { success, errorMessage } = await checkoutAction();
|
|
63
|
-
return { success, errorMessage };
|
|
62
|
+
const { success, errorMessage, results } = await checkoutAction(checkoutParams);
|
|
63
|
+
return { success, errorMessage, results };
|
|
64
64
|
}}
|
|
65
65
|
billableFeatures={[{ featureId: 'feature-seat', quantity: 30 }]}
|
|
66
66
|
onChangePlan={({ currentPlan }) => {
|