@stigg/react-sdk 4.13.1 → 4.14.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/dist/components/common/TiersSelectContainer.d.ts +8 -3
- package/dist/components/common/VolumeBulkSelect.d.ts +5 -0
- package/dist/components/common/VolumePerUnitInput.d.ts +5 -0
- package/dist/components/paywall/PlanOfferingButton.d.ts +2 -1
- package/dist/components/paywall/PlanPrice.d.ts +3 -1
- package/dist/components/paywall/index.d.ts +1 -1
- package/dist/components/paywall/paywallTextOverrides.d.ts +9 -5
- package/dist/components/utils/getPaidPriceText.d.ts +2 -1
- package/dist/components/utils/getPlanPrice.d.ts +1 -1
- package/dist/components/utils/priceTierUtils.d.ts +3 -2
- package/dist/index.d.ts +1 -1
- package/dist/react-sdk.cjs.development.js +558 -365
- 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 +628 -430
- package/dist/react-sdk.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/components/checkout/hooks/usePlanStepModel.ts +3 -3
- package/src/components/checkout/steps/payment/stripe/stripe.utils.ts +10 -7
- package/src/components/checkout/steps/plan/CheckoutChargeList.tsx +10 -2
- package/src/components/common/TiersSelectContainer.tsx +33 -62
- package/src/components/common/VolumeBulkSelect.tsx +68 -0
- package/src/components/common/VolumePerUnitInput.tsx +40 -0
- package/src/components/paywall/PlanOffering.tsx +15 -6
- package/src/components/paywall/PlanOfferingButton.tsx +8 -2
- package/src/components/paywall/PlanPrice.tsx +20 -0
- package/src/components/paywall/index.ts +1 -1
- package/src/components/paywall/paywallTextOverrides.ts +7 -2
- package/src/components/utils/getPaidPriceText.ts +9 -1
- package/src/components/utils/getPlanPrice.ts +6 -1
- package/src/components/utils/priceTierUtils.ts +60 -14
- package/src/index.ts +1 -0
- package/src/stories/mocks/checkout/mockCheckoutPreview.ts +1 -1
|
@@ -14,10 +14,12 @@ export function getTierByQuantity(tiers: PriceTierFragment[], quantity: number)
|
|
|
14
14
|
if (!tiers) return undefined;
|
|
15
15
|
|
|
16
16
|
const ascendingTiers = [...tiers];
|
|
17
|
-
|
|
17
|
+
// Sort tiers by upTo value, ascending, if upTo is not set,
|
|
18
|
+
// put it at the end as it represent the last infinity tier
|
|
19
|
+
ascendingTiers.sort((a, b) => (!a.upTo ? 1 : !b.upTo ? -1 : a.upTo - b.upTo));
|
|
18
20
|
|
|
19
21
|
for (const tier of ascendingTiers) {
|
|
20
|
-
if (quantity <= tier.upTo) {
|
|
22
|
+
if (tier.upTo && quantity <= tier.upTo) {
|
|
21
23
|
return tier;
|
|
22
24
|
}
|
|
23
25
|
}
|
|
@@ -30,21 +32,52 @@ export function calculateTierPrice(
|
|
|
30
32
|
currentTier: PriceTierFragment,
|
|
31
33
|
selectedBillingPeriod: BillingPeriod,
|
|
32
34
|
shouldShowMonthlyPriceAmount: boolean,
|
|
35
|
+
perUnitQuantity?: number,
|
|
33
36
|
): number {
|
|
37
|
+
const unitPrice =
|
|
38
|
+
selectedBillingPeriod === BillingPeriod.Annually && shouldShowMonthlyPriceAmount
|
|
39
|
+
? currentTier.unitPrice.amount / 12
|
|
40
|
+
: currentTier.unitPrice.amount;
|
|
34
41
|
switch (price.tiersMode) {
|
|
35
42
|
case TiersMode.Volume: {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return unitPrice * currentTier.upTo;
|
|
43
|
+
return unitPrice * (currentTier.upTo || 1);
|
|
44
|
+
}
|
|
45
|
+
case TiersMode.VolumePerUnit: {
|
|
46
|
+
return unitPrice * (perUnitQuantity || 1);
|
|
42
47
|
}
|
|
43
48
|
default:
|
|
44
49
|
return 0;
|
|
45
50
|
}
|
|
46
51
|
}
|
|
47
52
|
|
|
53
|
+
export function getSelectedTierQuantityBeFeature(
|
|
54
|
+
plan: PaywallPlan,
|
|
55
|
+
billingPeriod: BillingPeriod,
|
|
56
|
+
currentSubscription: Subscription | null,
|
|
57
|
+
) {
|
|
58
|
+
const result: Record<string, number> = {};
|
|
59
|
+
const planTierPrices = plan.pricePoints.filter(
|
|
60
|
+
(price) => price.billingPeriod === billingPeriod && price.isTieredPrice,
|
|
61
|
+
);
|
|
62
|
+
if (planTierPrices.length === 1) {
|
|
63
|
+
const [price] = planTierPrices;
|
|
64
|
+
const featureId = price?.feature!.featureId;
|
|
65
|
+
if (currentSubscription && currentSubscription.plan.id === plan.id) {
|
|
66
|
+
const tieredPrice = currentSubscription?.prices.find(
|
|
67
|
+
(subscriptionPrice) =>
|
|
68
|
+
subscriptionPrice.pricingModel === BillingModel.PerUnit &&
|
|
69
|
+
subscriptionPrice.tiersMode &&
|
|
70
|
+
subscriptionPrice.feature?.featureId === featureId,
|
|
71
|
+
);
|
|
72
|
+
if (tieredPrice) {
|
|
73
|
+
result[featureId] = tieredPrice.feature?.unitQuantity || 1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
|
|
48
81
|
export function getSelectedTier(
|
|
49
82
|
plan: PaywallPlan,
|
|
50
83
|
billingPeriod: BillingPeriod,
|
|
@@ -64,7 +97,7 @@ export function getSelectedTier(
|
|
|
64
97
|
|
|
65
98
|
if (selectedTierByFeature[featureId]) {
|
|
66
99
|
currentTier = price.tiers?.find((tier) => tier.upTo === selectedTierByFeature[featureId].upTo) || currentTier;
|
|
67
|
-
} else if (currentSubscription) {
|
|
100
|
+
} else if (currentSubscription && currentSubscription.plan.id === plan.id) {
|
|
68
101
|
const tieredPrice = currentSubscription.prices.find(
|
|
69
102
|
(subscriptionPrice) =>
|
|
70
103
|
subscriptionPrice.pricingModel === BillingModel.PerUnit &&
|
|
@@ -94,6 +127,7 @@ export enum PriceTierComparison {
|
|
|
94
127
|
|
|
95
128
|
export function compareSelectedTierToCurrentTier(
|
|
96
129
|
selectedTierByFeature: Record<string, PriceTierFragment>,
|
|
130
|
+
perUnitQuantityByFeature: Record<string, number>,
|
|
97
131
|
currentSubscription: Subscription | null,
|
|
98
132
|
): PriceTierComparison {
|
|
99
133
|
if (!currentSubscription || !selectedTierByFeature) {
|
|
@@ -108,22 +142,34 @@ export function compareSelectedTierToCurrentTier(
|
|
|
108
142
|
}
|
|
109
143
|
|
|
110
144
|
const { featureId, unitQuantity } = currentTierPrice.feature!;
|
|
145
|
+
const { tiersMode } = currentTierPrice;
|
|
111
146
|
|
|
112
147
|
if (!unitQuantity) {
|
|
113
148
|
return PriceTierComparison.Equal;
|
|
114
149
|
}
|
|
115
150
|
|
|
116
151
|
const selectedTier = selectedTierByFeature[featureId];
|
|
152
|
+
const selectedQuantity = perUnitQuantityByFeature[featureId];
|
|
117
153
|
if (!selectedTier) {
|
|
118
154
|
return PriceTierComparison.Equal;
|
|
119
155
|
}
|
|
120
156
|
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
|
|
157
|
+
if (tiersMode === TiersMode.Volume) {
|
|
158
|
+
if (selectedTier.upTo && selectedTier.upTo < unitQuantity) {
|
|
159
|
+
return PriceTierComparison.Lower;
|
|
160
|
+
}
|
|
124
161
|
|
|
125
|
-
|
|
126
|
-
|
|
162
|
+
if (selectedTier.upTo && selectedTier.upTo > unitQuantity) {
|
|
163
|
+
return PriceTierComparison.Higher;
|
|
164
|
+
}
|
|
165
|
+
} else if (tiersMode === TiersMode.VolumePerUnit) {
|
|
166
|
+
if (selectedQuantity && selectedQuantity < unitQuantity) {
|
|
167
|
+
return PriceTierComparison.Lower;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (selectedQuantity && selectedQuantity > unitQuantity) {
|
|
171
|
+
return PriceTierComparison.Higher;
|
|
172
|
+
}
|
|
127
173
|
}
|
|
128
174
|
|
|
129
175
|
return PriceTierComparison.Equal;
|
package/src/index.ts
CHANGED
|
@@ -69,7 +69,7 @@ const billableFeatureCost = (plan: Plan, billingPeriod: BillingPeriod, featureId
|
|
|
69
69
|
const { tiers } = price;
|
|
70
70
|
|
|
71
71
|
if (tiers) {
|
|
72
|
-
const quantityTier = tiers.find((tier) => tier.upTo >= quantity);
|
|
72
|
+
const quantityTier = tiers.find((tier) => tier.upTo && tier.upTo >= quantity);
|
|
73
73
|
const priceTier = quantityTier || tiers[tiers.length - 1];
|
|
74
74
|
return quantity * priceTier.unitPrice.amount;
|
|
75
75
|
}
|