@stigg/react-sdk 4.3.0-beta.0 → 4.3.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/README.md +1 -1
- package/dist/components/common/Icon.d.ts +2 -3
- package/dist/components/common/PoweredByStigg.d.ts +1 -1
- package/dist/components/common/customIcons.d.ts +5 -17
- package/dist/components/common/mapExternalTheme.d.ts +0 -2
- package/dist/components/customerPortal/subscriptionOverview/tabs/SubscriptionTabs.d.ts +1 -1
- package/dist/components/{common/TiersSelectContainer.d.ts → paywall/TiersLayout.d.ts} +3 -2
- package/dist/components/paywall/paywallTextOverrides.d.ts +2 -0
- package/dist/components/{utils/priceTierUtils.d.ts → paywall/planPriceTier.d.ts} +1 -3
- package/dist/components/utils/calculateDiscountRate.d.ts +0 -1
- package/dist/components/utils/currencyUtils.d.ts +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/react-sdk.cjs.development.js +201 -3447
- 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 +207 -3590
- package/dist/react-sdk.esm.js.map +1 -1
- package/dist/theme/getResolvedTheme.d.ts +0 -1
- package/dist/theme/types.d.ts +0 -1
- package/package.json +22 -11
- package/src/components/StiggProvider.tsx +2 -0
- package/src/components/common/Icon.tsx +22 -17
- package/src/components/common/PoweredByStigg.tsx +1 -1
- package/src/components/common/Typography.tsx +1 -11
- package/src/components/common/customIcons.ts +28 -17
- package/src/components/common/mapExternalTheme.ts +0 -6
- package/src/components/customerPortal/subscriptionOverview/tabs/SubscriptionTabs.tsx +12 -6
- package/src/components/paywall/Paywall.tsx +1 -1
- package/src/components/paywall/PlanOffering.tsx +1 -1
- package/src/components/paywall/PlanOfferingButton.tsx +1 -1
- package/src/components/paywall/PlanPrice.tsx +13 -5
- package/src/components/{common/TiersSelectContainer.tsx → paywall/TiersLayout.tsx} +7 -8
- package/src/components/paywall/paywallTextOverrides.ts +1 -0
- package/src/components/{utils/priceTierUtils.ts → paywall/planPriceTier.ts} +3 -25
- package/src/components/paywall/utils/calculateUnitQuantityText.ts +4 -9
- package/src/components/utils/calculateDiscountRate.ts +1 -1
- package/src/components/utils/currencyUtils.ts +1 -1
- package/src/components/utils/getPaidPriceText.ts +2 -2
- package/src/index.ts +0 -1
- package/src/stories/CustomerPortal.stories.tsx +11 -11
- package/src/stories/Paywall.stories.tsx +4 -6
- package/src/stories/baseArgs.ts +1 -1
- package/src/theme/Fonts.tsx +1 -1
- package/src/theme/Theme.tsx +7 -9
- package/src/theme/getResolvedTheme.ts +0 -1
- package/src/theme/types.ts +0 -1
- package/dist/components/checkout/Checkout.d.ts +0 -5
- package/dist/components/checkout/CheckoutContainer.d.ts +0 -22
- package/dist/components/checkout/CheckoutContainer.style.d.ts +0 -29
- package/dist/components/checkout/CheckoutProvider.d.ts +0 -33
- package/dist/components/checkout/CheckoutSummary.d.ts +0 -9
- package/dist/components/checkout/components/Button.d.ts +0 -6
- package/dist/components/checkout/components/InputField.d.ts +0 -8
- package/dist/components/checkout/components/index.d.ts +0 -2
- package/dist/components/checkout/formatting.d.ts +0 -2
- package/dist/components/checkout/hooks/index.d.ts +0 -8
- package/dist/components/checkout/hooks/useAddonsStepModel.d.ts +0 -21
- package/dist/components/checkout/hooks/useCheckoutModel.d.ts +0 -9
- package/dist/components/checkout/hooks/useCouponModel.d.ts +0 -7
- package/dist/components/checkout/hooks/useLoadCheckout.d.ts +0 -13
- package/dist/components/checkout/hooks/usePaymentStepModel.d.ts +0 -16
- package/dist/components/checkout/hooks/usePlanStepModel.d.ts +0 -23
- package/dist/components/checkout/hooks/usePreviewSubscription.d.ts +0 -13
- package/dist/components/checkout/hooks/useProgressBarModel.d.ts +0 -26
- package/dist/components/checkout/hooks/useSubscriptionModel.d.ts +0 -5
- package/dist/components/checkout/hooks/useSubscriptionState.d.ts +0 -2
- package/dist/components/checkout/index.d.ts +0 -3
- package/dist/components/checkout/planHeader/PlanHeader.d.ts +0 -7
- package/dist/components/checkout/planHeader/PlanHeader.style.d.ts +0 -25
- package/dist/components/checkout/planHeader/index.d.ts +0 -1
- package/dist/components/checkout/progressBar/CheckoutProgressBar.d.ts +0 -2
- package/dist/components/checkout/progressBar/CheckoutProgressBar.style.d.ts +0 -45
- package/dist/components/checkout/promotionCode/AddPromotionCode.d.ts +0 -5
- package/dist/components/checkout/promotionCode/AddPromotionCodeButton.d.ts +0 -7
- package/dist/components/checkout/promotionCode/AppliedPromotionCode.d.ts +0 -6
- package/dist/components/checkout/promotionCode/PromotionCodeSection.d.ts +0 -5
- package/dist/components/checkout/promotionCode/index.d.ts +0 -1
- package/dist/components/checkout/steps/addons/CheckoutAddonsStep.d.ts +0 -2
- package/dist/components/checkout/steps/addons/CheckoutAddonsStep.style.d.ts +0 -93
- package/dist/components/checkout/steps/addons/addon.utils.d.ts +0 -15
- package/dist/components/checkout/steps/addons/index.d.ts +0 -1
- package/dist/components/checkout/steps/payment/PaymentMethods.d.ts +0 -19
- package/dist/components/checkout/steps/payment/PaymentMethods.style.d.ts +0 -113
- package/dist/components/checkout/steps/payment/PaymentStep.d.ts +0 -2
- package/dist/components/checkout/steps/payment/index.d.ts +0 -1
- package/dist/components/checkout/steps/payment/stripe/StripePaymentForm.d.ts +0 -2
- package/dist/components/checkout/steps/payment/stripe/index.d.ts +0 -3
- package/dist/components/checkout/steps/payment/stripe/stripe.utils.d.ts +0 -33
- package/dist/components/checkout/steps/payment/stripe/useStripeIntegration.d.ts +0 -5
- package/dist/components/checkout/steps/payment/stripe/useSubmit.d.ts +0 -10
- package/dist/components/checkout/steps/plan/BillingPeriodPicker.d.ts +0 -9
- package/dist/components/checkout/steps/plan/BillingPeriodPicker.style.d.ts +0 -52
- package/dist/components/checkout/steps/plan/CheckoutChargeList.d.ts +0 -16
- package/dist/components/checkout/steps/plan/CheckoutPlanStep.d.ts +0 -4
- package/dist/components/checkout/steps/plan/CheckoutPlanStep.style.d.ts +0 -12
- package/dist/components/checkout/steps/plan/index.d.ts +0 -1
- package/dist/components/checkout/steps/surprise/SurpriseStep.d.ts +0 -2
- package/dist/components/checkout/textOverrides.d.ts +0 -28
- package/dist/components/checkout/theme.d.ts +0 -8
- package/dist/components/checkout/types.d.ts +0 -7
- package/dist/components/hooks/useChargeSort.d.ts +0 -3
- package/dist/components/utils/priceUtils.d.ts +0 -2
- package/dist/stories/Checkout.stories.d.ts +0 -3
- package/src/assets/arrow-forward.svg +0 -3
- package/src/assets/arrow-right.svg +0 -6
- package/src/assets/close.svg +0 -3
- package/src/assets/nyancat.svg +0 -634
- package/src/assets/outlined-checked-circle.svg +0 -6
- package/src/assets/outlined-circle.svg +0 -3
- package/src/assets/payment-method.svg +0 -11
- package/src/assets/plus-icon.svg +0 -6
- package/src/assets/trash.svg +0 -8
- package/src/components/checkout/Checkout.tsx +0 -30
- package/src/components/checkout/CheckoutContainer.style.ts +0 -34
- package/src/components/checkout/CheckoutContainer.tsx +0 -92
- package/src/components/checkout/CheckoutProvider.tsx +0 -135
- package/src/components/checkout/CheckoutSummary.tsx +0 -361
- package/src/components/checkout/components/Button.tsx +0 -30
- package/src/components/checkout/components/InputField.tsx +0 -23
- package/src/components/checkout/components/index.ts +0 -2
- package/src/components/checkout/formatting.ts +0 -12
- package/src/components/checkout/hooks/index.ts +0 -8
- package/src/components/checkout/hooks/useAddonsStepModel.ts +0 -96
- package/src/components/checkout/hooks/useCheckoutModel.ts +0 -31
- package/src/components/checkout/hooks/useCouponModel.ts +0 -28
- package/src/components/checkout/hooks/useLoadCheckout.ts +0 -40
- package/src/components/checkout/hooks/usePaymentStepModel.ts +0 -49
- package/src/components/checkout/hooks/usePlanStepModel.ts +0 -170
- package/src/components/checkout/hooks/usePreviewSubscription.ts +0 -82
- package/src/components/checkout/hooks/useProgressBarModel.ts +0 -89
- package/src/components/checkout/hooks/useSubscriptionModel.ts +0 -16
- package/src/components/checkout/hooks/useSubscriptionState.ts +0 -26
- package/src/components/checkout/index.ts +0 -3
- package/src/components/checkout/planHeader/PlanHeader.style.tsx +0 -23
- package/src/components/checkout/planHeader/PlanHeader.tsx +0 -61
- package/src/components/checkout/planHeader/index.ts +0 -1
- package/src/components/checkout/progressBar/CheckoutProgressBar.style.ts +0 -29
- package/src/components/checkout/progressBar/CheckoutProgressBar.tsx +0 -48
- package/src/components/checkout/promotionCode/AddPromotionCode.tsx +0 -85
- package/src/components/checkout/promotionCode/AddPromotionCodeButton.tsx +0 -39
- package/src/components/checkout/promotionCode/AppliedPromotionCode.tsx +0 -37
- package/src/components/checkout/promotionCode/PromotionCodeSection.tsx +0 -27
- package/src/components/checkout/promotionCode/index.ts +0 -1
- package/src/components/checkout/steps/addons/CheckoutAddonsStep.style.tsx +0 -24
- package/src/components/checkout/steps/addons/CheckoutAddonsStep.tsx +0 -125
- package/src/components/checkout/steps/addons/addon.utils.ts +0 -68
- package/src/components/checkout/steps/addons/index.ts +0 -1
- package/src/components/checkout/steps/payment/PaymentMethods.style.ts +0 -26
- package/src/components/checkout/steps/payment/PaymentMethods.tsx +0 -83
- package/src/components/checkout/steps/payment/PaymentStep.tsx +0 -41
- package/src/components/checkout/steps/payment/index.ts +0 -1
- package/src/components/checkout/steps/payment/stripe/StripePaymentForm.tsx +0 -43
- package/src/components/checkout/steps/payment/stripe/index.ts +0 -3
- package/src/components/checkout/steps/payment/stripe/stripe.utils.ts +0 -109
- package/src/components/checkout/steps/payment/stripe/useStripeIntegration.ts +0 -27
- package/src/components/checkout/steps/payment/stripe/useSubmit.ts +0 -100
- package/src/components/checkout/steps/plan/BillingPeriodPicker.style.tsx +0 -46
- package/src/components/checkout/steps/plan/BillingPeriodPicker.tsx +0 -63
- package/src/components/checkout/steps/plan/CheckoutChargeList.tsx +0 -138
- package/src/components/checkout/steps/plan/CheckoutPlanStep.style.tsx +0 -6
- package/src/components/checkout/steps/plan/CheckoutPlanStep.tsx +0 -22
- package/src/components/checkout/steps/plan/index.ts +0 -1
- package/src/components/checkout/steps/surprise/SurpriseStep.tsx +0 -27
- package/src/components/checkout/textOverrides.ts +0 -58
- package/src/components/checkout/theme.ts +0 -26
- package/src/components/checkout/types.ts +0 -7
- package/src/components/hooks/useChargeSort.ts +0 -17
- package/src/components/utils/priceUtils.ts +0 -10
- package/src/stories/Checkout.stories.tsx +0 -59
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import styled from '@emotion/styled/macro';
|
|
3
|
-
import { Grid } from '@mui/material';
|
|
4
|
-
import { Icon } from '../../common/Icon';
|
|
5
|
-
import { Typography } from '../../common/Typography';
|
|
6
|
-
import { Button } from '../components';
|
|
7
|
-
|
|
8
|
-
const AppliedCouponContainer = styled(Grid)`
|
|
9
|
-
width: auto;
|
|
10
|
-
display: inline-flex;
|
|
11
|
-
align-items: center;
|
|
12
|
-
flex-direction: row;
|
|
13
|
-
gap: 8px;
|
|
14
|
-
padding: 6px 16px;
|
|
15
|
-
border-radius: ${({ theme }) => theme.stigg.border.radius};
|
|
16
|
-
border: 1px solid ${({ theme }) => theme.stigg.palette.primary};
|
|
17
|
-
`;
|
|
18
|
-
|
|
19
|
-
export type AppliedPromotionCodeProps = {
|
|
20
|
-
promotionCode: string;
|
|
21
|
-
onClearPromotionCode: () => void;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const AppliedPromotionCode = ({ promotionCode, onClearPromotionCode }: AppliedPromotionCodeProps) => (
|
|
25
|
-
<AppliedCouponContainer container>
|
|
26
|
-
<Grid item>
|
|
27
|
-
<Typography variant="body1" color="primary.main">
|
|
28
|
-
{promotionCode}
|
|
29
|
-
</Typography>
|
|
30
|
-
</Grid>
|
|
31
|
-
<Grid item>
|
|
32
|
-
<Button variant="text" sx={{ minWidth: 'unset', padding: 0 }} onClick={onClearPromotionCode}>
|
|
33
|
-
<Icon icon="Close" style={{ display: 'flex' }} />
|
|
34
|
-
</Button>
|
|
35
|
-
</Grid>
|
|
36
|
-
</AppliedCouponContainer>
|
|
37
|
-
);
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import styled from '@emotion/styled/macro';
|
|
3
|
-
import { usePromotionCodeModel } from '../hooks/useCouponModel';
|
|
4
|
-
import { AddPromotionCode } from './AddPromotionCode';
|
|
5
|
-
import { AppliedPromotionCode } from './AppliedPromotionCode';
|
|
6
|
-
import { CheckoutLocalization } from '../textOverrides';
|
|
7
|
-
|
|
8
|
-
const PromotionCodeSectionContainer = styled.div`
|
|
9
|
-
margin: 16px 0;
|
|
10
|
-
`;
|
|
11
|
-
|
|
12
|
-
export const PromotionCodeSection = ({ checkoutLocalization }: { checkoutLocalization: CheckoutLocalization }) => {
|
|
13
|
-
const { promotionCode, setPromotionCode } = usePromotionCodeModel();
|
|
14
|
-
|
|
15
|
-
const onClearPromotionCode = () => {
|
|
16
|
-
setPromotionCode('');
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
let content: React.ReactNode = null;
|
|
20
|
-
if (promotionCode) {
|
|
21
|
-
content = <AppliedPromotionCode promotionCode={promotionCode} onClearPromotionCode={onClearPromotionCode} />;
|
|
22
|
-
} else {
|
|
23
|
-
content = <AddPromotionCode checkoutLocalization={checkoutLocalization} />;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return <PromotionCodeSectionContainer>{content}</PromotionCodeSectionContainer>;
|
|
27
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './PromotionCodeSection';
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import styled from '@emotion/styled/macro';
|
|
2
|
-
import { Grid } from '@mui/material';
|
|
3
|
-
|
|
4
|
-
import { Button } from '../../components';
|
|
5
|
-
|
|
6
|
-
export const CheckoutAddonsContainer = styled(Grid)`
|
|
7
|
-
width: 100%;
|
|
8
|
-
margin-top: 32px;
|
|
9
|
-
gap: 8px;
|
|
10
|
-
`;
|
|
11
|
-
|
|
12
|
-
export const AddonListItemContainer = styled(Grid)`
|
|
13
|
-
display: flex;
|
|
14
|
-
justify-content: space-between;
|
|
15
|
-
align-items: center;
|
|
16
|
-
height: 80px;
|
|
17
|
-
`;
|
|
18
|
-
|
|
19
|
-
export const TrashButton = styled(Button)`
|
|
20
|
-
min-width: unset;
|
|
21
|
-
width: 41px;
|
|
22
|
-
height: 41px;
|
|
23
|
-
padding: 0;
|
|
24
|
-
`;
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import { Grid } from '@mui/material';
|
|
4
|
-
import { Addon, BillingPeriod, SubscriptionAddon } from '@stigg/js-client-sdk';
|
|
5
|
-
|
|
6
|
-
import { Icon } from '../../../common/Icon';
|
|
7
|
-
import { Typography } from '../../../common/Typography';
|
|
8
|
-
import { currencyPriceFormatter } from '../../../utils/currencyUtils';
|
|
9
|
-
import { Button, InputField } from '../../components';
|
|
10
|
-
import { useAddonsStepModel } from '../../hooks/useAddonsStepModel';
|
|
11
|
-
import { usePlanStepModel } from '../../hooks/usePlanStepModel';
|
|
12
|
-
import { AddonListItemContainer, CheckoutAddonsContainer, TrashButton } from './CheckoutAddonsStep.style';
|
|
13
|
-
import { CheckoutLocalization } from '../../textOverrides';
|
|
14
|
-
import { useCheckoutModel } from '../../hooks';
|
|
15
|
-
|
|
16
|
-
type UseAddonsStepModel = ReturnType<typeof useAddonsStepModel>;
|
|
17
|
-
|
|
18
|
-
type AddonListItemProps = {
|
|
19
|
-
addon: Addon;
|
|
20
|
-
addonState?: SubscriptionAddon;
|
|
21
|
-
initialAddonState?: SubscriptionAddon;
|
|
22
|
-
billingPeriod: BillingPeriod;
|
|
23
|
-
setAddon: UseAddonsStepModel['setAddon'];
|
|
24
|
-
removeAddon: UseAddonsStepModel['removeAddon'];
|
|
25
|
-
checkoutLocalization: CheckoutLocalization;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
function AddonListItem({
|
|
29
|
-
addon,
|
|
30
|
-
billingPeriod,
|
|
31
|
-
addonState,
|
|
32
|
-
initialAddonState,
|
|
33
|
-
setAddon,
|
|
34
|
-
removeAddon,
|
|
35
|
-
checkoutLocalization,
|
|
36
|
-
}: AddonListItemProps) {
|
|
37
|
-
const addonPrice = addon.pricePoints.find((pricePoint) => pricePoint.billingPeriod === billingPeriod);
|
|
38
|
-
const isAdded = !!addonState;
|
|
39
|
-
const hasChanges =
|
|
40
|
-
(!!addonState && !!initialAddonState && addonState.quantity !== initialAddonState.quantity) ||
|
|
41
|
-
(!initialAddonState && !!addonState) ||
|
|
42
|
-
(!!initialAddonState && !addonState);
|
|
43
|
-
|
|
44
|
-
const handleQuantityChange = (quantity?: number) => {
|
|
45
|
-
setAddon(addon, quantity || 1);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const handleUndo = () => {
|
|
49
|
-
initialAddonState ? setAddon(addon, initialAddonState.quantity) : removeAddon(addon.id);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<AddonListItemContainer container>
|
|
54
|
-
<Grid item>
|
|
55
|
-
<Typography variant="h6" lineHeight="24px">
|
|
56
|
-
{addon.displayName}
|
|
57
|
-
</Typography>
|
|
58
|
-
{!!addonPrice && (
|
|
59
|
-
<Typography variant="body1" lineHeight="20px" color="secondary">
|
|
60
|
-
{`${currencyPriceFormatter({
|
|
61
|
-
amount: addonPrice.amount!,
|
|
62
|
-
currency: addonPrice.currency,
|
|
63
|
-
})}/${billingPeriod === BillingPeriod.Annually ? 'year' : 'month'}`}
|
|
64
|
-
</Typography>
|
|
65
|
-
)}
|
|
66
|
-
</Grid>
|
|
67
|
-
<Grid item>
|
|
68
|
-
{hasChanges && (
|
|
69
|
-
<Button variant="text" size="small" sx={{ padding: '8px', minWidth: 'unset' }} onClick={handleUndo}>
|
|
70
|
-
<Typography color="primary.main" variant="body1">
|
|
71
|
-
Undo
|
|
72
|
-
</Typography>
|
|
73
|
-
</Button>
|
|
74
|
-
)}
|
|
75
|
-
{isAdded && (
|
|
76
|
-
<>
|
|
77
|
-
<InputField
|
|
78
|
-
id={`${addon.id}-input`}
|
|
79
|
-
type="number"
|
|
80
|
-
sx={{ width: 120, marginX: 2 }}
|
|
81
|
-
value={addonState?.quantity || 1}
|
|
82
|
-
onChange={(event) => handleQuantityChange(event?.target?.value ? Number(event?.target?.value) : 1)}
|
|
83
|
-
/>
|
|
84
|
-
<TrashButton color="error" onClick={() => removeAddon(addon.id)}>
|
|
85
|
-
<Icon icon="Trash" style={{ display: 'flex' }} />
|
|
86
|
-
</TrashButton>
|
|
87
|
-
</>
|
|
88
|
-
)}
|
|
89
|
-
{!isAdded && (
|
|
90
|
-
<Button sx={{ paddingX: '22px', paddingY: '8px' }} onClick={() => handleQuantityChange()}>
|
|
91
|
-
{checkoutLocalization.addAddonText}
|
|
92
|
-
</Button>
|
|
93
|
-
)}
|
|
94
|
-
</Grid>
|
|
95
|
-
</AddonListItemContainer>
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function CheckoutAddonsStep() {
|
|
100
|
-
const { checkoutLocalization } = useCheckoutModel();
|
|
101
|
-
const { billingPeriod } = usePlanStepModel();
|
|
102
|
-
const { initialAddons, addons, availableAddons, setAddon, removeAddon } = useAddonsStepModel();
|
|
103
|
-
|
|
104
|
-
return (
|
|
105
|
-
<CheckoutAddonsContainer container>
|
|
106
|
-
{availableAddons?.map((addon) => {
|
|
107
|
-
const addonState = addons.find((x) => x.addon.id === addon.id);
|
|
108
|
-
const initialAddonState = initialAddons?.find((x) => x.addon.id === addon.id);
|
|
109
|
-
|
|
110
|
-
return (
|
|
111
|
-
<AddonListItem
|
|
112
|
-
key={addon.id}
|
|
113
|
-
addon={addon}
|
|
114
|
-
billingPeriod={billingPeriod}
|
|
115
|
-
addonState={addonState}
|
|
116
|
-
initialAddonState={initialAddonState}
|
|
117
|
-
setAddon={setAddon}
|
|
118
|
-
removeAddon={removeAddon}
|
|
119
|
-
checkoutLocalization={checkoutLocalization}
|
|
120
|
-
/>
|
|
121
|
-
);
|
|
122
|
-
})}
|
|
123
|
-
</CheckoutAddonsContainer>
|
|
124
|
-
);
|
|
125
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import sortBy from 'lodash/sortBy';
|
|
2
|
-
import { Addon, BillingPeriod, Currency, SubscriptionAddon } from '@stigg/js-client-sdk';
|
|
3
|
-
|
|
4
|
-
type filterAddonsBaseProps = {
|
|
5
|
-
billingPeriod: BillingPeriod;
|
|
6
|
-
currency: Currency;
|
|
7
|
-
billingCountryCode?: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const sortAddons = (addons: Addon[]) => {
|
|
11
|
-
return sortBy(addons, 'displayName');
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const sortSubscriptionAddons = (addons: SubscriptionAddon[]) => {
|
|
15
|
-
return sortBy(addons, 'addon.displayName');
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export function filterAddons({
|
|
19
|
-
addons,
|
|
20
|
-
billingPeriod,
|
|
21
|
-
billingCountryCode,
|
|
22
|
-
currency,
|
|
23
|
-
}: { addons?: Addon[] } & filterAddonsBaseProps): Addon[] {
|
|
24
|
-
return (
|
|
25
|
-
addons
|
|
26
|
-
?.filter(addon => filterAddonPricePointsByBillingPeriod(addon, billingPeriod))
|
|
27
|
-
?.map(addon => mapAddonPricePointsByBillingCountryCode({ addon, currency, billingCountryCode })) || []
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function filterSubscriptionAddons({
|
|
32
|
-
addons,
|
|
33
|
-
billingPeriod,
|
|
34
|
-
billingCountryCode,
|
|
35
|
-
currency,
|
|
36
|
-
}: { addons?: SubscriptionAddon[] } & filterAddonsBaseProps): SubscriptionAddon[] {
|
|
37
|
-
return (
|
|
38
|
-
addons
|
|
39
|
-
?.filter(addon => filterAddonPricePointsByBillingPeriod(addon.addon, billingPeriod))
|
|
40
|
-
?.map(addon => ({
|
|
41
|
-
...addon,
|
|
42
|
-
addon: mapAddonPricePointsByBillingCountryCode({ addon: addon.addon, currency, billingCountryCode }),
|
|
43
|
-
})) || []
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function filterAddonPricePointsByBillingPeriod(addon: Addon, billingPeriod: BillingPeriod) {
|
|
48
|
-
return addon.pricePoints.some(pricePoint => pricePoint.billingPeriod === billingPeriod);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function mapAddonPricePointsByBillingCountryCode({
|
|
52
|
-
addon,
|
|
53
|
-
currency,
|
|
54
|
-
billingCountryCode,
|
|
55
|
-
}: {
|
|
56
|
-
addon: Addon;
|
|
57
|
-
currency: Currency;
|
|
58
|
-
billingCountryCode?: string;
|
|
59
|
-
}) {
|
|
60
|
-
return {
|
|
61
|
-
...addon,
|
|
62
|
-
pricePoints: addon.pricePoints.filter(
|
|
63
|
-
pricePoint =>
|
|
64
|
-
pricePoint.currency === currency &&
|
|
65
|
-
(billingCountryCode ? pricePoint.billingCountryCode === billingCountryCode : true),
|
|
66
|
-
),
|
|
67
|
-
};
|
|
68
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './CheckoutAddonsStep';
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import styled from '@emotion/styled';
|
|
2
|
-
import { Grid } from '@mui/material';
|
|
3
|
-
|
|
4
|
-
export const PaymentMethodContainer = styled(Grid)`
|
|
5
|
-
padding: 8px;
|
|
6
|
-
border-radius: 10px;
|
|
7
|
-
border: 1px solid ${({ theme }) => theme.stigg.palette.outlinedBorder};
|
|
8
|
-
cursor: pointer;
|
|
9
|
-
`;
|
|
10
|
-
|
|
11
|
-
export const NewPaymentMethodContainer = styled(PaymentMethodContainer)`
|
|
12
|
-
flex-direction: column;
|
|
13
|
-
align-items: unset;
|
|
14
|
-
`;
|
|
15
|
-
|
|
16
|
-
export const PaymentMethodLayoutContainer = styled(Grid)`
|
|
17
|
-
display: flex;
|
|
18
|
-
align-items: center;
|
|
19
|
-
flex: 1;
|
|
20
|
-
gap: 12px;
|
|
21
|
-
`;
|
|
22
|
-
|
|
23
|
-
export const PaymentMethodTextContainer = styled(Grid)`
|
|
24
|
-
display: flex;
|
|
25
|
-
flex-direction: column;
|
|
26
|
-
`;
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import { Collapse, Grid, Radio } from '@mui/material';
|
|
4
|
-
import { Customer } from '@stigg/js-client-sdk';
|
|
5
|
-
|
|
6
|
-
import { Icon, Icons } from '../../../common/Icon';
|
|
7
|
-
import { Typography } from '../../../common/Typography';
|
|
8
|
-
import {
|
|
9
|
-
NewPaymentMethodContainer,
|
|
10
|
-
PaymentMethodContainer,
|
|
11
|
-
PaymentMethodLayoutContainer,
|
|
12
|
-
PaymentMethodTextContainer,
|
|
13
|
-
} from './PaymentMethods.style';
|
|
14
|
-
import { StripePaymentForm } from './stripe';
|
|
15
|
-
import { CheckoutLocalization } from '../../textOverrides';
|
|
16
|
-
|
|
17
|
-
export type PaymentMethodLayoutProps = {
|
|
18
|
-
checked: boolean;
|
|
19
|
-
icon: Icons;
|
|
20
|
-
text: React.ReactNode;
|
|
21
|
-
subtitle?: React.ReactNode;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export type PaymentMethodProps = Pick<Customer, 'paymentMethodDetails'> &
|
|
25
|
-
Pick<PaymentMethodLayoutProps, 'checked'> & { onSelect: () => void };
|
|
26
|
-
|
|
27
|
-
export type NewPaymentMethodProps = Pick<PaymentMethodLayoutProps, 'checked'> & {
|
|
28
|
-
onSelect: () => void;
|
|
29
|
-
checkoutLocalization: CheckoutLocalization;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
function PaymentMethodLayout({ checked, icon, text, subtitle }: PaymentMethodLayoutProps) {
|
|
33
|
-
return (
|
|
34
|
-
<PaymentMethodLayoutContainer>
|
|
35
|
-
<Radio checked={checked} />
|
|
36
|
-
<Icon icon={icon} style={{ display: 'contents' }} />
|
|
37
|
-
<PaymentMethodTextContainer container>
|
|
38
|
-
<Grid item>{text}</Grid>
|
|
39
|
-
{subtitle && <Grid item>{subtitle}</Grid>}
|
|
40
|
-
</PaymentMethodTextContainer>
|
|
41
|
-
</PaymentMethodLayoutContainer>
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function ExistingPaymentMethod({ checked, paymentMethodDetails, onSelect }: PaymentMethodProps) {
|
|
46
|
-
if (!paymentMethodDetails) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
const { last4Digits, expirationMonth, expirationYear } = paymentMethodDetails;
|
|
50
|
-
|
|
51
|
-
return (
|
|
52
|
-
<PaymentMethodContainer item onClick={onSelect}>
|
|
53
|
-
<PaymentMethodLayout
|
|
54
|
-
checked={checked}
|
|
55
|
-
icon="PaymentMethod"
|
|
56
|
-
text={<Typography variant="h6">{`Ending in ${last4Digits}`}</Typography>}
|
|
57
|
-
subtitle={
|
|
58
|
-
!!expirationMonth &&
|
|
59
|
-
!!expirationYear && (
|
|
60
|
-
<Typography variant="body1">{`Exp. ${expirationMonth
|
|
61
|
-
.toString()
|
|
62
|
-
.padStart(2, '0')}/${expirationYear}`}</Typography>
|
|
63
|
-
)
|
|
64
|
-
}
|
|
65
|
-
/>
|
|
66
|
-
</PaymentMethodContainer>
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function NewPaymentMethod({ checked, onSelect, checkoutLocalization }: NewPaymentMethodProps) {
|
|
71
|
-
return (
|
|
72
|
-
<NewPaymentMethodContainer item onClick={onSelect}>
|
|
73
|
-
<PaymentMethodLayout
|
|
74
|
-
checked={checked}
|
|
75
|
-
icon="PaymentMethod"
|
|
76
|
-
text={<Typography variant="h6">{checkoutLocalization.newPaymentMethodText}</Typography>}
|
|
77
|
-
/>
|
|
78
|
-
<Collapse in={checked}>
|
|
79
|
-
<StripePaymentForm />
|
|
80
|
-
</Collapse>
|
|
81
|
-
</NewPaymentMethodContainer>
|
|
82
|
-
);
|
|
83
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import styled from '@emotion/styled';
|
|
4
|
-
import { Alert, Grid } from '@mui/material';
|
|
5
|
-
|
|
6
|
-
import { useCheckoutModel, usePaymentStepModel } from '../../hooks';
|
|
7
|
-
import { ExistingPaymentMethod, NewPaymentMethod } from './PaymentMethods';
|
|
8
|
-
import { Typography } from '../../../common/Typography';
|
|
9
|
-
|
|
10
|
-
const PaymentContainer = styled(Grid)`
|
|
11
|
-
display: flex;
|
|
12
|
-
flex-direction: column;
|
|
13
|
-
gap: 24px;
|
|
14
|
-
margin: 32px 0;
|
|
15
|
-
`;
|
|
16
|
-
|
|
17
|
-
export function PaymentStep() {
|
|
18
|
-
const { checkoutState, checkoutLocalization } = useCheckoutModel();
|
|
19
|
-
const { customer } = checkoutState || {};
|
|
20
|
-
const { errorMessage, useNewPaymentMethod, setUseNewPaymentMethod } = usePaymentStepModel();
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<PaymentContainer container>
|
|
24
|
-
{!!errorMessage && (
|
|
25
|
-
<Alert severity="error" sx={{ alignItems: 'center' }}>
|
|
26
|
-
<Typography overrideColor="inherit">{errorMessage}</Typography>
|
|
27
|
-
</Alert>
|
|
28
|
-
)}
|
|
29
|
-
<ExistingPaymentMethod
|
|
30
|
-
checked={!useNewPaymentMethod}
|
|
31
|
-
onSelect={() => setUseNewPaymentMethod(false)}
|
|
32
|
-
paymentMethodDetails={customer?.paymentMethodDetails}
|
|
33
|
-
/>
|
|
34
|
-
<NewPaymentMethod
|
|
35
|
-
checked={useNewPaymentMethod}
|
|
36
|
-
checkoutLocalization={checkoutLocalization}
|
|
37
|
-
onSelect={() => setUseNewPaymentMethod(true)}
|
|
38
|
-
></NewPaymentMethod>
|
|
39
|
-
</PaymentContainer>
|
|
40
|
-
);
|
|
41
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './PaymentStep';
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Grid } from '@mui/material';
|
|
3
|
-
import { AddressElement, PaymentElement } from '@stripe/react-stripe-js';
|
|
4
|
-
import { Typography } from '../../../../common/Typography';
|
|
5
|
-
import { useCheckoutModel } from '../../../hooks';
|
|
6
|
-
|
|
7
|
-
export function StripePaymentForm() {
|
|
8
|
-
const { checkoutState, checkoutLocalization } = useCheckoutModel();
|
|
9
|
-
const { customer } = checkoutState || {};
|
|
10
|
-
|
|
11
|
-
return (
|
|
12
|
-
<Grid flexDirection="column" container gap={3} padding="16px">
|
|
13
|
-
<Grid flexDirection="column" container gap={2}>
|
|
14
|
-
<Typography variant="h6">{checkoutLocalization.newPaymentMethodBillingAddressTitle}</Typography>
|
|
15
|
-
<AddressElement
|
|
16
|
-
options={{
|
|
17
|
-
mode: 'billing',
|
|
18
|
-
fields: { phone: 'always' },
|
|
19
|
-
defaultValues: {
|
|
20
|
-
...(customer?.name && { name: customer.name }),
|
|
21
|
-
},
|
|
22
|
-
}}
|
|
23
|
-
/>
|
|
24
|
-
</Grid>
|
|
25
|
-
<Grid flexDirection="column" container gap={2}>
|
|
26
|
-
<Typography variant="h6">{checkoutLocalization.newPaymentMethodCardTitle}</Typography>
|
|
27
|
-
<PaymentElement
|
|
28
|
-
onChange={() => {}}
|
|
29
|
-
onReady={() => {}}
|
|
30
|
-
options={{
|
|
31
|
-
terms: { card: 'never' },
|
|
32
|
-
defaultValues: {
|
|
33
|
-
billingDetails: {
|
|
34
|
-
...(customer?.name && { name: customer.name }),
|
|
35
|
-
...(customer?.email && { email: customer.email }),
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
}}
|
|
39
|
-
/>
|
|
40
|
-
</Grid>
|
|
41
|
-
</Grid>
|
|
42
|
-
);
|
|
43
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { ApplySubscriptionResults, PaymentCollection } from '@stigg/js-client-sdk';
|
|
2
|
-
import { Stripe, StripeElements } from '@stripe/stripe-js';
|
|
3
|
-
|
|
4
|
-
type StripeElementsProps = {
|
|
5
|
-
stripe: Stripe | null;
|
|
6
|
-
elements: StripeElements | null;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export async function handleStripeFormValidations({ elements }: Pick<StripeElementsProps, 'elements'>) {
|
|
10
|
-
if (!elements) {
|
|
11
|
-
console.error('Stripe elements not initialized');
|
|
12
|
-
return { success: false };
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const { error: elementsError } = await elements.submit();
|
|
16
|
-
|
|
17
|
-
if (elementsError) {
|
|
18
|
-
console.log(elementsError.message);
|
|
19
|
-
return { success: false };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return { success: true };
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export async function handleNewPaymentMethod({
|
|
26
|
-
stripe,
|
|
27
|
-
elements,
|
|
28
|
-
setupIntentClientSecret,
|
|
29
|
-
}: {
|
|
30
|
-
stripe: Stripe | null;
|
|
31
|
-
elements: StripeElements | null;
|
|
32
|
-
setupIntentClientSecret?: string;
|
|
33
|
-
}) {
|
|
34
|
-
if (!stripe || !elements || !setupIntentClientSecret) {
|
|
35
|
-
return { success: false };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const { newPaymentMethodId, setupErrorMessage } = await handleStripeSetup({
|
|
39
|
-
stripe,
|
|
40
|
-
elements,
|
|
41
|
-
clientSecret: setupIntentClientSecret,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return { success: !!newPaymentMethodId, paymentMethodId: newPaymentMethodId, errorMessage: setupErrorMessage };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export async function handleStripeNextAction({
|
|
48
|
-
applySubscriptionResults,
|
|
49
|
-
stripe,
|
|
50
|
-
}: {
|
|
51
|
-
applySubscriptionResults: ApplySubscriptionResults;
|
|
52
|
-
stripe: Stripe | null;
|
|
53
|
-
}) {
|
|
54
|
-
const paymentIntentClientSecret = applySubscriptionResults?.subscription?.latestInvoice?.paymentSecret;
|
|
55
|
-
if (
|
|
56
|
-
stripe &&
|
|
57
|
-
paymentIntentClientSecret &&
|
|
58
|
-
applySubscriptionResults?.subscription?.paymentCollection === PaymentCollection.ActionRequired
|
|
59
|
-
) {
|
|
60
|
-
const { error: NextActionError } = await stripe.handleNextAction({ clientSecret: paymentIntentClientSecret });
|
|
61
|
-
if (NextActionError) {
|
|
62
|
-
return { errorMessage: NextActionError.message || '' };
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return { subscription: applySubscriptionResults?.subscription };
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async function handleStripeSetup({
|
|
70
|
-
stripe,
|
|
71
|
-
elements,
|
|
72
|
-
clientSecret,
|
|
73
|
-
}: {
|
|
74
|
-
stripe: Stripe;
|
|
75
|
-
elements: StripeElements;
|
|
76
|
-
clientSecret: string;
|
|
77
|
-
}) {
|
|
78
|
-
let newPaymentMethodId: string | undefined;
|
|
79
|
-
let setupErrorMessage: string | undefined;
|
|
80
|
-
|
|
81
|
-
const { error: setupError } = await stripe.confirmSetup({
|
|
82
|
-
elements,
|
|
83
|
-
confirmParams: { return_url: window.location.href },
|
|
84
|
-
redirect: 'if_required',
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
if (setupError) {
|
|
88
|
-
if (setupError.type === 'card_error' || setupError.type === 'validation_error') {
|
|
89
|
-
if (setupError.type === 'card_error') {
|
|
90
|
-
// Set some error message
|
|
91
|
-
setupErrorMessage = setupError.message || '';
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
setupErrorMessage = 'An unexpected error occurred.';
|
|
95
|
-
}
|
|
96
|
-
} else {
|
|
97
|
-
try {
|
|
98
|
-
const { setupIntent } = await stripe.retrieveSetupIntent(clientSecret);
|
|
99
|
-
if (setupIntent?.payment_method) {
|
|
100
|
-
newPaymentMethodId = setupIntent.payment_method as string;
|
|
101
|
-
}
|
|
102
|
-
} catch (e) {
|
|
103
|
-
setupErrorMessage = 'An unexpected error occurred.';
|
|
104
|
-
console.error(e);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return { newPaymentMethodId, setupErrorMessage };
|
|
109
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import { BillingVendorIdentifier } from '@stigg/js-client-sdk';
|
|
4
|
-
import { loadStripe, Stripe } from '@stripe/stripe-js';
|
|
5
|
-
|
|
6
|
-
import { useCheckoutModel } from '../../../hooks';
|
|
7
|
-
|
|
8
|
-
export function useStripeIntegration() {
|
|
9
|
-
const [stripePromise, setStripePromise] = useState<Promise<Stripe | null> | null>(null);
|
|
10
|
-
const { checkoutState } = useCheckoutModel();
|
|
11
|
-
const { billingIntegration, setupSecret } = checkoutState || {};
|
|
12
|
-
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
if (billingIntegration) {
|
|
15
|
-
const { billingIdentifier, credentials } = billingIntegration;
|
|
16
|
-
if (billingIdentifier !== BillingVendorIdentifier.Stripe) {
|
|
17
|
-
console.error('Currently only stripe integration is supported');
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const { accountId, publicKey } = credentials;
|
|
22
|
-
setStripePromise(loadStripe(publicKey, { stripeAccount: accountId }));
|
|
23
|
-
}
|
|
24
|
-
}, [billingIntegration]);
|
|
25
|
-
|
|
26
|
-
return { stripePromise, setupIntentClientSecret: setupSecret };
|
|
27
|
-
}
|