@lookiero/checkout 10.1.0 → 11.0.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.
Files changed (74) hide show
  1. package/cypress/integration/checkout.spec.ts +0 -3
  2. package/dist/fake-dependencies/@lookiero/payments-front/index.d.ts +8 -7
  3. package/dist/fake-dependencies/@lookiero/payments-front/index.js +11 -3
  4. package/dist/index.d.ts +3 -3
  5. package/dist/src/ExpoRoot.js +17 -12
  6. package/dist/src/infrastructure/domain/checkoutBooking/react/useBlockCheckoutBooking.d.ts +1 -1
  7. package/dist/src/infrastructure/domain/checkoutBooking/react/useBlockCheckoutBooking.js +2 -0
  8. package/dist/src/infrastructure/projection/checkout/checkout.mock.d.ts +1 -0
  9. package/dist/src/infrastructure/projection/checkout/checkout.mock.js +3 -3
  10. package/dist/src/infrastructure/projection/pricing/react/useViewPricingByCheckoutId.d.ts +1 -1
  11. package/dist/src/infrastructure/projection/pricing/react/useViewPricingByCheckoutId.js +2 -1
  12. package/dist/src/infrastructure/tracking/tracking.d.ts +2 -2
  13. package/dist/src/infrastructure/tracking/useTrackCheckout.d.ts +10 -17
  14. package/dist/src/infrastructure/tracking/useTrackCheckout.js +27 -12
  15. package/dist/src/infrastructure/ui/Root.d.ts +6 -6
  16. package/dist/src/infrastructure/ui/Root.js +2 -3
  17. package/dist/src/infrastructure/ui/hooks/useCheckoutFlow.d.ts +26 -0
  18. package/dist/src/infrastructure/ui/hooks/useCheckoutFlow.js +127 -0
  19. package/dist/src/infrastructure/ui/hooks/usePaymentInstrumentEvents.d.ts +3 -2
  20. package/dist/src/infrastructure/ui/hooks/usePaymentInstrumentEvents.js +17 -26
  21. package/dist/src/infrastructure/ui/i18n/i18n.d.ts +1 -0
  22. package/dist/src/infrastructure/ui/i18n/i18n.js +1 -0
  23. package/dist/src/infrastructure/ui/routing/CheckoutMiddleware.js +1 -12
  24. package/dist/src/infrastructure/ui/routing/Routing.d.ts +5 -5
  25. package/dist/src/infrastructure/ui/routing/Routing.js +2 -10
  26. package/dist/src/infrastructure/ui/routing/routes.d.ts +0 -1
  27. package/dist/src/infrastructure/ui/routing/routes.js +0 -1
  28. package/dist/src/infrastructure/ui/views/App.js +5 -6
  29. package/dist/src/infrastructure/ui/views/checkout/Checkout.d.ts +7 -2
  30. package/dist/src/infrastructure/ui/views/checkout/Checkout.js +20 -9
  31. package/dist/src/infrastructure/ui/views/checkout/Checkout.style.d.ts +3 -0
  32. package/dist/src/infrastructure/ui/views/checkout/Checkout.style.js +3 -0
  33. package/dist/src/infrastructure/ui/views/checkout/components/paymentInstrument/PaymentInstrument.js +7 -7
  34. package/dist/src/projection/customer/customer.d.ts +2 -0
  35. package/dist/src/projection/order/order.d.ts +1 -1
  36. package/dist/src/projection/subscription/subscription.d.ts +1 -1
  37. package/dist/src/version.d.ts +1 -1
  38. package/dist/src/version.js +1 -1
  39. package/fake-dependencies/@lookiero/payments-front/index.tsx +36 -8
  40. package/index.ts +10 -3
  41. package/package.json +3 -3
  42. package/src/ExpoRoot.tsx +43 -36
  43. package/src/infrastructure/domain/checkoutBooking/react/useBlockCheckoutBooking.ts +4 -1
  44. package/src/infrastructure/projection/checkout/checkout.mock.ts +8 -3
  45. package/src/infrastructure/projection/pricing/react/useViewPricingByCheckoutId.ts +3 -2
  46. package/src/infrastructure/tracking/tracking.ts +2 -2
  47. package/src/infrastructure/tracking/useTrackCheckout.test.tsx +51 -24
  48. package/src/infrastructure/tracking/useTrackCheckout.ts +66 -56
  49. package/src/infrastructure/ui/Root.tsx +9 -9
  50. package/src/infrastructure/ui/components/templates/header/itemHeader/ItemHeader.tsx +1 -0
  51. package/src/infrastructure/ui/hooks/useCheckoutFlow.test.tsx +302 -0
  52. package/src/infrastructure/ui/hooks/useCheckoutFlow.tsx +203 -0
  53. package/src/infrastructure/ui/hooks/usePaymentInstrumentEvents.ts +18 -60
  54. package/src/infrastructure/ui/i18n/i18n.ts +1 -0
  55. package/src/infrastructure/ui/routing/CheckoutMiddleware.test.tsx +0 -11
  56. package/src/infrastructure/ui/routing/CheckoutMiddleware.tsx +1 -15
  57. package/src/infrastructure/ui/routing/Routing.tsx +14 -25
  58. package/src/infrastructure/ui/routing/routes.ts +0 -1
  59. package/src/infrastructure/ui/views/App.tsx +5 -13
  60. package/src/infrastructure/ui/views/checkout/Checkout.style.ts +3 -0
  61. package/src/infrastructure/ui/views/checkout/Checkout.test.tsx +51 -43
  62. package/src/infrastructure/ui/views/checkout/Checkout.tsx +51 -13
  63. package/src/infrastructure/ui/views/checkout/components/paymentInstrument/PaymentInstrument.tsx +8 -8
  64. package/src/projection/customer/customer.ts +2 -0
  65. package/src/projection/order/order.ts +1 -1
  66. package/src/projection/subscription/subscription.ts +1 -1
  67. package/dist/src/infrastructure/ui/hooks/useSubmitCheckout.d.ts +0 -27
  68. package/dist/src/infrastructure/ui/hooks/useSubmitCheckout.js +0 -97
  69. package/dist/src/infrastructure/ui/views/checkout/components/checkoutPaymentModal/CheckoutPaymentModal.d.ts +0 -12
  70. package/dist/src/infrastructure/ui/views/checkout/components/checkoutPaymentModal/CheckoutPaymentModal.js +0 -88
  71. package/src/infrastructure/ui/hooks/useSubmitCheckout.test.ts +0 -297
  72. package/src/infrastructure/ui/hooks/useSubmitCheckout.ts +0 -169
  73. package/src/infrastructure/ui/views/checkout/components/checkoutPaymentModal/CheckoutPaymentModal.test.tsx +0 -134
  74. package/src/infrastructure/ui/views/checkout/components/checkoutPaymentModal/CheckoutPaymentModal.tsx +0 -124
@@ -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 };