@stigg/react-sdk 4.4.6 → 4.5.1
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/react-sdk.cjs.development.js +60 -45
- 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 +60 -45
- 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 +12 -12
- package/src/components/checkout/summary/components/CheckoutCaptions.tsx +7 -5
- package/src/components/checkout/summary/components/LineItems.tsx +13 -5
- package/src/stories/mocks/checkout/mockCheckoutPreview.ts +24 -10
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "4.
|
|
2
|
+
"version": "4.5.1",
|
|
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.1",
|
|
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?.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,9 @@ export const CheckoutSummary = ({
|
|
|
313
311
|
</>
|
|
314
312
|
) : null}
|
|
315
313
|
|
|
316
|
-
{
|
|
314
|
+
{immediateInvoice?.proration?.hasProrations &&
|
|
315
|
+
immediateInvoice?.subTotal &&
|
|
316
|
+
immediateInvoice?.subTotal.amount > 0 ? (
|
|
317
317
|
<LineItemContainer>
|
|
318
318
|
<LineItemRow>
|
|
319
319
|
<Typography variant="body1" color="secondary">
|
|
@@ -322,8 +322,8 @@ export const CheckoutSummary = ({
|
|
|
322
322
|
<Typography variant="body1" color="secondary">
|
|
323
323
|
<WithSkeleton isLoading={isFetchingSubscriptionPreview}>
|
|
324
324
|
{currencyPriceFormatter({
|
|
325
|
-
amount:
|
|
326
|
-
currency:
|
|
325
|
+
amount: immediateInvoice?.subTotal?.amount + (immediateInvoice?.tax?.amount || 0),
|
|
326
|
+
currency: immediateInvoice?.subTotal.currency,
|
|
327
327
|
minimumFractionDigits: 2,
|
|
328
328
|
})}
|
|
329
329
|
</WithSkeleton>
|
|
@@ -343,7 +343,7 @@ export const CheckoutSummary = ({
|
|
|
343
343
|
<TotalDueText variant="h6">{checkoutLocalization.summary.totalDueText}</TotalDueText>
|
|
344
344
|
<TotalDueText variant="h6">
|
|
345
345
|
<WithSkeleton isLoading={isFetchingSubscriptionPreview}>
|
|
346
|
-
{currencyPriceFormatter({ amount: 0, ...
|
|
346
|
+
{currencyPriceFormatter({ amount: 0, ...immediateInvoice?.total, minimumFractionDigits: 2 })}
|
|
347
347
|
</WithSkeleton>
|
|
348
348
|
</TotalDueText>
|
|
349
349
|
</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,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,20 @@ 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
|
+
hasProrations: false,
|
|
144
|
+
},
|
|
136
145
|
},
|
|
146
|
+
|
|
147
|
+
recurringInvoice: {
|
|
148
|
+
...total,
|
|
149
|
+
},
|
|
150
|
+
billingPeriodRange: mockBillingPeriod(billingPeriod),
|
|
137
151
|
};
|
|
138
152
|
}
|