@stigg/react-sdk 4.3.0-beta.1 → 4.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/README.md +1 -1
  2. package/dist/components/common/Icon.d.ts +2 -3
  3. package/dist/components/common/PoweredByStigg.d.ts +1 -1
  4. package/dist/components/common/customIcons.d.ts +5 -17
  5. package/dist/components/common/mapExternalTheme.d.ts +1 -2
  6. package/dist/components/customerPortal/subscriptionOverview/tabs/SubscriptionTabs.d.ts +1 -1
  7. package/dist/components/{common/TiersSelectContainer.d.ts → paywall/TiersLayout.d.ts} +3 -2
  8. package/dist/components/paywall/paywallTextOverrides.d.ts +4 -0
  9. package/dist/components/{utils/priceTierUtils.d.ts → paywall/planPriceTier.d.ts} +1 -3
  10. package/dist/components/utils/calculateDiscountRate.d.ts +0 -1
  11. package/dist/components/utils/currencyUtils.d.ts +1 -1
  12. package/dist/components/utils/getPaidPriceText.d.ts +3 -1
  13. package/dist/index.d.ts +0 -1
  14. package/dist/react-sdk.cjs.development.js +217 -3483
  15. package/dist/react-sdk.cjs.development.js.map +1 -1
  16. package/dist/react-sdk.cjs.production.min.js +1 -1
  17. package/dist/react-sdk.cjs.production.min.js.map +1 -1
  18. package/dist/react-sdk.esm.js +223 -3623
  19. package/dist/react-sdk.esm.js.map +1 -1
  20. package/dist/stories/CustomerPortal.stories.d.ts +1 -1
  21. package/dist/theme/getResolvedTheme.d.ts +0 -1
  22. package/dist/theme/types.d.ts +0 -1
  23. package/package.json +22 -11
  24. package/src/components/StiggProvider.tsx +2 -0
  25. package/src/components/common/Icon.tsx +22 -17
  26. package/src/components/common/PoweredByStigg.tsx +1 -1
  27. package/src/components/common/Typography.tsx +1 -11
  28. package/src/components/common/customIcons.ts +28 -17
  29. package/src/components/common/mapExternalTheme.ts +8 -24
  30. package/src/components/customerPortal/subscriptionOverview/tabs/SubscriptionTabs.tsx +12 -6
  31. package/src/components/paywall/Paywall.tsx +1 -1
  32. package/src/components/paywall/PlanOffering.tsx +1 -1
  33. package/src/components/paywall/PlanOfferingButton.tsx +1 -1
  34. package/src/components/paywall/PlanPrice.tsx +13 -5
  35. package/src/components/{common/TiersSelectContainer.tsx → paywall/TiersLayout.tsx} +7 -8
  36. package/src/components/paywall/paywallTextOverrides.ts +3 -0
  37. package/src/components/{utils/priceTierUtils.ts → paywall/planPriceTier.ts} +3 -25
  38. package/src/components/paywall/utils/calculateUnitQuantityText.ts +4 -9
  39. package/src/components/utils/calculateDiscountRate.ts +1 -1
  40. package/src/components/utils/currencyUtils.ts +1 -1
  41. package/src/components/utils/getPaidPriceText.ts +10 -4
  42. package/src/components/utils/getPlanPrice.ts +1 -1
  43. package/src/index.ts +0 -1
  44. package/src/stories/CustomerPortal.stories.tsx +12 -12
  45. package/src/stories/Paywall.stories.tsx +4 -6
  46. package/src/stories/baseArgs.ts +1 -1
  47. package/src/theme/Fonts.tsx +1 -1
  48. package/src/theme/Theme.tsx +7 -9
  49. package/src/theme/getResolvedTheme.ts +0 -1
  50. package/src/theme/types.ts +0 -1
  51. package/dist/components/checkout/Checkout.d.ts +0 -5
  52. package/dist/components/checkout/CheckoutContainer.d.ts +0 -22
  53. package/dist/components/checkout/CheckoutContainer.style.d.ts +0 -26
  54. package/dist/components/checkout/CheckoutProvider.d.ts +0 -35
  55. package/dist/components/checkout/CheckoutSummary.d.ts +0 -9
  56. package/dist/components/checkout/components/Button.d.ts +0 -6
  57. package/dist/components/checkout/components/InputField.d.ts +0 -8
  58. package/dist/components/checkout/components/index.d.ts +0 -2
  59. package/dist/components/checkout/formatting.d.ts +0 -2
  60. package/dist/components/checkout/hooks/index.d.ts +0 -8
  61. package/dist/components/checkout/hooks/useAddonsStepModel.d.ts +0 -21
  62. package/dist/components/checkout/hooks/useCheckoutModel.d.ts +0 -9
  63. package/dist/components/checkout/hooks/useCouponModel.d.ts +0 -7
  64. package/dist/components/checkout/hooks/useLoadCheckout.d.ts +0 -11
  65. package/dist/components/checkout/hooks/usePaymentStepModel.d.ts +0 -16
  66. package/dist/components/checkout/hooks/usePlanStepModel.d.ts +0 -23
  67. package/dist/components/checkout/hooks/usePreviewSubscription.d.ts +0 -13
  68. package/dist/components/checkout/hooks/useProgressBarModel.d.ts +0 -26
  69. package/dist/components/checkout/hooks/useSubscriptionModel.d.ts +0 -5
  70. package/dist/components/checkout/hooks/useSubscriptionState.d.ts +0 -2
  71. package/dist/components/checkout/index.d.ts +0 -3
  72. package/dist/components/checkout/planHeader/PlanHeader.d.ts +0 -7
  73. package/dist/components/checkout/planHeader/PlanHeader.style.d.ts +0 -25
  74. package/dist/components/checkout/planHeader/index.d.ts +0 -1
  75. package/dist/components/checkout/progressBar/CheckoutProgressBar.d.ts +0 -2
  76. package/dist/components/checkout/progressBar/CheckoutProgressBar.style.d.ts +0 -45
  77. package/dist/components/checkout/promotionCode/AddPromotionCode.d.ts +0 -5
  78. package/dist/components/checkout/promotionCode/AddPromotionCodeButton.d.ts +0 -7
  79. package/dist/components/checkout/promotionCode/AppliedPromotionCode.d.ts +0 -6
  80. package/dist/components/checkout/promotionCode/PromotionCodeSection.d.ts +0 -5
  81. package/dist/components/checkout/promotionCode/index.d.ts +0 -1
  82. package/dist/components/checkout/steps/addons/CheckoutAddonsStep.d.ts +0 -2
  83. package/dist/components/checkout/steps/addons/CheckoutAddonsStep.style.d.ts +0 -93
  84. package/dist/components/checkout/steps/addons/addon.utils.d.ts +0 -15
  85. package/dist/components/checkout/steps/addons/index.d.ts +0 -1
  86. package/dist/components/checkout/steps/payment/PaymentMethods.d.ts +0 -19
  87. package/dist/components/checkout/steps/payment/PaymentMethods.style.d.ts +0 -113
  88. package/dist/components/checkout/steps/payment/PaymentStep.d.ts +0 -2
  89. package/dist/components/checkout/steps/payment/index.d.ts +0 -1
  90. package/dist/components/checkout/steps/payment/stripe/StripePaymentForm.d.ts +0 -2
  91. package/dist/components/checkout/steps/payment/stripe/index.d.ts +0 -3
  92. package/dist/components/checkout/steps/payment/stripe/stripe.utils.d.ts +0 -33
  93. package/dist/components/checkout/steps/payment/stripe/useStripeIntegration.d.ts +0 -5
  94. package/dist/components/checkout/steps/payment/stripe/useSubmit.d.ts +0 -10
  95. package/dist/components/checkout/steps/plan/BillingPeriodPicker.d.ts +0 -9
  96. package/dist/components/checkout/steps/plan/BillingPeriodPicker.style.d.ts +0 -52
  97. package/dist/components/checkout/steps/plan/CheckoutChargeList.d.ts +0 -16
  98. package/dist/components/checkout/steps/plan/CheckoutPlanStep.d.ts +0 -4
  99. package/dist/components/checkout/steps/plan/CheckoutPlanStep.style.d.ts +0 -12
  100. package/dist/components/checkout/steps/plan/index.d.ts +0 -1
  101. package/dist/components/checkout/steps/surprise/SurpriseStep.d.ts +0 -2
  102. package/dist/components/checkout/textOverrides.d.ts +0 -28
  103. package/dist/components/checkout/theme.d.ts +0 -12
  104. package/dist/components/hooks/useChargeSort.d.ts +0 -3
  105. package/dist/components/utils/priceUtils.d.ts +0 -2
  106. package/dist/stories/Checkout.stories.d.ts +0 -3
  107. package/src/assets/arrow-forward.svg +0 -3
  108. package/src/assets/arrow-right.svg +0 -6
  109. package/src/assets/close.svg +0 -3
  110. package/src/assets/nyancat.svg +0 -634
  111. package/src/assets/outlined-checked-circle.svg +0 -6
  112. package/src/assets/outlined-circle.svg +0 -3
  113. package/src/assets/payment-method.svg +0 -11
  114. package/src/assets/plus-icon.svg +0 -6
  115. package/src/assets/trash.svg +0 -8
  116. package/src/components/checkout/Checkout.tsx +0 -30
  117. package/src/components/checkout/CheckoutContainer.style.ts +0 -34
  118. package/src/components/checkout/CheckoutContainer.tsx +0 -88
  119. package/src/components/checkout/CheckoutProvider.tsx +0 -140
  120. package/src/components/checkout/CheckoutSummary.tsx +0 -361
  121. package/src/components/checkout/components/Button.tsx +0 -30
  122. package/src/components/checkout/components/InputField.tsx +0 -22
  123. package/src/components/checkout/components/index.ts +0 -2
  124. package/src/components/checkout/formatting.ts +0 -12
  125. package/src/components/checkout/hooks/index.ts +0 -8
  126. package/src/components/checkout/hooks/useAddonsStepModel.ts +0 -96
  127. package/src/components/checkout/hooks/useCheckoutModel.ts +0 -31
  128. package/src/components/checkout/hooks/useCouponModel.ts +0 -28
  129. package/src/components/checkout/hooks/useLoadCheckout.ts +0 -40
  130. package/src/components/checkout/hooks/usePaymentStepModel.ts +0 -49
  131. package/src/components/checkout/hooks/usePlanStepModel.ts +0 -170
  132. package/src/components/checkout/hooks/usePreviewSubscription.ts +0 -82
  133. package/src/components/checkout/hooks/useProgressBarModel.ts +0 -89
  134. package/src/components/checkout/hooks/useSubscriptionModel.ts +0 -16
  135. package/src/components/checkout/hooks/useSubscriptionState.ts +0 -26
  136. package/src/components/checkout/index.ts +0 -3
  137. package/src/components/checkout/planHeader/PlanHeader.style.tsx +0 -23
  138. package/src/components/checkout/planHeader/PlanHeader.tsx +0 -61
  139. package/src/components/checkout/planHeader/index.ts +0 -1
  140. package/src/components/checkout/progressBar/CheckoutProgressBar.style.ts +0 -29
  141. package/src/components/checkout/progressBar/CheckoutProgressBar.tsx +0 -48
  142. package/src/components/checkout/promotionCode/AddPromotionCode.tsx +0 -85
  143. package/src/components/checkout/promotionCode/AddPromotionCodeButton.tsx +0 -39
  144. package/src/components/checkout/promotionCode/AppliedPromotionCode.tsx +0 -37
  145. package/src/components/checkout/promotionCode/PromotionCodeSection.tsx +0 -27
  146. package/src/components/checkout/promotionCode/index.ts +0 -1
  147. package/src/components/checkout/steps/addons/CheckoutAddonsStep.style.tsx +0 -24
  148. package/src/components/checkout/steps/addons/CheckoutAddonsStep.tsx +0 -125
  149. package/src/components/checkout/steps/addons/addon.utils.ts +0 -68
  150. package/src/components/checkout/steps/addons/index.ts +0 -1
  151. package/src/components/checkout/steps/payment/PaymentMethods.style.ts +0 -26
  152. package/src/components/checkout/steps/payment/PaymentMethods.tsx +0 -83
  153. package/src/components/checkout/steps/payment/PaymentStep.tsx +0 -41
  154. package/src/components/checkout/steps/payment/index.ts +0 -1
  155. package/src/components/checkout/steps/payment/stripe/StripePaymentForm.tsx +0 -43
  156. package/src/components/checkout/steps/payment/stripe/index.ts +0 -3
  157. package/src/components/checkout/steps/payment/stripe/stripe.utils.ts +0 -109
  158. package/src/components/checkout/steps/payment/stripe/useStripeIntegration.ts +0 -27
  159. package/src/components/checkout/steps/payment/stripe/useSubmit.ts +0 -100
  160. package/src/components/checkout/steps/plan/BillingPeriodPicker.style.tsx +0 -46
  161. package/src/components/checkout/steps/plan/BillingPeriodPicker.tsx +0 -63
  162. package/src/components/checkout/steps/plan/CheckoutChargeList.tsx +0 -138
  163. package/src/components/checkout/steps/plan/CheckoutPlanStep.style.tsx +0 -6
  164. package/src/components/checkout/steps/plan/CheckoutPlanStep.tsx +0 -22
  165. package/src/components/checkout/steps/plan/index.ts +0 -1
  166. package/src/components/checkout/steps/surprise/SurpriseStep.tsx +0 -27
  167. package/src/components/checkout/textOverrides.ts +0 -58
  168. package/src/components/checkout/theme.ts +0 -43
  169. package/src/components/hooks/useChargeSort.ts +0 -17
  170. package/src/components/utils/priceUtils.ts +0 -10
  171. package/src/stories/Checkout.stories.tsx +0 -62
@@ -1,100 +0,0 @@
1
- import { ApplySubscription, ApplySubscriptionResults } from '@stigg/js-client-sdk';
2
- import { useElements, useStripe } from '@stripe/react-stripe-js';
3
-
4
- import { useStiggContext } from '../../../../..';
5
- import { useCheckoutModel } from '../../../hooks';
6
- import { usePaymentStepModel } from '../../../hooks/usePaymentStepModel';
7
- import { useSubscriptionState } from '../../../hooks/useSubscriptionState';
8
- import { CheckoutContainerProps, CheckoutResult } from '../../../CheckoutContainer';
9
- import { handleNewPaymentMethod, handleStripeFormValidations, handleStripeNextAction } from './stripe.utils';
10
-
11
- export type HandleSubmitResult = { results?: ApplySubscriptionResults; errorMessage?: string } | undefined;
12
-
13
- export function useSubmit({
14
- onCheckout,
15
- onCheckoutCompleted,
16
- }: Pick<CheckoutContainerProps, 'onCheckout' | 'onCheckoutCompleted'>) {
17
- const { stigg } = useStiggContext();
18
- const { useNewPaymentMethod } = usePaymentStepModel();
19
- const subscriptionState = useSubscriptionState();
20
- const { checkoutState, widgetState, setWidgetLoading } = useCheckoutModel();
21
- const { setupSecret: setupIntentClientSecret } = checkoutState || {};
22
- const stripe = useStripe();
23
- const elements = useElements();
24
-
25
- const handleSubmit = async (e: any): Promise<HandleSubmitResult> => {
26
- e.preventDefault();
27
-
28
- if (!subscriptionState) {
29
- return;
30
- }
31
-
32
- let checkoutResults: ApplySubscriptionResults | undefined;
33
- let errorMessage: string | undefined;
34
- let paymentMethodId: string | undefined;
35
-
36
- setWidgetLoading(true);
37
-
38
- if (useNewPaymentMethod) {
39
- const { success } = await handleStripeFormValidations({ elements });
40
- if (!success) {
41
- setWidgetLoading(false);
42
- return;
43
- }
44
-
45
- const paymentMethodResults = await handleNewPaymentMethod({ elements, stripe, setupIntentClientSecret });
46
- if (!paymentMethodResults.success) {
47
- errorMessage = paymentMethodResults.errorMessage;
48
- }
49
-
50
- paymentMethodId = paymentMethodResults.paymentMethodId;
51
- }
52
-
53
- if (!errorMessage) {
54
- const checkoutParams: ApplySubscription = { ...subscriptionState, paymentMethodId };
55
-
56
- const checkoutAction = async (): Promise<CheckoutResult> => {
57
- try {
58
- const applySubscriptionResults = await stigg.applySubscription(checkoutParams);
59
- const nextActionResults = await handleStripeNextAction({
60
- applySubscriptionResults,
61
- stripe,
62
- });
63
-
64
- checkoutResults = nextActionResults;
65
- if (nextActionResults.errorMessage) {
66
- errorMessage = nextActionResults.errorMessage;
67
- }
68
-
69
- return { success: !nextActionResults.errorMessage, errorMessage: nextActionResults.errorMessage };
70
- } catch (e) {
71
- console.error(e);
72
- errorMessage = (e as any)?.message;
73
- return { success: false, errorMessage };
74
- }
75
- };
76
-
77
- if (onCheckout) {
78
- const externalCheckoutResults = await onCheckout({ checkoutParams, checkoutAction });
79
- if (!externalCheckoutResults.success && externalCheckoutResults.errorMessage) {
80
- errorMessage = externalCheckoutResults.errorMessage;
81
- }
82
- } else {
83
- await checkoutAction();
84
- }
85
- }
86
-
87
- setWidgetLoading(false);
88
-
89
- if (onCheckoutCompleted) {
90
- await onCheckoutCompleted({
91
- success: !errorMessage && !!checkoutResults?.subscription,
92
- error: errorMessage,
93
- });
94
- }
95
-
96
- return { results: checkoutResults, errorMessage };
97
- };
98
-
99
- return { handleSubmit, isLoading: !!widgetState?.isLoading };
100
- }
@@ -1,46 +0,0 @@
1
- import styled from '@emotion/styled/macro';
2
- import { Box, Chip } from '@mui/material';
3
-
4
- export const BillingPeriodPickerContainer = styled(Box)`
5
- padding: 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
- height: 80px;
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
- `;
@@ -1,63 +0,0 @@
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
- };
@@ -1,138 +0,0 @@
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
- }
@@ -1,6 +0,0 @@
1
- import styled from '@emotion/styled/macro';
2
- import { Box } from '@mui/material';
3
-
4
- export const CheckoutPlanContainer = styled(Box)`
5
- width: 100%;
6
- `;
@@ -1,22 +0,0 @@
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
- type CheckoutPlanStepProps = {};
10
-
11
- export const CheckoutPlanStep = ({}: CheckoutPlanStepProps) => {
12
- const { checkoutState, checkoutLocalization } = useCheckoutModel();
13
- const { plan } = checkoutState || {};
14
- const { billingPeriod } = usePlanStepModel();
15
-
16
- return (
17
- <CheckoutPlanContainer>
18
- <BillingPeriodPicker plan={plan} checkoutLocalization={checkoutLocalization} />
19
- <CheckoutChargeList plan={plan} billingPeriod={billingPeriod} />
20
- </CheckoutPlanContainer>
21
- );
22
- };
@@ -1 +0,0 @@
1
- export * from './CheckoutPlanStep';
@@ -1,27 +0,0 @@
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
- };
@@ -1,58 +0,0 @@
1
- import { BillingPeriod } from '@stigg/js-client-sdk';
2
- import moment from 'moment';
3
- import merge from 'lodash/merge';
4
- import { DeepPartial } from '../../types';
5
- import { formatBillingPeriod } from './formatting';
6
-
7
- export type CheckoutLocalization = {
8
- changePlan: string;
9
- billingPeriodsTitle: string;
10
- addAddonText: string;
11
- newPaymentMethodText: string;
12
- newPaymentMethodCardTitle: string;
13
- newPaymentMethodBillingAddressTitle: string;
14
- baseChargeText: string | ((params: { billingPeriod: BillingPeriod }) => string);
15
- totalText: string;
16
- subTotalText: string;
17
- addCouponCodeText: string;
18
- couponCodeTitle: string;
19
- addonsSectionTitle: string;
20
- changesWillApplyAtEndOfBillingPeriod: string | ((params: { billingPeriodEnd: Date }) => string);
21
- checkoutButton: {
22
- nextText: string;
23
- downgradeText: string;
24
- upgradeText: string;
25
- purchaseText: string;
26
- };
27
- };
28
-
29
- export function getResolvedCheckoutLocalize(
30
- localizeOverride?: DeepPartial<CheckoutLocalization>,
31
- ): CheckoutLocalization {
32
- const checkoutDefaultLocalization: CheckoutLocalization = {
33
- changePlan: 'Change plan',
34
- billingPeriodsTitle: 'Billing cycle',
35
- addAddonText: 'Add',
36
- newPaymentMethodText: 'New payment method',
37
- newPaymentMethodBillingAddressTitle: 'Billing address',
38
- newPaymentMethodCardTitle: 'Payment method',
39
- baseChargeText: ({ billingPeriod }) => `${formatBillingPeriod(billingPeriod)} charge`,
40
- totalText: 'Total due today',
41
- subTotalText: 'Subtotal',
42
- addCouponCodeText: 'Add coupon code',
43
- couponCodeTitle: 'Coupon code',
44
- addonsSectionTitle: 'Add-ons',
45
- changesWillApplyAtEndOfBillingPeriod: ({ billingPeriodEnd }) =>
46
- `Your changes will apply on the end of your current billing cycle on ${moment(billingPeriodEnd).format(
47
- 'MMM D, YYYY',
48
- )}.`,
49
- checkoutButton: {
50
- nextText: 'Next',
51
- downgradeText: 'Downgrade',
52
- upgradeText: 'Upgrade',
53
- purchaseText: 'Purchase',
54
- },
55
- };
56
-
57
- return merge(checkoutDefaultLocalization, localizeOverride);
58
- }
@@ -1,43 +0,0 @@
1
- import { CheckoutConfiguration } from '@stigg/js-client-sdk';
2
- import { StiggTheme } from '../../theme/types';
3
- import { DeepPartial } from '../../types';
4
-
5
- export type CheckoutTheme = {
6
- primary: string;
7
- textColor: string;
8
- backgroundColor: string;
9
- borderColor: string;
10
- selectionColor: string;
11
- summaryBackgroundColor: string;
12
- };
13
-
14
- const defaultCheckoutTheme: CheckoutTheme = {
15
- primary: 'rgb(50, 126, 238)',
16
- textColor: 'rgb(0, 30, 108)',
17
- backgroundColor: 'rgb(255, 255, 255)',
18
- borderColor: 'rgb(235, 237, 243)',
19
- selectionColor: 'rgb(229, 242, 255)',
20
- summaryBackgroundColor: 'rgb(109, 121, 144)',
21
- };
22
-
23
- export function getResolvedCheckoutTheme(
24
- globalTheme: StiggTheme,
25
- themeOverride?: DeepPartial<CheckoutTheme>,
26
- _remoteConfiguration?: CheckoutConfiguration | null, // all the remote colors override theme colors, no need to use them here
27
- ): CheckoutTheme {
28
- const { palette: globalPalette } = globalTheme || {};
29
-
30
- return {
31
- primary: themeOverride?.primary || globalPalette?.primary || defaultCheckoutTheme.primary,
32
- textColor: themeOverride?.textColor || globalPalette?.text.primary || defaultCheckoutTheme.textColor,
33
- backgroundColor:
34
- themeOverride?.backgroundColor || globalPalette?.backgroundPaper || defaultCheckoutTheme.backgroundColor,
35
- borderColor: themeOverride?.borderColor || globalPalette?.outlinedBorder || defaultCheckoutTheme.borderColor,
36
- selectionColor:
37
- themeOverride?.selectionColor || globalPalette?.backgroundSection || defaultCheckoutTheme.selectionColor,
38
- summaryBackgroundColor:
39
- themeOverride?.summaryBackgroundColor ||
40
- globalPalette?.backgroundHighlight ||
41
- defaultCheckoutTheme.summaryBackgroundColor,
42
- };
43
- }
@@ -1,17 +0,0 @@
1
- import sortBy from 'lodash/sortBy';
2
- import { useMemo } from 'react';
3
-
4
- import { BillingModel, Price } from '@stigg/js-client-sdk';
5
-
6
- const CHARGES_BILLING_MODEL_ORDER = [BillingModel.FlatFee, BillingModel.PerUnit, BillingModel.UsageBased];
7
-
8
- export const sortCharges = (charges: Price[]) => {
9
- return sortBy(charges, [
10
- charge => CHARGES_BILLING_MODEL_ORDER.indexOf(charge.pricingModel),
11
- charge => charge.feature?.displayName,
12
- ]);
13
- };
14
-
15
- export const useChargesSort = (charges: Price[]) => {
16
- return useMemo(() => sortCharges(charges), [charges]);
17
- };
@@ -1,10 +0,0 @@
1
- import { Price } from '@stigg/js-client-sdk';
2
-
3
- export const getValidPriceQuantity = (price: Price, quantity: number) => {
4
- if (price.minUnitQuantity && quantity < price.minUnitQuantity) {
5
- return price.minUnitQuantity;
6
- } else if (price.maxUnitQuantity && quantity > price.maxUnitQuantity) {
7
- return price.maxUnitQuantity;
8
- }
9
- return quantity;
10
- };
@@ -1,62 +0,0 @@
1
- import React from 'react';
2
- import styled from '@emotion/styled/macro';
3
- import { ComponentMeta, ComponentStory } from '@storybook/react';
4
- import { Checkout } from '../components/checkout';
5
- import { StiggProvider } from '../components/StiggProvider';
6
- import { defaultArgsWithCustomer } from './baseArgs';
7
-
8
- export default {
9
- title: 'Stigg React SDK/Checkout',
10
- component: Checkout,
11
- decorators: [
12
- (Story, { args }) => (
13
- <StiggProvider
14
- apiKey={args.apiKey}
15
- customerId={args.customerId}
16
- theme={args.theme}
17
- locale={args.locale}
18
- baseUri={args.baseUri}
19
- enableEdge={args.disableEdge}
20
- >
21
- <Story />
22
- </StiggProvider>
23
- ),
24
- ],
25
- } as ComponentMeta<typeof Checkout>;
26
-
27
- const Wrapper = styled.div`
28
- width: 1000px;
29
- `;
30
-
31
- const Template: ComponentStory<any> = args => (
32
- <Wrapper>
33
- <Checkout
34
- planId={args.planId}
35
- preferredBillingPeriod={args.preferredBillingPeriod}
36
- billingCountryCode={args.billingCountryCode}
37
- resourceId={args.resourceId}
38
- onCheckoutCompleted={results => {
39
- console.log('checkout finished!', results);
40
- return Promise.resolve();
41
- }}
42
- onCheckout={async ({ checkoutParams, checkoutAction }) => {
43
- console.log('checkout started!', checkoutParams);
44
- const { success, errorMessage } = await checkoutAction();
45
- return { success, errorMessage };
46
- }}
47
- onChangePlan={({ currentPlan }) => {
48
- console.log('plan changed clicked!', { currentPlan });
49
- }}
50
- />
51
- </Wrapper>
52
- );
53
-
54
- export const DefaultCheckout = Template.bind({});
55
- DefaultCheckout.args = {
56
- ...defaultArgsWithCustomer,
57
- planId: 'plan-revvenu-essentials',
58
- baseUri: 'http://localhost:4000',
59
- apiKey: 'client-72b058a6-0f22-4c86-adce-bf266d12e12e:9f356ceb-c94c-42a4-9572-10b12824da81',
60
- // baseUri: 'https://api-staging.stigg.io',
61
- // apiKey: 'client-79584f52-7ef9-4c58-b9ac-5080acf492e4:71f2274c-100a-4fa4-8a43-48fa3b16c627',
62
- };