@lookiero/checkout 9.8.4 → 9.9.0-beta.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 (129) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/pact.config.d.ts +21 -0
  3. package/dist/pact.config.js +16 -0
  4. package/dist/public/public/assets/adaptive-icon.png +0 -0
  5. package/dist/public/public/assets/favicon.png +0 -0
  6. package/dist/public/public/assets/icon.png +0 -0
  7. package/dist/public/public/assets/splash.png +0 -0
  8. package/dist/public/public/images/not-found.png +0 -0
  9. package/dist/src/ExpoRoot.js +6 -4
  10. package/dist/src/infrastructure/projection/bookedProductsVariants/httpBookedProductsVariantsForCheckoutItemView.pact.d.ts +1 -0
  11. package/dist/src/infrastructure/projection/bookedProductsVariants/httpBookedProductsVariantsForCheckoutItemView.pact.js +55 -0
  12. package/dist/src/infrastructure/projection/checkout/httpCheckoutByIdView.pact.d.ts +1 -0
  13. package/dist/src/infrastructure/projection/checkout/httpCheckoutByIdView.pact.js +116 -0
  14. package/dist/src/infrastructure/projection/checkout/httpFirstAvailableCheckoutByCustomerIdView.pact.d.ts +1 -0
  15. package/dist/src/infrastructure/projection/checkout/httpFirstAvailableCheckoutByCustomerIdView.pact.js +56 -0
  16. package/dist/src/infrastructure/projection/checkout/httpFiveItemsDiscountByCustomerIdView.pact.d.ts +1 -0
  17. package/dist/src/infrastructure/projection/checkout/httpFiveItemsDiscountByCustomerIdView.pact.js +51 -0
  18. package/dist/src/infrastructure/projection/checkout/httpIsCheckoutEnabledByCustomerIdView.pact.d.ts +1 -0
  19. package/dist/src/infrastructure/projection/checkout/httpIsCheckoutEnabledByCustomerIdView.pact.js +51 -0
  20. package/dist/src/infrastructure/projection/checkout/httpIsSizeChangeEnabledByCheckoutIdView.pact.d.ts +1 -0
  21. package/dist/src/infrastructure/projection/checkout/httpIsSizeChangeEnabledByCheckoutIdView.pact.js +51 -0
  22. package/dist/src/infrastructure/projection/checkout/react/useViewIsCheckoutAccessibleByCustomerId.d.ts +13 -0
  23. package/dist/src/infrastructure/projection/checkout/react/useViewIsCheckoutAccessibleByCustomerId.js +19 -0
  24. package/dist/src/infrastructure/projection/checkoutBooking/httpCheckoutBookingByIdView.pact.d.ts +1 -0
  25. package/dist/src/infrastructure/projection/checkoutBooking/httpCheckoutBookingByIdView.pact.js +56 -0
  26. package/dist/src/infrastructure/projection/checkoutItem/httpCheckoutItemByIdView.pact.d.ts +1 -0
  27. package/dist/src/infrastructure/projection/checkoutItem/httpCheckoutItemByIdView.pact.js +57 -0
  28. package/dist/src/infrastructure/projection/checkoutQuestion/httpCheckoutQuestionsByCheckoutIdView.pact.d.ts +1 -0
  29. package/dist/src/infrastructure/projection/checkoutQuestion/httpCheckoutQuestionsByCheckoutIdView.pact.js +55 -0
  30. package/dist/src/infrastructure/projection/payment/httpPaymentFlowPayloadByCheckoutIdView.pact.d.ts +1 -0
  31. package/dist/src/infrastructure/projection/payment/httpPaymentFlowPayloadByCheckoutIdView.pact.js +120 -0
  32. package/dist/src/infrastructure/projection/pricing/httpPricingByCheckoutIdView.pact.d.ts +1 -0
  33. package/dist/src/infrastructure/projection/pricing/httpPricingByCheckoutIdView.pact.js +55 -0
  34. package/dist/src/infrastructure/projection/returnQuestion/httpReturnQuestionsByCheckoutItemIdView.pact.d.ts +1 -0
  35. package/dist/src/infrastructure/projection/returnQuestion/httpReturnQuestionsByCheckoutItemIdView.pact.js +55 -0
  36. package/dist/src/infrastructure/ui/Root.d.ts +0 -2
  37. package/dist/src/infrastructure/ui/Root.js +2 -4
  38. package/dist/src/infrastructure/ui/components/layouts/layout/Layout.d.ts +22 -0
  39. package/dist/src/infrastructure/ui/components/layouts/layout/Layout.js +1 -0
  40. package/dist/src/infrastructure/ui/components/layouts/layout/components/footer/Footer.d.ts +7 -0
  41. package/dist/src/infrastructure/ui/components/layouts/layout/components/footer/Footer.js +5 -0
  42. package/dist/src/infrastructure/ui/components/layouts/layout/components/header/Header.d.ts +7 -0
  43. package/dist/src/infrastructure/ui/components/layouts/layout/components/header/Header.js +6 -0
  44. package/dist/src/infrastructure/ui/components/layouts/layout/components/header/Header.style.d.ts +4 -0
  45. package/dist/src/infrastructure/ui/components/layouts/layout/components/header/Header.style.js +20 -0
  46. package/dist/src/infrastructure/ui/components/layouts/layout/dummyLayout/DummyLayout.d.ts +4 -0
  47. package/dist/src/infrastructure/ui/components/layouts/layout/dummyLayout/DummyLayout.js +43 -0
  48. package/dist/src/infrastructure/ui/components/layouts/layout/dummyLayout/DummyLayout.style.d.ts +12 -0
  49. package/dist/src/infrastructure/ui/components/layouts/layout/dummyLayout/DummyLayout.style.js +14 -0
  50. package/dist/src/infrastructure/ui/components/templates/header/defaultHeader/DefaultHeader.d.ts +7 -0
  51. package/dist/src/infrastructure/ui/components/templates/header/defaultHeader/DefaultHeader.js +21 -0
  52. package/dist/src/infrastructure/ui/components/templates/header/defaultHeader/DefaultHeader.style.d.ts +8 -0
  53. package/dist/src/infrastructure/ui/components/templates/header/defaultHeader/DefaultHeader.style.js +12 -0
  54. package/dist/src/infrastructure/ui/hooks/useNewFeedbackExperiment.d.ts +12 -0
  55. package/dist/src/infrastructure/ui/hooks/useNewFeedbackExperiment.js +64 -0
  56. package/dist/src/infrastructure/ui/hooks/usePaymentInstrumentEvents.d.ts +3 -2
  57. package/dist/src/infrastructure/ui/hooks/usePaymentInstrumentEvents.js +17 -26
  58. package/dist/src/infrastructure/ui/hooks/useSubmitCheckout.d.ts +1 -1
  59. package/dist/src/infrastructure/ui/hooks/useSubmitCheckout.js +22 -55
  60. package/dist/src/infrastructure/ui/i18n/fetchTranslations.d.ts +10 -0
  61. package/dist/src/infrastructure/ui/i18n/fetchTranslations.js +17 -0
  62. package/dist/src/infrastructure/ui/i18n/i18n.d.ts +1 -0
  63. package/dist/src/infrastructure/ui/i18n/i18n.js +1 -0
  64. package/dist/src/infrastructure/ui/i18n/translationEndpoint.d.ts +20 -0
  65. package/dist/src/infrastructure/ui/i18n/translationEndpoint.js +27 -0
  66. package/dist/src/infrastructure/ui/routing/CheckoutAccessibilityMiddleware.d.ts +10 -0
  67. package/dist/src/infrastructure/ui/routing/CheckoutAccessibilityMiddleware.js +27 -0
  68. package/dist/src/infrastructure/ui/views/App.style.d.ts +6 -0
  69. package/dist/src/infrastructure/ui/views/App.style.js +8 -0
  70. package/dist/src/infrastructure/ui/views/checkout/components/checkoutPaymentModal/CheckoutPaymentModal.js +2 -2
  71. package/dist/src/infrastructure/ui/views/checkout/components/paymentInstrument/PaymentInstrument.js +7 -7
  72. package/dist/src/infrastructure/ui/views/feedback/components/checkoutQuestionsForm/CheckoutQuestionsForm.style.d.ts +7 -0
  73. package/dist/src/infrastructure/ui/views/feedback/components/checkoutQuestionsForm/CheckoutQuestionsForm.style.js +11 -0
  74. package/dist/src/infrastructure/ui/views/item/components/returnQuestionsForm/ReturnQuestionsForm.d.ts +12 -0
  75. package/dist/src/infrastructure/ui/views/item/components/returnQuestionsForm/ReturnQuestionsForm.js +64 -0
  76. package/dist/src/infrastructure/ui/views/item/components/returnQuestionsForm/ReturnQuestionsForm.style.d.ts +12 -0
  77. package/dist/src/infrastructure/ui/views/item/components/returnQuestionsForm/ReturnQuestionsForm.style.js +16 -0
  78. package/dist/src/infrastructure/ui/views/return/Return.style.d.ts +40 -0
  79. package/dist/src/infrastructure/ui/views/return/Return.style.js +44 -0
  80. package/dist/src/infrastructure/ui/views/summary/components/stickyPricing/StickyPricing.d.ts +14 -0
  81. package/dist/src/infrastructure/ui/views/summary/components/stickyPricing/StickyPricing.js +28 -0
  82. package/dist/src/infrastructure/ui/views/summary/components/stickyPricing/StickyPricing.style.d.ts +7 -0
  83. package/dist/src/infrastructure/ui/views/summary/components/stickyPricing/StickyPricing.style.js +11 -0
  84. package/dist/src/projection/checkout/viewIsCheckoutAccessibleByCustomerId.d.ts +26 -0
  85. package/dist/src/projection/checkout/viewIsCheckoutAccessibleByCustomerId.js +21 -0
  86. package/dist/src/projection/customer/customer.d.ts +2 -0
  87. package/dist/src/projection/shared/country.d.ts +14 -0
  88. package/dist/src/projection/shared/country.js +15 -0
  89. package/dist/src/projection/shared/customer.d.ts +9 -0
  90. package/dist/src/projection/shared/customer.js +1 -0
  91. package/dist/src/projection/shared/locale.d.ts +12 -0
  92. package/dist/src/projection/shared/locale.js +13 -0
  93. package/dist/src/projection/shared/order.d.ts +6 -0
  94. package/dist/src/projection/shared/order.js +1 -0
  95. package/dist/src/projection/shared/price.d.ts +11 -0
  96. package/dist/src/projection/shared/price.js +1 -0
  97. package/dist/src/projection/shared/size.d.ts +21 -0
  98. package/dist/src/projection/shared/size.js +4 -0
  99. package/dist/src/projection/shared/subscription.d.ts +2 -0
  100. package/dist/src/projection/shared/subscription.js +1 -0
  101. package/dist/src/shared/ui/components/atoms/aspectRatioView/AspectRatioView.d.ts +15 -0
  102. package/dist/src/shared/ui/components/atoms/aspectRatioView/AspectRatioView.js +16 -0
  103. package/dist/src/shared/ui/components/atoms/error/Error.d.ts +11 -0
  104. package/dist/src/shared/ui/components/atoms/error/Error.js +6 -0
  105. package/dist/src/shared/ui/components/atoms/field/Field.d.ts +14 -0
  106. package/dist/src/shared/ui/components/atoms/field/Field.js +29 -0
  107. package/dist/src/shared/ui/components/atoms/field/Field.style.d.ts +16 -0
  108. package/dist/src/shared/ui/components/atoms/field/Field.style.js +19 -0
  109. package/dist/src/shared/ui/components/molecules/inputField/InputField.d.ts +24 -0
  110. package/dist/src/shared/ui/components/molecules/inputField/InputField.js +28 -0
  111. package/dist/src/shared/ui/components/molecules/inputField/InputField.style.d.ts +29 -0
  112. package/dist/src/shared/ui/components/molecules/inputField/InputField.style.js +37 -0
  113. package/dist/src/version.d.ts +1 -1
  114. package/dist/src/version.js +1 -1
  115. package/index.ts +1 -1
  116. package/package.json +3 -3
  117. package/src/ExpoRoot.tsx +6 -4
  118. package/src/infrastructure/ui/Root.tsx +17 -30
  119. package/src/infrastructure/ui/hooks/usePaymentInstrumentEvents.ts +18 -60
  120. package/src/infrastructure/ui/hooks/useSubmitCheckout.test.ts +0 -58
  121. package/src/infrastructure/ui/hooks/useSubmitCheckout.ts +33 -77
  122. package/src/infrastructure/ui/i18n/i18n.ts +1 -0
  123. package/src/infrastructure/ui/views/checkout/components/checkoutPaymentModal/CheckoutPaymentModal.tsx +2 -2
  124. package/src/infrastructure/ui/views/checkout/components/paymentInstrument/PaymentInstrument.tsx +8 -8
  125. package/src/projection/customer/customer.ts +2 -0
  126. package/dist/src/infrastructure/ui/hooks/useQueryBus.d.ts +0 -9
  127. package/dist/src/infrastructure/ui/hooks/useQueryBus.js +0 -10
  128. package/src/infrastructure/ui/hooks/useQueryBus.test.tsx +0 -23
  129. package/src/infrastructure/ui/hooks/useQueryBus.tsx +0 -27
@@ -1,75 +1,33 @@
1
- import { useCallback, useEffect } from "react";
2
- import { useEvent } from "@lookiero/event";
3
- import { Logger } from "@lookiero/sty-psp-logging";
4
- import { NotificationLevel, useCreateToastNotification } from "@lookiero/sty-psp-notifications";
5
- import { MESSAGING_CONTEXT_ID } from "../../delivery/baseBootstrap";
6
- import { I18nMessages } from "../i18n/i18n";
7
-
8
- const PAYMENT_ERROR = "ERROR";
9
- const PAYMENT_SUCCESS = "PAYMENT_INSTRUMENT_UPDATED";
10
-
11
- interface Message {
12
- readonly id: string;
13
- }
14
- interface OnSuccessFunctionArgs {
15
- readonly message: Message;
16
- }
17
- interface OnSuccessFunction {
18
- (args: OnSuccessFunctionArgs): void;
19
- }
20
-
21
- interface Toaster {
22
- readonly id: string;
23
- }
24
- interface Error {
25
- readonly toaster?: Toaster;
26
- }
27
- interface OnErrorFunctionArgs {
28
- readonly error: Error;
29
- }
30
- interface OnErrorFunction {
31
- (args: OnErrorFunctionArgs): void;
32
- }
1
+ import { useEffect } from "react";
2
+ import { PaymentPayload, Section, usePaymentStatusManager } from "@lookiero/payments-front";
33
3
 
34
4
  interface UsePaymentInstrumentEventsFunctionArgs {
35
- readonly logger: Logger;
5
+ readonly onSuccess: (payload: PaymentPayload) => void;
6
+ readonly onError: (payload: PaymentPayload) => void;
36
7
  }
37
8
 
38
9
  interface UsePaymentInstrumentEventsFunction {
39
10
  (args: UsePaymentInstrumentEventsFunctionArgs): void;
40
11
  }
41
12
 
42
- const usePaymentInstrumentEvents: UsePaymentInstrumentEventsFunction = ({ logger }) => {
43
- const { subscribe, unsubscribe } = useEvent();
13
+ const usePaymentInstrumentEvents: UsePaymentInstrumentEventsFunction = ({ onSuccess, onError }) => {
14
+ const refreshStatus = usePaymentStatusManager(Section.BOX_CHECKOUT);
44
15
 
45
- const [createNotification] = useCreateToastNotification({ contextId: MESSAGING_CONTEXT_ID, logger });
16
+ useEffect(() => {
17
+ const { isLoading, consumePayload } = refreshStatus;
46
18
 
47
- const onSuccess: OnSuccessFunction = useCallback(
48
- ({ message }) => createNotification({ bodyI18nKey: message.id, level: NotificationLevel.SUCCESS }),
49
- [createNotification],
50
- );
19
+ if (isLoading) {
20
+ return;
21
+ }
51
22
 
52
- const onError: OnErrorFunction = useCallback(
53
- ({ error }) => {
54
- if (error.toaster) {
55
- createNotification({
56
- bodyI18nKey: error.toaster.id || I18nMessages.CHECKOUT_TOAST_PAYMENT_ERROR,
57
- level: NotificationLevel.ERROR,
58
- });
23
+ consumePayload((payload) => {
24
+ if (payload.success) {
25
+ onSuccess(payload);
26
+ } else {
27
+ onError(payload);
59
28
  }
60
- },
61
- [createNotification],
62
- );
63
-
64
- useEffect(() => {
65
- subscribe({ event: PAYMENT_ERROR }, onError);
66
- subscribe({ event: PAYMENT_SUCCESS }, onSuccess);
67
-
68
- return () => {
69
- unsubscribe({ event: PAYMENT_ERROR }, onError);
70
- unsubscribe({ event: PAYMENT_SUCCESS }, onSuccess);
71
- };
72
- }, [subscribe, unsubscribe, createNotification, onError, onSuccess]);
29
+ });
30
+ }, [onError, onSuccess, refreshStatus]);
73
31
  };
74
32
 
75
33
  export { usePaymentInstrumentEvents };
@@ -6,11 +6,9 @@ import { PaymentFlowRef } from "@lookiero/payments-front";
6
6
  import { ChargeStatus } from "@lookiero/payments-front/build/infrastructure/CheckoutAPI";
7
7
  import { Logger } from "@lookiero/sty-psp-logging";
8
8
  import { NotificationLevel, useCreateToastNotification } from "@lookiero/sty-psp-notifications";
9
- import { CheckoutBookingProjection } from "../../../projection/checkoutBooking/checkoutBooking";
10
9
  import { useSubmitCheckout } from "../../domain/checkout/react/useSubmitCheckout";
11
10
  import { useBlockCheckoutBooking } from "../../domain/checkoutBooking/react/useBlockCheckoutBooking";
12
11
  import { paymentFlowPayload as mockPaymentFlowPayload } from "../../projection/payment/paymentFlowPayload.mock";
13
- import { useQueryBus } from "./useQueryBus";
14
12
  import { useSubmitCheckout as sut } from "./useSubmitCheckout";
15
13
 
16
14
  const checkoutId = "9c450400-0cd7-44a4-b0e3-e0002a9bf8df";
@@ -20,7 +18,6 @@ const errorChargeStatuses = Object.values(ChargeStatus).filter((status) => statu
20
18
  const logger = mock<Logger>();
21
19
 
22
20
  jest.mock("@lookiero/sty-psp-notifications");
23
- jest.mock("./useQueryBus");
24
21
  jest.mock("../../domain/checkout/react/useSubmitCheckout");
25
22
  jest.mock("../../domain/checkoutBooking/react/useBlockCheckoutBooking");
26
23
 
@@ -41,7 +38,6 @@ describe("useSubmitCheckout custom hook", () => {
41
38
  },
42
39
  };
43
40
 
44
- (useQueryBus as jest.Mock).mockReturnValue(() => ({ isExpired: false }) as CheckoutBookingProjection);
45
41
  (useBlockCheckoutBooking as jest.Mock).mockReturnValue([mockBlockCheckoutBooking, CommandStatus.SUCCESS]);
46
42
  (useCreateToastNotification as jest.Mock).mockReturnValue([mockCreateToastNotification, CommandStatus.SUCCESS]);
47
43
  (useSubmitCheckout as jest.Mock).mockReturnValue([mockSubmitCheckout, CommandStatus.SUCCESS]);
@@ -90,7 +86,6 @@ describe("useSubmitCheckout custom hook", () => {
90
86
  },
91
87
  };
92
88
 
93
- (useQueryBus as jest.Mock).mockReturnValue(() => ({ isExpired: false }) as CheckoutBookingProjection);
94
89
  (useBlockCheckoutBooking as jest.Mock).mockReturnValue([mockBlockCheckoutBooking, CommandStatus.SUCCESS]);
95
90
  (useCreateToastNotification as jest.Mock).mockReturnValue([mockCreateToastNotification, CommandStatus.SUCCESS]);
96
91
  (useSubmitCheckout as jest.Mock).mockReturnValue([mockSubmitCheckout, CommandStatus.SUCCESS]);
@@ -131,7 +126,6 @@ describe("useSubmitCheckout custom hook", () => {
131
126
  },
132
127
  };
133
128
 
134
- (useQueryBus as jest.Mock).mockReturnValue(() => ({ isExpired: false }) as CheckoutBookingProjection);
135
129
  (useBlockCheckoutBooking as jest.Mock).mockReturnValue([mockBlockCheckoutBooking, CommandStatus.ERROR]);
136
130
  (useCreateToastNotification as jest.Mock).mockReturnValue([mockCreateToastNotification, CommandStatus.IDLE]);
137
131
  (useSubmitCheckout as jest.Mock).mockReturnValue([mockSubmitCheckout, CommandStatus.IDLE]);
@@ -172,7 +166,6 @@ describe("useSubmitCheckout custom hook", () => {
172
166
  },
173
167
  };
174
168
 
175
- (useQueryBus as jest.Mock).mockReturnValue(() => ({ isExpired: false }) as CheckoutBookingProjection);
176
169
  (useBlockCheckoutBooking as jest.Mock).mockReturnValue([mockBlockCheckoutBooking, CommandStatus.SUCCESS]);
177
170
  (useCreateToastNotification as jest.Mock).mockReturnValue([mockCreateToastNotification, CommandStatus.SUCCESS]);
178
171
  (useSubmitCheckout as jest.Mock).mockReturnValue([mockSubmitCheckout, CommandStatus.IDLE]);
@@ -219,7 +212,6 @@ describe("useSubmitCheckout custom hook", () => {
219
212
  },
220
213
  };
221
214
 
222
- (useQueryBus as jest.Mock).mockReturnValue(() => ({ isExpired: false }) as CheckoutBookingProjection);
223
215
  (useBlockCheckoutBooking as jest.Mock).mockReturnValue([mockBlockCheckoutBooking, CommandStatus.SUCCESS]);
224
216
  (useSubmitCheckout as jest.Mock).mockReturnValue([mockSubmitCheckout, CommandStatus.ERROR]);
225
217
  (useCreateToastNotification as jest.Mock).mockReturnValue([mockCreateToastNotification, CommandStatus.SUCCESS]);
@@ -244,54 +236,4 @@ describe("useSubmitCheckout custom hook", () => {
244
236
  expect(mockOnError).toHaveBeenCalled();
245
237
  });
246
238
  });
247
-
248
- test("returns submitCheckout error as the status right after calling 'submitCheckout' if CheckoutBooking isExpired", async () => {
249
- const mockBlockCheckoutBooking = jest.fn();
250
- const mockSubmitCheckout = jest.fn();
251
- const mockCreateToastNotification = jest.fn();
252
- const mockOnError = jest.fn();
253
- const mockOnSuccess = jest.fn();
254
- const mockPaymentFlowRef: RefObject<PaymentFlowRef> = {
255
- current: {
256
- // eslint-disable-next-line @typescript-eslint/naming-convention
257
- startLegacyBoxCheckout: jest.fn().mockImplementation((_payload, callback) => {
258
- callback({ status: ChargeStatus.EXECUTED, final: true });
259
- }),
260
- startCheckout: jest.fn(),
261
- },
262
- };
263
-
264
- (useQueryBus as jest.Mock).mockReturnValue(() => ({ isExpired: true }) as CheckoutBookingProjection);
265
- (useBlockCheckoutBooking as jest.Mock).mockReturnValue([mockBlockCheckoutBooking, CommandStatus.SUCCESS]);
266
- (useCreateToastNotification as jest.Mock).mockReturnValue([mockCreateToastNotification, CommandStatus.SUCCESS]);
267
- (useSubmitCheckout as jest.Mock).mockReturnValue([mockSubmitCheckout, CommandStatus.SUCCESS]);
268
-
269
- const { result } = renderHook(() =>
270
- sut({
271
- checkoutId,
272
- checkoutBookingId,
273
- paymentFlowRef: mockPaymentFlowRef,
274
- onError: mockOnError,
275
- onSuccess: mockOnSuccess,
276
- logger,
277
- }),
278
- );
279
-
280
- await act(async () => {
281
- const [submitCheckout] = result.current;
282
- await submitCheckout({ paymentFlowPayload: mockPaymentFlowPayload, sizeChangeEnabled: true });
283
- });
284
-
285
- await waitFor(() => {
286
- const [, status] = result.current;
287
-
288
- expect(mockBlockCheckoutBooking).toHaveBeenCalled();
289
- expect(mockCreateToastNotification).not.toHaveBeenCalled();
290
- expect(mockSubmitCheckout).not.toHaveBeenCalled();
291
-
292
- expect(status).toBe("error");
293
- expect(mockOnSuccess).not.toHaveBeenCalled();
294
- expect(mockOnError).toHaveBeenCalled();
295
- });
296
- });
297
239
  });
@@ -1,39 +1,14 @@
1
1
  import { RefObject, useCallback, useMemo, useState } from "react";
2
2
  import { CommandStatus } from "@lookiero/messaging-react";
3
- import { PaymentFlowRef } from "@lookiero/payments-front";
3
+ import { PaymentFlowRef, PaymentPayload } from "@lookiero/payments-front";
4
4
  import { Logger } from "@lookiero/sty-psp-logging";
5
5
  import { NotificationLevel, useCreateToastNotification } from "@lookiero/sty-psp-notifications";
6
- import {
7
- ViewCheckoutBookingById,
8
- viewCheckoutBookingById,
9
- ViewCheckoutBookingByIdResult,
10
- } from "../../../projection/checkoutBooking/viewCheckoutBookingById";
11
6
  import { PaymentFlowPayloadProjection } from "../../../projection/payment/paymentFlowPayload";
12
7
  import { MESSAGING_CONTEXT_ID } from "../../delivery/baseBootstrap";
13
8
  import { useSubmitCheckout as useSubmitCheckoutCommand } from "../../domain/checkout/react/useSubmitCheckout";
14
9
  import { useBlockCheckoutBooking } from "../../domain/checkoutBooking/react/useBlockCheckoutBooking";
15
10
  import { I18nMessages } from "../i18n/i18n";
16
- import { useQueryBus } from "./useQueryBus";
17
-
18
- enum ChargeStatus {
19
- EXECUTED = "EXECUTED",
20
- REQUIRES_ACTION = "REQUIRES_ACTION",
21
- REQUIRED_ACTION_CANCELLED = "REQUIRED_ACTION_CANCELLED",
22
- REJECTED = "REJECTED",
23
- CANCELLED = "CANCELLED",
24
- TO_CONFIRM = "TO_CONFIRM",
25
- ERROR = "ERROR",
26
- UNKNOWN = "UNKNOWN",
27
- }
28
- interface LegacyBoxCheckout {
29
- readonly status: ChargeStatus;
30
- readonly toaster: {
31
- id: string;
32
- } | null;
33
- readonly final: boolean;
34
- readonly id?: string;
35
- readonly translation?: string;
36
- }
11
+ import { usePaymentInstrumentEvents } from "./usePaymentInstrumentEvents";
37
12
 
38
13
  type Status = "idle" | "loading" | "success" | "error";
39
14
 
@@ -53,7 +28,7 @@ interface UseSubmitCheckoutFunctionArgs {
53
28
  readonly checkoutBookingId: string;
54
29
  readonly paymentFlowRef: RefObject<PaymentFlowRef>;
55
30
  readonly onError: () => void;
56
- readonly onSuccess?: () => void;
31
+ readonly onSuccess: () => void;
57
32
  readonly logger: Logger;
58
33
  }
59
34
 
@@ -69,11 +44,9 @@ const useSubmitCheckout: UseSubmitCheckoutFunction = ({
69
44
  onSuccess,
70
45
  logger,
71
46
  }) => {
72
- const queryBus = useQueryBus();
73
47
  const [submitCheckoutCommand, submitCheckoutCommandStatus] = useSubmitCheckoutCommand({ checkoutId, logger });
74
48
  const [blockCheckoutBooking, blockCheckoutBookingStatus] = useBlockCheckoutBooking({ checkoutBookingId, logger });
75
49
  const [createNotification] = useCreateToastNotification({ contextId: MESSAGING_CONTEXT_ID, logger });
76
- const [checkoutBookingExpired, setCheckoutBookingExpired] = useState(false);
77
50
 
78
51
  const [startLegacyBoxCheckoutStatus, setStartLegacyBoxCheckoutStatus] = useState<Status>("idle");
79
52
 
@@ -85,48 +58,37 @@ const useSubmitCheckout: UseSubmitCheckoutFunction = ({
85
58
  return;
86
59
  }
87
60
 
88
- const checkoutBooking = await queryBus<ViewCheckoutBookingById, ViewCheckoutBookingByIdResult>(
89
- viewCheckoutBookingById({ checkoutBookingId }),
90
- );
61
+ setStartLegacyBoxCheckoutStatus("loading");
91
62
 
92
- if (checkoutBooking?.isExpired) {
93
- setCheckoutBookingExpired(true);
94
- return;
95
- }
63
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
64
+ // @ts-ignore
65
+ paymentFlowRef.current?.startLegacyBoxCheckout(paymentFlowPayload);
66
+ },
67
+ [paymentFlowRef, blockCheckoutBooking],
68
+ );
69
+
70
+ const onPaymentSuccess = useCallback(async () => {
71
+ setStartLegacyBoxCheckoutStatus("success");
72
+
73
+ await submitCheckoutCommand();
74
+
75
+ createNotification({
76
+ bodyI18nKey: I18nMessages.CHECKOUT_TOAST_PAYMENT_SUCCESS,
77
+ level: NotificationLevel.SUCCESS,
78
+ });
79
+ }, [createNotification, submitCheckoutCommand]);
80
+ const onPaymentError = useCallback(
81
+ (payload: PaymentPayload) => {
82
+ setStartLegacyBoxCheckoutStatus("error");
96
83
 
97
- paymentFlowRef.current?.startLegacyBoxCheckout(
98
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
99
- // @ts-ignore
100
- paymentFlowPayload,
101
- async ({ status, toaster, final }: LegacyBoxCheckout) => {
102
- setStartLegacyBoxCheckoutStatus("loading");
103
-
104
- if (final) {
105
- if (status === ChargeStatus.EXECUTED) {
106
- setStartLegacyBoxCheckoutStatus("success");
107
- await submitCheckoutCommand();
108
- onSuccess?.();
109
- } else {
110
- createNotification({
111
- level: NotificationLevel.ERROR,
112
- bodyI18nKey: toaster?.id || I18nMessages.CHECKOUT_TOAST_PAYMENT_ERROR,
113
- });
114
- setStartLegacyBoxCheckoutStatus("error");
115
- }
116
- }
117
- },
118
- );
84
+ createNotification({
85
+ bodyI18nKey: payload.metadata?.toaster?.id || I18nMessages.CHECKOUT_TOAST_PAYMENT_ERROR,
86
+ level: NotificationLevel.ERROR,
87
+ });
119
88
  },
120
- [
121
- queryBus,
122
- checkoutBookingId,
123
- paymentFlowRef,
124
- blockCheckoutBooking,
125
- submitCheckoutCommand,
126
- onSuccess,
127
- createNotification,
128
- ],
89
+ [createNotification],
129
90
  );
91
+ usePaymentInstrumentEvents({ onSuccess: onPaymentSuccess, onError: onPaymentError });
130
92
 
131
93
  const status: Status = useMemo(() => {
132
94
  if (
@@ -141,26 +103,20 @@ const useSubmitCheckout: UseSubmitCheckoutFunction = ({
141
103
  startLegacyBoxCheckoutStatus === "success" &&
142
104
  submitCheckoutCommandStatus === CommandStatus.SUCCESS
143
105
  ) {
106
+ onSuccess();
144
107
  return "success";
145
108
  }
146
109
  if (
147
110
  blockCheckoutBookingStatus === CommandStatus.ERROR ||
148
111
  startLegacyBoxCheckoutStatus === "error" ||
149
- submitCheckoutCommandStatus === CommandStatus.ERROR ||
150
- checkoutBookingExpired
112
+ submitCheckoutCommandStatus === CommandStatus.ERROR
151
113
  ) {
152
114
  onError();
153
115
  return "error";
154
116
  }
155
117
 
156
118
  return "idle";
157
- }, [
158
- blockCheckoutBookingStatus,
159
- startLegacyBoxCheckoutStatus,
160
- submitCheckoutCommandStatus,
161
- checkoutBookingExpired,
162
- onError,
163
- ]);
119
+ }, [blockCheckoutBookingStatus, startLegacyBoxCheckoutStatus, submitCheckoutCommandStatus, onSuccess, onError]);
164
120
 
165
121
  return [submitCheckout, status];
166
122
  };
@@ -48,6 +48,7 @@ enum I18nMessages {
48
48
  CHECKOUT_TITLE = "checkout.title",
49
49
  CHECKOUT_PAY_BUTTON = "checkout.pay_button",
50
50
  CHECKOUT_TOAST_PAYMENT_ERROR = "checkout.toast_payment_error",
51
+ CHECKOUT_TOAST_PAYMENT_SUCCESS = "checkout.toast_payment_success",
51
52
  CHECKOUT_SUCCESS_MODAL_TITLE = "checkout.success_modal_title",
52
53
  CHECKOUT_SUCCESS_MODAL_DESCRIPTION = "checkout.success_modal_description",
53
54
  CHECKOUT_SUCCESS_MODAL_BUTTON = "checkout.success_modal_button",
@@ -1,7 +1,7 @@
1
1
  import React, { FC, useCallback, useEffect, useRef, useState } from "react";
2
2
  import { useNavigate } from "react-router-native";
3
3
  import { QueryStatus } from "@lookiero/messaging-react";
4
- import { PaymentFlow, PaymentFlowRef } from "@lookiero/payments-front";
4
+ import { PaymentFlow, PaymentFlowRef, Section } from "@lookiero/payments-front";
5
5
  import { useLogger } from "@lookiero/sty-psp-logging";
6
6
  import { CheckoutItemStatus } from "../../../../../../domain/checkoutItem/model/checkoutItem";
7
7
  import { Currency } from "../../../../../../domain/checkoutItem/model/currency";
@@ -119,7 +119,7 @@ const CheckoutPaymentModal: FC<CheckoutPaymentModalProps> = ({
119
119
 
120
120
  if (!dependenciesLoaded) return null;
121
121
 
122
- return <PaymentFlow ref={paymentFlowRef} token={authToken} />;
122
+ return <PaymentFlow ref={paymentFlowRef} section={Section.BOX_CHECKOUT} token={authToken} />;
123
123
  };
124
124
 
125
125
  export { CheckoutPaymentModal };
@@ -1,24 +1,24 @@
1
- import React, { FC, useRef } from "react";
1
+ import React, { FC } from "react";
2
2
  import { PaymentInstrumentSelect, Section } from "@lookiero/payments-front";
3
- import { useLogger } from "@lookiero/sty-psp-logging";
4
- import { usePaymentInstrumentEvents } from "../../../../hooks/usePaymentInstrumentEvents";
3
+ import { useStaticInfo } from "../../../../hooks/useStaticInfo";
5
4
 
6
5
  interface PaymentInstrumentProps {
7
6
  readonly useRedirect: () => Record<string, string>;
8
7
  }
9
8
  const PaymentInstrument: FC<PaymentInstrumentProps> = ({ useRedirect }) => {
10
- const paymentInstrumentSelectRef = useRef(null);
11
9
  const { returnUrl } = useRedirect();
12
- const logger = useLogger();
13
-
14
- usePaymentInstrumentEvents({ logger });
10
+ const { customer } = useStaticInfo();
15
11
 
16
12
  return (
17
13
  <PaymentInstrumentSelect
18
- ref={paymentInstrumentSelectRef}
19
14
  beforeRedirect={returnUrl ? () => Promise.resolve(returnUrl) : undefined}
20
15
  hasError={false}
21
16
  section={Section.BOX_CHECKOUT}
17
+ userInformation={{
18
+ email: customer.email,
19
+ name: customer.name,
20
+ }}
21
+ showSingleUsePaymentMethods
22
22
  />
23
23
  );
24
24
  };
@@ -5,6 +5,8 @@ interface Customer {
5
5
  readonly customerId: string;
6
6
  readonly country: Country;
7
7
  readonly segment: Segment;
8
+ readonly name: string;
9
+ readonly email: string;
8
10
  }
9
11
 
10
12
  export type { Customer };
@@ -1,9 +0,0 @@
1
- import { FC, ReactNode } from "react";
2
- import { QueryBus } from "@lookiero/messaging";
3
- interface QueryBusProviderProps {
4
- readonly children: ReactNode;
5
- readonly queryBus: QueryBus;
6
- }
7
- declare const QueryBusProvider: FC<QueryBusProviderProps>;
8
- declare const useQueryBus: () => QueryBus;
9
- export { useQueryBus, QueryBusProvider };
@@ -1,10 +0,0 @@
1
- import React, { createContext, useContext } from "react";
2
- import invariant from "tiny-invariant";
3
- const QueryBusContext = createContext(null);
4
- const QueryBusProvider = ({ children, queryBus }) => (React.createElement(QueryBusContext.Provider, { value: queryBus }, children));
5
- const useQueryBus = () => {
6
- const queryBus = useContext(QueryBusContext);
7
- invariant(queryBus, "Your are trying to use the useQueryBus hook without wrapping your app with the <QueryBusProvider>.");
8
- return queryBus;
9
- };
10
- export { useQueryBus, QueryBusProvider };
@@ -1,23 +0,0 @@
1
- import { renderHook, waitFor } from "@testing-library/react-native";
2
- import { mockFn } from "jest-mock-extended";
3
- import React, { FC } from "react";
4
- import { QueryBus } from "@lookiero/messaging";
5
- import { QueryBusProvider, useQueryBus as sut } from "./useQueryBus";
6
-
7
- const mockQueryBus = mockFn<QueryBus>();
8
-
9
- interface WrapperProps {
10
- readonly children: JSX.Element;
11
- }
12
-
13
- const Wrapper: FC<WrapperProps> = ({ children }) => (
14
- <QueryBusProvider queryBus={mockQueryBus}>{children}</QueryBusProvider>
15
- );
16
-
17
- describe("useQueryBus hook", () => {
18
- it("returns the QueryBusProvider provided queryBus", async () => {
19
- const { result } = renderHook(() => sut(), { wrapper: Wrapper });
20
-
21
- await waitFor(() => expect(result.current).toEqual(mockQueryBus));
22
- });
23
- });
@@ -1,27 +0,0 @@
1
- import React, { createContext, FC, ReactNode, useContext } from "react";
2
- import invariant from "tiny-invariant";
3
- import { QueryBus } from "@lookiero/messaging";
4
-
5
- const QueryBusContext = createContext<QueryBus>(null as unknown as QueryBus);
6
-
7
- interface QueryBusProviderProps {
8
- readonly children: ReactNode;
9
- readonly queryBus: QueryBus;
10
- }
11
-
12
- const QueryBusProvider: FC<QueryBusProviderProps> = ({ children, queryBus }) => (
13
- <QueryBusContext.Provider value={queryBus}>{children}</QueryBusContext.Provider>
14
- );
15
-
16
- const useQueryBus = () => {
17
- const queryBus = useContext(QueryBusContext);
18
-
19
- invariant(
20
- queryBus,
21
- "Your are trying to use the useQueryBus hook without wrapping your app with the <QueryBusProvider>.",
22
- );
23
-
24
- return queryBus;
25
- };
26
-
27
- export { useQueryBus, QueryBusProvider };