@stigg/react-sdk 4.4.0-beta.9 → 4.4.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.
Files changed (92) hide show
  1. package/dist/components/checkout/Checkout.d.ts +3 -2
  2. package/dist/components/checkout/CheckoutContainer.d.ts +4 -2
  3. package/dist/components/checkout/CheckoutProvider.d.ts +3 -2
  4. package/dist/components/checkout/components/DowngradeToFreeContainer.d.ts +3 -7
  5. package/dist/components/checkout/components/StyledArrow.d.ts +5 -0
  6. package/dist/components/checkout/hooks/useCheckoutModel.d.ts +2 -0
  7. package/dist/components/checkout/hooks/useLoadCheckout.d.ts +3 -1
  8. package/dist/components/checkout/hooks/usePreviewSubscription.d.ts +17 -8
  9. package/dist/components/checkout/progressBar/CheckoutProgressBar.style.d.ts +1 -1
  10. package/dist/components/checkout/promotionCode/AddPromotionCode.d.ts +2 -4
  11. package/dist/components/checkout/promotionCode/AddPromotionCodeButton.d.ts +2 -1
  12. package/dist/components/checkout/promotionCode/PromotionCodeSection.d.ts +6 -2
  13. package/dist/components/checkout/steps/plan/BillingPeriodPicker.d.ts +1 -1
  14. package/dist/components/checkout/steps/plan/CheckoutPlanStep.d.ts +2 -1
  15. package/dist/components/checkout/summary/CheckoutSummary.d.ts +1 -1
  16. package/dist/components/checkout/summary/components/CheckoutCaptions.d.ts +2 -2
  17. package/dist/components/checkout/summary/components/LineItems.d.ts +12 -8
  18. package/dist/components/checkout/textOverrides.d.ts +63 -20
  19. package/dist/components/checkout/theme.d.ts +0 -1
  20. package/dist/components/checkout/types.d.ts +7 -1
  21. package/dist/components/common/TiersSelectContainer.d.ts +1 -2
  22. package/dist/components/common/Typography.d.ts +2 -2
  23. package/dist/components/common/customIcons.d.ts +2 -0
  24. package/dist/components/customerPortal/subscriptionOverview/subscriptionView/SubscriptionView.style.d.ts +1 -1
  25. package/dist/components/paywall/PlanPrice.d.ts +1 -1
  26. package/dist/components/utils/currencyUtils.d.ts +2 -1
  27. package/dist/components/utils/getFeatureName.d.ts +1 -0
  28. package/dist/react-sdk.cjs.development.js +1030 -560
  29. package/dist/react-sdk.cjs.development.js.map +1 -1
  30. package/dist/react-sdk.cjs.production.min.js +1 -1
  31. package/dist/react-sdk.cjs.production.min.js.map +1 -1
  32. package/dist/react-sdk.esm.js +1051 -590
  33. package/dist/react-sdk.esm.js.map +1 -1
  34. package/dist/stories/mocks/checkout/consts.d.ts +11 -0
  35. package/dist/stories/mocks/checkout/mockCheckoutPreview.d.ts +2 -0
  36. package/dist/stories/mocks/checkout/mockCheckoutState.d.ts +2 -0
  37. package/dist/theme/getResolvedTheme.d.ts +1 -0
  38. package/dist/theme/types.d.ts +1 -0
  39. package/package.json +28 -20
  40. package/src/assets/coupon.svg +6 -0
  41. package/src/assets/pay-as-you-go-charge.svg +11 -0
  42. package/src/components/checkout/Checkout.tsx +5 -2
  43. package/src/components/checkout/CheckoutContainer.tsx +20 -13
  44. package/src/components/checkout/CheckoutProvider.tsx +5 -3
  45. package/src/components/checkout/components/DowngradeToFreeContainer.tsx +33 -36
  46. package/src/components/checkout/components/InputField.tsx +3 -0
  47. package/src/components/checkout/components/StyledArrow.tsx +9 -0
  48. package/src/components/checkout/hooks/useCheckoutModel.ts +12 -2
  49. package/src/components/checkout/hooks/useLoadCheckout.ts +10 -2
  50. package/src/components/checkout/hooks/usePreviewSubscription.ts +102 -50
  51. package/src/components/checkout/planHeader/PlanHeader.tsx +18 -25
  52. package/src/components/checkout/progressBar/CheckoutProgressBar.style.ts +10 -12
  53. package/src/components/checkout/progressBar/CheckoutProgressBar.tsx +6 -6
  54. package/src/components/checkout/promotionCode/AddPromotionCode.tsx +32 -9
  55. package/src/components/checkout/promotionCode/AddPromotionCodeButton.tsx +15 -11
  56. package/src/components/checkout/promotionCode/AppliedPromotionCode.tsx +4 -3
  57. package/src/components/checkout/promotionCode/PromotionCodeSection.tsx +21 -7
  58. package/src/components/checkout/steps/addons/CheckoutAddonsStep.style.tsx +0 -1
  59. package/src/components/checkout/steps/addons/CheckoutAddonsStep.tsx +4 -3
  60. package/src/components/checkout/steps/payment/PaymentMethods.style.ts +4 -1
  61. package/src/components/checkout/steps/payment/PaymentStep.tsx +0 -1
  62. package/src/components/checkout/steps/plan/BillingPeriodPicker.style.tsx +3 -2
  63. package/src/components/checkout/steps/plan/BillingPeriodPicker.tsx +5 -2
  64. package/src/components/checkout/steps/plan/CheckoutChargeList.tsx +35 -14
  65. package/src/components/checkout/steps/plan/CheckoutPlanStep.tsx +10 -5
  66. package/src/components/checkout/summary/CheckoutSuccess.tsx +1 -1
  67. package/src/components/checkout/summary/CheckoutSummary.tsx +143 -46
  68. package/src/components/checkout/summary/components/CheckoutCaptions.tsx +38 -15
  69. package/src/components/checkout/summary/components/LineItems.tsx +77 -28
  70. package/src/components/checkout/textOverrides.ts +107 -27
  71. package/src/components/checkout/theme.ts +0 -4
  72. package/src/components/checkout/types.ts +15 -1
  73. package/src/components/common/Icon.tsx +4 -6
  74. package/src/components/common/TiersSelectContainer.tsx +7 -8
  75. package/src/components/common/Typography.tsx +12 -3
  76. package/src/components/common/customIcons.ts +2 -0
  77. package/src/components/common/mapExternalTheme.ts +1 -2
  78. package/src/components/customerPortal/paywall/CustomerPortalPaywall.style.ts +4 -3
  79. package/src/components/paywall/PlanOfferingButton.tsx +6 -8
  80. package/src/components/paywall/PlanPrice.tsx +14 -17
  81. package/src/components/utils/currencyUtils.ts +4 -2
  82. package/src/components/utils/getFeatureName.ts +13 -5
  83. package/src/stories/Checkout.stories.tsx +37 -6
  84. package/src/stories/CustomerPortal.stories.tsx +2 -2
  85. package/src/stories/mocks/checkout/consts.ts +15 -0
  86. package/src/stories/mocks/checkout/mockCheckoutPreview.ts +138 -0
  87. package/src/stories/mocks/checkout/mockCheckoutState.ts +206 -0
  88. package/src/theme/Theme.tsx +10 -1
  89. package/src/theme/getResolvedTheme.ts +1 -0
  90. package/src/theme/types.ts +1 -0
  91. package/dist/components/checkout/planHeader/PlanHeader.style.d.ts +0 -25
  92. package/src/components/checkout/planHeader/PlanHeader.style.tsx +0 -23
@@ -0,0 +1,11 @@
1
+ export declare const BASE_FEE_MONTHLY = 200;
2
+ export declare const BASE_FEE_YEARLY: number;
3
+ export declare const TIERS: number[];
4
+ export declare const TIERS_PRICE_MONTHLY: number[];
5
+ export declare const TIERS_PRICE_YEARLY: number[];
6
+ export declare const PER_UNIT_PRICE_MONTHLY = 12;
7
+ export declare const PER_UNIT_PRICE_YEARLY: number;
8
+ export declare const ADDON_PRICE_MONTHLY = 50;
9
+ export declare const ADDON_PRICE_YEARLY: number;
10
+ export declare const STRIPE_MOCK_ACCOUNT_ID = "acct_1NnHoQG6EyqgvTaj";
11
+ export declare const STRIPE_MOCK_ACCOUNT_PK = "pk_test_51NnHoQG6EyqgvTajznajopWC01AozNtq7zgySeQ1qx4PH9TAXvMj0TnbZvYT3yOt46jbQAcCDs1EU2QKcfG8eEoO00tlW0Jp3r";
@@ -0,0 +1,2 @@
1
+ import { PreviewSubscription, SubscriptionPreviewV2 } from '@stigg/js-client-sdk';
2
+ export declare function mockPreviewSubscription(input: PreviewSubscription): SubscriptionPreviewV2;
@@ -0,0 +1,2 @@
1
+ import { GetCheckoutState, GetCheckoutStateResults } from '../../../../../js-client-sdk';
2
+ export declare function mockCheckoutState(params: GetCheckoutState): GetCheckoutStateResults;
@@ -4,6 +4,7 @@ export declare const getResolvedTheme: (customizedTheme?: {
4
4
  palette?: {
5
5
  primary?: string | undefined;
6
6
  primaryDark?: string | undefined;
7
+ primaryLight?: string | undefined;
7
8
  backgroundPaper?: string | undefined;
8
9
  backgroundHighlight?: string | undefined;
9
10
  backgroundSection?: string | undefined;
@@ -9,6 +9,7 @@ export declare type StiggTheme = {
9
9
  palette: {
10
10
  primary: string;
11
11
  primaryDark: string;
12
+ primaryLight: string;
12
13
  backgroundPaper: string;
13
14
  backgroundHighlight: string;
14
15
  backgroundSection: string;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.4.0-beta.9",
2
+ "version": "4.4.1",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -20,6 +20,7 @@
20
20
  "analyze": "size-limit --why",
21
21
  "storybook": "export NODE_OPTIONS=--openssl-legacy-provider && start-storybook -p 6006",
22
22
  "build-storybook": "build-storybook",
23
+ "prepare": "husky install",
23
24
  "docs": "typedoc",
24
25
  "link-sdk": "yarn link && cd node_modules/react && yarn link && cd ../../node_modules/react-dom && yarn link && cd ../../",
25
26
  "publish-storybook": "export NODE_OPTIONS=--openssl-legacy-provider && yarn build-storybook && npx chromatic --project-token=cbd1660d8132"
@@ -32,6 +33,12 @@
32
33
  "pre-commit": "yarn lint"
33
34
  }
34
35
  },
36
+ "lint-staged": {
37
+ "src/**/*.{js,jsx,ts,tsx}": [
38
+ "prettier --check",
39
+ "eslint --cache --max-warnings=0 --fix"
40
+ ]
41
+ },
35
42
  "name": "@stigg/react-sdk",
36
43
  "author": "Stigg",
37
44
  "module": "dist/react-sdk.esm.js",
@@ -51,6 +58,7 @@
51
58
  "@commitlint/config-conventional": "^17.0.3",
52
59
  "@rollup/plugin-image": "^2.1.1",
53
60
  "@size-limit/preset-small-lib": "^7.0.8",
61
+ "@stigg/eslint-config-stigg": "^0.0.7",
54
62
  "@storybook/addon-actions": "^6.5.9",
55
63
  "@storybook/addon-essentials": "^6.5.9",
56
64
  "@storybook/addon-interactions": "^6.5.9",
@@ -64,14 +72,29 @@
64
72
  "@types/color": "^3.0.3",
65
73
  "@types/react": "^18.0.6",
66
74
  "@types/react-dom": "^18.0.2",
67
- "@types/react-lottie":"^1.2.6",
75
+ "@types/react-lottie": "^1.2.6",
76
+ "@typescript-eslint/eslint-plugin": "^5.0.0",
77
+ "@typescript-eslint/parser": "^5.0.0",
68
78
  "autoprefixer": "^10.4.14",
69
79
  "babel-jest": "^28.1.2",
70
80
  "babel-loader": "^8.2.5",
71
81
  "chromatic": "^6.11.4",
72
82
  "cssnano": "^6.0.1",
83
+ "eslint": "^7.11.0",
84
+ "eslint-config-airbnb": "^18.0.4",
85
+ "eslint-config-airbnb-typescript": "^16.1.0",
86
+ "eslint-config-prettier": "^8.3.0",
87
+ "eslint-plugin-import": "^2.28.1",
88
+ "eslint-plugin-jest": "^25.3.2",
89
+ "eslint-plugin-jsx-a11y": "^6.3.1",
90
+ "eslint-plugin-prettier": "^5.0.0",
91
+ "eslint-plugin-react": "^7.28.0",
92
+ "eslint-plugin-react-hooks": "^4.2.0",
93
+ "eslint-plugin-unused-imports": "^2.0.0",
73
94
  "husky": "^7.0.4",
95
+ "lint-staged": "^14.0.1",
74
96
  "postcss": "^8.4.24",
97
+ "prettier": "^3.0.2",
75
98
  "react": "^18.0.0",
76
99
  "react-dom": "^18.0.0",
77
100
  "rollup-plugin-postcss": "^4.0.2",
@@ -80,28 +103,13 @@
80
103
  "tsdx": "^0.14.1",
81
104
  "tslib": "^2.4.0",
82
105
  "typedoc": "^0.23.7",
83
- "typescript": "^4.6.3",
84
- "prettier": "^3.0.2",
85
- "eslint": "^7.11.0",
86
- "@stigg/eslint-config-stigg": "^0.0.7",
87
- "@typescript-eslint/eslint-plugin": "^5.0.0",
88
- "@typescript-eslint/parser": "^5.0.0",
89
- "eslint-config-airbnb": "^18.0.4",
90
- "eslint-config-airbnb-typescript": "^16.1.0",
91
- "eslint-config-prettier": "^8.3.0",
92
- "eslint-plugin-jsx-a11y": "^6.3.1",
93
- "eslint-plugin-import": "^2.28.1",
94
- "eslint-plugin-jest": "^25.3.2",
95
- "eslint-plugin-prettier": "^5.0.0",
96
- "eslint-plugin-react": "^7.28.0",
97
- "eslint-plugin-react-hooks": "^4.2.0",
98
- "eslint-plugin-unused-imports": "^2.0.0"
106
+ "typescript": "^4.6.3"
99
107
  },
100
108
  "dependencies": {
101
109
  "@emotion/react": "^11.10.5",
102
110
  "@emotion/styled": "^11.10.5",
103
111
  "@mui/material": "^5.10.13",
104
- "@stigg/js-client-sdk": "2.22.0",
112
+ "@stigg/js-client-sdk": "2.23.1",
105
113
  "@stripe/react-stripe-js": "^2.1.1",
106
114
  "@stripe/stripe-js": "^1.54.1",
107
115
  "@types/styled-components": "^5.1.26",
@@ -121,5 +129,5 @@
121
129
  "styled-typography": "^1.0.3"
122
130
  },
123
131
  "readme": "ERROR: No README data found!",
124
- "_id": "@stigg/react-sdk@1.0.0"
132
+ "_id": "@stigg/react-sdk@0.18.0"
125
133
  }
@@ -0,0 +1,6 @@
1
+ <svg width="16" height="16" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <g id="tag--tags-bookmark-favorite">
3
+ <path id="Vector" d="M1.26995 11.9426L6.05743 16.7301C6.2305 16.903 6.4651 17.0001 6.7097 17.0001C6.95431 17.0001 7.18891 16.903 7.36198 16.7301L16.8631 7.22895C16.9108 7.18332 16.9478 7.12758 16.9712 7.06583C16.9946 7.00408 17.0039 6.93787 16.9985 6.87205L16.2724 2.15839C16.2664 2.04607 16.2192 1.93992 16.1396 1.86038C16.0601 1.78085 15.9539 1.73357 15.8416 1.72764L11.128 1.00152C11.0622 0.996055 10.9959 1.00538 10.9342 1.0288C10.8724 1.05222 10.8167 1.08916 10.7711 1.1369L1.26995 10.638C1.09709 10.8111 1 11.0457 1 11.2903C1 11.5349 1.09709 11.7695 1.26995 11.9426Z" stroke="#327EEE" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
4
+ <path id="Vector_2" d="M12.5548 6.05884C12.3916 6.05884 12.2351 5.99401 12.1197 5.87861C12.0043 5.76321 11.9395 5.60669 11.9395 5.44348C11.9395 5.28028 12.0043 5.12376 12.1197 5.00836C12.2351 4.89296 12.3916 4.82812 12.5548 4.82812C12.718 4.82812 12.8745 4.89296 12.9899 5.00836C13.1053 5.12376 13.1702 5.28028 13.1702 5.44348C13.1702 5.60669 13.1053 5.76321 12.9899 5.87861C12.8745 5.99401 12.718 6.05884 12.5548 6.05884Z" stroke="#327EEE" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
5
+ </g>
6
+ </svg>
@@ -0,0 +1,11 @@
1
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <g clip-path="url(#clip0_1889_12169)">
3
+ <path d="M11.4286 7.42578L8 13.1401" stroke="#7586B0" stroke-width="1.71429" stroke-linecap="round" stroke-linejoin="round"/>
4
+ <path d="M14.857 13.1412C15.3274 12.0123 15.5118 10.7848 15.3938 9.56751C15.2758 8.35027 14.8592 7.18097 14.1808 6.16341C13.5024 5.14585 12.5833 4.31152 11.5051 3.73446C10.4268 3.1574 9.22281 2.85547 7.99986 2.85547C6.77691 2.85547 5.57288 3.1574 4.49463 3.73446C3.41639 4.31152 2.49729 5.14585 1.81892 6.16341C1.14055 7.18097 0.723889 8.35027 0.605928 9.56751C0.487968 10.7848 0.672354 12.0123 1.14272 13.1412H14.857Z" stroke="#7586B0" stroke-width="1.71429" stroke-linecap="round" stroke-linejoin="round"/>
5
+ </g>
6
+ <defs>
7
+ <clipPath id="clip0_1889_12169">
8
+ <rect width="16" height="16" fill="white"/>
9
+ </clipPath>
10
+ </defs>
11
+ </svg>
@@ -1,8 +1,9 @@
1
1
  import React from 'react';
2
2
  import { CheckoutProvider, CheckoutProviderProps } from './CheckoutProvider';
3
3
  import { CheckoutContainer, CheckoutContainerProps } from './CheckoutContainer';
4
+ import { CheckoutMockProps } from './types';
4
5
 
5
- export type CheckoutProps = CheckoutProviderProps & CheckoutContainerProps;
6
+ export type CheckoutProps = CheckoutProviderProps & CheckoutContainerProps & CheckoutMockProps;
6
7
 
7
8
  export const Checkout = ({
8
9
  textOverrides,
@@ -13,6 +14,7 @@ export const Checkout = ({
13
14
  billingCountryCode,
14
15
  billableFeatures,
15
16
  billingInformation,
17
+ onMockCheckoutState,
16
18
  ...containerProps
17
19
  }: CheckoutProps) => {
18
20
  return (
@@ -24,7 +26,8 @@ export const Checkout = ({
24
26
  preferredBillingPeriod={preferredBillingPeriod}
25
27
  billingCountryCode={billingCountryCode}
26
28
  billableFeatures={billableFeatures}
27
- billingInformation={billingInformation}>
29
+ billingInformation={billingInformation}
30
+ onMockCheckoutState={onMockCheckoutState}>
28
31
  <CheckoutContainer {...containerProps} />
29
32
  </CheckoutProvider>
30
33
  );
@@ -1,11 +1,10 @@
1
- import React from 'react';
1
+ import React, { useMemo } from 'react';
2
2
  import { Elements } from '@stripe/react-stripe-js';
3
- import { ApplySubscription, BillingAddress, CheckoutStatePlan, PricingType } from '@stigg/js-client-sdk';
3
+ import { PricingType, BillingAddress, ApplySubscription, CheckoutStatePlan } from '@stigg/js-client-sdk';
4
4
  import { CheckoutContent, CheckoutLayout, CheckoutPanel } from './CheckoutContainer.style';
5
5
  import { CheckoutProgressBar } from './progressBar/CheckoutProgressBar';
6
6
  import { CheckoutSummary, CheckoutSummarySkeleton } from './summary';
7
7
  import { CheckoutStep, CheckoutStepKey, useCheckoutModel, useProgressBarModel } from './hooks';
8
- import { PlanHeader } from './planHeader';
9
8
  import { CheckoutAddonsStep } from './steps/addons';
10
9
  import { PaymentStep } from './steps/payment';
11
10
  import { useStripeIntegration } from './steps/payment/stripe';
@@ -13,19 +12,22 @@ import { CheckoutPlanStep } from './steps/plan';
13
12
  import { useCheckoutContext } from './CheckoutProvider';
14
13
  import { ContentLoadingSkeleton } from './components';
15
14
  import { DowngradeToFreePlan } from './components/DowngradeToFreeContainer';
15
+ import { MockCheckoutPreviewCallback } from './types';
16
16
 
17
17
  type StepProps = {
18
- allowChangePlan?: boolean;
19
18
  content: React.ReactNode;
20
19
  };
21
20
 
21
+ type StripeClientSecret = { clientSecret: string };
22
+ type StripeManualMode = { mode: 'setup' | 'payment' | 'subscription'; currency: string };
23
+
22
24
  const getStepProps = (
23
25
  currentStep: CheckoutStep,
24
- { onBillingAddressChange }: Pick<CheckoutContainerProps, 'onBillingAddressChange'>,
26
+ { onBillingAddressChange, onChangePlan }: Pick<CheckoutContainerProps, 'onBillingAddressChange' | 'onChangePlan'>,
25
27
  ): StepProps => {
26
28
  switch (currentStep.key) {
27
29
  case CheckoutStepKey.PLAN:
28
- return { allowChangePlan: true, content: <CheckoutPlanStep /> };
30
+ return { content: <CheckoutPlanStep onChangePlan={onChangePlan} /> };
29
31
  case CheckoutStepKey.ADDONS:
30
32
  return { content: <CheckoutAddonsStep /> };
31
33
  case CheckoutStepKey.PAYMENT:
@@ -48,6 +50,7 @@ export type CheckoutContainerProps = {
48
50
  onBillingAddressChange?: (params: { billingAddress: BillingAddress }) => Promise<void>;
49
51
  disablePromotionCode?: boolean;
50
52
  disableSuccessAnimation?: boolean;
53
+ onMockCheckoutPreview?: MockCheckoutPreviewCallback;
51
54
  };
52
55
 
53
56
  export function CheckoutContainer({
@@ -57,6 +60,7 @@ export function CheckoutContainer({
57
60
  onBillingAddressChange,
58
61
  disablePromotionCode,
59
62
  disableSuccessAnimation,
63
+ onMockCheckoutPreview,
60
64
  }: CheckoutContainerProps) {
61
65
  const { stripePromise, setupIntentClientSecret } = useStripeIntegration();
62
66
  const [{ stiggTheme, widgetState }] = useCheckoutContext();
@@ -72,7 +76,7 @@ export function CheckoutContainer({
72
76
  !!activeSubscription &&
73
77
  activeSubscription.pricingType !== PricingType.Free;
74
78
 
75
- const { content, allowChangePlan } = getStepProps(currentStep, { onBillingAddressChange });
79
+ const { content } = getStepProps(currentStep, { onBillingAddressChange, onChangePlan });
76
80
 
77
81
  const checkoutContent = (
78
82
  <>
@@ -81,23 +85,25 @@ export function CheckoutContainer({
81
85
  checkoutLocalization={checkoutLocalization}
82
86
  freePlan={plan!}
83
87
  activeSubscription={activeSubscription!}
84
- allowChangePlan={allowChangePlan}
88
+ allowChangePlan
85
89
  onChangePlan={onChangePlan}
86
90
  />
87
91
  ) : (
88
- <>
89
- <PlanHeader allowChangePlan={allowChangePlan} onChangePlan={onChangePlan} />
90
- {content}
91
- </>
92
+ <>{content}</>
92
93
  )}
93
94
  </>
94
95
  );
95
96
 
97
+ const stripeElementsMode: StripeClientSecret | StripeManualMode = useMemo(
98
+ () => (setupIntentClientSecret ? { clientSecret: setupIntentClientSecret } : { mode: 'setup', currency: 'usd' }),
99
+ [setupIntentClientSecret],
100
+ );
101
+
96
102
  return (
97
103
  <Elements
98
104
  stripe={stripePromise}
99
105
  options={{
100
- clientSecret: setupIntentClientSecret,
106
+ ...stripeElementsMode,
101
107
  appearance: {
102
108
  theme: 'stripe',
103
109
  variables: {
@@ -121,6 +127,7 @@ export function CheckoutContainer({
121
127
  onCheckout={onCheckout}
122
128
  onCheckoutCompleted={onCheckoutCompleted}
123
129
  isFreeDowngrade={isFreeDowngrade}
130
+ onMockCheckoutPreview={onMockCheckoutPreview}
124
131
  />
125
132
  )}
126
133
  </CheckoutContent>
@@ -19,7 +19,7 @@ import {
19
19
  import { CheckoutLocalization, getResolvedCheckoutLocalize } from './textOverrides';
20
20
  import { CheckoutTheme, getResolvedCheckoutTheme } from './theme';
21
21
  import { StiggTheme } from '../../theme/types';
22
- import { BillingInformation } from './types';
22
+ import { BillingInformation, MockCheckoutStateCallback } from './types';
23
23
 
24
24
  export interface CheckoutContextState {
25
25
  checkout?: GetCheckoutStateResults | null;
@@ -80,6 +80,7 @@ export type CheckoutProviderProps = {
80
80
  billingCountryCode?: string;
81
81
  billableFeatures?: BillableFeature[];
82
82
  billingInformation?: BillingInformation;
83
+ onMockCheckoutState?: MockCheckoutStateCallback;
83
84
  };
84
85
 
85
86
  export function CheckoutProvider({
@@ -92,10 +93,11 @@ export function CheckoutProvider({
92
93
  planId,
93
94
  billingCountryCode,
94
95
  billingInformation,
96
+ onMockCheckoutState,
95
97
  }: {
96
98
  children: React.ReactNode;
97
99
  } & CheckoutProviderProps) {
98
- const { checkout, isLoading } = useLoadCheckout({ resourceId, planId, billingCountryCode });
100
+ const { checkout, isLoading } = useLoadCheckout({ resourceId, planId, billingCountryCode, onMockCheckoutState });
99
101
  const configuration: CustomizedTheme | undefined = checkout?.configuration
100
102
  ? mapCheckoutConfiguration(checkout.configuration)
101
103
  : undefined;
@@ -134,7 +136,7 @@ export function CheckoutProvider({
134
136
  addonsStep,
135
137
  paymentStep,
136
138
  resourceId: checkout?.resource?.id,
137
- widgetState: { readOnly: false, isLoadingCheckoutData: isLoading },
139
+ widgetState: { readOnly: false, isValid: true, isLoadingCheckoutData: isLoading },
138
140
  };
139
141
 
140
142
  return initialState;
@@ -1,11 +1,9 @@
1
1
  import React from 'react';
2
- import { StyledArrowRightIcon } from '../planHeader/PlanHeader.style';
3
2
  import styled from '@emotion/styled/macro';
4
3
  import { Alert, Box } from '@mui/material';
5
- import { Typography } from '../../common/Typography';
6
4
  import { CheckoutStatePlan, Subscription } from '@stigg/js-client-sdk';
7
- import { Currency, BillingPeriod } from '@stigg/js-client-sdk';
8
- import { currencyPriceFormatter } from '../../utils/currencyUtils';
5
+ import { StyledArrowRightIcon } from './StyledArrow';
6
+ import { Typography } from '../../common/Typography';
9
7
  import { CheckoutLocalization } from '../textOverrides';
10
8
  import { CheckoutContainerProps } from '../CheckoutContainer';
11
9
  import { ChangePlanButton } from './ChangePlanButton';
@@ -26,40 +24,29 @@ export const DowngradeToFreePlanBox = styled(Box)`
26
24
  `;
27
25
 
28
26
  export const DowngradeToFreeContent = ({
27
+ headerText,
29
28
  planName,
30
- totalPrice,
31
- billingPeriod,
29
+ priceText,
32
30
  }: {
31
+ headerText: string;
33
32
  planName: string;
34
- totalPrice?: {
35
- amount: number;
36
- currency: Currency;
37
- };
38
- billingPeriod?: BillingPeriod;
33
+ priceText: string;
39
34
  }) => {
40
- const priceText = totalPrice
41
- ? currencyPriceFormatter({ amount: totalPrice.amount, currency: totalPrice.currency })
42
- : 'Free';
43
-
44
- const billingPeriodText = billingPeriod ? ` / Paid ${billingPeriod.toLowerCase()}` : '';
45
35
  return (
46
- <DowngradeToFreePlanBox className="stigg-checkout-free-downgrade-plan-box">
47
- <Typography className="stigg-checkout-downgrade-to-free-text-plan" color="secondary">
36
+ <DowngradeToFreePlanBox className="stigg-checkout-downgrade-to-free-container">
37
+ <Typography
38
+ className="stigg-checkout-downgrade-to-free-text-header"
39
+ style={{ opacity: 0.8 }}
40
+ variant="caption"
41
+ color="disabled">
42
+ {headerText}
43
+ </Typography>
44
+ <Typography className="stigg-checkout-downgrade-to-free-plan-name" bold variant="h3" color="primary">
48
45
  {planName}
49
46
  </Typography>
50
- <div>
51
- <Typography
52
- className="stigg-checkout-downgrade-to-free-text-price"
53
- span
54
- bold={true}
55
- variant="h3"
56
- color="primary">
57
- {priceText}
58
- </Typography>
59
- <Typography className="stigg-checkout-downgrade-to-free-text-billing-period" span color="secondary">
60
- {billingPeriodText}
61
- </Typography>
62
- </div>
47
+ <Typography className="stigg-checkout-downgrade-to-free-price-text" color="secondary">
48
+ {priceText}
49
+ </Typography>
63
50
  </DowngradeToFreePlanBox>
64
51
  );
65
52
  };
@@ -91,19 +78,25 @@ export const DowngradeToFreePlan = ({
91
78
  );
92
79
  }
93
80
 
81
+ const paidBillingPeriod =
82
+ activeSubscription.prices.length > 0 ? activeSubscription.prices[0].billingPeriod : undefined;
83
+
94
84
  return (
95
85
  <>
96
86
  <DowngradeToFreeAlert action={alertAction} className="stigg-checkout-downgrade-to-free-alert" severity="info">
97
87
  <Typography span color="secondary">
98
- {checkoutLocalization.downgradeToFreeAlertText({ plan: activeSubscription.plan })}
88
+ {checkoutLocalization.downgradeToFree.alertText({ plan: activeSubscription.plan })}
99
89
  </Typography>
100
90
  </DowngradeToFreeAlert>
101
91
 
102
92
  <DowngradeToFreePlansContainer className="stigg-checkout-downgrade-to-free-plans-container">
103
93
  <DowngradeToFreeContent
104
- planName={activeSubscription.plan.displayName}
105
- totalPrice={activeSubscription.totalPrice?.total}
106
- billingPeriod={activeSubscription.prices[0].billingPeriod}
94
+ headerText={checkoutLocalization.downgradeToFree.paidPlanHeader({ plan: activeSubscription.plan })}
95
+ planName={checkoutLocalization.downgradeToFree.paidPlanName({ plan: activeSubscription.plan })}
96
+ priceText={checkoutLocalization.downgradeToFree.paidPlanPriceText({
97
+ plan: activeSubscription.plan,
98
+ billingPeriod: paidBillingPeriod,
99
+ })}
107
100
  />
108
101
 
109
102
  <StyledArrowRightIcon
@@ -111,7 +104,11 @@ export const DowngradeToFreePlan = ({
111
104
  style={{ margin: 'auto 16px', minWidth: '16px' }}
112
105
  />
113
106
 
114
- <DowngradeToFreeContent planName={freePlan.displayName} />
107
+ <DowngradeToFreeContent
108
+ headerText={checkoutLocalization.downgradeToFree.freePlanHeader({ plan: freePlan })}
109
+ planName={checkoutLocalization.downgradeToFree.freePlanName({ plan: freePlan })}
110
+ priceText={checkoutLocalization.downgradeToFree.freePlanPriceText({ plan: freePlan })}
111
+ />
115
112
  </DowngradeToFreePlansContainer>
116
113
  </>
117
114
  );
@@ -19,4 +19,7 @@ export const InputField = styled(TextField)<OutlinedInputProps>(({ theme }) => (
19
19
  color: theme.stigg.palette.text.primary,
20
20
  ...theme.stigg.typography.body,
21
21
  },
22
+ '& .Mui-error': {
23
+ fontFamily: theme.stigg.typography.fontFamily,
24
+ },
22
25
  }));
@@ -0,0 +1,9 @@
1
+ import styled from '@emotion/styled/macro';
2
+
3
+ import ArrowRightIcon from '../../../assets/arrow-right.svg';
4
+
5
+ export const StyledArrowRightIcon = styled(ArrowRightIcon)`
6
+ path {
7
+ stroke: ${({ theme }) => theme.stigg.palette.text.secondary};
8
+ }
9
+ `;
@@ -3,6 +3,7 @@ import { useCheckoutContext } from '../CheckoutProvider';
3
3
  export type WidgetState = {
4
4
  readOnly?: boolean;
5
5
  isLoadingCheckoutData?: boolean;
6
+ isValid?: boolean;
6
7
  };
7
8
 
8
9
  function useCheckoutState() {
@@ -19,14 +20,23 @@ function useSetWidgetReadonly() {
19
20
  });
20
21
  }
21
22
 
23
+ function useSetIsValid() {
24
+ const [, setState] = useCheckoutContext();
25
+
26
+ return (isValid: boolean) =>
27
+ setState((draft) => {
28
+ draft.widgetState.isValid = isValid;
29
+ });
30
+ }
31
+
22
32
  export function useCheckoutModel() {
23
33
  const { checkoutState, widgetState, checkoutLocalization } = useCheckoutState();
24
- const setWidgetReadOnly = useSetWidgetReadonly();
25
34
 
26
35
  return {
27
36
  checkoutState,
28
37
  widgetState,
29
38
  checkoutLocalization,
30
- setWidgetReadOnly,
39
+ setWidgetReadOnly: useSetWidgetReadonly(),
40
+ setIsValid: useSetIsValid(),
31
41
  };
32
42
  }
@@ -2,14 +2,16 @@ import { GetCheckoutStateResults } from '@stigg/js-client-sdk';
2
2
  import { useEffect, useState } from 'react';
3
3
  import logger from '../../../services/logger';
4
4
  import { useStiggContext } from '../../StiggProvider';
5
+ import { MockCheckoutStateCallback } from '../types';
5
6
 
6
7
  type UseLoadCheckoutProps = {
7
8
  planId: string;
8
9
  resourceId?: string;
9
10
  billingCountryCode?: string;
11
+ onMockCheckoutState?: MockCheckoutStateCallback;
10
12
  };
11
13
 
12
- export function useLoadCheckout({ planId, resourceId, billingCountryCode }: UseLoadCheckoutProps) {
14
+ export function useLoadCheckout({ planId, resourceId, billingCountryCode, onMockCheckoutState }: UseLoadCheckoutProps) {
13
15
  const { stigg } = useStiggContext();
14
16
  const [isLoading, setIsLoading] = useState(true);
15
17
  const [checkout, setCheckout] = useState<GetCheckoutStateResults | null>();
@@ -26,11 +28,17 @@ export function useLoadCheckout({ planId, resourceId, billingCountryCode }: UseL
26
28
  }
27
29
  };
28
30
 
31
+ if (onMockCheckoutState) {
32
+ setIsLoading(false);
33
+ setCheckout(onMockCheckoutState({ planId, resourceId, billingCountryCode }));
34
+ return;
35
+ }
36
+
29
37
  if (stigg.isCustomerLoaded) {
30
38
  setIsLoading(true);
31
39
  void loadCheckout();
32
40
  }
33
- }, [stigg, stigg.isCustomerLoaded, resourceId, planId, billingCountryCode]);
41
+ }, [stigg, stigg.isCustomerLoaded, resourceId, planId, billingCountryCode, onMockCheckoutState]);
34
42
 
35
43
  return {
36
44
  checkout,