@stigg/react-sdk 4.4.5 → 4.5.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/checkout/summary/components/LineItems.d.ts +2 -2
- package/dist/components/common/TiersSelectContainer.d.ts +2 -1
- package/dist/components/paywall/PlanPrice.d.ts +2 -2
- package/dist/react-sdk.cjs.development.js +80 -67
- 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 +80 -67
- package/dist/react-sdk.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/components/checkout/promotionCode/AddPromotionCode.tsx +1 -1
- package/src/components/checkout/summary/CheckoutSummary.tsx +10 -12
- package/src/components/checkout/summary/components/CheckoutCaptions.tsx +7 -5
- package/src/components/checkout/summary/components/LineItems.tsx +13 -5
- package/src/components/common/TiersSelectContainer.tsx +3 -1
- package/src/components/paywall/PlanPrice.tsx +12 -17
- package/src/stories/mocks/checkout/mockCheckoutPreview.ts +23 -10
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "4.
|
|
2
|
+
"version": "4.5.0",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
"@emotion/react": "^11.10.5",
|
|
110
110
|
"@emotion/styled": "^11.10.5",
|
|
111
111
|
"@mui/material": "^5.10.13",
|
|
112
|
-
"@stigg/js-client-sdk": "2.
|
|
112
|
+
"@stigg/js-client-sdk": "2.24.0",
|
|
113
113
|
"@stripe/react-stripe-js": "^2.1.1",
|
|
114
114
|
"@stripe/stripe-js": "^1.54.1",
|
|
115
115
|
"@types/styled-components": "^5.1.26",
|
|
@@ -37,7 +37,7 @@ export const AddPromotionCode = ({
|
|
|
37
37
|
|
|
38
38
|
const { subscriptionPreview, errorMessage } = await previewSubscriptionAction({ promotionCode });
|
|
39
39
|
|
|
40
|
-
if (!errorMessage && subscriptionPreview?.discountDetails) {
|
|
40
|
+
if (!errorMessage && subscriptionPreview?.immediateInvoice?.discountDetails) {
|
|
41
41
|
persistPromotionCode(promotionCode.toUpperCase());
|
|
42
42
|
setShowInput(false);
|
|
43
43
|
} else if (errorMessage) {
|
|
@@ -153,13 +153,11 @@ export const CheckoutSummary = ({
|
|
|
153
153
|
}
|
|
154
154
|
};
|
|
155
155
|
|
|
156
|
+
const { immediateInvoice, recurringInvoice } = subscriptionPreview || {};
|
|
156
157
|
const checkoutHasChanges =
|
|
157
|
-
!!subscriptionPreview && (!!
|
|
158
|
+
!!subscriptionPreview && (!!immediateInvoice?.proration || !!subscriptionPreview.hasScheduledUpdates);
|
|
158
159
|
const showPromotionCodeLine = !disablePromotionCode && !isFreeDowngrade;
|
|
159
|
-
const showDiscountLine =
|
|
160
|
-
!!subscriptionPreview?.recurringSubscription &&
|
|
161
|
-
!!subscriptionPreview?.recurringSubscription?.discountDetails &&
|
|
162
|
-
!isFreeDowngrade;
|
|
160
|
+
const showDiscountLine = !!recurringInvoice && !!recurringInvoice?.discountDetails && !isFreeDowngrade;
|
|
163
161
|
const hasDiscounts = showPromotionCodeLine || showDiscountLine;
|
|
164
162
|
|
|
165
163
|
const hasPayAsYouGoCharges = usageCharges.some((price) => price.pricingModel === BillingModel.UsageBased);
|
|
@@ -274,8 +272,8 @@ export const CheckoutSummary = ({
|
|
|
274
272
|
{hasDiscounts && <StyledDivider className="stigg-checkout-summary-divider" />}
|
|
275
273
|
|
|
276
274
|
<TaxLineItem
|
|
277
|
-
tax={
|
|
278
|
-
taxDetails={
|
|
275
|
+
tax={recurringInvoice?.tax}
|
|
276
|
+
taxDetails={recurringInvoice?.taxDetails}
|
|
279
277
|
isFetchingSubscriptionPreview={isFetchingSubscriptionPreview}
|
|
280
278
|
checkoutLocalization={checkoutLocalization}
|
|
281
279
|
/>
|
|
@@ -295,7 +293,7 @@ export const CheckoutSummary = ({
|
|
|
295
293
|
{!onlyPayAsYouGoCharges
|
|
296
294
|
? currencyPriceFormatter({
|
|
297
295
|
amount: 0,
|
|
298
|
-
...
|
|
296
|
+
...recurringInvoice?.total,
|
|
299
297
|
minimumFractionDigits: 2,
|
|
300
298
|
})
|
|
301
299
|
: null}
|
|
@@ -313,7 +311,7 @@ export const CheckoutSummary = ({
|
|
|
313
311
|
</>
|
|
314
312
|
) : null}
|
|
315
313
|
|
|
316
|
-
{
|
|
314
|
+
{immediateInvoice?.subTotal && immediateInvoice?.subTotal.amount > 0 ? (
|
|
317
315
|
<LineItemContainer>
|
|
318
316
|
<LineItemRow>
|
|
319
317
|
<Typography variant="body1" color="secondary">
|
|
@@ -322,8 +320,8 @@ export const CheckoutSummary = ({
|
|
|
322
320
|
<Typography variant="body1" color="secondary">
|
|
323
321
|
<WithSkeleton isLoading={isFetchingSubscriptionPreview}>
|
|
324
322
|
{currencyPriceFormatter({
|
|
325
|
-
amount:
|
|
326
|
-
currency:
|
|
323
|
+
amount: immediateInvoice?.subTotal?.amount + (immediateInvoice?.tax?.amount || 0),
|
|
324
|
+
currency: immediateInvoice?.subTotal.currency,
|
|
327
325
|
minimumFractionDigits: 2,
|
|
328
326
|
})}
|
|
329
327
|
</WithSkeleton>
|
|
@@ -343,7 +341,7 @@ export const CheckoutSummary = ({
|
|
|
343
341
|
<TotalDueText variant="h6">{checkoutLocalization.summary.totalDueText}</TotalDueText>
|
|
344
342
|
<TotalDueText variant="h6">
|
|
345
343
|
<WithSkeleton isLoading={isFetchingSubscriptionPreview}>
|
|
346
|
-
{currencyPriceFormatter({ amount: 0, ...
|
|
344
|
+
{currencyPriceFormatter({ amount: 0, ...immediateInvoice?.total, minimumFractionDigits: 2 })}
|
|
347
345
|
</WithSkeleton>
|
|
348
346
|
</TotalDueText>
|
|
349
347
|
</LineItemRow>
|
|
@@ -21,15 +21,16 @@ const RemainingCreditsCaption = ({
|
|
|
21
21
|
isFetchingSubscriptionPreview,
|
|
22
22
|
checkoutLocalization,
|
|
23
23
|
}: CheckoutCaptionProps) => {
|
|
24
|
-
|
|
24
|
+
const { immediateInvoice } = subscriptionPreview || {};
|
|
25
|
+
if (!immediateInvoice?.proration?.netAmount?.amount || immediateInvoice?.proration?.netAmount?.amount >= 0) {
|
|
25
26
|
return null;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
const positiveAmount =
|
|
29
|
+
const positiveAmount = immediateInvoice.proration.netAmount.amount * -1;
|
|
29
30
|
|
|
30
31
|
const credits = currencyPriceFormatter({
|
|
31
32
|
amount: positiveAmount,
|
|
32
|
-
currency:
|
|
33
|
+
currency: immediateInvoice.proration.netAmount.currency,
|
|
33
34
|
minimumFractionDigits: 2,
|
|
34
35
|
});
|
|
35
36
|
|
|
@@ -74,7 +75,8 @@ const NextBillingCaption = ({
|
|
|
74
75
|
isFetchingSubscriptionPreview,
|
|
75
76
|
billingPeriod,
|
|
76
77
|
}: CheckoutCaptionProps) => {
|
|
77
|
-
|
|
78
|
+
const { recurringInvoice } = subscriptionPreview || {};
|
|
79
|
+
if (!subscriptionPreview || !recurringInvoice?.total.amount) {
|
|
78
80
|
return null;
|
|
79
81
|
}
|
|
80
82
|
|
|
@@ -83,7 +85,7 @@ const NextBillingCaption = ({
|
|
|
83
85
|
: subscriptionPreview?.billingPeriodRange.end;
|
|
84
86
|
|
|
85
87
|
const total = currencyPriceFormatter({
|
|
86
|
-
...
|
|
88
|
+
...recurringInvoice.total,
|
|
87
89
|
minimumFractionDigits: 2,
|
|
88
90
|
});
|
|
89
91
|
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import styled from '@emotion/styled/macro';
|
|
3
3
|
import { Grid } from '@mui/material';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
BillingModel,
|
|
6
|
+
BillingPeriod,
|
|
7
|
+
Price,
|
|
8
|
+
SubscriptionPreviewInvoice,
|
|
9
|
+
SubscriptionPreviewV2,
|
|
10
|
+
} from '@stigg/js-client-sdk';
|
|
5
11
|
import { Typography } from '../../../common/Typography';
|
|
6
12
|
import { currencyPriceFormatter } from '../../../utils/currencyUtils';
|
|
7
13
|
import { getTierByQuantity } from '../../../utils/priceTierUtils';
|
|
@@ -123,7 +129,8 @@ export const DiscountLineItem = ({
|
|
|
123
129
|
isFetchingSubscriptionPreview: boolean;
|
|
124
130
|
checkoutLocalization: CheckoutLocalization;
|
|
125
131
|
}) => {
|
|
126
|
-
const {
|
|
132
|
+
const { immediateInvoice, recurringInvoice } = subscriptionPreview;
|
|
133
|
+
const { discount, discountDetails } = recurringInvoice || {};
|
|
127
134
|
if (!discount || !discountDetails) {
|
|
128
135
|
return null;
|
|
129
136
|
}
|
|
@@ -134,7 +141,7 @@ export const DiscountLineItem = ({
|
|
|
134
141
|
<Typography variant="body1" color="secondary">
|
|
135
142
|
{checkoutLocalization.summary.discountText({
|
|
136
143
|
discountDetails,
|
|
137
|
-
currency:
|
|
144
|
+
currency: immediateInvoice.total.currency,
|
|
138
145
|
})}
|
|
139
146
|
</Typography>
|
|
140
147
|
<Typography variant="body1" color="secondary">
|
|
@@ -162,7 +169,8 @@ export const AppliedCreditsLineItem = ({
|
|
|
162
169
|
isFetchingSubscriptionPreview: boolean;
|
|
163
170
|
checkoutLocalization: CheckoutLocalization;
|
|
164
171
|
}) => {
|
|
165
|
-
const {
|
|
172
|
+
const { immediateInvoice } = subscriptionPreview || {};
|
|
173
|
+
const { credits } = immediateInvoice || {};
|
|
166
174
|
|
|
167
175
|
if (!credits || !credits.used || credits.used.amount <= 0) {
|
|
168
176
|
return null;
|
|
@@ -196,7 +204,7 @@ export const TaxLineItem = ({
|
|
|
196
204
|
}: {
|
|
197
205
|
isFetchingSubscriptionPreview: boolean;
|
|
198
206
|
checkoutLocalization: CheckoutLocalization;
|
|
199
|
-
} & Pick<
|
|
207
|
+
} & Pick<SubscriptionPreviewInvoice, 'tax' | 'taxDetails'>) => {
|
|
200
208
|
if (!taxDetails || !tax || tax?.amount <= 0) {
|
|
201
209
|
return null;
|
|
202
210
|
}
|
|
@@ -29,11 +29,13 @@ const TierInput = styled(OutlinedInput)`
|
|
|
29
29
|
export function TiersSelectContainer({
|
|
30
30
|
componentId,
|
|
31
31
|
tiers,
|
|
32
|
+
tierUnits,
|
|
32
33
|
selectedTier,
|
|
33
34
|
handleTierChange,
|
|
34
35
|
}: {
|
|
35
36
|
componentId: string;
|
|
36
37
|
tiers?: PriceTierFragment[] | null;
|
|
38
|
+
tierUnits?: string;
|
|
37
39
|
selectedTier?: PriceTierFragment;
|
|
38
40
|
handleTierChange: (tier: PriceTierFragment) => void;
|
|
39
41
|
}) {
|
|
@@ -61,7 +63,7 @@ export function TiersSelectContainer({
|
|
|
61
63
|
{map(tiers, (tier: PriceTierFragment) => (
|
|
62
64
|
<MenuItem className="stigg-price-tier-menu-item-text" key={tier.upTo} value={tier.upTo.toString()}>
|
|
63
65
|
<Typography variant="body1" color="primary" style={{ lineHeight: 'unset' }}>
|
|
64
|
-
{tier.upTo}
|
|
66
|
+
{tier.upTo} {tierUnits}
|
|
65
67
|
</Typography>
|
|
66
68
|
</MenuItem>
|
|
67
69
|
))}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import styled from '@emotion/styled/macro';
|
|
3
3
|
import { BillingPeriod, PriceTierFragment } from '@stigg/js-client-sdk';
|
|
4
4
|
import { PaywallPlan } from './types';
|
|
@@ -71,7 +71,7 @@ export const PlanPrice = ({
|
|
|
71
71
|
withStartingAtRow: boolean;
|
|
72
72
|
withTiersRow: boolean;
|
|
73
73
|
selectedTierByFeature: Record<string, PriceTierFragment>;
|
|
74
|
-
setSelectedTierByFeature:
|
|
74
|
+
setSelectedTierByFeature: React.Dispatch<React.SetStateAction<Record<string, PriceTierFragment>>>;
|
|
75
75
|
plan: PaywallPlan;
|
|
76
76
|
billingPeriod: BillingPeriod;
|
|
77
77
|
paywallLocale: PaywallLocalization;
|
|
@@ -79,7 +79,7 @@ export const PlanPrice = ({
|
|
|
79
79
|
hasAnnuallyPrice: boolean;
|
|
80
80
|
locale: string;
|
|
81
81
|
}) => {
|
|
82
|
-
const { price, unit, tiers } = getPlanPrice(
|
|
82
|
+
const { price, unit, tiers, tierUnits } = getPlanPrice(
|
|
83
83
|
plan,
|
|
84
84
|
billingPeriod,
|
|
85
85
|
paywallLocale,
|
|
@@ -87,31 +87,25 @@ export const PlanPrice = ({
|
|
|
87
87
|
hasMonthlyPrice,
|
|
88
88
|
selectedTierByFeature,
|
|
89
89
|
);
|
|
90
|
-
const [selectedTier, setSelectedTier] = useState<PriceTierFragment>();
|
|
91
90
|
|
|
92
91
|
// We currently only support prices with one tier - so we select the first one
|
|
93
92
|
const tieredPrice = plan.pricePoints.find((planPrice) => {
|
|
94
93
|
return planPrice.billingPeriod === billingPeriod && planPrice.isTieredPrice;
|
|
95
94
|
});
|
|
96
95
|
const featureId = tieredPrice ? tieredPrice.feature!.featureId : undefined;
|
|
97
|
-
|
|
98
|
-
useEffect(() => {
|
|
99
|
-
setSelectedTier(featureId ? selectedTierByFeature[featureId] : undefined);
|
|
100
|
-
}, [featureId, selectedTierByFeature]);
|
|
96
|
+
const selectedTier = featureId ? selectedTierByFeature[featureId] : undefined;
|
|
101
97
|
|
|
102
98
|
const handleTierChange = (tier: PriceTierFragment) => {
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
if (!featureId) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
105
102
|
|
|
106
|
-
setSelectedTierByFeature(
|
|
103
|
+
setSelectedTierByFeature((prevState) => ({
|
|
104
|
+
...prevState,
|
|
105
|
+
[featureId]: tier,
|
|
106
|
+
}));
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
-
useEffect(() => {
|
|
110
|
-
if (tiers) {
|
|
111
|
-
handleTierChange(selectedTierByFeature[featureId!]);
|
|
112
|
-
}
|
|
113
|
-
}, []);
|
|
114
|
-
|
|
115
109
|
return (
|
|
116
110
|
<PlanPriceContainer className="stigg-price-text">
|
|
117
111
|
<>
|
|
@@ -147,6 +141,7 @@ export const PlanPrice = ({
|
|
|
147
141
|
<TiersSelectContainer
|
|
148
142
|
componentId={`${plan.id}_${featureId}_tier`}
|
|
149
143
|
tiers={tiers}
|
|
144
|
+
tierUnits={tierUnits}
|
|
150
145
|
selectedTier={selectedTier}
|
|
151
146
|
handleTierChange={handleTierChange}
|
|
152
147
|
/>
|
|
@@ -29,9 +29,16 @@ const defaultPreviewSubscription = (): SubscriptionPreviewV2 => {
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
return {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
immediateInvoice: {
|
|
33
|
+
subTotal: defaultCost,
|
|
34
|
+
total: defaultCost,
|
|
35
|
+
totalExcludingTax: defaultCost,
|
|
36
|
+
},
|
|
37
|
+
recurringInvoice: {
|
|
38
|
+
subTotal: defaultCost,
|
|
39
|
+
total: defaultCost,
|
|
40
|
+
totalExcludingTax: defaultCost,
|
|
41
|
+
},
|
|
35
42
|
billingPeriodRange: mockBillingPeriod(),
|
|
36
43
|
};
|
|
37
44
|
};
|
|
@@ -126,13 +133,19 @@ export function mockPreviewSubscription(input: PreviewSubscription): Subscriptio
|
|
|
126
133
|
}
|
|
127
134
|
|
|
128
135
|
return {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
immediateInvoice: {
|
|
137
|
+
...total,
|
|
138
|
+
proration: {
|
|
139
|
+
prorationDate: moment().toDate(),
|
|
140
|
+
credit: total.total,
|
|
141
|
+
debit: total.total,
|
|
142
|
+
netAmount: total.total,
|
|
143
|
+
},
|
|
136
144
|
},
|
|
145
|
+
|
|
146
|
+
recurringInvoice: {
|
|
147
|
+
...total,
|
|
148
|
+
},
|
|
149
|
+
billingPeriodRange: mockBillingPeriod(billingPeriod),
|
|
137
150
|
};
|
|
138
151
|
}
|