@stigg/react-sdk 4.3.0 → 4.4.0-beta.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 (184) hide show
  1. package/README.md +1 -1
  2. package/dist/components/checkout/Checkout.d.ts +5 -0
  3. package/dist/components/checkout/CheckoutContainer.d.ts +22 -0
  4. package/dist/components/checkout/CheckoutContainer.style.d.ts +26 -0
  5. package/dist/components/checkout/CheckoutProvider.d.ts +34 -0
  6. package/dist/components/checkout/components/Button.d.ts +8 -0
  7. package/dist/components/checkout/components/ContentLoadingSkeleton.d.ts +2 -0
  8. package/dist/components/checkout/components/InputField.d.ts +8 -0
  9. package/dist/components/checkout/components/Skeletons.style.d.ts +97 -0
  10. package/dist/components/checkout/components/index.d.ts +3 -0
  11. package/dist/components/checkout/formatting.d.ts +2 -0
  12. package/dist/components/checkout/hooks/index.d.ts +8 -0
  13. package/dist/components/checkout/hooks/useAddonsStepModel.d.ts +21 -0
  14. package/dist/components/checkout/hooks/useCheckoutModel.d.ts +10 -0
  15. package/dist/components/checkout/hooks/useCouponModel.d.ts +7 -0
  16. package/dist/components/checkout/hooks/useLoadCheckout.d.ts +11 -0
  17. package/dist/components/checkout/hooks/usePaymentStepModel.d.ts +16 -0
  18. package/dist/components/checkout/hooks/usePlanStepModel.d.ts +23 -0
  19. package/dist/components/checkout/hooks/usePreviewSubscription.d.ts +13 -0
  20. package/dist/components/checkout/hooks/useProgressBarModel.d.ts +26 -0
  21. package/dist/components/checkout/hooks/useSubscriptionModel.d.ts +5 -0
  22. package/dist/components/checkout/hooks/useSubscriptionState.d.ts +2 -0
  23. package/dist/components/checkout/index.d.ts +3 -0
  24. package/dist/components/checkout/planHeader/PlanHeader.d.ts +7 -0
  25. package/dist/components/checkout/planHeader/PlanHeader.style.d.ts +25 -0
  26. package/dist/components/checkout/planHeader/index.d.ts +1 -0
  27. package/dist/components/checkout/progressBar/CheckoutProgressBar.d.ts +2 -0
  28. package/dist/components/checkout/progressBar/CheckoutProgressBar.style.d.ts +48 -0
  29. package/dist/components/checkout/promotionCode/AddPromotionCode.d.ts +5 -0
  30. package/dist/components/checkout/promotionCode/AddPromotionCodeButton.d.ts +7 -0
  31. package/dist/components/checkout/promotionCode/AppliedPromotionCode.d.ts +6 -0
  32. package/dist/components/checkout/promotionCode/PromotionCodeSection.d.ts +5 -0
  33. package/dist/components/checkout/promotionCode/index.d.ts +1 -0
  34. package/dist/components/checkout/steps/addons/CheckoutAddonsStep.d.ts +2 -0
  35. package/dist/components/checkout/steps/addons/CheckoutAddonsStep.style.d.ts +93 -0
  36. package/dist/components/checkout/steps/addons/addon.utils.d.ts +15 -0
  37. package/dist/components/checkout/steps/addons/index.d.ts +1 -0
  38. package/dist/components/checkout/steps/payment/PaymentMethods.d.ts +20 -0
  39. package/dist/components/checkout/steps/payment/PaymentMethods.style.d.ts +117 -0
  40. package/dist/components/checkout/steps/payment/PaymentStep.d.ts +2 -0
  41. package/dist/components/checkout/steps/payment/index.d.ts +1 -0
  42. package/dist/components/checkout/steps/payment/stripe/StripePaymentForm.d.ts +2 -0
  43. package/dist/components/checkout/steps/payment/stripe/index.d.ts +3 -0
  44. package/dist/components/checkout/steps/payment/stripe/stripe.utils.d.ts +33 -0
  45. package/dist/components/checkout/steps/payment/stripe/useStripeIntegration.d.ts +5 -0
  46. package/dist/components/checkout/steps/payment/stripe/useSubmit.d.ts +13 -0
  47. package/dist/components/checkout/steps/plan/BillingPeriodPicker.d.ts +9 -0
  48. package/dist/components/checkout/steps/plan/BillingPeriodPicker.style.d.ts +52 -0
  49. package/dist/components/checkout/steps/plan/CheckoutChargeList.d.ts +16 -0
  50. package/dist/components/checkout/steps/plan/CheckoutPlanStep.d.ts +2 -0
  51. package/dist/components/checkout/steps/plan/CheckoutPlanStep.style.d.ts +12 -0
  52. package/dist/components/checkout/steps/plan/index.d.ts +1 -0
  53. package/dist/components/checkout/steps/surprise/SurpriseStep.d.ts +2 -0
  54. package/dist/components/checkout/summary/CheckoutSuccess.d.ts +3 -0
  55. package/dist/components/checkout/summary/CheckoutSummary.d.ts +16 -0
  56. package/dist/components/checkout/summary/CheckoutSummarySkeleton.d.ts +2 -0
  57. package/dist/components/checkout/summary/components/CheckoutCaptions.d.ts +11 -0
  58. package/dist/components/checkout/summary/components/LineItems.d.ts +36 -0
  59. package/dist/components/checkout/summary/components/WithSkeleton.d.ts +6 -0
  60. package/dist/components/checkout/summary/index.d.ts +2 -0
  61. package/dist/components/checkout/textOverrides.d.ts +32 -0
  62. package/dist/components/checkout/theme.d.ts +12 -0
  63. package/dist/components/common/Icon.d.ts +3 -2
  64. package/dist/components/common/PoweredByStigg.d.ts +1 -1
  65. package/dist/components/{paywall/TiersLayout.d.ts → common/TiersSelectContainer.d.ts} +2 -3
  66. package/dist/components/common/customIcons.d.ts +19 -5
  67. package/dist/components/common/mapExternalTheme.d.ts +2 -1
  68. package/dist/components/customerPortal/subscriptionOverview/tabs/SubscriptionTabs.d.ts +1 -1
  69. package/dist/components/hooks/useChargeSort.d.ts +3 -0
  70. package/dist/components/paywall/paywallTextOverrides.d.ts +0 -2
  71. package/dist/components/utils/calculateDiscountRate.d.ts +1 -0
  72. package/dist/components/utils/currencyUtils.d.ts +1 -1
  73. package/dist/components/{paywall/planPriceTier.d.ts → utils/priceTierUtils.d.ts} +3 -1
  74. package/dist/components/utils/priceUtils.d.ts +2 -0
  75. package/dist/index.d.ts +1 -0
  76. package/dist/react-sdk.cjs.development.js +6930 -228
  77. package/dist/react-sdk.cjs.development.js.map +1 -1
  78. package/dist/react-sdk.cjs.production.min.js +1 -1
  79. package/dist/react-sdk.cjs.production.min.js.map +1 -1
  80. package/dist/react-sdk.esm.js +7089 -232
  81. package/dist/react-sdk.esm.js.map +1 -1
  82. package/dist/stories/Checkout.stories.d.ts +3 -0
  83. package/dist/stories/CustomerPortal.stories.d.ts +1 -1
  84. package/dist/theme/getResolvedTheme.d.ts +4 -0
  85. package/dist/theme/types.d.ts +4 -0
  86. package/package.json +11 -5
  87. package/src/assets/arrow-forward.svg +3 -0
  88. package/src/assets/arrow-right.svg +6 -0
  89. package/src/assets/check.svg +5 -0
  90. package/src/assets/close.svg +3 -0
  91. package/src/assets/lottie/checkout-success.json +1 -0
  92. package/src/assets/nyancat.svg +634 -0
  93. package/src/assets/outlined-checked-circle-disabled.svg +6 -0
  94. package/src/assets/outlined-checked-circle.svg +6 -0
  95. package/src/assets/outlined-circle.svg +3 -0
  96. package/src/assets/payment-method.svg +11 -0
  97. package/src/assets/plus-icon.svg +6 -0
  98. package/src/assets/trash.svg +8 -0
  99. package/src/components/checkout/Checkout.tsx +30 -0
  100. package/src/components/checkout/CheckoutContainer.style.ts +35 -0
  101. package/src/components/checkout/CheckoutContainer.tsx +99 -0
  102. package/src/components/checkout/CheckoutProvider.tsx +149 -0
  103. package/src/components/checkout/components/Button.tsx +51 -0
  104. package/src/components/checkout/components/ContentLoadingSkeleton.tsx +41 -0
  105. package/src/components/checkout/components/InputField.tsx +22 -0
  106. package/src/components/checkout/components/Skeletons.style.ts +27 -0
  107. package/src/components/checkout/components/index.ts +3 -0
  108. package/src/components/checkout/formatting.ts +12 -0
  109. package/src/components/checkout/hooks/index.ts +8 -0
  110. package/src/components/checkout/hooks/useAddonsStepModel.ts +96 -0
  111. package/src/components/checkout/hooks/useCheckoutModel.ts +32 -0
  112. package/src/components/checkout/hooks/useCouponModel.ts +28 -0
  113. package/src/components/checkout/hooks/useLoadCheckout.ts +39 -0
  114. package/src/components/checkout/hooks/usePaymentStepModel.ts +49 -0
  115. package/src/components/checkout/hooks/usePlanStepModel.ts +169 -0
  116. package/src/components/checkout/hooks/usePreviewSubscription.ts +82 -0
  117. package/src/components/checkout/hooks/useProgressBarModel.ts +89 -0
  118. package/src/components/checkout/hooks/useSubscriptionModel.ts +16 -0
  119. package/src/components/checkout/hooks/useSubscriptionState.ts +26 -0
  120. package/src/components/checkout/index.ts +3 -0
  121. package/src/components/checkout/planHeader/PlanHeader.style.tsx +23 -0
  122. package/src/components/checkout/planHeader/PlanHeader.tsx +59 -0
  123. package/src/components/checkout/planHeader/index.ts +1 -0
  124. package/src/components/checkout/progressBar/CheckoutProgressBar.style.ts +34 -0
  125. package/src/components/checkout/progressBar/CheckoutProgressBar.tsx +53 -0
  126. package/src/components/checkout/promotionCode/AddPromotionCode.tsx +85 -0
  127. package/src/components/checkout/promotionCode/AddPromotionCodeButton.tsx +39 -0
  128. package/src/components/checkout/promotionCode/AppliedPromotionCode.tsx +37 -0
  129. package/src/components/checkout/promotionCode/PromotionCodeSection.tsx +27 -0
  130. package/src/components/checkout/promotionCode/index.ts +1 -0
  131. package/src/components/checkout/steps/addons/CheckoutAddonsStep.style.tsx +24 -0
  132. package/src/components/checkout/steps/addons/CheckoutAddonsStep.tsx +125 -0
  133. package/src/components/checkout/steps/addons/addon.utils.ts +68 -0
  134. package/src/components/checkout/steps/addons/index.ts +1 -0
  135. package/src/components/checkout/steps/payment/PaymentMethods.style.ts +26 -0
  136. package/src/components/checkout/steps/payment/PaymentMethods.tsx +86 -0
  137. package/src/components/checkout/steps/payment/PaymentStep.tsx +50 -0
  138. package/src/components/checkout/steps/payment/index.ts +1 -0
  139. package/src/components/checkout/steps/payment/stripe/StripePaymentForm.tsx +45 -0
  140. package/src/components/checkout/steps/payment/stripe/index.ts +3 -0
  141. package/src/components/checkout/steps/payment/stripe/stripe.utils.ts +109 -0
  142. package/src/components/checkout/steps/payment/stripe/useStripeIntegration.ts +27 -0
  143. package/src/components/checkout/steps/payment/stripe/useSubmit.ts +104 -0
  144. package/src/components/checkout/steps/plan/BillingPeriodPicker.style.tsx +46 -0
  145. package/src/components/checkout/steps/plan/BillingPeriodPicker.tsx +63 -0
  146. package/src/components/checkout/steps/plan/CheckoutChargeList.tsx +138 -0
  147. package/src/components/checkout/steps/plan/CheckoutPlanStep.style.tsx +6 -0
  148. package/src/components/checkout/steps/plan/CheckoutPlanStep.tsx +20 -0
  149. package/src/components/checkout/steps/plan/index.ts +1 -0
  150. package/src/components/checkout/steps/surprise/SurpriseStep.tsx +27 -0
  151. package/src/components/checkout/summary/CheckoutSuccess.tsx +32 -0
  152. package/src/components/checkout/summary/CheckoutSummary.tsx +288 -0
  153. package/src/components/checkout/summary/CheckoutSummarySkeleton.tsx +40 -0
  154. package/src/components/checkout/summary/components/CheckoutCaptions.tsx +120 -0
  155. package/src/components/checkout/summary/components/LineItems.tsx +177 -0
  156. package/src/components/checkout/summary/components/WithSkeleton.tsx +16 -0
  157. package/src/components/checkout/summary/index.ts +2 -0
  158. package/src/components/checkout/textOverrides.ts +62 -0
  159. package/src/components/checkout/theme.ts +43 -0
  160. package/src/components/common/Icon.tsx +17 -22
  161. package/src/components/common/PoweredByStigg.tsx +1 -1
  162. package/src/components/{paywall/TiersLayout.tsx → common/TiersSelectContainer.tsx} +8 -7
  163. package/src/components/common/Typography.tsx +11 -1
  164. package/src/components/common/customIcons.ts +19 -28
  165. package/src/components/common/mapExternalTheme.ts +29 -9
  166. package/src/components/customerPortal/subscriptionOverview/tabs/SubscriptionTabs.tsx +6 -12
  167. package/src/components/hooks/useChargeSort.ts +17 -0
  168. package/src/components/paywall/Paywall.tsx +1 -1
  169. package/src/components/paywall/PlanOffering.tsx +1 -1
  170. package/src/components/paywall/PlanOfferingButton.tsx +1 -1
  171. package/src/components/paywall/PlanPrice.tsx +5 -13
  172. package/src/components/paywall/paywallTextOverrides.ts +0 -1
  173. package/src/components/paywall/utils/calculateUnitQuantityText.ts +9 -4
  174. package/src/components/utils/calculateDiscountRate.ts +1 -1
  175. package/src/components/utils/currencyUtils.ts +1 -1
  176. package/src/components/utils/getPaidPriceText.ts +2 -2
  177. package/src/components/{paywall/planPriceTier.ts → utils/priceTierUtils.ts} +25 -3
  178. package/src/components/utils/priceUtils.ts +10 -0
  179. package/src/index.ts +1 -0
  180. package/src/stories/Checkout.stories.tsx +61 -0
  181. package/src/stories/CustomerPortal.stories.tsx +1 -1
  182. package/src/theme/Theme.tsx +6 -6
  183. package/src/theme/getResolvedTheme.ts +7 -1
  184. package/src/theme/types.ts +4 -0
@@ -0,0 +1,109 @@
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
+ }
@@ -0,0 +1,27 @@
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
+ }
@@ -0,0 +1,104 @@
1
+ import { ApplySubscription, ApplySubscriptionResults } from '@stigg/js-client-sdk';
2
+ import { useElements, useStripe } from '@stripe/react-stripe-js';
3
+ import { useStiggContext } from '../../../../..';
4
+ import { useCheckoutModel } from '../../../hooks';
5
+ import { usePaymentStepModel } from '../../../hooks/usePaymentStepModel';
6
+ import { useSubscriptionState } from '../../../hooks/useSubscriptionState';
7
+ import { CheckoutContainerProps, CheckoutResult } from '../../../CheckoutContainer';
8
+ import { handleNewPaymentMethod, handleStripeFormValidations, handleStripeNextAction } from './stripe.utils';
9
+ import { ANIMATION_DURATION } from '../../../summary/CheckoutSuccess';
10
+
11
+ const delay = (ms: number) => new Promise(res => setTimeout(res, ms));
12
+
13
+ export type HandleSubmitResult = { results?: ApplySubscriptionResults; errorMessage?: string } | undefined;
14
+
15
+ export type UseSubmitProps = {
16
+ onSuccess?: () => void;
17
+ } & Pick<CheckoutContainerProps, 'onCheckout' | 'onCheckoutCompleted'>;
18
+
19
+ export function useSubmit({ onCheckout, onCheckoutCompleted, onSuccess }: UseSubmitProps) {
20
+ const { stigg } = useStiggContext();
21
+ const { useNewPaymentMethod } = usePaymentStepModel();
22
+ const subscriptionState = useSubscriptionState();
23
+ const { checkoutState, widgetState, setWidgetReadOnly } = useCheckoutModel();
24
+ const { setupSecret: setupIntentClientSecret } = checkoutState || {};
25
+ const stripe = useStripe();
26
+ const elements = useElements();
27
+
28
+ const handleSubmit = async (e: any): Promise<HandleSubmitResult> => {
29
+ e.preventDefault();
30
+
31
+ if (!subscriptionState) {
32
+ return;
33
+ }
34
+
35
+ let checkoutResults: ApplySubscriptionResults | undefined;
36
+ let errorMessage: string | undefined;
37
+ let paymentMethodId: string | undefined;
38
+
39
+ setWidgetReadOnly(true);
40
+
41
+ if (useNewPaymentMethod) {
42
+ const { success } = await handleStripeFormValidations({ elements });
43
+ if (!success) {
44
+ setWidgetReadOnly(false);
45
+ return;
46
+ }
47
+
48
+ const paymentMethodResults = await handleNewPaymentMethod({ elements, stripe, setupIntentClientSecret });
49
+ if (!paymentMethodResults.success) {
50
+ errorMessage = paymentMethodResults.errorMessage;
51
+ }
52
+
53
+ paymentMethodId = paymentMethodResults.paymentMethodId;
54
+ }
55
+
56
+ if (!errorMessage) {
57
+ const checkoutParams: ApplySubscription = { ...subscriptionState, paymentMethodId };
58
+
59
+ const checkoutAction = async (): Promise<CheckoutResult> => {
60
+ try {
61
+ const applySubscriptionResults = await stigg.applySubscription(checkoutParams);
62
+ const nextActionResults = await handleStripeNextAction({
63
+ applySubscriptionResults,
64
+ stripe,
65
+ });
66
+
67
+ checkoutResults = nextActionResults;
68
+ if (nextActionResults.errorMessage) {
69
+ errorMessage = nextActionResults.errorMessage;
70
+ }
71
+
72
+ return { success: !nextActionResults.errorMessage, errorMessage: nextActionResults.errorMessage };
73
+ } catch (e) {
74
+ console.error(e);
75
+ errorMessage = (e as any)?.message;
76
+ return { success: false, errorMessage };
77
+ }
78
+ };
79
+
80
+ if (onCheckout) {
81
+ const externalCheckoutResults = await onCheckout({ checkoutParams, checkoutAction });
82
+ if (!externalCheckoutResults.success && externalCheckoutResults.errorMessage) {
83
+ errorMessage = externalCheckoutResults.errorMessage;
84
+ }
85
+ } else {
86
+ await checkoutAction();
87
+ }
88
+ }
89
+
90
+ setWidgetReadOnly(false);
91
+
92
+ const success = !errorMessage && !!checkoutResults?.subscription;
93
+ if (success && onSuccess) {
94
+ onSuccess();
95
+ }
96
+
97
+ await delay(ANIMATION_DURATION); // Wait for animation to finish
98
+ await onCheckoutCompleted({ success, error: errorMessage });
99
+
100
+ return { results: checkoutResults, errorMessage };
101
+ };
102
+
103
+ return { handleSubmit, isLoading: !!widgetState?.readOnly };
104
+ }
@@ -0,0 +1,46 @@
1
+ import styled from '@emotion/styled/macro';
2
+ import { Box, Chip } from '@mui/material';
3
+
4
+ export const BillingPeriodPickerContainer = styled(Box)`
5
+ margin: 16px 0;
6
+ `;
7
+
8
+ export const BillingPeriodButton = styled.button<{ $isActive?: boolean; $disabled?: boolean }>`
9
+ cursor: ${({ $disabled }) => ($disabled ? 'default' : 'pointer')};
10
+ flex: 1;
11
+ display: flex;
12
+ align-items: center;
13
+ justify-content: flex-start;
14
+ padding: 8px 8px 8px 4px;
15
+ border-radius: 10px;
16
+ border: ${({ theme, $isActive }) =>
17
+ `1px solid ${$isActive ? theme.stigg.palette.outlinedRestingBorder : theme.stigg.palette.outlinedBorder}`};
18
+ background: ${({ theme, $isActive }) => ($isActive ? theme.stigg.palette.backgroundSection : 'transparent')};
19
+ text-transform: none;
20
+ text-align: start;
21
+
22
+ &.MuiButton-root {
23
+ padding: 0 16px 0 8px;
24
+ &:hover {
25
+ background: none;
26
+ }
27
+ }
28
+ `;
29
+
30
+ export const BillingPeriodOptions = styled(Box)`
31
+ display: flex;
32
+ gap: 16px;
33
+ margin-top: 16px;
34
+ `;
35
+
36
+ export const BillingPeriodPrice = styled.div`
37
+ display: flex;
38
+ align-items: baseline;
39
+ gap: 8px;
40
+ `;
41
+
42
+ export const DiscountChip = styled(Chip)`
43
+ & .MuiChip-label {
44
+ font-size: 12px;
45
+ }
46
+ `;
@@ -0,0 +1,63 @@
1
+ import { partition } from 'lodash';
2
+ import React from 'react';
3
+ import { FontWeight } from 'styled-typography';
4
+
5
+ import { Box, Radio } from '@mui/material';
6
+ import { BillingPeriod, Plan } from '@stigg/js-client-sdk';
7
+
8
+ import { Typography } from '../../../common/Typography';
9
+ import { formatBillingPeriod } from '../../formatting';
10
+ import { usePlanStepModel } from '../../hooks/usePlanStepModel';
11
+ import { BillingPeriodButton, BillingPeriodOptions, BillingPeriodPickerContainer } from './BillingPeriodPicker.style';
12
+ import { CheckoutLocalization } from '../../textOverrides';
13
+
14
+ const BillingPeriodOption = ({ billingPeriod }: { billingPeriod: BillingPeriod }) => {
15
+ const { billingPeriod: selectedBillingPeriod, setBillingPeriod } = usePlanStepModel();
16
+ const isActive = selectedBillingPeriod === billingPeriod;
17
+
18
+ return (
19
+ <BillingPeriodButton onClick={() => setBillingPeriod(billingPeriod)} $isActive={isActive}>
20
+ <Radio
21
+ checked={isActive}
22
+ onChange={() => setBillingPeriod(billingPeriod)}
23
+ value={billingPeriod}
24
+ inputProps={{ 'aria-label': formatBillingPeriod(billingPeriod) }}
25
+ />
26
+
27
+ <Box>
28
+ <Typography variant="h6" color="primary" fontWeight={FontWeight.Medium}>
29
+ {formatBillingPeriod(billingPeriod)}
30
+ </Typography>
31
+ </Box>
32
+ </BillingPeriodButton>
33
+ );
34
+ };
35
+
36
+ type BillingPeriodPickerProps = {
37
+ plan?: Plan;
38
+ checkoutLocalization: CheckoutLocalization;
39
+ };
40
+
41
+ export const BillingPeriodPicker = ({ plan, checkoutLocalization }: BillingPeriodPickerProps) => {
42
+ const [monthlyPrices, annualPrices] = partition(
43
+ plan?.pricePoints,
44
+ (price) => price.billingPeriod === BillingPeriod.Monthly,
45
+ );
46
+
47
+ return (
48
+ <BillingPeriodPickerContainer>
49
+ <Typography variant="h6" color="primary" fontWeight={FontWeight.Medium}>
50
+ {checkoutLocalization.billingPeriodsTitle}
51
+ </Typography>
52
+
53
+ <BillingPeriodOptions>
54
+ {!!monthlyPrices?.length && (
55
+ <BillingPeriodOption key={BillingPeriod.Monthly} billingPeriod={BillingPeriod.Monthly} />
56
+ )}
57
+ {!!annualPrices?.length && (
58
+ <BillingPeriodOption key={BillingPeriod.Annually} billingPeriod={BillingPeriod.Annually} />
59
+ )}
60
+ </BillingPeriodOptions>
61
+ </BillingPeriodPickerContainer>
62
+ );
63
+ };
@@ -0,0 +1,138 @@
1
+ import React from 'react';
2
+
3
+ import styled from '@emotion/styled';
4
+ import { Box } from '@mui/material';
5
+ import { BillableFeatureInput } from '@stigg/api-client-js/src/generated/sdk';
6
+ import { BillingModel, BillingPeriod, Plan, Price, PriceTierFragment } from '@stigg/js-client-sdk';
7
+
8
+ import { Typography } from '../../../common/Typography';
9
+ import { useChargesSort } from '../../../hooks/useChargeSort';
10
+ import { calculateUnitQuantityText } from '../../../paywall/utils/calculateUnitQuantityText';
11
+ import { currencyPriceFormatter } from '../../../utils/currencyUtils';
12
+ import { InputField } from '../../components';
13
+ import { usePlanStepModel } from '../../hooks';
14
+ import { TiersSelectContainer } from '../../../common/TiersSelectContainer';
15
+ import { getPriceFeatureUnit, getTierByQuantity } from '../../../utils/priceTierUtils';
16
+ import { getValidPriceQuantity } from '../../../utils/priceUtils';
17
+
18
+ export type UsePlanStepModel = ReturnType<typeof usePlanStepModel>;
19
+
20
+ type CheckoutChargeListProps = {
21
+ plan?: Plan;
22
+ billingPeriod: BillingPeriod;
23
+ };
24
+
25
+ const StyledPlanCharge = styled.div`
26
+ display: flex;
27
+ flex-direction: row;
28
+ justify-content: space-between;
29
+ align-items: center;
30
+ min-height: 60px;
31
+ margin-top: 16px;
32
+ `;
33
+
34
+ export function PlanCharge({
35
+ charge,
36
+ setBillableFeature,
37
+ billableFeature,
38
+ }: {
39
+ charge: Price;
40
+ billableFeature?: BillableFeatureInput;
41
+ setBillableFeature: UsePlanStepModel['setBillableFeature'];
42
+ }) {
43
+ const featureId = charge.feature?.featureId;
44
+ const isBaseCharge = !featureId;
45
+ const isPayAsYouGo = charge.pricingModel === BillingModel.UsageBased;
46
+ const displayName = isBaseCharge ? 'Base charge' : charge.feature?.displayName;
47
+ const hasQuantityRestrictions = !!(charge?.minUnitQuantity || charge?.maxUnitQuantity);
48
+
49
+ const handleQuantityChange = (event: React.ChangeEvent<HTMLInputElement>) => {
50
+ if (isBaseCharge || !featureId) return;
51
+
52
+ const value = event?.target?.value ? Number(event?.target?.value) : charge.minUnitQuantity || 1;
53
+ const quantity = getValidPriceQuantity(charge, value || 1);
54
+
55
+ setBillableFeature(featureId, quantity);
56
+ };
57
+
58
+ let chargeRow;
59
+
60
+ if (isBaseCharge || isPayAsYouGo) {
61
+ const formattedAmount = currencyPriceFormatter({
62
+ amount: charge.amount!,
63
+ currency: charge.currency,
64
+ locale: 'en-us',
65
+ });
66
+
67
+ chargeRow = `${formattedAmount}`;
68
+ if (isPayAsYouGo) {
69
+ chargeRow += ' / unit';
70
+ }
71
+ } else if (charge.isTieredPrice) {
72
+ const tier = getTierByQuantity(charge.tiers!, billableFeature!.quantity || 1);
73
+ chargeRow = (
74
+ <TiersSelectContainer
75
+ componentId={`${featureId}-tiers`}
76
+ tiers={charge.tiers}
77
+ tierUnits={getPriceFeatureUnit(charge)}
78
+ selectedTier={tier}
79
+ handleTierChange={(tier: PriceTierFragment) => {
80
+ setBillableFeature(featureId!, tier!.upTo);
81
+ }}
82
+ />
83
+ );
84
+ } else {
85
+ chargeRow = (
86
+ <InputField
87
+ sx={{ width: 120 }}
88
+ id={`${featureId}-input`}
89
+ type="number"
90
+ InputProps={
91
+ hasQuantityRestrictions ? { inputProps: { min: charge.minUnitQuantity, max: charge.maxUnitQuantity } } : {}
92
+ }
93
+ value={billableFeature?.quantity || charge.minUnitQuantity || 1}
94
+ onChange={handleQuantityChange}
95
+ />
96
+ );
97
+ }
98
+
99
+ return (
100
+ <StyledPlanCharge>
101
+ <Box display="flex" flexDirection="column">
102
+ <Typography variant="h6" color="primary" lineHeight="24px">
103
+ {displayName}
104
+ </Typography>
105
+ {hasQuantityRestrictions && (
106
+ <Typography variant="body1" color="secondary" lineHeight="20px">
107
+ {calculateUnitQuantityText(charge.minUnitQuantity, charge.maxUnitQuantity, charge.feature?.unitsPlural)}
108
+ </Typography>
109
+ )}
110
+ </Box>
111
+
112
+ <Typography variant="h6" color="primary">
113
+ {chargeRow}
114
+ </Typography>
115
+ </StyledPlanCharge>
116
+ );
117
+ }
118
+
119
+ export function CheckoutChargeList({ plan, billingPeriod }: CheckoutChargeListProps) {
120
+ const { billableFeatures, setBillableFeature } = usePlanStepModel();
121
+ const planCharges = useChargesSort(plan?.pricePoints?.filter(p => p.billingPeriod === billingPeriod) || []);
122
+
123
+ return (
124
+ <div>
125
+ {planCharges?.map(charge => {
126
+ const billableFeature = billableFeatures.find(x => x.featureId === charge.feature?.featureId);
127
+ return (
128
+ <PlanCharge
129
+ key={charge.feature?.featureId || 'base-charge'}
130
+ charge={charge}
131
+ setBillableFeature={setBillableFeature}
132
+ billableFeature={billableFeature}
133
+ />
134
+ );
135
+ })}
136
+ </div>
137
+ );
138
+ }
@@ -0,0 +1,6 @@
1
+ import styled from '@emotion/styled/macro';
2
+ import { Box } from '@mui/material';
3
+
4
+ export const CheckoutPlanContainer = styled(Box)`
5
+ width: 100%;
6
+ `;
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+
3
+ import { useCheckoutModel } from '../../hooks/useCheckoutModel';
4
+ import { usePlanStepModel } from '../../hooks/usePlanStepModel';
5
+ import { BillingPeriodPicker } from './BillingPeriodPicker';
6
+ import { CheckoutChargeList } from './CheckoutChargeList';
7
+ import { CheckoutPlanContainer } from './CheckoutPlanStep.style';
8
+
9
+ export const CheckoutPlanStep = () => {
10
+ const { checkoutState, checkoutLocalization } = useCheckoutModel();
11
+ const { plan } = checkoutState || {};
12
+ const { billingPeriod } = usePlanStepModel();
13
+
14
+ return (
15
+ <CheckoutPlanContainer>
16
+ <BillingPeriodPicker plan={plan} checkoutLocalization={checkoutLocalization} />
17
+ <CheckoutChargeList plan={plan} billingPeriod={billingPeriod} />
18
+ </CheckoutPlanContainer>
19
+ );
20
+ };
@@ -0,0 +1 @@
1
+ export * from './CheckoutPlanStep';
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import NyanCat from '../../../../assets/nyancat.svg';
3
+ import styled from '@emotion/styled/macro';
4
+
5
+ const StyledNyanCat = styled(NyanCat)`
6
+ background: #000;
7
+ width: 100%;
8
+ max-width: 920px;
9
+ height: 548px;
10
+ `;
11
+
12
+ const SurpriseContainer = styled.div`
13
+ display: flex;
14
+ flex-direction: column;
15
+ align-content: center;
16
+ justify-content: center;
17
+ min-height: 430px;
18
+ width: 100%;
19
+ `;
20
+
21
+ export const SurpriseStep = () => {
22
+ return (
23
+ <SurpriseContainer>
24
+ <StyledNyanCat />
25
+ </SurpriseContainer>
26
+ );
27
+ };
@@ -0,0 +1,32 @@
1
+ import styled from '@emotion/styled/macro';
2
+ import { Box } from '@mui/material';
3
+ import Color from 'color';
4
+ import React from 'react';
5
+ import Lottie from 'react-lottie';
6
+ import animationData from '../../../assets/lottie/checkout-success.json';
7
+
8
+ export const ANIMATION_DURATION = 5000;
9
+
10
+ const BACKGROUND_COLOR = Color('#0b2f7a')
11
+ .alpha(0.3)
12
+ .toString();
13
+
14
+ const CheckoutSuccessContainer = styled(Box)`
15
+ position: absolute;
16
+ top: 0;
17
+ left: 0;
18
+ bottom: 0;
19
+ right: 0;
20
+ background-color: ${BACKGROUND_COLOR};
21
+ * rect {
22
+ fill: transparent;
23
+ }
24
+ `;
25
+
26
+ export function CheckoutSuccess() {
27
+ return (
28
+ <CheckoutSuccessContainer>
29
+ <Lottie options={{ loop: false, autoplay: true, animationData }} />
30
+ </CheckoutSuccessContainer>
31
+ );
32
+ }