@stigg/react-sdk 4.6.1 → 4.7.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.
Files changed (77) hide show
  1. package/README.md +7 -0
  2. package/dist/components/checkout/CheckoutContainer.d.ts +4 -2
  3. package/dist/components/checkout/components/Button.d.ts +1 -1
  4. package/dist/components/checkout/components/InputField.d.ts +2 -2
  5. package/dist/components/checkout/components/Skeletons.style.d.ts +3 -3
  6. package/dist/components/checkout/hooks/useSubscriptionState.d.ts +2 -2
  7. package/dist/components/checkout/progressBar/CheckoutProgressBar.style.d.ts +2 -2
  8. package/dist/components/checkout/steps/addons/CheckoutAddonsStep.style.d.ts +2 -2
  9. package/dist/components/checkout/steps/payment/PaymentMethods.style.d.ts +4 -4
  10. package/dist/components/checkout/steps/payment/stripe/stripe.utils.d.ts +9 -13
  11. package/dist/components/checkout/steps/payment/stripe/useSubmit.d.ts +2 -1
  12. package/dist/components/checkout/steps/plan/BillingPeriodPicker.style.d.ts +1 -1
  13. package/dist/components/checkout/summary/CheckoutSummary.d.ts +1 -1
  14. package/dist/components/common/InformationTooltip.d.ts +1 -1
  15. package/dist/components/common/LongText.d.ts +1 -1
  16. package/dist/components/customerPortal/paywall/CustomerPortalPaywall.d.ts +0 -1
  17. package/dist/components/customerPortal/paywall/CustomerPortalPaywall.style.d.ts +0 -1
  18. package/dist/components/customerPortal/usage/featureUsage/FeatureUsageProgressBar.d.ts +2 -2
  19. package/dist/components/paywall/Paywall.d.ts +0 -1
  20. package/dist/components/paywall/PlanOffering.d.ts +2 -1
  21. package/dist/components/paywall/PlanOfferingButton.d.ts +1 -2
  22. package/dist/react-sdk.cjs.development.js +489 -426
  23. package/dist/react-sdk.cjs.development.js.map +1 -1
  24. package/dist/react-sdk.cjs.production.min.js +1 -1
  25. package/dist/react-sdk.cjs.production.min.js.map +1 -1
  26. package/dist/react-sdk.esm.js +409 -347
  27. package/dist/react-sdk.esm.js.map +1 -1
  28. package/package.json +2 -2
  29. package/src/components/checkout/CheckoutContainer.tsx +13 -3
  30. package/src/components/checkout/components/Button.tsx +1 -1
  31. package/src/components/checkout/components/ChangePlanButton.tsx +1 -2
  32. package/src/components/checkout/components/ContentLoadingSkeleton.tsx +2 -1
  33. package/src/components/checkout/components/DowngradeToFreeContainer.tsx +2 -1
  34. package/src/components/checkout/components/InputField.tsx +2 -1
  35. package/src/components/checkout/components/Skeletons.style.ts +1 -1
  36. package/src/components/checkout/hooks/useSubscriptionState.ts +2 -3
  37. package/src/components/checkout/planHeader/PlanHeader.tsx +2 -1
  38. package/src/components/checkout/progressBar/CheckoutProgressBar.style.ts +2 -1
  39. package/src/components/checkout/progressBar/CheckoutProgressBar.tsx +3 -1
  40. package/src/components/checkout/promotionCode/AddPromotionCode.tsx +2 -1
  41. package/src/components/checkout/promotionCode/AppliedPromotionCode.tsx +1 -1
  42. package/src/components/checkout/steps/addons/CheckoutAddonsStep.style.tsx +1 -1
  43. package/src/components/checkout/steps/addons/CheckoutAddonsStep.tsx +1 -1
  44. package/src/components/checkout/steps/payment/PaymentMethods.style.ts +1 -1
  45. package/src/components/checkout/steps/payment/PaymentMethods.tsx +3 -1
  46. package/src/components/checkout/steps/payment/PaymentStep.tsx +2 -1
  47. package/src/components/checkout/steps/payment/stripe/StripePaymentForm.tsx +1 -1
  48. package/src/components/checkout/steps/payment/stripe/stripe.utils.ts +31 -22
  49. package/src/components/checkout/steps/payment/stripe/useSubmit.ts +63 -46
  50. package/src/components/checkout/steps/plan/BillingPeriodPicker.style.tsx +2 -1
  51. package/src/components/checkout/steps/plan/BillingPeriodPicker.tsx +2 -1
  52. package/src/components/checkout/steps/plan/CheckoutChargeList.tsx +1 -1
  53. package/src/components/checkout/steps/plan/CheckoutPlanStep.style.tsx +1 -1
  54. package/src/components/checkout/summary/CheckoutSuccess.tsx +1 -1
  55. package/src/components/checkout/summary/CheckoutSummary.tsx +6 -1
  56. package/src/components/checkout/summary/components/LineItems.tsx +1 -1
  57. package/src/components/common/InformationTooltip.tsx +13 -9
  58. package/src/components/common/LongText.tsx +3 -5
  59. package/src/components/common/TiersSelectContainer.tsx +3 -1
  60. package/src/components/customerPortal/CustomerPortalContainer.tsx +5 -8
  61. package/src/components/customerPortal/billing/PaymentDetailsSection.tsx +2 -3
  62. package/src/components/customerPortal/paywall/CustomerPortalPaywall.style.ts +0 -10
  63. package/src/components/customerPortal/paywall/CustomerPortalPaywall.tsx +2 -5
  64. package/src/components/customerPortal/subscriptionOverview/subscriptionScheduledUpdates/SubscriptionScheduledUpdateRow.tsx +2 -2
  65. package/src/components/customerPortal/subscriptionOverview/subscriptionScheduledUpdates/SubscriptionScheduledUpdatesAlert.tsx +6 -7
  66. package/src/components/customerPortal/subscriptionOverview/subscriptionView/TrialPanel.tsx +1 -1
  67. package/src/components/customerPortal/usage/CustomerUsageData.style.tsx +2 -2
  68. package/src/components/customerPortal/usage/CustomerUsageData.tsx +24 -16
  69. package/src/components/customerPortal/usage/featureUsage/FeatureUsageProgressBar.tsx +3 -9
  70. package/src/components/paywall/EntitlementRow.tsx +25 -7
  71. package/src/components/paywall/Paywall.tsx +36 -20
  72. package/src/components/paywall/PaywallContainer.tsx +2 -2
  73. package/src/components/paywall/PlanOffering.tsx +36 -22
  74. package/src/components/paywall/PlanOfferingButton.tsx +1 -3
  75. package/src/components/paywall/utils/mapPaywallData.ts +13 -11
  76. package/src/stories/Checkout.stories.tsx +2 -2
  77. package/src/stories/baseArgs.ts +3 -3
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.6.1",
2
+ "version": "4.7.0",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -109,7 +109,7 @@
109
109
  "@emotion/react": "^11.10.5",
110
110
  "@emotion/styled": "^11.10.5",
111
111
  "@mui/material": "^5.12.0",
112
- "@stigg/js-client-sdk": "2.24.1",
112
+ "@stigg/js-client-sdk": "2.24.3",
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",
@@ -1,6 +1,12 @@
1
1
  import React, { useMemo } from 'react';
2
2
  import { Elements } from '@stripe/react-stripe-js';
3
- import { PricingType, BillingAddress, ApplySubscription, CheckoutStatePlan } from '@stigg/js-client-sdk';
3
+ import {
4
+ PricingType,
5
+ BillingAddress,
6
+ ApplySubscription,
7
+ CheckoutStatePlan,
8
+ ApplySubscriptionResults,
9
+ } from '@stigg/js-client-sdk';
4
10
  import { CheckoutContent, CheckoutLayout, CheckoutPanel } from './CheckoutContainer.style';
5
11
  import { CheckoutProgressBar } from './progressBar/CheckoutProgressBar';
6
12
  import { CheckoutSummary, CheckoutSummarySkeleton } from './summary';
@@ -45,9 +51,13 @@ const getStepProps = (
45
51
  }
46
52
  };
47
53
 
48
- export type CheckoutResult = { success: boolean; errorMessage?: string };
54
+ export type CheckoutResult = { success: boolean; errorMessage?: string; results?: ApplySubscriptionResults };
49
55
 
50
- export type OnCheckoutParams = { checkoutParams: ApplySubscription; checkoutAction: () => Promise<CheckoutResult> };
56
+ export type OnCheckoutParams = {
57
+ customerId: string;
58
+ checkoutParams: ApplySubscription;
59
+ checkoutAction: (params: ApplySubscription) => Promise<CheckoutResult>;
60
+ };
51
61
 
52
62
  export type OnCheckoutCompletedParams = { success: boolean; error?: string };
53
63
 
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
 
3
3
  import styled from '@emotion/styled/macro';
4
- import { Button as MuiButton, ButtonProps } from '@mui/material';
4
+ import MuiButton, { ButtonProps } from '@mui/material/Button';
5
5
 
6
6
  export type StyledButtonProps = { $success?: boolean; $error?: boolean };
7
7
 
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
- import { ButtonProps } from '@mui/material/Button';
3
- import { Button } from '@mui/material';
2
+ import Button, { ButtonProps } from '@mui/material/Button';
4
3
  import { Typography } from '../../common/Typography';
5
4
  import { CheckoutLocalization } from '../configurations/textOverrides';
6
5
 
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
- import { Grid, Divider } from '@mui/material';
2
+ import Divider from '@mui/material/Divider';
3
+ import Grid from '@mui/material/Grid';
3
4
  import styled from '@emotion/styled/macro';
4
5
  import { FlexedSkeleton, FlexedSkeletonContainer, Skeleton, SkeletonsContainer } from './Skeletons.style';
5
6
 
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import styled from '@emotion/styled/macro';
3
- import { Alert, Box } from '@mui/material';
3
+ import Box from '@mui/material/Box';
4
+ import Alert from '@mui/material/Alert';
4
5
  import { CheckoutStatePlan, Subscription } from '@stigg/js-client-sdk';
5
6
  import { StyledArrowRightIcon } from './StyledArrow';
6
7
  import { Typography } from '../../common/Typography';
@@ -1,5 +1,6 @@
1
1
  import styled from '@emotion/styled';
2
- import { OutlinedInputProps, TextField } from '@mui/material';
2
+ import { OutlinedInputProps } from '@mui/material/OutlinedInput';
3
+ import TextField from '@mui/material/TextField';
3
4
 
4
5
  export const InputField = styled(TextField)<OutlinedInputProps>(({ theme }) => ({
5
6
  '& .MuiOutlinedInput-root': {
@@ -1,5 +1,5 @@
1
1
  import styled from '@emotion/styled/macro';
2
- import { Grid } from '@mui/material';
2
+ import Grid from '@mui/material/Grid';
3
3
  import ReactSkeleton from 'react-loading-skeleton';
4
4
 
5
5
  export const SkeletonsContainer = styled(Grid, { shouldForwardProp: (prop) => !prop.startsWith('$') })<{
@@ -1,9 +1,9 @@
1
- import { ApplySubscription } from '@stigg/js-client-sdk';
1
+ import { ApplySubscription, PreviewSubscription } from '@stigg/js-client-sdk';
2
2
  import { useCheckoutContext } from '../CheckoutProvider';
3
3
  import { useCheckoutModel } from './useCheckoutModel';
4
4
  import { useSubscriptionModel } from './useSubscriptionModel';
5
5
 
6
- export function useSubscriptionState(): ApplySubscription | undefined {
6
+ export function useSubscriptionState(): ApplySubscription | PreviewSubscription | undefined {
7
7
  const subscription = useSubscriptionModel();
8
8
  const [{ resourceId }] = useCheckoutContext();
9
9
  const { checkoutState } = useCheckoutModel();
@@ -22,6 +22,5 @@ export function useSubscriptionState(): ApplySubscription | undefined {
22
22
  addons,
23
23
  promotionCode: subscription.promotionCode,
24
24
  billingCountryCode: subscription.billingCountryCode,
25
- ...(subscription.taxPercentage ? { billingInformation: { taxPercentage: subscription.taxPercentage } } : {}),
26
25
  };
27
26
  }
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
 
3
- import { Box, Divider } from '@mui/material';
3
+ import Box from '@mui/material/Box';
4
+ import Divider from '@mui/material/Divider';
4
5
 
5
6
  import { Typography } from '../../common/Typography';
6
7
  import { useCheckoutModel } from '../hooks/useCheckoutModel';
@@ -1,5 +1,6 @@
1
1
  import styled from '@emotion/styled/macro';
2
- import { Button, buttonClasses, LinearProgress, linearProgressClasses } from '@mui/material';
2
+ import LinearProgress, { linearProgressClasses } from '@mui/material/LinearProgress';
3
+ import Button, { buttonClasses } from '@mui/material/Button';
3
4
  import { Icon } from '../../common/Icon';
4
5
 
5
6
  export const StyledProgress = styled(LinearProgress, { shouldForwardProp: (prop) => !prop.startsWith('$') })<{
@@ -1,5 +1,7 @@
1
1
  import React from 'react';
2
- import { Box, StepIcon, Grid } from '@mui/material';
2
+ import Grid from '@mui/material/Grid';
3
+ import Box from '@mui/material/Box';
4
+ import StepIcon from '@mui/material/StepIcon';
3
5
  import { useCheckoutModel, useProgressBarModel } from '../hooks';
4
6
  import { Typography } from '../../common/Typography';
5
7
  import { StyledProgress, StyledStepButton, StyledIcon } from './CheckoutProgressBar.style';
@@ -1,7 +1,8 @@
1
1
  import React, { useState } from 'react';
2
2
 
3
3
  import styled from '@emotion/styled/macro';
4
- import { CircularProgress, Grid } from '@mui/material';
4
+ import CircularProgress from '@mui/material/CircularProgress';
5
+ import Grid from '@mui/material/Grid';
5
6
 
6
7
  import { Icon } from '../../common/Icon';
7
8
  import { Typography } from '../../common/Typography';
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import styled from '@emotion/styled/macro';
3
- import { Grid } from '@mui/material';
3
+ import Grid from '@mui/material/Grid';
4
4
  import { Icon } from '../../common/Icon';
5
5
  import { Typography } from '../../common/Typography';
6
6
  import { Button } from '../components';
@@ -1,5 +1,5 @@
1
1
  import styled from '@emotion/styled/macro';
2
- import { Grid } from '@mui/material';
2
+ import Grid from '@mui/material/Grid';
3
3
 
4
4
  import { Button } from '../../components';
5
5
 
@@ -1,6 +1,6 @@
1
1
  import React, { useEffect, useState } from 'react';
2
2
 
3
- import { Grid } from '@mui/material';
3
+ import Grid from '@mui/material/Grid';
4
4
  import { Addon, BillingPeriod, SubscriptionAddon } from '@stigg/js-client-sdk';
5
5
 
6
6
  import { Icon } from '../../../common/Icon';
@@ -1,5 +1,5 @@
1
1
  import styled from '@emotion/styled';
2
- import { Grid } from '@mui/material';
2
+ import Grid from '@mui/material/Grid';
3
3
 
4
4
  export const PaymentMethodContainer = styled(Grid, { shouldForwardProp: (prop) => !prop.startsWith('$') })<{
5
5
  $disabled?: boolean;
@@ -1,6 +1,8 @@
1
1
  import React from 'react';
2
2
 
3
- import { Collapse, Grid, Radio } from '@mui/material';
3
+ import Collapse from '@mui/material/Collapse';
4
+ import Grid from '@mui/material/Grid';
5
+ import Radio from '@mui/material/Radio';
4
6
  import { Customer } from '@stigg/js-client-sdk';
5
7
 
6
8
  import { Icon, Icons } from '../../../common/Icon';
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import styled from '@emotion/styled';
3
- import { Alert, Grid } from '@mui/material';
3
+ import Alert from '@mui/material/Alert';
4
+ import Grid from '@mui/material/Grid';
4
5
  import { useCheckoutModel, usePaymentStepModel } from '../../hooks';
5
6
  import { ExistingPaymentMethod, NewPaymentMethod } from './PaymentMethods';
6
7
  import { Typography } from '../../../common/Typography';
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { StripeAddressElementChangeEvent } from '@stripe/stripe-js';
3
- import { Grid } from '@mui/material';
3
+ import Grid from '@mui/material/Grid';
4
4
  import { BillingAddress } from '@stigg/js-client-sdk';
5
5
  import { AddressElement, PaymentElement } from '@stripe/react-stripe-js';
6
6
  import { Typography } from '../../../../common/Typography';
@@ -23,28 +23,6 @@ export async function handleStripeFormValidations({ elements }: Pick<StripeEleme
23
23
  return { success: true };
24
24
  }
25
25
 
26
- export async function handleNewPaymentMethod({
27
- stripe,
28
- elements,
29
- setupIntentClientSecret,
30
- }: {
31
- stripe: Stripe | null;
32
- elements: StripeElements | null;
33
- setupIntentClientSecret?: string;
34
- }) {
35
- if (!stripe || !elements || !setupIntentClientSecret) {
36
- return { success: false };
37
- }
38
-
39
- const { newPaymentMethodId, setupErrorMessage } = await handleStripeSetup({
40
- stripe,
41
- elements,
42
- clientSecret: setupIntentClientSecret,
43
- });
44
-
45
- return { success: !!newPaymentMethodId, paymentMethodId: newPaymentMethodId, errorMessage: setupErrorMessage };
46
- }
47
-
48
26
  export async function handleStripeNextAction({
49
27
  applySubscriptionResults,
50
28
  stripe,
@@ -108,3 +86,34 @@ async function handleStripeSetup({
108
86
 
109
87
  return { newPaymentMethodId, setupErrorMessage };
110
88
  }
89
+
90
+ export async function handleNewPaymentMethod({
91
+ stripe,
92
+ elements,
93
+ setupIntentClientSecret,
94
+ }: {
95
+ stripe: Stripe | null;
96
+ elements: StripeElements | null;
97
+ setupIntentClientSecret?: string;
98
+ }): Promise<{ success: boolean; errorMessage?: string; paymentMethodId?: string }> {
99
+ if (!stripe || !elements || !setupIntentClientSecret) {
100
+ return { success: false };
101
+ }
102
+
103
+ const stripeFormValidationsResults = await handleStripeFormValidations({ elements });
104
+ if (!stripeFormValidationsResults.success) {
105
+ return { success: false, errorMessage: stripeFormValidationsResults.errorMessage };
106
+ }
107
+
108
+ const { newPaymentMethodId, setupErrorMessage } = await handleStripeSetup({
109
+ stripe,
110
+ elements,
111
+ clientSecret: setupIntentClientSecret,
112
+ });
113
+
114
+ if (setupErrorMessage || !newPaymentMethodId) {
115
+ return { success: false, errorMessage: setupErrorMessage };
116
+ }
117
+
118
+ return { success: true, paymentMethodId: newPaymentMethodId };
119
+ }
@@ -5,7 +5,7 @@ import { useCheckoutModel } from '../../../hooks';
5
5
  import { usePaymentStepModel } from '../../../hooks/usePaymentStepModel';
6
6
  import { useSubscriptionState } from '../../../hooks/useSubscriptionState';
7
7
  import { CheckoutContainerProps, CheckoutResult } from '../../../CheckoutContainer';
8
- import { handleNewPaymentMethod, handleStripeFormValidations, handleStripeNextAction } from './stripe.utils';
8
+ import { handleNewPaymentMethod, handleStripeNextAction } from './stripe.utils';
9
9
  import { ANIMATION_DURATION } from '../../../summary/CheckoutSuccess';
10
10
 
11
11
  const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));
@@ -14,14 +14,21 @@ export type HandleSubmitResult = { results?: ApplySubscriptionResults; success:
14
14
 
15
15
  export type UseSubmitProps = {
16
16
  onSuccess?: () => void;
17
+ isMocked?: boolean;
17
18
  } & Pick<CheckoutContainerProps, 'onCheckout' | 'onCheckoutCompleted' | 'disableSuccessAnimation'>;
18
19
 
19
- export function useSubmit({ onCheckout, onCheckoutCompleted, onSuccess, disableSuccessAnimation }: UseSubmitProps) {
20
+ export function useSubmit({
21
+ isMocked = false,
22
+ onCheckout,
23
+ onCheckoutCompleted,
24
+ onSuccess,
25
+ disableSuccessAnimation,
26
+ }: UseSubmitProps) {
20
27
  const { stigg } = useStiggContext();
21
28
  const { useNewPaymentMethod } = usePaymentStepModel();
22
29
  const subscriptionState = useSubscriptionState();
23
30
  const { checkoutState, widgetState, setWidgetReadOnly } = useCheckoutModel();
24
- const { setupSecret: setupIntentClientSecret } = checkoutState || {};
31
+ const { setupSecret: setupIntentClientSecret, customer } = checkoutState || {};
25
32
  const stripe = useStripe();
26
33
  const elements = useElements();
27
34
 
@@ -32,48 +39,38 @@ export function useSubmit({ onCheckout, onCheckoutCompleted, onSuccess, disableS
32
39
  return { success: false, errorMessage: 'Unexpected error, please contact support.' };
33
40
  }
34
41
 
35
- let checkoutParams: ApplySubscription = { ...subscriptionState };
36
- let checkoutResults: ApplySubscriptionResults | undefined;
42
+ let success = true;
37
43
  let errorMessage: string | undefined;
44
+ let usedStiggCheckoutAction = false;
38
45
  let paymentMethodId: string | undefined;
39
46
 
40
- const checkoutAction = async (): Promise<CheckoutResult> => {
41
- if (useNewPaymentMethod) {
42
- const { success, errorMessage: stripeValidationsErrorMessage } = await handleStripeFormValidations({
43
- elements,
44
- });
45
-
46
- if (!success) {
47
- return { success: false, errorMessage: stripeValidationsErrorMessage };
48
- }
49
-
50
- const paymentMethodResults = await handleNewPaymentMethod({ elements, stripe, setupIntentClientSecret });
51
- if (!paymentMethodResults.success) {
52
- errorMessage = paymentMethodResults.errorMessage;
53
- }
47
+ setWidgetReadOnly(true);
54
48
 
49
+ if (!isMocked && useNewPaymentMethod) {
50
+ const paymentMethodResults = await handleNewPaymentMethod({ elements, stripe, setupIntentClientSecret });
51
+ if (!paymentMethodResults.success) {
52
+ errorMessage = paymentMethodResults.errorMessage;
53
+ success = false;
54
+ } else {
55
55
  paymentMethodId = paymentMethodResults.paymentMethodId;
56
56
  }
57
+ }
57
58
 
58
- if (errorMessage) {
59
- return { success: false, errorMessage };
60
- }
59
+ const checkoutParams: ApplySubscription = { ...subscriptionState, paymentMethodId };
61
60
 
62
- checkoutParams = { ...checkoutParams, paymentMethodId };
61
+ const checkoutAction = async (params: ApplySubscription): Promise<CheckoutResult> => {
62
+ usedStiggCheckoutAction = true;
63
63
 
64
64
  try {
65
- const applySubscriptionResults = await stigg.applySubscription(checkoutParams);
66
- const nextActionResults = await handleStripeNextAction({
67
- applySubscriptionResults,
68
- stripe,
69
- });
65
+ const applySubscriptionResults = await stigg.applySubscription(params);
70
66
 
71
- checkoutResults = nextActionResults;
72
- if (nextActionResults.errorMessage) {
73
- errorMessage = nextActionResults.errorMessage;
74
- }
67
+ const nextActionResults = await handleStripeNextAction({ applySubscriptionResults, stripe });
75
68
 
76
- return { success: !nextActionResults.errorMessage, errorMessage: nextActionResults.errorMessage };
69
+ return {
70
+ success: !nextActionResults.errorMessage,
71
+ errorMessage: nextActionResults.errorMessage,
72
+ results: applySubscriptionResults,
73
+ };
77
74
  } catch (e) {
78
75
  console.error(e);
79
76
  errorMessage = (e as any)?.message;
@@ -81,21 +78,41 @@ export function useSubmit({ onCheckout, onCheckoutCompleted, onSuccess, disableS
81
78
  }
82
79
  };
83
80
 
84
- setWidgetReadOnly(true);
81
+ let checkoutResults: ApplySubscriptionResults | undefined;
85
82
 
86
- let success = false;
87
- if (onCheckout) {
88
- const externalCheckoutResults = await onCheckout({ checkoutParams, checkoutAction });
89
- if (!externalCheckoutResults.success && externalCheckoutResults.errorMessage) {
90
- errorMessage = externalCheckoutResults.errorMessage;
91
- }
92
- success = externalCheckoutResults.success && !errorMessage;
93
- } else {
94
- const checkoutActionResults = await checkoutAction();
95
- if (!checkoutActionResults.success && checkoutActionResults.errorMessage) {
96
- errorMessage = checkoutActionResults.errorMessage;
83
+ if (success) {
84
+ if (onCheckout) {
85
+ const externalCheckoutResults = await onCheckout({
86
+ customerId: customer!.id,
87
+ checkoutParams,
88
+ checkoutAction,
89
+ });
90
+ if (externalCheckoutResults.errorMessage) {
91
+ errorMessage = externalCheckoutResults.errorMessage;
92
+ }
93
+
94
+ if (!usedStiggCheckoutAction && externalCheckoutResults.results && externalCheckoutResults.success) {
95
+ const nextActionResults = await handleStripeNextAction({
96
+ applySubscriptionResults: externalCheckoutResults.results,
97
+ stripe,
98
+ });
99
+
100
+ if (nextActionResults.errorMessage) {
101
+ errorMessage = nextActionResults.errorMessage;
102
+ success = false;
103
+ }
104
+ }
105
+
106
+ success = success && externalCheckoutResults.success && !errorMessage;
107
+ checkoutResults = externalCheckoutResults.results;
108
+ } else {
109
+ const checkoutActionResults = await checkoutAction(checkoutParams);
110
+ if (!checkoutActionResults.success && checkoutActionResults.errorMessage) {
111
+ errorMessage = checkoutActionResults.errorMessage;
112
+ }
113
+ success = checkoutActionResults.success && !errorMessage;
114
+ checkoutResults = checkoutActionResults.results;
97
115
  }
98
- success = checkoutActionResults.success && !errorMessage;
99
116
  }
100
117
 
101
118
  setWidgetReadOnly(false);
@@ -1,5 +1,6 @@
1
1
  import styled from '@emotion/styled/macro';
2
- import { Box, Chip } from '@mui/material';
2
+ import Box from '@mui/material/Box';
3
+ import Chip from '@mui/material/Chip';
3
4
  import Color from 'color';
4
5
 
5
6
  export const BillingPeriodPickerContainer = styled(Box)`
@@ -2,7 +2,8 @@ import { partition } from 'lodash';
2
2
  import React from 'react';
3
3
  import { FontWeight } from 'styled-typography';
4
4
 
5
- import { Box, Radio } from '@mui/material';
5
+ import Box from '@mui/material/Box';
6
+ import Radio from '@mui/material/Radio';
6
7
  import { BillingPeriod, Plan } from '@stigg/js-client-sdk';
7
8
 
8
9
  import { Typography } from '../../../common/Typography';
@@ -1,7 +1,7 @@
1
1
  import React, { useEffect, useState } from 'react';
2
2
 
3
3
  import styled from '@emotion/styled';
4
- import { Box } from '@mui/material';
4
+ import Box from '@mui/material/Box';
5
5
  import { BillableFeatureInput } from '@stigg/api-client-js/src/generated/sdk';
6
6
  import { BillingModel, BillingPeriod, Plan, Price, PriceTierFragment } from '@stigg/js-client-sdk';
7
7
 
@@ -1,5 +1,5 @@
1
1
  import styled from '@emotion/styled/macro';
2
- import { Box } from '@mui/material';
2
+ import Box from '@mui/material/Box';
3
3
 
4
4
  export const CheckoutPlanContainer = styled(Box)`
5
5
  width: 100%;
@@ -1,5 +1,5 @@
1
1
  import styled from '@emotion/styled/macro';
2
- import { Box } from '@mui/material';
2
+ import Box from '@mui/material/Box';
3
3
  import Color from 'color';
4
4
  import React from 'react';
5
5
  import Lottie from 'react-lottie';
@@ -1,7 +1,11 @@
1
1
  import React, { useState } from 'react';
2
2
  import partition from 'lodash/partition';
3
3
  import styled from '@emotion/styled/macro';
4
- import { Box, CircularProgress, Divider, Grid, Paper } from '@mui/material';
4
+ import Box from '@mui/material/Box';
5
+ import CircularProgress from '@mui/material/CircularProgress';
6
+ import Divider from '@mui/material/Divider';
7
+ import Grid from '@mui/material/Grid';
8
+ import Paper from '@mui/material/Paper';
5
9
  import { BillingModel } from '@stigg/js-client-sdk';
6
10
  import { PoweredByStigg } from '../../common/PoweredByStigg';
7
11
  import { Typography } from '../../common/Typography';
@@ -118,6 +122,7 @@ export const CheckoutSummary = ({
118
122
  const { subscriptionPreview, isFetchingSubscriptionPreview } = usePreviewSubscription({ onMockCheckoutPreview });
119
123
 
120
124
  const { handleSubmit, isLoading } = useSubmit({
125
+ isMocked: !!onMockCheckoutPreview, // This is a hack to make the submit button work with mocked data
121
126
  disableSuccessAnimation,
122
127
  onCheckout,
123
128
  onCheckoutCompleted,
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import styled from '@emotion/styled/macro';
3
- import { Grid } from '@mui/material';
3
+ import Grid from '@mui/material/Grid';
4
4
  import {
5
5
  BillingModel,
6
6
  BillingPeriod,
@@ -1,16 +1,20 @@
1
1
  import React from 'react';
2
- import { Tooltip, tooltipClasses, TooltipProps } from '@mui/material';
2
+ import Tooltip, { tooltipClasses, TooltipProps } from '@mui/material/Tooltip';
3
3
  import styled from '@emotion/styled/macro';
4
4
 
5
- export type InformationTooltipProps = TooltipProps & { $padding?: number; $maxWidth?: number; };
5
+ export type InformationTooltipProps = TooltipProps & { $padding?: number; $maxWidth?: number };
6
6
 
7
- export const InformationTooltip = styled(({ children, className, placement = 'top', ...props }: InformationTooltipProps) => (
8
- <Tooltip arrow placement={placement} {...props} classes={{ popper: className, tooltip: 'stigg-tooltip', arrow: 'stigg-tooltip-arrow' }}>
9
- <div>
10
- {children}
11
- </div>
12
- </Tooltip>
13
- ))(({ theme, $padding = 8, $maxWidth = 300 }) => ({
7
+ export const InformationTooltip = styled(
8
+ ({ children, className, placement = 'top', ...props }: InformationTooltipProps) => (
9
+ <Tooltip
10
+ arrow
11
+ placement={placement}
12
+ {...props}
13
+ classes={{ popper: className, tooltip: 'stigg-tooltip', arrow: 'stigg-tooltip-arrow' }}>
14
+ <div>{children}</div>
15
+ </Tooltip>
16
+ ),
17
+ )(({ theme, $padding = 8, $maxWidth = 300 }) => ({
14
18
  [`& .${tooltipClasses.tooltip}`]: {
15
19
  backgroundColor: theme.stigg.palette.white,
16
20
  maxWidth: $maxWidth,
@@ -1,6 +1,6 @@
1
1
  import { CSSProperties, ReactNode, useEffect, useRef, useState } from 'react';
2
2
  import styled, { css } from 'styled-components';
3
- import { TooltipProps } from '@mui/material';
3
+ import { TooltipProps } from '@mui/material/Tooltip';
4
4
  import { InformationTooltip } from './InformationTooltip';
5
5
  import React from 'react';
6
6
  import { Typography, TypographyProps } from './Typography';
@@ -70,8 +70,7 @@ export const LongText = ({
70
70
  className={className}
71
71
  $display={display}
72
72
  style={style}
73
- data-testid={dataTestId}
74
- >
73
+ data-testid={dataTestId}>
75
74
  {children}
76
75
  </StyledText>
77
76
  );
@@ -91,8 +90,7 @@ export const LongText = ({
91
90
  <InformationTooltip
92
91
  placement={tooltipPlacement}
93
92
  leaveDelay={leaveDelay}
94
- title={<Typography variant="body1">{children}</Typography>}
95
- >
93
+ title={<Typography variant="body1">{children}</Typography>}>
96
94
  {content}
97
95
  </InformationTooltip>
98
96
  ) : (
@@ -1,5 +1,7 @@
1
1
  import { PriceTierFragment } from '@stigg/js-client-sdk';
2
- import { MenuItem, OutlinedInput, Select, SelectChangeEvent } from '@mui/material';
2
+ import MenuItem from '@mui/material/MenuItem';
3
+ import OutlinedInput from '@mui/material/OutlinedInput';
4
+ import Select, { SelectChangeEvent } from '@mui/material/Select';
3
5
  import { map } from 'lodash';
4
6
  import React, { ReactNode } from 'react';
5
7
  import styled from '@emotion/styled/macro';
@@ -4,7 +4,6 @@ import { CustomerPortalHeader } from './CustomerPortalHeader';
4
4
  import { PaymentDetailsSection } from './billing/PaymentDetailsSection';
5
5
  import { CustomerPortalPaywall } from './paywall/CustomerPortalPaywall';
6
6
  import { useCustomerPortalContext } from './CustomerPortalProvider';
7
- import { PricingType } from '@stigg/js-client-sdk';
8
7
  import { CustomerPortalLayout, CustomerPortalSections } from './CustomerPortal.style';
9
8
  import { CustomerPortalProps } from './CustomerPortal';
10
9
  import { InvoicesSection, useStiggContext } from '../..';
@@ -24,20 +23,19 @@ export function CustomerPortalContainer({
24
23
 
25
24
  const onManageClick = () => {
26
25
  if (onManageSubscription) {
26
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
27
27
  onManageSubscription();
28
28
  } else {
29
29
  customerPortalSectionRef?.current?.scrollIntoView({ behavior: 'smooth' });
30
30
  }
31
31
  };
32
- const hasCustomSubscription = customerPortal?.subscriptions.some(
33
- subscription => subscription.pricingType === PricingType.Custom,
34
- );
35
- const shouldShowUsage = !hiddenSections?.some(section => section === 'usage');
32
+
33
+ const shouldShowUsage = !hiddenSections?.some((section) => section === 'usage');
36
34
  const shouldShowPaymentDetails = !hiddenSections?.some(
37
- section => section === 'paymentDetails' || section === 'billingInformation',
35
+ (section) => section === 'paymentDetails' || section === 'billingInformation',
38
36
  );
39
37
  const shouldShowInvoices = !hiddenSections?.some(
40
- section => section === 'invoices' || section === 'billingInformation',
38
+ (section) => section === 'invoices' || section === 'billingInformation',
41
39
  );
42
40
 
43
41
  return (
@@ -56,7 +54,6 @@ export function CustomerPortalContainer({
56
54
  <CustomerPortalPaywall
57
55
  ref={customerPortalSectionRef}
58
56
  paywallComponent={paywallComponent}
59
- hidePaywallButtons={!!hasCustomSubscription}
60
57
  theme={theme}
61
58
  title={textOverrides.paywallSectionTitle}
62
59
  isLoading={!customerPortal || isLoading}