@lookiero/checkout 10.1.0 → 11.1.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.
- package/cypress/integration/checkout.spec.ts +0 -3
- package/dist/fake-dependencies/@lookiero/payments-front/index.d.ts +8 -7
- package/dist/fake-dependencies/@lookiero/payments-front/index.js +11 -3
- package/dist/index.d.ts +3 -3
- package/dist/src/Expo.js +8 -2
- package/dist/src/ExpoRoot.d.ts +5 -1
- package/dist/src/ExpoRoot.js +26 -17
- package/dist/src/infrastructure/domain/checkoutBooking/react/useBlockCheckoutBooking.d.ts +1 -1
- package/dist/src/infrastructure/domain/checkoutBooking/react/useBlockCheckoutBooking.js +2 -0
- package/dist/src/infrastructure/projection/checkout/checkout.mock.d.ts +1 -0
- package/dist/src/infrastructure/projection/checkout/checkout.mock.js +3 -3
- package/dist/src/infrastructure/projection/pricing/react/useViewPricingByCheckoutId.d.ts +1 -1
- package/dist/src/infrastructure/projection/pricing/react/useViewPricingByCheckoutId.js +2 -1
- package/dist/src/infrastructure/tracking/tracking.d.ts +2 -2
- package/dist/src/infrastructure/tracking/useTrackCheckout.d.ts +10 -17
- package/dist/src/infrastructure/tracking/useTrackCheckout.js +27 -12
- package/dist/src/infrastructure/ui/Root.d.ts +6 -6
- package/dist/src/infrastructure/ui/Root.js +2 -3
- package/dist/src/infrastructure/ui/hooks/useCheckoutFlow.d.ts +26 -0
- package/dist/src/infrastructure/ui/hooks/useCheckoutFlow.js +127 -0
- package/dist/src/infrastructure/ui/hooks/usePaymentInstrumentEvents.d.ts +3 -2
- package/dist/src/infrastructure/ui/hooks/usePaymentInstrumentEvents.js +17 -26
- package/dist/src/infrastructure/ui/i18n/i18n.d.ts +1 -0
- package/dist/src/infrastructure/ui/i18n/i18n.js +1 -0
- package/dist/src/infrastructure/ui/routing/CheckoutMiddleware.js +1 -12
- package/dist/src/infrastructure/ui/routing/Routing.d.ts +5 -5
- package/dist/src/infrastructure/ui/routing/Routing.js +2 -10
- package/dist/src/infrastructure/ui/routing/routes.d.ts +0 -1
- package/dist/src/infrastructure/ui/routing/routes.js +0 -1
- package/dist/src/infrastructure/ui/views/App.js +5 -6
- package/dist/src/infrastructure/ui/views/checkout/Checkout.d.ts +7 -2
- package/dist/src/infrastructure/ui/views/checkout/Checkout.js +20 -9
- package/dist/src/infrastructure/ui/views/checkout/Checkout.style.d.ts +3 -0
- package/dist/src/infrastructure/ui/views/checkout/Checkout.style.js +3 -0
- package/dist/src/infrastructure/ui/views/checkout/components/paymentInstrument/PaymentInstrument.js +7 -7
- package/dist/src/projection/customer/customer.d.ts +2 -0
- package/dist/src/projection/order/order.d.ts +1 -1
- package/dist/src/projection/subscription/subscription.d.ts +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/fake-dependencies/@lookiero/payments-front/index.tsx +36 -8
- package/index.ts +10 -3
- package/package.json +3 -4
- package/src/Expo.tsx +10 -2
- package/src/ExpoRoot.tsx +58 -43
- package/src/infrastructure/domain/checkoutBooking/react/useBlockCheckoutBooking.ts +4 -1
- package/src/infrastructure/projection/checkout/checkout.mock.ts +8 -3
- package/src/infrastructure/projection/pricing/react/useViewPricingByCheckoutId.ts +3 -2
- package/src/infrastructure/tracking/tracking.ts +2 -2
- package/src/infrastructure/tracking/useTrackCheckout.test.tsx +51 -24
- package/src/infrastructure/tracking/useTrackCheckout.ts +66 -56
- package/src/infrastructure/ui/Root.tsx +9 -9
- package/src/infrastructure/ui/components/templates/header/itemHeader/ItemHeader.tsx +1 -0
- package/src/infrastructure/ui/hooks/useCheckoutFlow.test.tsx +302 -0
- package/src/infrastructure/ui/hooks/useCheckoutFlow.tsx +203 -0
- package/src/infrastructure/ui/hooks/usePaymentInstrumentEvents.ts +18 -60
- package/src/infrastructure/ui/i18n/i18n.ts +1 -0
- package/src/infrastructure/ui/routing/CheckoutMiddleware.test.tsx +0 -11
- package/src/infrastructure/ui/routing/CheckoutMiddleware.tsx +1 -15
- package/src/infrastructure/ui/routing/Routing.tsx +14 -25
- package/src/infrastructure/ui/routing/routes.ts +0 -1
- package/src/infrastructure/ui/views/App.tsx +5 -13
- package/src/infrastructure/ui/views/checkout/Checkout.style.ts +3 -0
- package/src/infrastructure/ui/views/checkout/Checkout.test.tsx +51 -43
- package/src/infrastructure/ui/views/checkout/Checkout.tsx +51 -13
- package/src/infrastructure/ui/views/checkout/components/paymentInstrument/PaymentInstrument.tsx +8 -8
- package/src/infrastructure/ui/views/item/components/itemActions/__snapshots__/ItemActions.test.tsx.snap +8 -0
- package/src/infrastructure/ui/views/item/components/selectModal/__snapshots__/SelecModal.test.tsx.snap +8 -0
- package/src/infrastructure/ui/views/item/components/sizeWithoutStockModal/__snapshots__/SizeWithoutStockModal.test.tsx.snap +8 -0
- package/src/projection/customer/customer.ts +2 -0
- package/src/projection/order/order.ts +1 -1
- package/src/projection/subscription/subscription.ts +1 -1
- package/dist/src/infrastructure/ui/hooks/useSubmitCheckout.d.ts +0 -27
- package/dist/src/infrastructure/ui/hooks/useSubmitCheckout.js +0 -97
- package/dist/src/infrastructure/ui/views/checkout/components/checkoutPaymentModal/CheckoutPaymentModal.d.ts +0 -12
- package/dist/src/infrastructure/ui/views/checkout/components/checkoutPaymentModal/CheckoutPaymentModal.js +0 -88
- package/src/infrastructure/ui/hooks/useSubmitCheckout.test.ts +0 -297
- package/src/infrastructure/ui/hooks/useSubmitCheckout.ts +0 -169
- package/src/infrastructure/ui/views/checkout/components/checkoutPaymentModal/CheckoutPaymentModal.test.tsx +0 -134
- package/src/infrastructure/ui/views/checkout/components/checkoutPaymentModal/CheckoutPaymentModal.tsx +0 -124
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { waitFor } from "@testing-library/react-native";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { QueryStatus } from "@lookiero/messaging-react";
|
|
4
|
-
import { Country } from "@lookiero/sty-psp-locale";
|
|
5
|
-
import { Segment } from "@lookiero/sty-psp-segment";
|
|
6
|
-
import { CheckoutItemStatus } from "../../../../../../domain/checkoutItem/model/checkoutItem";
|
|
7
|
-
import { checkout } from "../../../../../projection/checkout/checkout.mock";
|
|
8
|
-
import { useViewFirstAvailableCheckoutByCustomerId } from "../../../../../projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId";
|
|
9
|
-
import { useViewIsSizeChangeEnabledByCheckoutId } from "../../../../../projection/checkout/react/useViewIsSizeChangeEnabledByCheckoutId";
|
|
10
|
-
import { paymentFlowPayload as mockPaymentFlowPayload } from "../../../../../projection/payment/paymentFlowPayload.mock";
|
|
11
|
-
import { useViewPaymentFlowPayloadByCheckoutId } from "../../../../../projection/payment/react/useViewPaymentFlowPayloadByCheckoutId";
|
|
12
|
-
import { pricing } from "../../../../../projection/pricing/pricing.mock";
|
|
13
|
-
import { useViewPricingByCheckoutId } from "../../../../../projection/pricing/react/useViewPricingByCheckoutId";
|
|
14
|
-
import { useSubmitCheckout } from "../../../../hooks/useSubmitCheckout";
|
|
15
|
-
import { Routes } from "../../../../routing/routes";
|
|
16
|
-
import { render } from "../../../../test/render";
|
|
17
|
-
import { CheckoutPaymentModal } from "./CheckoutPaymentModal";
|
|
18
|
-
|
|
19
|
-
const customerId = "a8fff6d7-708c-41a7-b42a-58c5706d33df";
|
|
20
|
-
const country = Country.ES;
|
|
21
|
-
const segment = Segment.WOMEN;
|
|
22
|
-
const orderNumber = 3691625;
|
|
23
|
-
const isFirstOrder = false;
|
|
24
|
-
const getAuthToken = () => Promise.resolve("token");
|
|
25
|
-
const mockCheckout = checkout({
|
|
26
|
-
items: [
|
|
27
|
-
{ status: CheckoutItemStatus.RETURNED },
|
|
28
|
-
{ status: CheckoutItemStatus.KEPT },
|
|
29
|
-
{ status: CheckoutItemStatus.KEPT },
|
|
30
|
-
{ status: CheckoutItemStatus.KEPT },
|
|
31
|
-
{ status: CheckoutItemStatus.REPLACED },
|
|
32
|
-
],
|
|
33
|
-
});
|
|
34
|
-
const mockPricing = pricing();
|
|
35
|
-
|
|
36
|
-
jest.mock("../../../../hooks/useStaticInfo", () => ({
|
|
37
|
-
useStaticInfo: () => ({
|
|
38
|
-
customer: { customerId, country, segment },
|
|
39
|
-
basePath: "",
|
|
40
|
-
}),
|
|
41
|
-
}));
|
|
42
|
-
|
|
43
|
-
jest.mock("../../../../../projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId");
|
|
44
|
-
jest.mock("../../../../../projection/payment/react/useViewPaymentFlowPayloadByCheckoutId");
|
|
45
|
-
jest.mock("../../../../../projection/checkout/react/useViewIsSizeChangeEnabledByCheckoutId");
|
|
46
|
-
jest.mock("../../../../../projection/pricing/react/useViewPricingByCheckoutId");
|
|
47
|
-
jest.mock("../../../../hooks/useSubmitCheckout");
|
|
48
|
-
jest.mock("../../../../../tracking/useTrackCheckout");
|
|
49
|
-
|
|
50
|
-
const mockStartLegacyBoxCheckout = jest.fn();
|
|
51
|
-
jest.mock("@lookiero/payments-front", () => {
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
53
|
-
const { useImperativeHandle, forwardRef } = require("react");
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
CheckoutStatus: {
|
|
57
|
-
REJECTED: "REJECTED",
|
|
58
|
-
ERROR: "ERROR",
|
|
59
|
-
FULFILLED: "FULFILLED",
|
|
60
|
-
},
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
62
|
-
// @ts-ignore
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention, react/display-name
|
|
64
|
-
PaymentFlow: forwardRef((params, ref) => {
|
|
65
|
-
useImperativeHandle(ref, () => ({
|
|
66
|
-
startLegacyBoxCheckout: mockStartLegacyBoxCheckout,
|
|
67
|
-
}));
|
|
68
|
-
|
|
69
|
-
return null;
|
|
70
|
-
}),
|
|
71
|
-
PaymentMethod: {
|
|
72
|
-
["GOOGLE_PAY"]: "google_pay",
|
|
73
|
-
},
|
|
74
|
-
Section: {
|
|
75
|
-
["BOX_CHECKOUT"]: "box-checkout",
|
|
76
|
-
},
|
|
77
|
-
PaymentInstrumentSelect: jest.fn(() => <></>),
|
|
78
|
-
};
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
const mockUseNavigate = jest.fn();
|
|
82
|
-
jest.mock("react-router-native", () => ({
|
|
83
|
-
...jest.requireActual("react-router-native"),
|
|
84
|
-
useNavigate: () => mockUseNavigate,
|
|
85
|
-
}));
|
|
86
|
-
|
|
87
|
-
describe("CheckoutPaymentModal component", () => {
|
|
88
|
-
it("renders correctly", async () => {
|
|
89
|
-
const mockSubmitCheckout = jest.fn();
|
|
90
|
-
(useViewFirstAvailableCheckoutByCustomerId as jest.Mock).mockReturnValue([mockCheckout, QueryStatus.SUCCESS]);
|
|
91
|
-
(useViewPaymentFlowPayloadByCheckoutId as jest.Mock).mockReturnValue([mockPaymentFlowPayload, QueryStatus.SUCCESS]);
|
|
92
|
-
(useViewIsSizeChangeEnabledByCheckoutId as jest.Mock).mockReturnValue([true, QueryStatus.SUCCESS]);
|
|
93
|
-
(useViewPricingByCheckoutId as jest.Mock).mockReturnValue([mockPricing, QueryStatus.SUCCESS]);
|
|
94
|
-
(useSubmitCheckout as jest.Mock).mockReturnValue([mockSubmitCheckout, "success"]);
|
|
95
|
-
|
|
96
|
-
await waitFor(() => {
|
|
97
|
-
render(
|
|
98
|
-
<CheckoutPaymentModal
|
|
99
|
-
coupon={null}
|
|
100
|
-
getAuthToken={getAuthToken}
|
|
101
|
-
isFirstOrder={isFirstOrder}
|
|
102
|
-
orderNumber={orderNumber}
|
|
103
|
-
subscription="b"
|
|
104
|
-
/>,
|
|
105
|
-
);
|
|
106
|
-
expect(mockSubmitCheckout).toHaveBeenCalled();
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it("navigates back to /checkout when checkout-flow fails", async () => {
|
|
111
|
-
(useViewFirstAvailableCheckoutByCustomerId as jest.Mock).mockReturnValue([mockCheckout, QueryStatus.SUCCESS]);
|
|
112
|
-
(useViewPaymentFlowPayloadByCheckoutId as jest.Mock).mockReturnValue([mockPaymentFlowPayload, QueryStatus.SUCCESS]);
|
|
113
|
-
(useViewIsSizeChangeEnabledByCheckoutId as jest.Mock).mockReturnValue([true, QueryStatus.SUCCESS]);
|
|
114
|
-
(useViewPricingByCheckoutId as jest.Mock).mockReturnValue([mockPricing, QueryStatus.SUCCESS]);
|
|
115
|
-
(useSubmitCheckout as jest.Mock).mockImplementation(({ onError }) => {
|
|
116
|
-
const submitCheckout = () => onError();
|
|
117
|
-
|
|
118
|
-
return [submitCheckout, "error"];
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
await waitFor(() => {
|
|
122
|
-
render(
|
|
123
|
-
<CheckoutPaymentModal
|
|
124
|
-
coupon={null}
|
|
125
|
-
getAuthToken={getAuthToken}
|
|
126
|
-
isFirstOrder={isFirstOrder}
|
|
127
|
-
orderNumber={orderNumber}
|
|
128
|
-
subscription="b"
|
|
129
|
-
/>,
|
|
130
|
-
);
|
|
131
|
-
expect(mockUseNavigate).toHaveBeenCalledWith(`/${Routes.CHECKOUT}`, { replace: true });
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
});
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import React, { FC, useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
-
import { useNavigate } from "react-router-native";
|
|
3
|
-
import { QueryStatus } from "@lookiero/messaging-react";
|
|
4
|
-
import { PaymentFlow, PaymentFlowRef } from "@lookiero/payments-front";
|
|
5
|
-
import { useLogger } from "@lookiero/sty-psp-logging";
|
|
6
|
-
import { CheckoutItemStatus } from "../../../../../../domain/checkoutItem/model/checkoutItem";
|
|
7
|
-
import { Currency } from "../../../../../../domain/checkoutItem/model/currency";
|
|
8
|
-
import { Subscription } from "../../../../../../projection/subscription/subscription";
|
|
9
|
-
import { useViewFirstAvailableCheckoutByCustomerId } from "../../../../../projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId";
|
|
10
|
-
import { useViewIsSizeChangeEnabledByCheckoutId } from "../../../../../projection/checkout/react/useViewIsSizeChangeEnabledByCheckoutId";
|
|
11
|
-
import { useViewPaymentFlowPayloadByCheckoutId } from "../../../../../projection/payment/react/useViewPaymentFlowPayloadByCheckoutId";
|
|
12
|
-
import { useViewPricingByCheckoutId } from "../../../../../projection/pricing/react/useViewPricingByCheckoutId";
|
|
13
|
-
import { TrackingPage } from "../../../../../tracking/tracking";
|
|
14
|
-
import { useTrackCheckout } from "../../../../../tracking/useTrackCheckout";
|
|
15
|
-
import { useStaticInfo } from "../../../../hooks/useStaticInfo";
|
|
16
|
-
import { useSubmitCheckout } from "../../../../hooks/useSubmitCheckout";
|
|
17
|
-
import { Routes } from "../../../../routing/routes";
|
|
18
|
-
|
|
19
|
-
interface CheckoutPaymentModalProps {
|
|
20
|
-
readonly coupon: string | null;
|
|
21
|
-
readonly orderNumber: number;
|
|
22
|
-
readonly isFirstOrder: boolean;
|
|
23
|
-
readonly subscription: Subscription;
|
|
24
|
-
readonly getAuthToken: () => Promise<string>;
|
|
25
|
-
readonly onCheckoutSubmitted?: () => void;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const CheckoutPaymentModal: FC<CheckoutPaymentModalProps> = ({
|
|
29
|
-
coupon,
|
|
30
|
-
isFirstOrder,
|
|
31
|
-
subscription,
|
|
32
|
-
orderNumber,
|
|
33
|
-
getAuthToken,
|
|
34
|
-
onCheckoutSubmitted,
|
|
35
|
-
}) => {
|
|
36
|
-
const paymentFlowRef = useRef<PaymentFlowRef>(null);
|
|
37
|
-
const logger = useLogger();
|
|
38
|
-
const {
|
|
39
|
-
customer: { customerId, country, segment },
|
|
40
|
-
basePath,
|
|
41
|
-
} = useStaticInfo();
|
|
42
|
-
|
|
43
|
-
const [checkout, checkoutStatus] = useViewFirstAvailableCheckoutByCustomerId({ customerId });
|
|
44
|
-
const [paymentFlowPayload] = useViewPaymentFlowPayloadByCheckoutId({
|
|
45
|
-
checkoutId: checkout?.id as string,
|
|
46
|
-
});
|
|
47
|
-
const [sizeChangeEnabled] = useViewIsSizeChangeEnabledByCheckoutId({ checkoutId: checkout?.id as string });
|
|
48
|
-
const [pricing] = useViewPricingByCheckoutId({
|
|
49
|
-
checkoutId: checkout?.id as string,
|
|
50
|
-
queryOptions: { refetchOnMount: true },
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const [authToken, setAuthToken] = useState<string>();
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
const loadAuthToken = async () => setAuthToken(await getAuthToken());
|
|
56
|
-
loadAuthToken();
|
|
57
|
-
}, [getAuthToken]);
|
|
58
|
-
|
|
59
|
-
const navigate = useNavigate();
|
|
60
|
-
const trackCheckout = useTrackCheckout({
|
|
61
|
-
page: TrackingPage.CHECKOUT,
|
|
62
|
-
checkoutId: checkout?.id as string,
|
|
63
|
-
country,
|
|
64
|
-
segment,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const handleOnSubmitCheckoutError = useCallback(
|
|
68
|
-
() => navigate(`${basePath}/${Routes.CHECKOUT}`, { replace: true }),
|
|
69
|
-
[basePath, navigate],
|
|
70
|
-
);
|
|
71
|
-
const handleOnSubmitCheckoutSuccess = useCallback(() => {
|
|
72
|
-
const checkoutItemsKept = checkout?.items.filter(
|
|
73
|
-
(checkoutItem) =>
|
|
74
|
-
checkoutItem.status === CheckoutItemStatus.KEPT || checkoutItem.status === CheckoutItemStatus.REPLACED,
|
|
75
|
-
);
|
|
76
|
-
const totalReplacedFor = checkoutItemsKept?.filter(({ replacedFor }) => Boolean(replacedFor)).length || 0;
|
|
77
|
-
|
|
78
|
-
trackCheckout({
|
|
79
|
-
totalCheckoutItemsKept: checkoutItemsKept?.length || 0,
|
|
80
|
-
pendingToPay: (pricing?.pendingToPay.amount as number) / 100,
|
|
81
|
-
coupon,
|
|
82
|
-
currencyCode: pricing?.pendingToPay.currency as Currency,
|
|
83
|
-
isFirstOrder,
|
|
84
|
-
orderNumber,
|
|
85
|
-
totalReplacedFor,
|
|
86
|
-
subscription,
|
|
87
|
-
userId: customerId,
|
|
88
|
-
});
|
|
89
|
-
onCheckoutSubmitted?.();
|
|
90
|
-
}, [
|
|
91
|
-
checkout?.items,
|
|
92
|
-
coupon,
|
|
93
|
-
customerId,
|
|
94
|
-
isFirstOrder,
|
|
95
|
-
onCheckoutSubmitted,
|
|
96
|
-
orderNumber,
|
|
97
|
-
pricing?.pendingToPay.amount,
|
|
98
|
-
pricing?.pendingToPay.currency,
|
|
99
|
-
subscription,
|
|
100
|
-
trackCheckout,
|
|
101
|
-
]);
|
|
102
|
-
const [submitCheckout] = useSubmitCheckout({
|
|
103
|
-
checkoutId: checkout?.id as string,
|
|
104
|
-
checkoutBookingId: checkout?.checkoutBookingId as string,
|
|
105
|
-
paymentFlowRef,
|
|
106
|
-
onError: handleOnSubmitCheckoutError,
|
|
107
|
-
onSuccess: handleOnSubmitCheckoutSuccess,
|
|
108
|
-
logger,
|
|
109
|
-
});
|
|
110
|
-
useEffect(() => {
|
|
111
|
-
if (paymentFlowPayload && sizeChangeEnabled !== undefined && pricing !== undefined) {
|
|
112
|
-
submitCheckout({ paymentFlowPayload, sizeChangeEnabled });
|
|
113
|
-
}
|
|
114
|
-
}, [paymentFlowPayload, pricing, sizeChangeEnabled, submitCheckout]);
|
|
115
|
-
|
|
116
|
-
const dependenciesLoadedStatuses = [QueryStatus.ERROR, QueryStatus.SUCCESS];
|
|
117
|
-
const dependenciesLoaded = (dependenciesLoadedStatuses.includes(checkoutStatus) || checkout) && authToken;
|
|
118
|
-
|
|
119
|
-
if (!dependenciesLoaded) return null;
|
|
120
|
-
|
|
121
|
-
return <PaymentFlow ref={paymentFlowRef} token={authToken} />;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
export { CheckoutPaymentModal };
|