@stigg/react-sdk 4.2.2 → 4.2.3
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/react-sdk.cjs.development.js +30 -26
- 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 +30 -26
- package/dist/react-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/paywall/BillingPeriodPicker.tsx +1 -1
- package/src/components/utils/calculateDiscountRate.ts +25 -13
package/package.json
CHANGED
|
@@ -87,7 +87,7 @@ export function BillingPeriodPicker({
|
|
|
87
87
|
>
|
|
88
88
|
Annual
|
|
89
89
|
</PeriodText>
|
|
90
|
-
<DiscountRate discount={discountRate} disabled={isMonthlyBillingPeriod} />
|
|
90
|
+
{discountRate !== 0 && <DiscountRate discount={discountRate} disabled={isMonthlyBillingPeriod} />}
|
|
91
91
|
</PickerContainer>
|
|
92
92
|
);
|
|
93
93
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BillingPeriod } from '@stigg/js-client-sdk';
|
|
1
|
+
import { BillingPeriod, PaywallCalculatedPricePoint, Price } from '@stigg/js-client-sdk';
|
|
2
2
|
import isNil from 'lodash/isNil';
|
|
3
3
|
import { PaywallPlan } from '../paywall';
|
|
4
4
|
|
|
@@ -11,20 +11,32 @@ function calculateDiscountRate(monthlyPrice?: number | null, annuallyPrice?: num
|
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
function getPlanBillingPeriodAmount(plan: PaywallPlan, billingPeriod: BillingPeriod) {
|
|
15
|
+
let pricePoint: PaywallCalculatedPricePoint | Price | undefined;
|
|
16
|
+
|
|
17
|
+
pricePoint = plan.paywallCalculatedPricePoints?.find(price => price.billingPeriod === billingPeriod);
|
|
18
|
+
|
|
19
|
+
if (!pricePoint) {
|
|
20
|
+
pricePoint = plan.pricePoints.find(price => price.billingPeriod === billingPeriod);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (!pricePoint?.amount) {
|
|
24
|
+
const tieredPrice = plan.pricePoints.find(price => {
|
|
25
|
+
return price.isTieredPrice && price.billingPeriod === billingPeriod;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (tieredPrice) {
|
|
29
|
+
return tieredPrice.tiers![0].unitPrice.amount;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return pricePoint?.amount;
|
|
34
|
+
}
|
|
35
|
+
|
|
14
36
|
export function calculatePaywallDiscountRate(plans: PaywallPlan[]) {
|
|
15
37
|
return plans.reduce((maxDiscount, plan) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (plan.paywallCalculatedPricePoints?.length) {
|
|
20
|
-
monthlyAmount = plan.paywallCalculatedPricePoints?.find(price => price.billingPeriod === BillingPeriod.Monthly)
|
|
21
|
-
?.amount;
|
|
22
|
-
annuallyAmount = plan.paywallCalculatedPricePoints?.find(price => price.billingPeriod === BillingPeriod.Annually)
|
|
23
|
-
?.amount;
|
|
24
|
-
} else {
|
|
25
|
-
monthlyAmount = plan.pricePoints.find(price => price.billingPeriod === BillingPeriod.Monthly)?.amount;
|
|
26
|
-
annuallyAmount = plan.pricePoints.find(price => price.billingPeriod === BillingPeriod.Annually)?.amount;
|
|
27
|
-
}
|
|
38
|
+
const monthlyAmount = getPlanBillingPeriodAmount(plan, BillingPeriod.Monthly);
|
|
39
|
+
const annuallyAmount = getPlanBillingPeriodAmount(plan, BillingPeriod.Annually);
|
|
28
40
|
|
|
29
41
|
const discountRate = calculateDiscountRate(monthlyAmount, annuallyAmount);
|
|
30
42
|
if (discountRate) {
|