@stigg/react-sdk 4.4.0 → 4.4.2

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.
@@ -1,2 +1,2 @@
1
- import { GetCheckoutState, GetCheckoutStateResults } from '../../../../../js-client-sdk';
1
+ import { GetCheckoutState, GetCheckoutStateResults } from '@stigg/js-client-sdk';
2
2
  export declare function mockCheckoutState(params: GetCheckoutState): GetCheckoutStateResults;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.4.0",
2
+ "version": "4.4.2",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useMemo } from 'react';
2
2
  import { Elements } from '@stripe/react-stripe-js';
3
3
  import { PricingType, BillingAddress, ApplySubscription, CheckoutStatePlan } from '@stigg/js-client-sdk';
4
4
  import { CheckoutContent, CheckoutLayout, CheckoutPanel } from './CheckoutContainer.style';
@@ -23,7 +23,11 @@ type StripeManualMode = { mode: 'setup' | 'payment' | 'subscription'; currency:
23
23
 
24
24
  const getStepProps = (
25
25
  currentStep: CheckoutStep,
26
- { onBillingAddressChange, onChangePlan }: Pick<CheckoutContainerProps, 'onBillingAddressChange' | 'onChangePlan'>,
26
+ {
27
+ onBillingAddressChange,
28
+ onChangePlan,
29
+ collectPhoneNumber,
30
+ }: Pick<CheckoutContainerProps, 'onBillingAddressChange' | 'onChangePlan' | 'collectPhoneNumber'>,
27
31
  ): StepProps => {
28
32
  switch (currentStep.key) {
29
33
  case CheckoutStepKey.PLAN:
@@ -31,7 +35,11 @@ const getStepProps = (
31
35
  case CheckoutStepKey.ADDONS:
32
36
  return { content: <CheckoutAddonsStep /> };
33
37
  case CheckoutStepKey.PAYMENT:
34
- return { content: <PaymentStep onBillingAddressChange={onBillingAddressChange} /> };
38
+ return {
39
+ content: (
40
+ <PaymentStep onBillingAddressChange={onBillingAddressChange} collectPhoneNumber={collectPhoneNumber} />
41
+ ),
42
+ };
35
43
  default:
36
44
  return { content: null };
37
45
  }
@@ -50,6 +58,7 @@ export type CheckoutContainerProps = {
50
58
  onBillingAddressChange?: (params: { billingAddress: BillingAddress }) => Promise<void>;
51
59
  disablePromotionCode?: boolean;
52
60
  disableSuccessAnimation?: boolean;
61
+ collectPhoneNumber?: boolean;
53
62
  onMockCheckoutPreview?: MockCheckoutPreviewCallback;
54
63
  };
55
64
 
@@ -58,6 +67,7 @@ export function CheckoutContainer({
58
67
  onCheckoutCompleted,
59
68
  onChangePlan,
60
69
  onBillingAddressChange,
70
+ collectPhoneNumber,
61
71
  disablePromotionCode,
62
72
  disableSuccessAnimation,
63
73
  onMockCheckoutPreview,
@@ -76,16 +86,16 @@ export function CheckoutContainer({
76
86
  !!activeSubscription &&
77
87
  activeSubscription.pricingType !== PricingType.Free;
78
88
 
79
- const { content } = getStepProps(currentStep, { onBillingAddressChange, onChangePlan });
89
+ const { content } = getStepProps(currentStep, { onBillingAddressChange, onChangePlan, collectPhoneNumber });
80
90
 
81
91
  const checkoutContent = (
82
92
  <>
83
93
  {isFreeDowngrade ? (
84
94
  <DowngradeToFreePlan
85
- checkoutLocalization={checkoutLocalization}
86
95
  freePlan={plan!}
87
96
  activeSubscription={activeSubscription!}
88
97
  allowChangePlan
98
+ checkoutLocalization={checkoutLocalization}
89
99
  onChangePlan={onChangePlan}
90
100
  />
91
101
  ) : (
@@ -94,9 +104,10 @@ export function CheckoutContainer({
94
104
  </>
95
105
  );
96
106
 
97
- const stripeElementsMode: StripeClientSecret | StripeManualMode = setupIntentClientSecret
98
- ? { clientSecret: setupIntentClientSecret }
99
- : { mode: 'setup', currency: 'usd' };
107
+ const stripeElementsMode: StripeClientSecret | StripeManualMode = useMemo(
108
+ () => (setupIntentClientSecret ? { clientSecret: setupIntentClientSecret } : { mode: 'setup', currency: 'usd' }),
109
+ [setupIntentClientSecret],
110
+ );
100
111
 
101
112
  return (
102
113
  <Elements
@@ -19,4 +19,7 @@ export const InputField = styled(TextField)<OutlinedInputProps>(({ theme }) => (
19
19
  color: theme.stigg.palette.text.primary,
20
20
  ...theme.stigg.typography.body,
21
21
  },
22
+ '& .Mui-error': {
23
+ fontFamily: theme.stigg.typography.fontFamily,
24
+ },
22
25
  }));
@@ -1,5 +1,11 @@
1
1
  export { CheckoutTheme } from './theme';
2
- export { Checkout, CheckoutProps } from './Checkout';
3
- export { OnCheckoutCompletedParams, OnCheckoutParams, CheckoutResult } from './CheckoutContainer';
2
+ export {
3
+ OnCheckoutCompletedParams,
4
+ OnCheckoutParams,
5
+ CheckoutResult,
6
+ CheckoutContainerProps,
7
+ } from './CheckoutContainer';
8
+ export { CheckoutProviderProps } from './CheckoutProvider';
4
9
  export { CheckoutLocalization } from './textOverrides';
10
+ export { Checkout, CheckoutProps } from './Checkout';
5
11
  export * from './types';
@@ -25,11 +25,10 @@ export const StyledStepButton = styled(Button)(() => ({
25
25
 
26
26
  export const StyledIcon = styled(Icon, { shouldForwardProp: (prop) => !prop.startsWith('$') })<{
27
27
  $disabled?: boolean;
28
- $shouldStroke?: boolean;
29
28
  $shouldFill?: boolean;
30
- }>(({ theme, $disabled, $shouldStroke = true, $shouldFill }) => ({
29
+ }>(({ theme, $disabled, $shouldFill }) => ({
31
30
  circle: {
32
- stroke: $shouldStroke ? ($disabled ? theme.stigg.palette.primaryLight : theme.stigg.palette.primary) : undefined,
31
+ stroke: $disabled ? theme.stigg.palette.primaryLight : theme.stigg.palette.primary,
33
32
  fill: $shouldFill ? ($disabled ? theme.stigg.palette.primaryLight : theme.stigg.palette.primary) : undefined,
34
33
  },
35
34
  }));
@@ -37,7 +37,6 @@ export const CheckoutProgressBar = () => {
37
37
  <StyledIcon
38
38
  icon={isCompleted ? checkedIcon : 'OutlinedCircle'}
39
39
  $disabled={isDisabled}
40
- $shouldStroke={(isCompleted && !isDisabled) || isDisabled}
41
40
  $shouldFill={isCompleted}
42
41
  />
43
42
  }
@@ -29,7 +29,7 @@ export type PaymentMethodProps = Pick<Customer, 'paymentMethodDetails'> &
29
29
  export type NewPaymentMethodProps = Pick<PaymentMethodLayoutProps, 'checked' | 'readOnly'> & {
30
30
  onSelect: () => void;
31
31
  checkoutLocalization: CheckoutLocalization;
32
- } & Pick<CheckoutContainerProps, 'onBillingAddressChange'>;
32
+ } & Pick<CheckoutContainerProps, 'onBillingAddressChange' | 'collectPhoneNumber'>;
33
33
 
34
34
  function PaymentMethodLayout({ checked, icon, text, subtitle, readOnly }: PaymentMethodLayoutProps) {
35
35
  return (
@@ -76,6 +76,7 @@ export function NewPaymentMethod({
76
76
  readOnly,
77
77
  checkoutLocalization,
78
78
  onBillingAddressChange,
79
+ collectPhoneNumber,
79
80
  }: NewPaymentMethodProps) {
80
81
  return (
81
82
  <NewPaymentMethodContainer item onClick={onSelect} $disabled={readOnly}>
@@ -86,7 +87,7 @@ export function NewPaymentMethod({
86
87
  text={<Typography variant="h6">{checkoutLocalization.newPaymentMethodText}</Typography>}
87
88
  />
88
89
  <Collapse in={checked}>
89
- <StripePaymentForm onBillingAddressChange={onBillingAddressChange} />
90
+ <StripePaymentForm onBillingAddressChange={onBillingAddressChange} collectPhoneNumber={collectPhoneNumber} />
90
91
  </Collapse>
91
92
  </NewPaymentMethodContainer>
92
93
  );
@@ -12,7 +12,10 @@ const PaymentContainer = styled(Grid)`
12
12
  gap: 24px;
13
13
  `;
14
14
 
15
- export function PaymentStep({ onBillingAddressChange }: Pick<CheckoutContainerProps, 'onBillingAddressChange'>) {
15
+ export function PaymentStep({
16
+ onBillingAddressChange,
17
+ collectPhoneNumber,
18
+ }: Pick<CheckoutContainerProps, 'onBillingAddressChange' | 'collectPhoneNumber'>) {
16
19
  const { checkoutState, checkoutLocalization, widgetState } = useCheckoutModel();
17
20
  const { customer } = checkoutState || {};
18
21
  const { errorMessage, useNewPaymentMethod, setUseNewPaymentMethod } = usePaymentStepModel();
@@ -45,6 +48,7 @@ export function PaymentStep({ onBillingAddressChange }: Pick<CheckoutContainerPr
45
48
  checkoutLocalization={checkoutLocalization}
46
49
  onSelect={() => handleOnSelect(true)}
47
50
  onBillingAddressChange={onBillingAddressChange}
51
+ collectPhoneNumber={collectPhoneNumber}
48
52
  />
49
53
  </PaymentContainer>
50
54
  );
@@ -7,11 +7,15 @@ import { Typography } from '../../../../common/Typography';
7
7
  import { useCheckoutModel, usePaymentStepModel } from '../../../hooks';
8
8
  import { CheckoutContainerProps } from '../../../CheckoutContainer';
9
9
 
10
- export function StripePaymentForm({ onBillingAddressChange }: Pick<CheckoutContainerProps, 'onBillingAddressChange'>) {
10
+ export function StripePaymentForm({
11
+ onBillingAddressChange,
12
+ collectPhoneNumber,
13
+ }: Pick<CheckoutContainerProps, 'onBillingAddressChange' | 'collectPhoneNumber'>) {
11
14
  const { checkoutState, checkoutLocalization, widgetState, setWidgetReadOnly } = useCheckoutModel();
12
15
  const { setBillingAddress } = usePaymentStepModel();
13
16
  const { customer, configuration } = checkoutState || {};
14
17
  const { readOnly } = widgetState;
18
+ const shouldCollectPhoneNumber = !!(collectPhoneNumber ?? configuration?.content?.collectPhoneNumber);
15
19
 
16
20
  const handleAddressChange = (args: StripeAddressElementChangeEvent) => {
17
21
  if (!args.complete) {
@@ -47,7 +51,7 @@ export function StripePaymentForm({ onBillingAddressChange }: Pick<CheckoutConta
47
51
  onChange={handleAddressChange}
48
52
  options={{
49
53
  mode: 'billing',
50
- fields: { phone: configuration?.content?.collectPhoneNumber ? 'always' : 'auto' },
54
+ fields: { phone: shouldCollectPhoneNumber ? 'always' : 'auto' },
51
55
  defaultValues: {
52
56
  ...(customer?.name && { name: customer.name }),
53
57
  },
@@ -16,7 +16,7 @@ import {
16
16
  PromotionalEntitlement,
17
17
  Subscription,
18
18
  Addon,
19
- } from '../../../../../js-client-sdk';
19
+ } from '@stigg/js-client-sdk';
20
20
  import {
21
21
  BASE_FEE_MONTHLY,
22
22
  TIERS_PRICE_MONTHLY,