@stigg/react-sdk 4.2.1 → 4.2.2
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/paywall/utils/computeDefaultBillingPeriod.d.ts +2 -2
- package/dist/react-sdk.cjs.development.js +16 -6
- 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 +17 -7
- package/dist/react-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/paywall/hooks/useLoadPaywallData.ts +1 -0
- package/src/components/paywall/planPriceTier.ts +2 -3
- package/src/components/paywall/utils/computeDefaultBillingPeriod.ts +12 -3
- package/src/stories/Paywall.stories.tsx +1 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BillingPeriod, Plan } from '@stigg/js-client-sdk';
|
|
2
|
-
export declare function computeBillingPeriods(plans: Plan[], preferredBillingPeriod?: BillingPeriod): {
|
|
1
|
+
import { BillingPeriod, Plan, Subscription } from '@stigg/js-client-sdk';
|
|
2
|
+
export declare function computeBillingPeriods(plans: Plan[], activeSubscriptions?: Subscription[] | null, preferredBillingPeriod?: BillingPeriod): {
|
|
3
3
|
defaultBillingPeriod: BillingPeriod;
|
|
4
4
|
availableBillingPeriods: BillingPeriod[];
|
|
5
5
|
};
|
|
@@ -687,14 +687,14 @@ function getSelectedTier(plan, billingPeriod, currentSubscription, selectedTierB
|
|
|
687
687
|
var tieredPrice = currentSubscription.prices.find(function (subscriptionPrice) {
|
|
688
688
|
var _subscriptionPrice$fe;
|
|
689
689
|
|
|
690
|
-
return subscriptionPrice.pricingModel == Stigg.BillingModel.PerUnit && subscriptionPrice.
|
|
690
|
+
return subscriptionPrice.pricingModel == Stigg.BillingModel.PerUnit && subscriptionPrice.tiersMode && ((_subscriptionPrice$fe = subscriptionPrice.feature) == null ? void 0 : _subscriptionPrice$fe.featureId) === featureId;
|
|
691
691
|
});
|
|
692
692
|
|
|
693
693
|
if (tieredPrice) {
|
|
694
|
-
var customerTier =
|
|
694
|
+
var customerTier = price.tiers.find(function (tier) {
|
|
695
695
|
return tier.upTo === tieredPrice.feature.unitQuantity;
|
|
696
696
|
});
|
|
697
|
-
currentTier = customerTier ||
|
|
697
|
+
currentTier = customerTier || price.tiers[0];
|
|
698
698
|
}
|
|
699
699
|
}
|
|
700
700
|
|
|
@@ -2849,7 +2849,7 @@ var useStiggContext = function useStiggContext() {
|
|
|
2849
2849
|
return ctx;
|
|
2850
2850
|
};
|
|
2851
2851
|
|
|
2852
|
-
function computeBillingPeriods(plans, preferredBillingPeriod) {
|
|
2852
|
+
function computeBillingPeriods(plans, activeSubscriptions, preferredBillingPeriod) {
|
|
2853
2853
|
var billingPeriods = plans.flatMap(function (x) {
|
|
2854
2854
|
return x.pricePoints;
|
|
2855
2855
|
}).map(function (x) {
|
|
@@ -2861,7 +2861,17 @@ function computeBillingPeriods(plans, preferredBillingPeriod) {
|
|
|
2861
2861
|
|
|
2862
2862
|
if (preferredBillingPeriod && availableBillingPeriods.includes(preferredBillingPeriod)) {
|
|
2863
2863
|
defaultBillingPeriod = preferredBillingPeriod;
|
|
2864
|
-
} else {
|
|
2864
|
+
} else if (activeSubscriptions) {
|
|
2865
|
+
var activeSubscription = activeSubscriptions.find(function (x) {
|
|
2866
|
+
return x.status == Stigg.SubscriptionStatus.Active;
|
|
2867
|
+
});
|
|
2868
|
+
|
|
2869
|
+
if (activeSubscription && activeSubscription.prices.length > 0) {
|
|
2870
|
+
defaultBillingPeriod = activeSubscription == null ? void 0 : activeSubscription.prices[0].billingPeriod;
|
|
2871
|
+
}
|
|
2872
|
+
}
|
|
2873
|
+
|
|
2874
|
+
if (!defaultBillingPeriod) {
|
|
2865
2875
|
defaultBillingPeriod = (counts[Stigg.BillingPeriod.Monthly] || 0) > (counts[Stigg.BillingPeriod.Annually] || 0) ? Stigg.BillingPeriod.Monthly : Stigg.BillingPeriod.Annually;
|
|
2866
2876
|
}
|
|
2867
2877
|
|
|
@@ -3163,7 +3173,7 @@ function useLoadPaywallData(_ref) {
|
|
|
3163
3173
|
|
|
3164
3174
|
case 6:
|
|
3165
3175
|
paywallResult = _context.sent;
|
|
3166
|
-
_computeBillingPeriod = computeBillingPeriods(paywallResult.plans, preferredBillingPeriod), _availableBillingPeriods = _computeBillingPeriod.availableBillingPeriods, defaultBillingPeriod = _computeBillingPeriod.defaultBillingPeriod;
|
|
3176
|
+
_computeBillingPeriod = computeBillingPeriods(paywallResult.plans, paywallResult.activeSubscriptions, preferredBillingPeriod), _availableBillingPeriods = _computeBillingPeriod.availableBillingPeriods, defaultBillingPeriod = _computeBillingPeriod.defaultBillingPeriod;
|
|
3167
3177
|
setPaywall(paywallResult);
|
|
3168
3178
|
setAvailableBillingPeriods(_availableBillingPeriods);
|
|
3169
3179
|
setSelectedBillingPeriod(defaultBillingPeriod);
|