@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.
- package/dist/components/checkout/CheckoutContainer.d.ts +2 -1
- package/dist/components/checkout/index.d.ts +3 -2
- package/dist/components/checkout/progressBar/CheckoutProgressBar.style.d.ts +0 -1
- package/dist/components/checkout/steps/payment/PaymentMethods.d.ts +2 -2
- package/dist/components/checkout/steps/payment/PaymentStep.d.ts +1 -1
- package/dist/components/checkout/steps/payment/stripe/StripePaymentForm.d.ts +1 -1
- package/dist/react-sdk.cjs.development.js +36 -24
- package/dist/react-sdk.cjs.development.js.map +1 -1
- package/dist/react-sdk.cjs.production.min.js +1 -1
- package/dist/react-sdk.cjs.production.min.js.map +1 -1
- package/dist/react-sdk.esm.js +36 -24
- package/dist/react-sdk.esm.js.map +1 -1
- package/dist/stories/mocks/checkout/mockCheckoutState.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/checkout/CheckoutContainer.tsx +19 -8
- package/src/components/checkout/components/InputField.tsx +3 -0
- package/src/components/checkout/index.ts +8 -2
- package/src/components/checkout/progressBar/CheckoutProgressBar.style.ts +2 -3
- package/src/components/checkout/progressBar/CheckoutProgressBar.tsx +0 -1
- package/src/components/checkout/steps/payment/PaymentMethods.tsx +3 -2
- package/src/components/checkout/steps/payment/PaymentStep.tsx +5 -1
- package/src/components/checkout/steps/payment/stripe/StripePaymentForm.tsx +6 -2
- package/src/stories/mocks/checkout/mockCheckoutState.ts +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { GetCheckoutState, GetCheckoutStateResults } from '
|
|
1
|
+
import { GetCheckoutState, GetCheckoutStateResults } from '@stigg/js-client-sdk';
|
|
2
2
|
export declare function mockCheckoutState(params: GetCheckoutState): GetCheckoutStateResults;
|
package/package.json
CHANGED
|
@@ -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
|
-
{
|
|
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 {
|
|
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 =
|
|
98
|
-
? { clientSecret: setupIntentClientSecret }
|
|
99
|
-
|
|
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
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export { CheckoutTheme } from './theme';
|
|
2
|
-
export {
|
|
3
|
-
|
|
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, $
|
|
29
|
+
}>(({ theme, $disabled, $shouldFill }) => ({
|
|
31
30
|
circle: {
|
|
32
|
-
stroke: $
|
|
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
|
}));
|
|
@@ -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({
|
|
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({
|
|
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:
|
|
54
|
+
fields: { phone: shouldCollectPhoneNumber ? 'always' : 'auto' },
|
|
51
55
|
defaultValues: {
|
|
52
56
|
...(customer?.name && { name: customer.name }),
|
|
53
57
|
},
|