@stigg/react-sdk 4.4.1 → 4.4.3
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/promotionCode/AppliedPromotionCode.d.ts +6 -0
- 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/index.d.ts +1 -1
- package/dist/react-sdk.cjs.development.js +43 -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 +49 -25
- 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 +14 -4
- package/src/components/checkout/index.ts +8 -2
- package/src/components/checkout/promotionCode/AppliedPromotionCode.tsx +14 -2
- 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/index.ts +17 -1
- 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
|
@@ -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
|
) : (
|
|
@@ -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';
|
|
@@ -16,6 +16,18 @@ const AppliedCouponContainer = styled(Grid)`
|
|
|
16
16
|
border: 1px solid ${({ theme }) => theme.stigg.palette.primary};
|
|
17
17
|
`;
|
|
18
18
|
|
|
19
|
+
export const StyledIcon = styled(Icon, { shouldForwardProp: (prop) => prop !== 'style' })<{ $shouldFill?: boolean }>`
|
|
20
|
+
display: flex;
|
|
21
|
+
|
|
22
|
+
g {
|
|
23
|
+
stroke: ${({ theme }) => theme.stigg.palette.primary};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
path {
|
|
27
|
+
fill: ${({ theme, $shouldFill }) => ($shouldFill ? theme.stigg.palette.primary : undefined)};
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
|
|
19
31
|
export type AppliedPromotionCodeProps = {
|
|
20
32
|
promotionCode: string;
|
|
21
33
|
onClearPromotionCode: () => void;
|
|
@@ -24,14 +36,14 @@ export type AppliedPromotionCodeProps = {
|
|
|
24
36
|
export const AppliedPromotionCode = ({ promotionCode, onClearPromotionCode }: AppliedPromotionCodeProps) => (
|
|
25
37
|
<AppliedCouponContainer container>
|
|
26
38
|
<Grid item display="flex" gap={1} alignItems="center">
|
|
27
|
-
<
|
|
39
|
+
<StyledIcon icon="Coupon" />
|
|
28
40
|
<Typography variant="body1" color="primary.main" lineHeight="auto">
|
|
29
41
|
{promotionCode}
|
|
30
42
|
</Typography>
|
|
31
43
|
</Grid>
|
|
32
44
|
<Grid item>
|
|
33
45
|
<Button variant="text" sx={{ minWidth: 'unset', padding: 0 }} onClick={onClearPromotionCode}>
|
|
34
|
-
<
|
|
46
|
+
<StyledIcon icon="Close" $shouldFill />
|
|
35
47
|
</Button>
|
|
36
48
|
</Grid>
|
|
37
49
|
</AppliedCouponContainer>
|
|
@@ -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
|
},
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import './styles.css';
|
|
2
|
+
|
|
2
3
|
export * from '@stigg/js-client-sdk';
|
|
3
4
|
export {
|
|
4
5
|
Paywall,
|
|
@@ -29,7 +30,22 @@ export {
|
|
|
29
30
|
StiggContextValue,
|
|
30
31
|
StiggContext,
|
|
31
32
|
} from './components/StiggProvider';
|
|
32
|
-
export {
|
|
33
|
+
export {
|
|
34
|
+
Checkout,
|
|
35
|
+
CheckoutProps,
|
|
36
|
+
CheckoutProviderProps,
|
|
37
|
+
CheckoutContainerProps,
|
|
38
|
+
CheckoutLocalization,
|
|
39
|
+
CheckoutResult,
|
|
40
|
+
OnCheckoutCompletedParams,
|
|
41
|
+
OnCheckoutParams,
|
|
42
|
+
CheckoutTheme,
|
|
43
|
+
CheckoutMockProps,
|
|
44
|
+
MockCheckoutPreviewCallback,
|
|
45
|
+
MockCheckoutStateCallback,
|
|
46
|
+
BillingInformation,
|
|
47
|
+
TaxDetailsInput,
|
|
48
|
+
} from './components/checkout';
|
|
33
49
|
export { useWaitForCheckoutCompleted, ProvisionStatus } from './components/hooks';
|
|
34
50
|
export { HorizontalAlignment, TextAlignment } from './theme/types';
|
|
35
51
|
export { CustomizedTheme as Theme } from './theme/Theme';
|