@stigg/react-sdk 4.3.0-beta.1 → 4.3.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/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 +1 -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 +4 -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/components/utils/getPaidPriceText.d.ts +3 -1
- package/dist/index.d.ts +0 -1
- package/dist/react-sdk.cjs.development.js +217 -3483
- 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 +223 -3623
- package/dist/react-sdk.esm.js.map +1 -1
- package/dist/stories/CustomerPortal.stories.d.ts +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 +8 -24
- 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 +3 -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 +10 -4
- package/src/components/utils/getPlanPrice.ts +1 -1
- package/src/index.ts +0 -1
- package/src/stories/CustomerPortal.stories.tsx +12 -12
- 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 -26
- package/dist/components/checkout/CheckoutProvider.d.ts +0 -35
- 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 -11
- 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 -12
- 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 -88
- package/src/components/checkout/CheckoutProvider.tsx +0 -140
- 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 -22
- 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 -43
- package/src/components/hooks/useChargeSort.ts +0 -17
- package/src/components/utils/priceUtils.ts +0 -10
- package/src/stories/Checkout.stories.tsx +0 -62
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
-
<g id="Group 16159">
|
|
3
|
-
<circle id="Ellipse 5" cx="10" cy="10" r="9.25" fill="#327EEE" stroke="#327EEE" stroke-width="1.5"/>
|
|
4
|
-
<path id="Shape" d="M5 10.3636L8.63667 14L12.637 10L14.6372 8" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
5
|
-
</g>
|
|
6
|
-
</svg>
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
<svg width="24" height="16" viewBox="0 0 24 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
-
<g clip-path="url(#clip0_239_13697)">
|
|
3
|
-
<path d="M22 0H2C0.89543 0 0 0.89543 0 2V14C0 15.1046 0.89543 16 2 16H22C23.1046 16 24 15.1046 24 14V2C24 0.89543 23.1046 0 22 0Z" fill="#C6C6C7"/>
|
|
4
|
-
</g>
|
|
5
|
-
<path opacity="0.3" d="M18.75 12.4286H16.5C16.0125 12.4286 15.75 12.2 15.75 11.6667C15.75 11.1334 16.0125 10.9048 16.5 10.9048H18.75C19.2375 10.9048 19.5 11.1334 19.5 11.6667C19.5 12.2 19.2375 12.4286 18.75 12.4286ZM14.25 12.4286H12C11.5125 12.4286 11.25 12.2 11.25 11.6667C11.25 11.1334 11.5125 10.9048 12 10.9048H14.25C14.7375 10.9048 15 11.1334 15 11.6667C15 12.2 14.7375 12.4286 14.25 12.4286ZM9.75 12.4286H7.5C7.0125 12.4286 6.75 12.2 6.75 11.6667C6.75 11.1334 7.0125 10.9048 7.5 10.9048H9.75C10.2375 10.9048 10.5 11.1334 10.5 11.6667C10.5 12.2 10.2375 12.4286 9.75 12.4286ZM5.25 12.4286H3C2.5125 12.4286 2.25 12.2 2.25 11.6667C2.25 11.1334 2.5125 10.9048 3 10.9048H5.25C5.7375 10.9048 6 11.1334 6 11.6667C6 12.2 5.7375 12.4286 5.25 12.4286Z" fill="black"/>
|
|
6
|
-
<defs>
|
|
7
|
-
<clipPath id="clip0_239_13697">
|
|
8
|
-
<rect width="24" height="16" fill="white"/>
|
|
9
|
-
</clipPath>
|
|
10
|
-
</defs>
|
|
11
|
-
</svg>
|
package/src/assets/plus-icon.svg
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
-
<g id="plus">
|
|
3
|
-
<path id="Shape" d="M10 4.16666V15.8333" stroke="#327EEE" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
4
|
-
<path id="Shape_2" d="M4.16699 10H15.8337" stroke="#327EEE" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
5
|
-
</g>
|
|
6
|
-
</svg>
|
package/src/assets/trash.svg
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
-
<g id="trash-2">
|
|
3
|
-
<path id="Shape" d="M3 6H5H21" stroke="#F88078" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
4
|
-
<path id="Shape_2" d="M20 6C20 5.44772 19.5523 5 19 5C18.4477 5 18 5.44772 18 6H20ZM6 6C6 5.44772 5.55228 5 5 5C4.44772 5 4 5.44772 4 6H6ZM7 6C7 6.55228 7.44772 7 8 7C8.55228 7 9 6.55228 9 6H7ZM15 6C15 6.55228 15.4477 7 16 7C16.5523 7 17 6.55228 17 6H15ZM18 6V20H20V6H18ZM18 20C18 20.5523 17.5523 21 17 21V23C18.6569 23 20 21.6569 20 20H18ZM17 21H7V23H17V21ZM7 21C6.44772 21 6 20.5523 6 20H4C4 21.6569 5.34315 23 7 23V21ZM6 20V6H4V20H6ZM9 6V4H7V6H9ZM9 4C9 3.44772 9.44772 3 10 3V1C8.34315 1 7 2.34315 7 4H9ZM10 3H14V1H10V3ZM14 3C14.5523 3 15 3.44772 15 4H17C17 2.34315 15.6569 1 14 1V3ZM15 4V6H17V4H15Z" fill="#F88078"/>
|
|
5
|
-
<path id="Shape_3" d="M10 11V17" stroke="#F88078" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
6
|
-
<path id="Shape_4" d="M14 11V17" stroke="#F88078" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
7
|
-
</g>
|
|
8
|
-
</svg>
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { CheckoutProvider, CheckoutProviderProps } from './CheckoutProvider';
|
|
3
|
-
import { CheckoutContainer, CheckoutContainerProps } from './CheckoutContainer';
|
|
4
|
-
|
|
5
|
-
export type CheckoutProps = CheckoutProviderProps & CheckoutContainerProps;
|
|
6
|
-
|
|
7
|
-
export const Checkout = ({
|
|
8
|
-
textOverrides,
|
|
9
|
-
theme,
|
|
10
|
-
resourceId,
|
|
11
|
-
planId,
|
|
12
|
-
preferredBillingPeriod,
|
|
13
|
-
billingCountryCode,
|
|
14
|
-
billableFeatures,
|
|
15
|
-
...containerProps
|
|
16
|
-
}: CheckoutProps) => {
|
|
17
|
-
return (
|
|
18
|
-
<CheckoutProvider
|
|
19
|
-
textOverrides={textOverrides}
|
|
20
|
-
theme={theme}
|
|
21
|
-
resourceId={resourceId}
|
|
22
|
-
planId={planId}
|
|
23
|
-
preferredBillingPeriod={preferredBillingPeriod}
|
|
24
|
-
billingCountryCode={billingCountryCode}
|
|
25
|
-
billableFeatures={billableFeatures}
|
|
26
|
-
>
|
|
27
|
-
<CheckoutContainer {...containerProps} />
|
|
28
|
-
</CheckoutProvider>
|
|
29
|
-
);
|
|
30
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import styled from '@emotion/styled/macro';
|
|
2
|
-
import Box from '@mui/material/Box';
|
|
3
|
-
|
|
4
|
-
export const CheckoutLayout = styled.div`
|
|
5
|
-
margin: auto;
|
|
6
|
-
width: 100%;
|
|
7
|
-
max-width: 920px;
|
|
8
|
-
display: flex;
|
|
9
|
-
flex-direction: column;
|
|
10
|
-
align-items: center;
|
|
11
|
-
|
|
12
|
-
padding: 16px 32px;
|
|
13
|
-
border-radius: 10px;
|
|
14
|
-
background-color: ${({ theme }) => theme.stigg.palette.backgroundPaper};
|
|
15
|
-
border: ${({ theme }) => `1px solid ${theme.stigg.palette.outlinedBorder}`};
|
|
16
|
-
|
|
17
|
-
& * {
|
|
18
|
-
box-sizing: border-box;
|
|
19
|
-
}
|
|
20
|
-
`;
|
|
21
|
-
export const CheckoutContent = styled(Box)`
|
|
22
|
-
display: flex;
|
|
23
|
-
align-items: flex-start;
|
|
24
|
-
gap: 32px;
|
|
25
|
-
flex-wrap: wrap;
|
|
26
|
-
width: 100%;
|
|
27
|
-
`;
|
|
28
|
-
|
|
29
|
-
export const CheckoutPanel = styled(Box)`
|
|
30
|
-
display: flex;
|
|
31
|
-
flex-direction: column;
|
|
32
|
-
gap: 0;
|
|
33
|
-
flex: 2;
|
|
34
|
-
`;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { Elements } from '@stripe/react-stripe-js';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { CheckoutContent, CheckoutLayout, CheckoutPanel } from './CheckoutContainer.style';
|
|
4
|
-
import { CheckoutProgressBar } from './progressBar/CheckoutProgressBar';
|
|
5
|
-
import { CheckoutSummary } from './CheckoutSummary';
|
|
6
|
-
import { useProgressBarModel } from './hooks';
|
|
7
|
-
import { PlanHeader } from './planHeader';
|
|
8
|
-
import { CheckoutAddonsStep } from './steps/addons';
|
|
9
|
-
import { PaymentStep } from './steps/payment';
|
|
10
|
-
import { useStripeIntegration } from './steps/payment/stripe';
|
|
11
|
-
import { CheckoutPlanStep } from './steps/plan';
|
|
12
|
-
import { ApplySubscription, CheckoutStatePlan } from '@stigg/js-client-sdk';
|
|
13
|
-
import { useCheckoutContext } from './CheckoutProvider';
|
|
14
|
-
|
|
15
|
-
// import { SurpriseStep } from './steps/surprise/SurpriseStep';
|
|
16
|
-
|
|
17
|
-
type StepProps = {
|
|
18
|
-
allowChangePlan?: boolean;
|
|
19
|
-
content: React.ReactNode;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const getStepProps = (step: number): StepProps => {
|
|
23
|
-
switch (step) {
|
|
24
|
-
case 0:
|
|
25
|
-
return { allowChangePlan: true, content: <CheckoutPlanStep /> };
|
|
26
|
-
case 1:
|
|
27
|
-
return { content: <CheckoutAddonsStep /> };
|
|
28
|
-
case 2:
|
|
29
|
-
return { content: <PaymentStep /> };
|
|
30
|
-
default:
|
|
31
|
-
return { content: null };
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export type CheckoutResult = { success: boolean; errorMessage?: string };
|
|
36
|
-
|
|
37
|
-
export type OnCheckoutParams = { checkoutParams: ApplySubscription; checkoutAction: () => Promise<CheckoutResult> };
|
|
38
|
-
|
|
39
|
-
export type OnCheckoutCompletedParams = { success: boolean; error?: string };
|
|
40
|
-
|
|
41
|
-
export type CheckoutContainerProps = {
|
|
42
|
-
onCheckout?: (params: OnCheckoutParams) => Promise<CheckoutResult>;
|
|
43
|
-
onCheckoutCompleted: (params: OnCheckoutCompletedParams) => Promise<void>;
|
|
44
|
-
onChangePlan?: (params: { currentPlan: CheckoutStatePlan | undefined }) => void;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export function CheckoutContainer({ onCheckout, onCheckoutCompleted, onChangePlan }: CheckoutContainerProps) {
|
|
48
|
-
const { stripePromise, setupIntentClientSecret } = useStripeIntegration();
|
|
49
|
-
const [{ stiggTheme }] = useCheckoutContext();
|
|
50
|
-
const { progressBarState } = useProgressBarModel();
|
|
51
|
-
const { activeStep } = progressBarState;
|
|
52
|
-
|
|
53
|
-
// uncomment for fun!
|
|
54
|
-
// if (activeStep > 2) {
|
|
55
|
-
// return <SurpriseStep />;
|
|
56
|
-
// }
|
|
57
|
-
|
|
58
|
-
const { content, allowChangePlan } = getStepProps(activeStep);
|
|
59
|
-
|
|
60
|
-
return (
|
|
61
|
-
<Elements
|
|
62
|
-
stripe={stripePromise}
|
|
63
|
-
options={{
|
|
64
|
-
clientSecret: setupIntentClientSecret,
|
|
65
|
-
appearance: {
|
|
66
|
-
theme: 'stripe',
|
|
67
|
-
variables: {
|
|
68
|
-
colorText: stiggTheme.palette.text.primary,
|
|
69
|
-
colorPrimaryText: stiggTheme.palette.text.primary,
|
|
70
|
-
colorTextPlaceholder: stiggTheme.palette.text.disabled,
|
|
71
|
-
fontFamily: stiggTheme.typography.fontFamily,
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
}}
|
|
75
|
-
>
|
|
76
|
-
<CheckoutLayout className="stigg-checkout-layout">
|
|
77
|
-
<CheckoutProgressBar />
|
|
78
|
-
<CheckoutContent>
|
|
79
|
-
<CheckoutPanel>
|
|
80
|
-
<PlanHeader allowChangePlan={allowChangePlan} onChangePlan={onChangePlan} />
|
|
81
|
-
{content}
|
|
82
|
-
</CheckoutPanel>
|
|
83
|
-
<CheckoutSummary onCheckout={onCheckout} onCheckoutCompleted={onCheckoutCompleted} />
|
|
84
|
-
</CheckoutContent>
|
|
85
|
-
</CheckoutLayout>
|
|
86
|
-
</Elements>
|
|
87
|
-
);
|
|
88
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { produce } from 'immer';
|
|
2
|
-
import React, { useCallback, useContext, useMemo, useState } from 'react';
|
|
3
|
-
|
|
4
|
-
import { BillableFeature, BillingPeriod, GetCheckoutStateResults } from '@stigg/js-client-sdk';
|
|
5
|
-
|
|
6
|
-
import { CustomizedTheme, SdkThemeProvider, useStiggTheme } from '../../theme/Theme';
|
|
7
|
-
import { DeepPartial } from '../../types';
|
|
8
|
-
import { mapCheckoutConfiguration } from '../common/mapExternalTheme';
|
|
9
|
-
import {
|
|
10
|
-
AddonsStepState,
|
|
11
|
-
getAddonsStepInitialState,
|
|
12
|
-
getPaymentStepInitialState,
|
|
13
|
-
getPlanStepInitialState,
|
|
14
|
-
getProgressBarInitialState,
|
|
15
|
-
PaymentStepState,
|
|
16
|
-
PlanStepState,
|
|
17
|
-
ProgressBarState,
|
|
18
|
-
useLoadCheckout,
|
|
19
|
-
WidgetState,
|
|
20
|
-
} from './hooks';
|
|
21
|
-
import { CheckoutLocalization, getResolvedCheckoutLocalize } from './textOverrides';
|
|
22
|
-
import { CheckoutTheme, getResolvedCheckoutTheme } from './theme';
|
|
23
|
-
import { StiggTheme } from '../../theme/types';
|
|
24
|
-
|
|
25
|
-
export interface CheckoutContextState {
|
|
26
|
-
checkout?: GetCheckoutStateResults | null;
|
|
27
|
-
checkoutLocalization: CheckoutLocalization;
|
|
28
|
-
stiggTheme: StiggTheme;
|
|
29
|
-
theme: CheckoutTheme;
|
|
30
|
-
isLoading: boolean;
|
|
31
|
-
resourceId?: string;
|
|
32
|
-
promotionCode?: string;
|
|
33
|
-
progressBar: ProgressBarState;
|
|
34
|
-
planStep: PlanStepState;
|
|
35
|
-
addonsStep: AddonsStepState;
|
|
36
|
-
paymentStep: PaymentStepState;
|
|
37
|
-
widgetState: WidgetState;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const CheckoutContext = React.createContext<
|
|
41
|
-
[CheckoutContextState, (updater: (state: CheckoutContextState) => void) => void] | null
|
|
42
|
-
>(null);
|
|
43
|
-
|
|
44
|
-
CheckoutContext.displayName = 'CheckoutContext';
|
|
45
|
-
|
|
46
|
-
export const useCheckoutContext = () => {
|
|
47
|
-
const ctx = useContext(CheckoutContext);
|
|
48
|
-
if (!ctx) {
|
|
49
|
-
throw new Error(
|
|
50
|
-
'Could not find Checkout context; You need to wrap your checkout components in an <CheckoutProvider> component.',
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
return ctx;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const CheckoutContextProvider: React.FC<{ children: React.ReactNode; initialState: CheckoutContextState }> = ({
|
|
57
|
-
children,
|
|
58
|
-
initialState,
|
|
59
|
-
}) => {
|
|
60
|
-
const [state, innerSetState] = useState(initialState);
|
|
61
|
-
|
|
62
|
-
const setState = useCallback(
|
|
63
|
-
(updater: (state: CheckoutContextState) => void) => innerSetState(old => produce(old, draft => updater(draft))),
|
|
64
|
-
[innerSetState],
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
const [contextValue, setContextValue] = useMemo(() => [state, setState], [state]);
|
|
68
|
-
|
|
69
|
-
return <CheckoutContext.Provider value={[contextValue, setContextValue]}>{children}</CheckoutContext.Provider>;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export type CheckoutProviderProps = {
|
|
73
|
-
textOverrides?: DeepPartial<CheckoutLocalization>;
|
|
74
|
-
theme?: DeepPartial<CheckoutTheme>;
|
|
75
|
-
resourceId?: string;
|
|
76
|
-
planId: string;
|
|
77
|
-
preferredBillingPeriod?: BillingPeriod;
|
|
78
|
-
billingCountryCode?: string;
|
|
79
|
-
billableFeatures?: BillableFeature[];
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export function CheckoutProvider({
|
|
83
|
-
children,
|
|
84
|
-
textOverrides,
|
|
85
|
-
theme,
|
|
86
|
-
resourceId,
|
|
87
|
-
planId,
|
|
88
|
-
preferredBillingPeriod,
|
|
89
|
-
billingCountryCode,
|
|
90
|
-
billableFeatures,
|
|
91
|
-
}: {
|
|
92
|
-
children: React.ReactNode;
|
|
93
|
-
} & CheckoutProviderProps) {
|
|
94
|
-
const { checkout, isLoading } = useLoadCheckout({ resourceId, planId, billingCountryCode });
|
|
95
|
-
const configuration: CustomizedTheme | undefined = checkout?.configuration
|
|
96
|
-
? mapCheckoutConfiguration(checkout.configuration)
|
|
97
|
-
: undefined;
|
|
98
|
-
const globalTheme: StiggTheme = useStiggTheme(configuration);
|
|
99
|
-
const checkoutTheme = getResolvedCheckoutTheme(globalTheme, theme, checkout?.configuration);
|
|
100
|
-
const checkoutLocalization = getResolvedCheckoutLocalize(textOverrides);
|
|
101
|
-
|
|
102
|
-
const initialState = useMemo(() => {
|
|
103
|
-
const planStep = getPlanStepInitialState({
|
|
104
|
-
preferredBillingPeriod,
|
|
105
|
-
plan: checkout?.plan,
|
|
106
|
-
activeSubscription: checkout?.activeSubscription,
|
|
107
|
-
billingCountryCode,
|
|
108
|
-
preconfiguredBillableFeatures: billableFeatures ? billableFeatures : [],
|
|
109
|
-
});
|
|
110
|
-
const addonsStep = getAddonsStepInitialState({
|
|
111
|
-
plan: checkout?.plan,
|
|
112
|
-
billingPeriod: planStep.billingPeriod,
|
|
113
|
-
activeSubscription: checkout?.activeSubscription,
|
|
114
|
-
});
|
|
115
|
-
const paymentStep = getPaymentStepInitialState({ customer: checkout?.customer });
|
|
116
|
-
const progressBar = getProgressBarInitialState({ availableAddons: addonsStep.availableAddons || [] });
|
|
117
|
-
|
|
118
|
-
const initialState: CheckoutContextState = {
|
|
119
|
-
checkout,
|
|
120
|
-
isLoading,
|
|
121
|
-
checkoutLocalization,
|
|
122
|
-
stiggTheme: globalTheme,
|
|
123
|
-
theme: checkoutTheme,
|
|
124
|
-
progressBar,
|
|
125
|
-
planStep,
|
|
126
|
-
addonsStep,
|
|
127
|
-
paymentStep,
|
|
128
|
-
resourceId: checkout?.resource?.id,
|
|
129
|
-
widgetState: { isLoading: false },
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
return initialState;
|
|
133
|
-
}, [theme, globalTheme, billingCountryCode, preferredBillingPeriod, checkout]);
|
|
134
|
-
|
|
135
|
-
return (
|
|
136
|
-
<SdkThemeProvider key={checkout?.plan.id} componentTheme={configuration}>
|
|
137
|
-
<CheckoutContextProvider initialState={initialState}>{children}</CheckoutContextProvider>
|
|
138
|
-
</SdkThemeProvider>
|
|
139
|
-
);
|
|
140
|
-
}
|