@lookiero/checkout 12.5.2 → 12.6.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 -2
- package/dist/src/domain/checkoutBooking/model/checkoutBooking.d.ts +1 -3
- package/dist/src/domain/checkoutBooking/model/checkoutBooking.js +1 -16
- package/dist/src/infrastructure/delivery/baseBootstrap.js +1 -3
- package/dist/src/infrastructure/domain/checkoutBooking/model/httpCheckoutBookings.js +1 -5
- package/dist/src/infrastructure/ui/hooks/useCheckoutFlow.js +5 -32
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
- package/src/domain/checkoutBooking/model/checkoutBooking.test.ts +1 -41
- package/src/domain/checkoutBooking/model/checkoutBooking.ts +1 -22
- package/src/infrastructure/delivery/baseBootstrap.ts +0 -7
- package/src/infrastructure/domain/checkoutBooking/model/httpCheckoutBookings.test.ts +1 -6
- package/src/infrastructure/domain/checkoutBooking/model/httpCheckoutBookings.ts +1 -5
- package/src/infrastructure/ui/hooks/useCheckoutFlow.test.tsx +0 -111
- package/src/infrastructure/ui/hooks/useCheckoutFlow.tsx +4 -35
- package/cypress/support/interceptBlockCheckoutBooking.ts +0 -4
- package/dist/src/domain/checkoutBooking/command/blockCheckoutBooking.d.ts +0 -13
- package/dist/src/domain/checkoutBooking/command/blockCheckoutBooking.js +0 -4
- package/dist/src/domain/checkoutBooking/model/checkoutBookingBlocked.d.ts +0 -13
- package/dist/src/domain/checkoutBooking/model/checkoutBookingBlocked.js +0 -4
- package/dist/src/infrastructure/domain/checkoutBooking/model/httpCheckoutBookingsBlock.d.ts +0 -5
- package/dist/src/infrastructure/domain/checkoutBooking/model/httpCheckoutBookingsBlock.js +0 -15
- package/dist/src/infrastructure/domain/checkoutBooking/react/useBlockCheckoutBooking.d.ts +0 -15
- package/dist/src/infrastructure/domain/checkoutBooking/react/useBlockCheckoutBooking.js +0 -29
- package/src/domain/checkoutBooking/command/blockCheckoutBooking.test.ts +0 -12
- package/src/domain/checkoutBooking/command/blockCheckoutBooking.ts +0 -19
- package/src/domain/checkoutBooking/model/checkoutBookingBlocked.test.ts +0 -12
- package/src/domain/checkoutBooking/model/checkoutBookingBlocked.ts +0 -19
- package/src/infrastructure/domain/checkoutBooking/model/httpCheckoutBookingsBlock.test.ts +0 -41
- package/src/infrastructure/domain/checkoutBooking/model/httpCheckoutBookingsBlock.ts +0 -30
- package/src/infrastructure/domain/checkoutBooking/react/useBlockCheckoutBooking.test.ts +0 -83
- package/src/infrastructure/domain/checkoutBooking/react/useBlockCheckoutBooking.ts +0 -52
|
@@ -10,7 +10,6 @@ import { returnQuestions } from "../../src/infrastructure/projection/returnQuest
|
|
|
10
10
|
import { Routes } from "../../src/infrastructure/ui/routing/routes";
|
|
11
11
|
import { CheckoutFeedbackQuestionType } from "../../src/projection/checkoutFeedback/checkoutFeedback.constants";
|
|
12
12
|
import { checkoutFeedbackQuestionHasChildren } from "../../src/projection/checkoutFeedback/checkoutFeedback.typeguards";
|
|
13
|
-
import { interceptBlockCheckoutBooking } from "../support/interceptBlockCheckoutBooking";
|
|
14
13
|
import { interceptGiveCheckoutFeedback } from "../support/interceptGiveCheckoutFeedback";
|
|
15
14
|
import { interceptKeepCheckoutItem } from "../support/interceptKeepCheckoutItem";
|
|
16
15
|
import { interceptListReturnQuestionsByCheckoutItemId } from "../support/interceptListReturnQuestionsByCheckoutItemId";
|
|
@@ -135,7 +134,6 @@ describe("Checkout", () => {
|
|
|
135
134
|
interceptKeepCheckoutItem();
|
|
136
135
|
interceptReplaceCheckoutItem();
|
|
137
136
|
interceptReturnCheckoutItem();
|
|
138
|
-
interceptBlockCheckoutBooking();
|
|
139
137
|
interceptPayment();
|
|
140
138
|
interceptSubmitCheckout().as("submitCheckout");
|
|
141
139
|
interceptGiveCheckoutFeedback().as("giveCheckoutFeedback");
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { AggregateRoot, CommandHandlerFunction } from "@lookiero/messaging";
|
|
2
|
-
import { BlockCheckoutBooking } from "../command/blockCheckoutBooking";
|
|
3
2
|
import { BookCheckoutBookingForCheckoutItem } from "../command/bookCheckoutBookingForCheckoutItem";
|
|
4
3
|
interface CheckoutBooking extends AggregateRoot {
|
|
5
4
|
readonly checkoutItemIds: string[];
|
|
6
5
|
readonly isExpired: boolean;
|
|
7
6
|
}
|
|
8
7
|
declare const bookCheckoutBookingForCheckoutItemHandler: CommandHandlerFunction<BookCheckoutBookingForCheckoutItem, CheckoutBooking>;
|
|
9
|
-
declare const blockCheckoutBookingHandler: CommandHandlerFunction<BlockCheckoutBooking, CheckoutBooking>;
|
|
10
8
|
export type { CheckoutBooking };
|
|
11
|
-
export { bookCheckoutBookingForCheckoutItemHandler
|
|
9
|
+
export { bookCheckoutBookingForCheckoutItemHandler };
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { checkoutBookingBlocked } from "./checkoutBookingBlocked";
|
|
2
1
|
import { checkoutBookingBooked } from "./checkoutBookingBooked";
|
|
3
|
-
import { checkoutBookingExpired } from "./checkoutBookingExpired";
|
|
4
2
|
const bookCheckoutBookingForCheckoutItemHandler = () => async ({ aggregateRoot, command }) => {
|
|
5
3
|
const { aggregateId, checkoutItemId } = command;
|
|
6
4
|
return {
|
|
@@ -8,17 +6,4 @@ const bookCheckoutBookingForCheckoutItemHandler = () => async ({ aggregateRoot,
|
|
|
8
6
|
domainEvents: [checkoutBookingBooked({ aggregateId, checkoutItemId })],
|
|
9
7
|
};
|
|
10
8
|
};
|
|
11
|
-
|
|
12
|
-
const { aggregateId } = command;
|
|
13
|
-
if (aggregateRoot.isExpired) {
|
|
14
|
-
return {
|
|
15
|
-
...aggregateRoot,
|
|
16
|
-
domainEvents: [checkoutBookingExpired({ aggregateId })],
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
return {
|
|
20
|
-
...aggregateRoot,
|
|
21
|
-
domainEvents: [checkoutBookingBlocked({ aggregateId })],
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
export { bookCheckoutBookingForCheckoutItemHandler, blockCheckoutBookingHandler };
|
|
9
|
+
export { bookCheckoutBookingForCheckoutItemHandler };
|
|
@@ -6,10 +6,9 @@ import { SUBMIT_CHECKOUT } from "../../domain/checkout/command/submitCheckout";
|
|
|
6
6
|
import { createModalNotificationWhenCheckoutSubmitted } from "../../domain/checkout/event/createModalNotificationWhenCheckoutSubmitted";
|
|
7
7
|
import { submitCheckoutHandler, startCheckoutHandler } from "../../domain/checkout/model/checkout";
|
|
8
8
|
import { CHECKOUT_SUBMITTED } from "../../domain/checkout/model/checkoutSubmitted";
|
|
9
|
-
import { BLOCK_CHECKOUT_BOOKING } from "../../domain/checkoutBooking/command/blockCheckoutBooking";
|
|
10
9
|
import { BOOK_CHECKOUT_BOOKING_FOR_CHECKOUT_ITEM } from "../../domain/checkoutBooking/command/bookCheckoutBookingForCheckoutItem";
|
|
11
10
|
import { createToastNotificationWhenCheckoutBookingExpired } from "../../domain/checkoutBooking/event/createToastNotificationWhenCheckoutBookingExpired";
|
|
12
|
-
import {
|
|
11
|
+
import { bookCheckoutBookingForCheckoutItemHandler, } from "../../domain/checkoutBooking/model/checkoutBooking";
|
|
13
12
|
import { CHECKOUT_BOOKING_EXPIRED } from "../../domain/checkoutBooking/model/checkoutBookingExpired";
|
|
14
13
|
import { GIVE_CHECKOUT_FEEDBACK } from "../../domain/checkoutFeedback/command/giveCheckoutFeedback";
|
|
15
14
|
import { giveCheckoutFeedbackHandler } from "../../domain/checkoutFeedback/model/checkoutFeedback";
|
|
@@ -78,7 +77,6 @@ const baseBootstrap = ({ checkoutByIdView, firstAvailableCheckoutByCustomerIdVie
|
|
|
78
77
|
view: bookedProductsVariantsForCheckoutItemView,
|
|
79
78
|
})
|
|
80
79
|
.command(BOOK_CHECKOUT_BOOKING_FOR_CHECKOUT_ITEM, bookCheckoutBookingForCheckoutItemHandler)(getCheckoutBooking, saveCheckoutBooking, ...checkoutBookingsDependencies)
|
|
81
|
-
.command(BLOCK_CHECKOUT_BOOKING, blockCheckoutBookingHandler)(getCheckoutBooking, saveCheckoutBooking, ...checkoutBookingsDependencies)
|
|
82
80
|
.command(GIVE_CHECKOUT_FEEDBACK, giveCheckoutFeedbackHandler)(getCheckoutFeedback, saveCheckoutFeedback, ...checkoutFeedbacksDependencies)
|
|
83
81
|
.processManager(CHECKOUT_BOOKING_EXPIRED, createToastNotificationWhenCheckoutBookingExpired)
|
|
84
82
|
.processManager(CHECKOUT_ITEM_REPLACED, createModalNotificationWhenCheckoutItemReplaced)
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import invariant from "tiny-invariant";
|
|
2
2
|
import { viewCheckoutBookingById, } from "../../../../projection/checkoutBooking/viewCheckoutBookingById";
|
|
3
|
-
import { httpCheckoutBookingsBlock } from "./httpCheckoutBookingsBlock";
|
|
4
3
|
import { httpCheckoutBookingsBook } from "./httpCheckoutBookingsBook";
|
|
5
4
|
const toDomain = (checkoutBooking) => {
|
|
6
5
|
invariant(checkoutBooking, "No checkout booking found!");
|
|
@@ -13,9 +12,6 @@ const toDomain = (checkoutBooking) => {
|
|
|
13
12
|
};
|
|
14
13
|
const getCheckoutBooking = ({ queryBus }) => async (aggregateId) => toDomain(await queryBus(viewCheckoutBookingById({ checkoutBookingId: aggregateId })));
|
|
15
14
|
const saveCheckoutBooking = ({ httpPost }) => async (aggregateRoot) => {
|
|
16
|
-
await
|
|
17
|
-
httpCheckoutBookingsBook({ httpPost })(aggregateRoot),
|
|
18
|
-
httpCheckoutBookingsBlock({ httpPost })(aggregateRoot),
|
|
19
|
-
]);
|
|
15
|
+
await httpCheckoutBookingsBook({ httpPost })(aggregateRoot);
|
|
20
16
|
};
|
|
21
17
|
export { getCheckoutBooking, saveCheckoutBooking };
|
|
@@ -6,8 +6,6 @@ import { NotificationLevel, useCreateToastNotification } from "@lookiero/sty-psp
|
|
|
6
6
|
import { viewCheckoutBookingById, } from "../../../projection/checkoutBooking/viewCheckoutBookingById";
|
|
7
7
|
import { MESSAGING_CONTEXT_ID } from "../../delivery/baseBootstrap";
|
|
8
8
|
import { useSubmitCheckout } from "../../domain/checkout/react/useSubmitCheckout";
|
|
9
|
-
import { useBlockCheckoutBooking } from "../../domain/checkoutBooking/react/useBlockCheckoutBooking";
|
|
10
|
-
import { useViewIsSizeChangeEnabledByCheckoutId } from "../../projection/checkout/react/useViewIsSizeChangeEnabledByCheckoutId";
|
|
11
9
|
import { useViewPaymentFlowPayloadByCheckoutId } from "../../projection/payment/react/useViewPaymentFlowPayloadByCheckoutId";
|
|
12
10
|
import { useViewPricingByCheckoutId } from "../../projection/pricing/react/useViewPricingByCheckoutId";
|
|
13
11
|
import { useTrackCheckout } from "../../tracking/useTrackCheckout";
|
|
@@ -24,7 +22,6 @@ const useCheckoutFlow = ({ checkout: checkoutProjection, order: orderProjection,
|
|
|
24
22
|
const [paymentFlowPayload] = useViewPaymentFlowPayloadByCheckoutId({
|
|
25
23
|
checkoutId: checkoutProjection?.id,
|
|
26
24
|
});
|
|
27
|
-
const [sizeChangeEnabled] = useViewIsSizeChangeEnabledByCheckoutId({ checkoutId: checkoutProjection?.id });
|
|
28
25
|
const [pricing] = useViewPricingByCheckoutId({
|
|
29
26
|
checkoutId: checkoutProjection?.id,
|
|
30
27
|
queryOptions: { refetchOnMount: true },
|
|
@@ -33,10 +30,6 @@ const useCheckoutFlow = ({ checkout: checkoutProjection, order: orderProjection,
|
|
|
33
30
|
checkoutId: checkoutProjection?.id,
|
|
34
31
|
logger,
|
|
35
32
|
});
|
|
36
|
-
const [blockCheckoutBooking, blockCheckoutBookingStatus] = useBlockCheckoutBooking({
|
|
37
|
-
checkoutBookingId: checkoutProjection?.checkoutBookingId,
|
|
38
|
-
logger,
|
|
39
|
-
});
|
|
40
33
|
const [createNotification] = useCreateToastNotification({ contextId: MESSAGING_CONTEXT_ID, logger });
|
|
41
34
|
const [checkoutBookingExpired, setCheckoutBookingExpired] = useState(false);
|
|
42
35
|
const [startLegacyBoxCheckoutStatus, setStartLegacyBoxCheckoutStatus] = useState("idle");
|
|
@@ -56,12 +49,6 @@ const useCheckoutFlow = ({ checkout: checkoutProjection, order: orderProjection,
|
|
|
56
49
|
tradename,
|
|
57
50
|
});
|
|
58
51
|
const checkoutFlow = useCallback(async () => {
|
|
59
|
-
try {
|
|
60
|
-
sizeChangeEnabled && (await blockCheckoutBooking());
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
52
|
if (checkoutProjection?.checkoutBookingId) {
|
|
66
53
|
const checkoutBooking = await queryBus(viewCheckoutBookingById({ checkoutBookingId: checkoutProjection?.checkoutBookingId }));
|
|
67
54
|
if (checkoutBooking?.isExpired) {
|
|
@@ -75,16 +62,7 @@ const useCheckoutFlow = ({ checkout: checkoutProjection, order: orderProjection,
|
|
|
75
62
|
userInformation: { email, name },
|
|
76
63
|
returnUrl: `${basePath}/${Routes.CHECKOUT}`,
|
|
77
64
|
});
|
|
78
|
-
}, [
|
|
79
|
-
checkoutProjection?.checkoutBookingId,
|
|
80
|
-
paymentFlowPayload,
|
|
81
|
-
email,
|
|
82
|
-
name,
|
|
83
|
-
basePath,
|
|
84
|
-
sizeChangeEnabled,
|
|
85
|
-
blockCheckoutBooking,
|
|
86
|
-
queryBus,
|
|
87
|
-
]);
|
|
65
|
+
}, [checkoutProjection?.checkoutBookingId, paymentFlowPayload, email, name, basePath, queryBus]);
|
|
88
66
|
const onPaymentSuccess = useCallback(async () => {
|
|
89
67
|
setStartLegacyBoxCheckoutStatus("success");
|
|
90
68
|
await submitCheckout();
|
|
@@ -104,24 +82,19 @@ const useCheckoutFlow = ({ checkout: checkoutProjection, order: orderProjection,
|
|
|
104
82
|
}, [createNotification]);
|
|
105
83
|
usePaymentInstrumentEvents({ onSuccess: onPaymentSuccess, onError: onPaymentError });
|
|
106
84
|
const checkoutFlowStatus = useMemo(() => {
|
|
107
|
-
if (
|
|
108
|
-
startLegacyBoxCheckoutStatus === "loading" ||
|
|
109
|
-
submitCheckoutStatus === CommandStatus.LOADING) {
|
|
85
|
+
if (startLegacyBoxCheckoutStatus === "loading" || submitCheckoutStatus === CommandStatus.LOADING) {
|
|
110
86
|
return "loading";
|
|
111
87
|
}
|
|
112
|
-
if (
|
|
113
|
-
startLegacyBoxCheckoutStatus === "success" &&
|
|
114
|
-
submitCheckoutStatus === CommandStatus.SUCCESS) {
|
|
88
|
+
if (startLegacyBoxCheckoutStatus === "success" && submitCheckoutStatus === CommandStatus.SUCCESS) {
|
|
115
89
|
return "success";
|
|
116
90
|
}
|
|
117
|
-
if (
|
|
118
|
-
startLegacyBoxCheckoutStatus === "error" ||
|
|
91
|
+
if (startLegacyBoxCheckoutStatus === "error" ||
|
|
119
92
|
submitCheckoutStatus === CommandStatus.ERROR ||
|
|
120
93
|
checkoutBookingExpired) {
|
|
121
94
|
return "error";
|
|
122
95
|
}
|
|
123
96
|
return "idle";
|
|
124
|
-
}, [
|
|
97
|
+
}, [startLegacyBoxCheckoutStatus, submitCheckoutStatus, checkoutBookingExpired]);
|
|
125
98
|
const paymentFlow = useMemo(() => (authToken ? React.createElement(PaymentFlow, { ref: paymentFlowRef, section: Section.BOX_CHECKOUT, token: authToken }) : null), [authToken]);
|
|
126
99
|
return useMemo(() => [checkoutFlow, checkoutFlowStatus, paymentFlow], [checkoutFlow, paymentFlow, checkoutFlowStatus]);
|
|
127
100
|
};
|
package/dist/src/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "12.
|
|
1
|
+
export declare const VERSION = "12.6.0";
|
package/dist/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "12.
|
|
1
|
+
export const VERSION = "12.6.0";
|
package/package.json
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import { mock } from "jest-mock-extended";
|
|
2
2
|
import { QueryBus } from "@lookiero/messaging";
|
|
3
|
-
import { blockCheckoutBooking } from "../command/blockCheckoutBooking";
|
|
4
3
|
import { bookCheckoutBookingForCheckoutItem } from "../command/bookCheckoutBookingForCheckoutItem";
|
|
5
|
-
import {
|
|
6
|
-
bookCheckoutBookingForCheckoutItemHandler as sutBook,
|
|
7
|
-
blockCheckoutBookingHandler as sutBlock,
|
|
8
|
-
CheckoutBooking,
|
|
9
|
-
} from "./checkoutBooking";
|
|
10
|
-
import { CHECKOUT_BOOKING_BLOCKED } from "./checkoutBookingBlocked";
|
|
4
|
+
import { bookCheckoutBookingForCheckoutItemHandler as sutBook, CheckoutBooking } from "./checkoutBooking";
|
|
11
5
|
import { CHECKOUT_BOOKING_BOOKED } from "./checkoutBookingBooked";
|
|
12
|
-
import { CHECKOUT_BOOKING_EXPIRED } from "./checkoutBookingExpired";
|
|
13
6
|
|
|
14
7
|
const checkoutItemId = "b4563f59-9786-4544-aafe-405d9d21a6fc";
|
|
15
8
|
const checkoutBooking: CheckoutBooking = {
|
|
@@ -35,37 +28,4 @@ describe("checkoutBooking", () => {
|
|
|
35
28
|
expect(aggregateRoot.isExpired).toBe(checkoutBooking.isExpired);
|
|
36
29
|
expect(aggregateRoot.domainEvents[0].name).toBe(CHECKOUT_BOOKING_BOOKED);
|
|
37
30
|
});
|
|
38
|
-
|
|
39
|
-
test("blocks", async () => {
|
|
40
|
-
const command = blockCheckoutBooking({
|
|
41
|
-
aggregateId: checkoutBooking.aggregateId,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const aggregateRoot = await sutBlock({ queryBus })({ aggregateRoot: checkoutBooking, command });
|
|
45
|
-
|
|
46
|
-
expect(aggregateRoot.aggregateId).toBe(checkoutBooking.aggregateId);
|
|
47
|
-
expect(aggregateRoot.checkoutItemIds).toBe(checkoutBooking.checkoutItemIds);
|
|
48
|
-
expect(aggregateRoot.isExpired).toBe(checkoutBooking.isExpired);
|
|
49
|
-
expect(aggregateRoot.domainEvents[0].name).toBe(CHECKOUT_BOOKING_BLOCKED);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test("trying to block a expired checkout ", async () => {
|
|
53
|
-
const checkoutBooking: CheckoutBooking = {
|
|
54
|
-
aggregateId: "ca331fba-68a6-4ed4-973f-9afc2e27569d",
|
|
55
|
-
checkoutItemIds: [checkoutItemId],
|
|
56
|
-
isExpired: true,
|
|
57
|
-
domainEvents: [],
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const command = blockCheckoutBooking({
|
|
61
|
-
aggregateId: checkoutBooking.aggregateId,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const aggregateRoot = await sutBlock({ queryBus })({ aggregateRoot: checkoutBooking, command });
|
|
65
|
-
|
|
66
|
-
expect(aggregateRoot.aggregateId).toBe(checkoutBooking.aggregateId);
|
|
67
|
-
expect(aggregateRoot.checkoutItemIds).toBe(checkoutBooking.checkoutItemIds);
|
|
68
|
-
expect(aggregateRoot.isExpired).toBe(checkoutBooking.isExpired);
|
|
69
|
-
expect(aggregateRoot.domainEvents[0].name).toBe(CHECKOUT_BOOKING_EXPIRED);
|
|
70
|
-
});
|
|
71
31
|
});
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { AggregateRoot, CommandHandlerFunction } from "@lookiero/messaging";
|
|
2
|
-
import { BlockCheckoutBooking } from "../command/blockCheckoutBooking";
|
|
3
2
|
import { BookCheckoutBookingForCheckoutItem } from "../command/bookCheckoutBookingForCheckoutItem";
|
|
4
|
-
import { checkoutBookingBlocked } from "./checkoutBookingBlocked";
|
|
5
3
|
import { checkoutBookingBooked } from "./checkoutBookingBooked";
|
|
6
|
-
import { checkoutBookingExpired } from "./checkoutBookingExpired";
|
|
7
4
|
|
|
8
5
|
interface CheckoutBooking extends AggregateRoot {
|
|
9
6
|
readonly checkoutItemIds: string[];
|
|
@@ -24,23 +21,5 @@ const bookCheckoutBookingForCheckoutItemHandler: CommandHandlerFunction<
|
|
|
24
21
|
};
|
|
25
22
|
};
|
|
26
23
|
|
|
27
|
-
const blockCheckoutBookingHandler: CommandHandlerFunction<BlockCheckoutBooking, CheckoutBooking> =
|
|
28
|
-
() =>
|
|
29
|
-
async ({ aggregateRoot, command }) => {
|
|
30
|
-
const { aggregateId } = command;
|
|
31
|
-
|
|
32
|
-
if (aggregateRoot.isExpired) {
|
|
33
|
-
return {
|
|
34
|
-
...aggregateRoot,
|
|
35
|
-
domainEvents: [checkoutBookingExpired({ aggregateId })],
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
...aggregateRoot,
|
|
41
|
-
domainEvents: [checkoutBookingBlocked({ aggregateId })],
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
|
|
45
24
|
export type { CheckoutBooking };
|
|
46
|
-
export { bookCheckoutBookingForCheckoutItemHandler
|
|
25
|
+
export { bookCheckoutBookingForCheckoutItemHandler };
|
|
@@ -17,11 +17,9 @@ import { createModalNotificationWhenCheckoutSubmitted } from "../../domain/check
|
|
|
17
17
|
import { Checkout, submitCheckoutHandler, startCheckoutHandler } from "../../domain/checkout/model/checkout";
|
|
18
18
|
import { CHECKOUT_SUBMITTED } from "../../domain/checkout/model/checkoutSubmitted";
|
|
19
19
|
import { CheckoutsGetFunction, CheckoutsSaveFunction } from "../../domain/checkout/model/checkouts";
|
|
20
|
-
import { BLOCK_CHECKOUT_BOOKING } from "../../domain/checkoutBooking/command/blockCheckoutBooking";
|
|
21
20
|
import { BOOK_CHECKOUT_BOOKING_FOR_CHECKOUT_ITEM } from "../../domain/checkoutBooking/command/bookCheckoutBookingForCheckoutItem";
|
|
22
21
|
import { createToastNotificationWhenCheckoutBookingExpired } from "../../domain/checkoutBooking/event/createToastNotificationWhenCheckoutBookingExpired";
|
|
23
22
|
import {
|
|
24
|
-
blockCheckoutBookingHandler,
|
|
25
23
|
bookCheckoutBookingForCheckoutItemHandler,
|
|
26
24
|
CheckoutBooking,
|
|
27
25
|
} from "../../domain/checkoutBooking/model/checkoutBooking";
|
|
@@ -282,11 +280,6 @@ const baseBootstrap: BaseBootstrapFunction = ({
|
|
|
282
280
|
saveCheckoutBooking,
|
|
283
281
|
...checkoutBookingsDependencies,
|
|
284
282
|
)
|
|
285
|
-
.command(BLOCK_CHECKOUT_BOOKING, blockCheckoutBookingHandler)(
|
|
286
|
-
getCheckoutBooking,
|
|
287
|
-
saveCheckoutBooking,
|
|
288
|
-
...checkoutBookingsDependencies,
|
|
289
|
-
)
|
|
290
283
|
.command(GIVE_CHECKOUT_FEEDBACK, giveCheckoutFeedbackHandler)(
|
|
291
284
|
getCheckoutFeedback,
|
|
292
285
|
saveCheckoutFeedback,
|
|
@@ -6,10 +6,6 @@ const mockHttpCheckoutBookingsBook = jest.fn();
|
|
|
6
6
|
jest.mock("./httpCheckoutBookingsBook", () => ({
|
|
7
7
|
httpCheckoutBookingsBook: () => mockHttpCheckoutBookingsBook,
|
|
8
8
|
}));
|
|
9
|
-
const mockHttpCheckoutBookingsBlock = jest.fn();
|
|
10
|
-
jest.mock("./httpCheckoutBookingsBlock", () => ({
|
|
11
|
-
httpCheckoutBookingsBlock: () => mockHttpCheckoutBookingsBlock,
|
|
12
|
-
}));
|
|
13
9
|
|
|
14
10
|
const checkoutBookingProjection = checkoutBookingMock;
|
|
15
11
|
const checkoutItemIds = checkoutBookingProjection.checkoutItemIds;
|
|
@@ -36,10 +32,9 @@ describe("httpCheckoutBookings", () => {
|
|
|
36
32
|
});
|
|
37
33
|
});
|
|
38
34
|
|
|
39
|
-
it("saves a checkoutBooking: calls httpCheckoutBookingsBook
|
|
35
|
+
it("saves a checkoutBooking: calls httpCheckoutBookingsBook", async () => {
|
|
40
36
|
await sutSave({ httpPost: jest.fn() })(checkoutBooking);
|
|
41
37
|
|
|
42
38
|
expect(mockHttpCheckoutBookingsBook).toHaveBeenCalled();
|
|
43
|
-
expect(mockHttpCheckoutBookingsBlock).toHaveBeenCalled();
|
|
44
39
|
});
|
|
45
40
|
});
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
ViewCheckoutBookingById,
|
|
12
12
|
ViewCheckoutBookingByIdResult,
|
|
13
13
|
} from "../../../../projection/checkoutBooking/viewCheckoutBookingById";
|
|
14
|
-
import { httpCheckoutBookingsBlock } from "./httpCheckoutBookingsBlock";
|
|
15
14
|
import { httpCheckoutBookingsBook } from "./httpCheckoutBookingsBook";
|
|
16
15
|
|
|
17
16
|
interface ToDomainFunction {
|
|
@@ -51,10 +50,7 @@ interface HttpCheckoutBookingsSaveFunction extends CheckoutBookingsSaveFunction<
|
|
|
51
50
|
const saveCheckoutBooking: HttpCheckoutBookingsSaveFunction =
|
|
52
51
|
({ httpPost }) =>
|
|
53
52
|
async (aggregateRoot) => {
|
|
54
|
-
await
|
|
55
|
-
httpCheckoutBookingsBook({ httpPost })(aggregateRoot),
|
|
56
|
-
httpCheckoutBookingsBlock({ httpPost })(aggregateRoot),
|
|
57
|
-
]);
|
|
53
|
+
await httpCheckoutBookingsBook({ httpPost })(aggregateRoot);
|
|
58
54
|
};
|
|
59
55
|
|
|
60
56
|
export type { HttpCheckoutBookingsSaveFunction };
|
|
@@ -10,7 +10,6 @@ import { Customer } from "../../../projection/customer/customer";
|
|
|
10
10
|
import { OrderProjection } from "../../../projection/order/order";
|
|
11
11
|
import { SubscriptionProjection } from "../../../projection/subscription/subscription";
|
|
12
12
|
import { useSubmitCheckout } from "../../domain/checkout/react/useSubmitCheckout";
|
|
13
|
-
import { useBlockCheckoutBooking } from "../../domain/checkoutBooking/react/useBlockCheckoutBooking";
|
|
14
13
|
import { checkout } from "../../projection/checkout/checkout.mock";
|
|
15
14
|
import { useViewIsSizeChangeEnabledByCheckoutId } from "../../projection/checkout/react/useViewIsSizeChangeEnabledByCheckoutId";
|
|
16
15
|
import { paymentFlowPayload as mockPaymentFlowPayload } from "../../projection/payment/paymentFlowPayload.mock";
|
|
@@ -89,7 +88,6 @@ jest.mock("@lookiero/sty-psp-logging", () => ({
|
|
|
89
88
|
jest.mock("@lookiero/sty-psp-notifications");
|
|
90
89
|
jest.mock("./useQueryBus");
|
|
91
90
|
jest.mock("../../domain/checkout/react/useSubmitCheckout");
|
|
92
|
-
jest.mock("../../domain/checkoutBooking/react/useBlockCheckoutBooking");
|
|
93
91
|
jest.mock("../../domain/checkout/react/useSubmitCheckout");
|
|
94
92
|
jest.mock("../../projection/payment/react/useViewPaymentFlowPayloadByCheckoutId");
|
|
95
93
|
jest.mock("../../projection/checkout/react/useViewIsSizeChangeEnabledByCheckoutId");
|
|
@@ -102,13 +100,11 @@ beforeEach(() => {
|
|
|
102
100
|
|
|
103
101
|
describe("useCheckoutFlow custom hook", () => {
|
|
104
102
|
test("successfully executes 'checkoutFlow'", async () => {
|
|
105
|
-
const mockBlockCheckoutBooking = jest.fn();
|
|
106
103
|
const mockSubmitCheckout = jest.fn();
|
|
107
104
|
const mockCreateToastNotification = jest.fn();
|
|
108
105
|
const mockOnSuccess = jest.fn();
|
|
109
106
|
|
|
110
107
|
(useQueryBus as jest.Mock).mockReturnValue(() => ({ isExpired: false }) as CheckoutBookingProjection);
|
|
111
|
-
(useBlockCheckoutBooking as jest.Mock).mockReturnValue([mockBlockCheckoutBooking, CommandStatus.SUCCESS]);
|
|
112
108
|
(useCreateToastNotification as jest.Mock).mockReturnValue([mockCreateToastNotification, CommandStatus.SUCCESS]);
|
|
113
109
|
(useViewPaymentFlowPayloadByCheckoutId as jest.Mock).mockReturnValue([mockPaymentFlowPayload, QueryStatus.SUCCESS]);
|
|
114
110
|
(useViewIsSizeChangeEnabledByCheckoutId as jest.Mock).mockReturnValue([true, QueryStatus.SUCCESS]);
|
|
@@ -140,7 +136,6 @@ describe("useCheckoutFlow custom hook", () => {
|
|
|
140
136
|
[, status] = result.current;
|
|
141
137
|
|
|
142
138
|
expect(status).toBe("success");
|
|
143
|
-
expect(mockBlockCheckoutBooking).toHaveBeenCalled();
|
|
144
139
|
expect(mockStartLegacyBoxCheckout).toHaveBeenCalledWith(
|
|
145
140
|
expect.objectContaining({
|
|
146
141
|
...mockPaymentFlowPayload,
|
|
@@ -157,117 +152,12 @@ describe("useCheckoutFlow custom hook", () => {
|
|
|
157
152
|
});
|
|
158
153
|
});
|
|
159
154
|
|
|
160
|
-
test("does not call blockCheckoutBooking if sizeChange is not enabled", async () => {
|
|
161
|
-
const mockBlockCheckoutBooking = jest.fn();
|
|
162
|
-
const mockSubmitCheckout = jest.fn();
|
|
163
|
-
const mockCreateToastNotification = jest.fn();
|
|
164
|
-
const mockOnSuccess = jest.fn();
|
|
165
|
-
|
|
166
|
-
(useQueryBus as jest.Mock).mockReturnValue(() => ({ isExpired: false }) as CheckoutBookingProjection);
|
|
167
|
-
(useBlockCheckoutBooking as jest.Mock).mockReturnValue([mockBlockCheckoutBooking, CommandStatus.SUCCESS]);
|
|
168
|
-
(useCreateToastNotification as jest.Mock).mockReturnValue([mockCreateToastNotification, CommandStatus.SUCCESS]);
|
|
169
|
-
(useViewPaymentFlowPayloadByCheckoutId as jest.Mock).mockReturnValue([mockPaymentFlowPayload, QueryStatus.SUCCESS]);
|
|
170
|
-
(useViewIsSizeChangeEnabledByCheckoutId as jest.Mock).mockReturnValue([false, QueryStatus.SUCCESS]);
|
|
171
|
-
(useViewPricingByCheckoutId as jest.Mock).mockReturnValue([mockPricing, QueryStatus.SUCCESS]);
|
|
172
|
-
(useSubmitCheckout as jest.Mock).mockReturnValue([mockSubmitCheckout, "success"]);
|
|
173
|
-
(usePaymentInstrumentEvents as jest.Mock).mockImplementation(({ onSuccess }) => {
|
|
174
|
-
setTimeout(() => onSuccess(), 1000);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
const { result } = renderHook(() =>
|
|
178
|
-
sut({ checkout: mockCheckout, order, subscription, getAuthToken, onSuccess: mockOnSuccess }),
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
let checkoutFlow: () => void, status, paymentFlowComponent;
|
|
182
|
-
|
|
183
|
-
await waitFor(() => {
|
|
184
|
-
[checkoutFlow, , paymentFlowComponent] = result.current;
|
|
185
|
-
|
|
186
|
-
expect(paymentFlowComponent).not.toBeNull();
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
render(<>{paymentFlowComponent}</>);
|
|
190
|
-
|
|
191
|
-
await act(async () => {
|
|
192
|
-
await checkoutFlow();
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
await waitFor(() => {
|
|
196
|
-
[, status] = result.current;
|
|
197
|
-
|
|
198
|
-
expect(status).toBe("success");
|
|
199
|
-
expect(mockBlockCheckoutBooking).not.toHaveBeenCalled();
|
|
200
|
-
expect(mockStartLegacyBoxCheckout).toHaveBeenCalledWith(
|
|
201
|
-
expect.objectContaining({
|
|
202
|
-
...mockPaymentFlowPayload,
|
|
203
|
-
userInformation: { email, name },
|
|
204
|
-
returnUrl: `${basePath}/${Routes.CHECKOUT}`,
|
|
205
|
-
}),
|
|
206
|
-
);
|
|
207
|
-
expect(mockSubmitCheckout).toHaveBeenCalled();
|
|
208
|
-
expect(mockCreateToastNotification).toHaveBeenCalledWith({
|
|
209
|
-
bodyI18nKey: I18nMessages.CHECKOUT_TOAST_PAYMENT_SUCCESS,
|
|
210
|
-
level: NotificationLevel.SUCCESS,
|
|
211
|
-
});
|
|
212
|
-
expect(mockOnSuccess).toHaveBeenCalled();
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
test("breaks execution and returns error as the status when blockCheckoutBooking fails", async () => {
|
|
217
|
-
const mockBlockCheckoutBooking = jest.fn().mockRejectedValue("error");
|
|
218
|
-
const mockSubmitCheckout = jest.fn();
|
|
219
|
-
const mockCreateToastNotification = jest.fn();
|
|
220
|
-
const mockOnSuccess = jest.fn();
|
|
221
|
-
|
|
222
|
-
(useQueryBus as jest.Mock).mockReturnValue(() => ({ isExpired: false }) as CheckoutBookingProjection);
|
|
223
|
-
(useBlockCheckoutBooking as jest.Mock).mockReturnValue([mockBlockCheckoutBooking, CommandStatus.ERROR]);
|
|
224
|
-
(useCreateToastNotification as jest.Mock).mockReturnValue([mockCreateToastNotification, CommandStatus.SUCCESS]);
|
|
225
|
-
(useViewPaymentFlowPayloadByCheckoutId as jest.Mock).mockReturnValue([mockPaymentFlowPayload, QueryStatus.SUCCESS]);
|
|
226
|
-
(useViewIsSizeChangeEnabledByCheckoutId as jest.Mock).mockReturnValue([true, QueryStatus.SUCCESS]);
|
|
227
|
-
(useViewPricingByCheckoutId as jest.Mock).mockReturnValue([mockPricing, QueryStatus.SUCCESS]);
|
|
228
|
-
(useSubmitCheckout as jest.Mock).mockReturnValue([mockSubmitCheckout, "success"]);
|
|
229
|
-
(usePaymentInstrumentEvents as jest.Mock).mockImplementation(({ onSuccess }) => {
|
|
230
|
-
setTimeout(() => onSuccess(), 1000);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
const { result } = renderHook(() =>
|
|
234
|
-
sut({ checkout: mockCheckout, order, subscription, getAuthToken, onSuccess: mockOnSuccess }),
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
let checkoutFlow: () => void, status, paymentFlowComponent;
|
|
238
|
-
|
|
239
|
-
await waitFor(() => {
|
|
240
|
-
[checkoutFlow, , paymentFlowComponent] = result.current;
|
|
241
|
-
|
|
242
|
-
expect(paymentFlowComponent).not.toBeNull();
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
render(<>{paymentFlowComponent}</>);
|
|
246
|
-
|
|
247
|
-
await act(async () => {
|
|
248
|
-
await checkoutFlow();
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
await waitFor(() => {
|
|
252
|
-
[, status] = result.current;
|
|
253
|
-
|
|
254
|
-
expect(status).toBe("error");
|
|
255
|
-
expect(mockBlockCheckoutBooking).toHaveBeenCalled();
|
|
256
|
-
expect(mockStartLegacyBoxCheckout).not.toHaveBeenCalled();
|
|
257
|
-
expect(mockSubmitCheckout).not.toHaveBeenCalled();
|
|
258
|
-
expect(mockCreateToastNotification).not.toHaveBeenCalled();
|
|
259
|
-
expect(mockOnSuccess).not.toHaveBeenCalled();
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
|
|
263
155
|
test("shows a notification and returns error as the status when payment fails", async () => {
|
|
264
|
-
const mockBlockCheckoutBooking = jest.fn();
|
|
265
156
|
const mockSubmitCheckout = jest.fn();
|
|
266
157
|
const mockCreateToastNotification = jest.fn();
|
|
267
158
|
const mockOnSuccess = jest.fn();
|
|
268
159
|
|
|
269
160
|
(useQueryBus as jest.Mock).mockReturnValue(() => ({ isExpired: false }) as CheckoutBookingProjection);
|
|
270
|
-
(useBlockCheckoutBooking as jest.Mock).mockReturnValue([mockBlockCheckoutBooking, CommandStatus.SUCCESS]);
|
|
271
161
|
(useCreateToastNotification as jest.Mock).mockReturnValue([mockCreateToastNotification, CommandStatus.SUCCESS]);
|
|
272
162
|
(useViewPaymentFlowPayloadByCheckoutId as jest.Mock).mockReturnValue([mockPaymentFlowPayload, QueryStatus.SUCCESS]);
|
|
273
163
|
(useViewIsSizeChangeEnabledByCheckoutId as jest.Mock).mockReturnValue([true, QueryStatus.SUCCESS]);
|
|
@@ -299,7 +189,6 @@ describe("useCheckoutFlow custom hook", () => {
|
|
|
299
189
|
[, status] = result.current;
|
|
300
190
|
|
|
301
191
|
expect(status).toBe("error");
|
|
302
|
-
expect(mockBlockCheckoutBooking).toHaveBeenCalled();
|
|
303
192
|
expect(mockStartLegacyBoxCheckout).toHaveBeenCalled();
|
|
304
193
|
expect(mockSubmitCheckout).not.toHaveBeenCalled();
|
|
305
194
|
expect(mockCreateToastNotification).toHaveBeenCalledWith({
|
|
@@ -14,8 +14,6 @@ import { OrderProjection } from "../../../projection/order/order";
|
|
|
14
14
|
import { SubscriptionProjection } from "../../../projection/subscription/subscription";
|
|
15
15
|
import { MESSAGING_CONTEXT_ID } from "../../delivery/baseBootstrap";
|
|
16
16
|
import { useSubmitCheckout } from "../../domain/checkout/react/useSubmitCheckout";
|
|
17
|
-
import { useBlockCheckoutBooking } from "../../domain/checkoutBooking/react/useBlockCheckoutBooking";
|
|
18
|
-
import { useViewIsSizeChangeEnabledByCheckoutId } from "../../projection/checkout/react/useViewIsSizeChangeEnabledByCheckoutId";
|
|
19
17
|
import { useViewPaymentFlowPayloadByCheckoutId } from "../../projection/payment/react/useViewPaymentFlowPayloadByCheckoutId";
|
|
20
18
|
import { useViewPricingByCheckoutId } from "../../projection/pricing/react/useViewPricingByCheckoutId";
|
|
21
19
|
import { useTrackCheckout } from "../../tracking/useTrackCheckout";
|
|
@@ -67,7 +65,6 @@ const useCheckoutFlow: UseCheckoutFlowFunction = ({
|
|
|
67
65
|
const [paymentFlowPayload] = useViewPaymentFlowPayloadByCheckoutId({
|
|
68
66
|
checkoutId: checkoutProjection?.id as string,
|
|
69
67
|
});
|
|
70
|
-
const [sizeChangeEnabled] = useViewIsSizeChangeEnabledByCheckoutId({ checkoutId: checkoutProjection?.id as string });
|
|
71
68
|
const [pricing] = useViewPricingByCheckoutId({
|
|
72
69
|
checkoutId: checkoutProjection?.id,
|
|
73
70
|
queryOptions: { refetchOnMount: true },
|
|
@@ -76,10 +73,6 @@ const useCheckoutFlow: UseCheckoutFlowFunction = ({
|
|
|
76
73
|
checkoutId: checkoutProjection?.id,
|
|
77
74
|
logger,
|
|
78
75
|
});
|
|
79
|
-
const [blockCheckoutBooking, blockCheckoutBookingStatus] = useBlockCheckoutBooking({
|
|
80
|
-
checkoutBookingId: checkoutProjection?.checkoutBookingId,
|
|
81
|
-
logger,
|
|
82
|
-
});
|
|
83
76
|
const [createNotification] = useCreateToastNotification({ contextId: MESSAGING_CONTEXT_ID, logger });
|
|
84
77
|
const [checkoutBookingExpired, setCheckoutBookingExpired] = useState(false);
|
|
85
78
|
const [startLegacyBoxCheckoutStatus, setStartLegacyBoxCheckoutStatus] = useState<CheckoutFlowStatus>("idle");
|
|
@@ -100,12 +93,6 @@ const useCheckoutFlow: UseCheckoutFlowFunction = ({
|
|
|
100
93
|
});
|
|
101
94
|
|
|
102
95
|
const checkoutFlow: CheckoutFlowFunction = useCallback(async () => {
|
|
103
|
-
try {
|
|
104
|
-
sizeChangeEnabled && (await blockCheckoutBooking());
|
|
105
|
-
} catch (error) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
96
|
if (checkoutProjection?.checkoutBookingId) {
|
|
110
97
|
const checkoutBooking = await queryBus<ViewCheckoutBookingById, ViewCheckoutBookingByIdResult>(
|
|
111
98
|
viewCheckoutBookingById({ checkoutBookingId: checkoutProjection?.checkoutBookingId }),
|
|
@@ -124,16 +111,7 @@ const useCheckoutFlow: UseCheckoutFlowFunction = ({
|
|
|
124
111
|
userInformation: { email, name },
|
|
125
112
|
returnUrl: `${basePath}/${Routes.CHECKOUT}`,
|
|
126
113
|
} as unknown as LegacyBoxCheckoutStrategyPayload);
|
|
127
|
-
}, [
|
|
128
|
-
checkoutProjection?.checkoutBookingId,
|
|
129
|
-
paymentFlowPayload,
|
|
130
|
-
email,
|
|
131
|
-
name,
|
|
132
|
-
basePath,
|
|
133
|
-
sizeChangeEnabled,
|
|
134
|
-
blockCheckoutBooking,
|
|
135
|
-
queryBus,
|
|
136
|
-
]);
|
|
114
|
+
}, [checkoutProjection?.checkoutBookingId, paymentFlowPayload, email, name, basePath, queryBus]);
|
|
137
115
|
|
|
138
116
|
const onPaymentSuccess = useCallback(async () => {
|
|
139
117
|
setStartLegacyBoxCheckoutStatus("success");
|
|
@@ -162,24 +140,15 @@ const useCheckoutFlow: UseCheckoutFlowFunction = ({
|
|
|
162
140
|
usePaymentInstrumentEvents({ onSuccess: onPaymentSuccess, onError: onPaymentError });
|
|
163
141
|
|
|
164
142
|
const checkoutFlowStatus: CheckoutFlowStatus = useMemo(() => {
|
|
165
|
-
if (
|
|
166
|
-
blockCheckoutBookingStatus === CommandStatus.LOADING ||
|
|
167
|
-
startLegacyBoxCheckoutStatus === "loading" ||
|
|
168
|
-
submitCheckoutStatus === CommandStatus.LOADING
|
|
169
|
-
) {
|
|
143
|
+
if (startLegacyBoxCheckoutStatus === "loading" || submitCheckoutStatus === CommandStatus.LOADING) {
|
|
170
144
|
return "loading";
|
|
171
145
|
}
|
|
172
146
|
|
|
173
|
-
if (
|
|
174
|
-
blockCheckoutBookingStatus === CommandStatus.SUCCESS &&
|
|
175
|
-
startLegacyBoxCheckoutStatus === "success" &&
|
|
176
|
-
submitCheckoutStatus === CommandStatus.SUCCESS
|
|
177
|
-
) {
|
|
147
|
+
if (startLegacyBoxCheckoutStatus === "success" && submitCheckoutStatus === CommandStatus.SUCCESS) {
|
|
178
148
|
return "success";
|
|
179
149
|
}
|
|
180
150
|
|
|
181
151
|
if (
|
|
182
|
-
blockCheckoutBookingStatus === CommandStatus.ERROR ||
|
|
183
152
|
startLegacyBoxCheckoutStatus === "error" ||
|
|
184
153
|
submitCheckoutStatus === CommandStatus.ERROR ||
|
|
185
154
|
checkoutBookingExpired
|
|
@@ -188,7 +157,7 @@ const useCheckoutFlow: UseCheckoutFlowFunction = ({
|
|
|
188
157
|
}
|
|
189
158
|
|
|
190
159
|
return "idle";
|
|
191
|
-
}, [
|
|
160
|
+
}, [startLegacyBoxCheckoutStatus, submitCheckoutStatus, checkoutBookingExpired]);
|
|
192
161
|
|
|
193
162
|
const paymentFlow = useMemo(
|
|
194
163
|
() => (authToken ? <PaymentFlow ref={paymentFlowRef} section={Section.BOX_CHECKOUT} token={authToken} /> : null),
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Command } from "@lookiero/messaging";
|
|
2
|
-
declare const BLOCK_CHECKOUT_BOOKING = "block_checkout_booking";
|
|
3
|
-
interface BlockCheckoutBookingPayload {
|
|
4
|
-
readonly aggregateId: string;
|
|
5
|
-
}
|
|
6
|
-
interface BlockCheckoutBooking extends Command<typeof BLOCK_CHECKOUT_BOOKING>, BlockCheckoutBookingPayload {
|
|
7
|
-
}
|
|
8
|
-
interface BlockCheckoutBookingFunction {
|
|
9
|
-
(payload: BlockCheckoutBookingPayload): BlockCheckoutBooking;
|
|
10
|
-
}
|
|
11
|
-
declare const blockCheckoutBooking: BlockCheckoutBookingFunction;
|
|
12
|
-
export type { BlockCheckoutBooking };
|
|
13
|
-
export { BLOCK_CHECKOUT_BOOKING, blockCheckoutBooking };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { DomainEvent } from "@lookiero/messaging";
|
|
2
|
-
declare const CHECKOUT_BOOKING_BLOCKED = "checkout_booking_blocked";
|
|
3
|
-
interface CheckoutBookingBlokedPaylcoad {
|
|
4
|
-
readonly aggregateId: string;
|
|
5
|
-
}
|
|
6
|
-
interface CheckoutBookingBlocked extends DomainEvent<typeof CHECKOUT_BOOKING_BLOCKED>, CheckoutBookingBlokedPaylcoad {
|
|
7
|
-
}
|
|
8
|
-
interface CheckoutBookingBlokedFunctcion {
|
|
9
|
-
(payload: CheckoutBookingBlokedPaylcoad): CheckoutBookingBlocked;
|
|
10
|
-
}
|
|
11
|
-
declare const checkoutBookingBlocked: CheckoutBookingBlokedFunctcion;
|
|
12
|
-
export type { CheckoutBookingBlocked };
|
|
13
|
-
export { CHECKOUT_BOOKING_BLOCKED, checkoutBookingBlocked };
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { domainEvent } from "@lookiero/messaging";
|
|
2
|
-
const CHECKOUT_BOOKING_BLOCKED = "checkout_booking_blocked";
|
|
3
|
-
const checkoutBookingBlocked = ({ aggregateId }) => domainEvent({ aggregateId, name: CHECKOUT_BOOKING_BLOCKED });
|
|
4
|
-
export { CHECKOUT_BOOKING_BLOCKED, checkoutBookingBlocked };
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { HttpCheckoutBookingsSaveFunction } from "./httpCheckoutBookings";
|
|
2
|
-
interface HttpCheckoutBookingsBlockFunction extends HttpCheckoutBookingsSaveFunction {
|
|
3
|
-
}
|
|
4
|
-
declare const httpCheckoutBookingsBlock: HttpCheckoutBookingsBlockFunction;
|
|
5
|
-
export { httpCheckoutBookingsBlock };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { CHECKOUT_BOOKING_BLOCKED, } from "../../../../domain/checkoutBooking/model/checkoutBookingBlocked";
|
|
2
|
-
const isCheckoutBookingBlocked = (event) => event.name === CHECKOUT_BOOKING_BLOCKED;
|
|
3
|
-
const httpCheckoutBookingsBlock = ({ httpPost }) => async ({ aggregateId, domainEvents }) => {
|
|
4
|
-
const checkoutBookingBlocked = domainEvents.find(isCheckoutBookingBlocked);
|
|
5
|
-
if (!checkoutBookingBlocked) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
await httpPost({
|
|
9
|
-
endpoint: "/block-checkout-booking",
|
|
10
|
-
body: {
|
|
11
|
-
checkoutBookingId: aggregateId,
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
export { httpCheckoutBookingsBlock };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { CommandStatus } from "@lookiero/messaging-react";
|
|
2
|
-
import { Logger } from "@lookiero/sty-psp-logging";
|
|
3
|
-
interface BlockCheckoutBookingFunction {
|
|
4
|
-
(): Promise<void>;
|
|
5
|
-
}
|
|
6
|
-
type UseBlockCheckoutBooking = [blockCheckoutBooking: BlockCheckoutBookingFunction, status: CommandStatus];
|
|
7
|
-
interface UseBlockCheckoutBookingFunctionArgs {
|
|
8
|
-
readonly checkoutBookingId: string | undefined;
|
|
9
|
-
readonly logger: Logger;
|
|
10
|
-
}
|
|
11
|
-
interface UseBlockCheckoutBookingFunction {
|
|
12
|
-
(args: UseBlockCheckoutBookingFunctionArgs): UseBlockCheckoutBooking;
|
|
13
|
-
}
|
|
14
|
-
declare const useBlockCheckoutBooking: UseBlockCheckoutBookingFunction;
|
|
15
|
-
export { useBlockCheckoutBooking };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
2
|
-
import invariant from "tiny-invariant";
|
|
3
|
-
import { useCommand } from "@lookiero/messaging-react";
|
|
4
|
-
import { NotificationLevel, useCreateToastNotification } from "@lookiero/sty-psp-notifications";
|
|
5
|
-
import { blockCheckoutBooking as blockCheckoutBookingCommand } from "../../../../domain/checkoutBooking/command/blockCheckoutBooking";
|
|
6
|
-
import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
|
|
7
|
-
import { I18nMessages } from "../../../ui/i18n/i18n";
|
|
8
|
-
const useBlockCheckoutBooking = ({ checkoutBookingId, logger }) => {
|
|
9
|
-
const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
|
|
10
|
-
const [createNotification] = useCreateToastNotification({ contextId: MESSAGING_CONTEXT_ID, logger });
|
|
11
|
-
const blockCheckoutBooking = useCallback(async () => {
|
|
12
|
-
invariant(checkoutBookingId, "checkoutBookingId is required");
|
|
13
|
-
try {
|
|
14
|
-
await commandBus(blockCheckoutBookingCommand({
|
|
15
|
-
aggregateId: checkoutBookingId,
|
|
16
|
-
}));
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
logger.captureException(error);
|
|
20
|
-
createNotification({
|
|
21
|
-
level: NotificationLevel.ERROR,
|
|
22
|
-
bodyI18nKey: I18nMessages.TOAST_GENERIC_ERROR,
|
|
23
|
-
});
|
|
24
|
-
throw error;
|
|
25
|
-
}
|
|
26
|
-
}, [checkoutBookingId, commandBus, createNotification, logger]);
|
|
27
|
-
return [blockCheckoutBooking, status];
|
|
28
|
-
};
|
|
29
|
-
export { useBlockCheckoutBooking };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { blockCheckoutBooking as sut, BLOCK_CHECKOUT_BOOKING } from "./blockCheckoutBooking";
|
|
2
|
-
|
|
3
|
-
describe("blockCheckoutBooking", () => {
|
|
4
|
-
it("returns an BlockCheckoutBooking command", () => {
|
|
5
|
-
const aggregateId = "118f0698-a194-4edf-9f30-e936f985fde0";
|
|
6
|
-
|
|
7
|
-
const command = sut({ aggregateId });
|
|
8
|
-
|
|
9
|
-
expect(command.aggregateId).toBe(aggregateId);
|
|
10
|
-
expect(command.name).toBe(BLOCK_CHECKOUT_BOOKING);
|
|
11
|
-
});
|
|
12
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { command, Command } from "@lookiero/messaging";
|
|
2
|
-
|
|
3
|
-
const BLOCK_CHECKOUT_BOOKING = "block_checkout_booking";
|
|
4
|
-
|
|
5
|
-
interface BlockCheckoutBookingPayload {
|
|
6
|
-
readonly aggregateId: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface BlockCheckoutBooking extends Command<typeof BLOCK_CHECKOUT_BOOKING>, BlockCheckoutBookingPayload {}
|
|
10
|
-
|
|
11
|
-
interface BlockCheckoutBookingFunction {
|
|
12
|
-
(payload: BlockCheckoutBookingPayload): BlockCheckoutBooking;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const blockCheckoutBooking: BlockCheckoutBookingFunction = ({ aggregateId }) =>
|
|
16
|
-
command({ aggregateId, name: BLOCK_CHECKOUT_BOOKING });
|
|
17
|
-
|
|
18
|
-
export type { BlockCheckoutBooking };
|
|
19
|
-
export { BLOCK_CHECKOUT_BOOKING, blockCheckoutBooking };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { checkoutBookingBlocked as sut, CHECKOUT_BOOKING_BLOCKED } from "./checkoutBookingBlocked";
|
|
2
|
-
|
|
3
|
-
describe("checkoutBookingBlocked", () => {
|
|
4
|
-
it("returns an CheckoutBookingBlocked domain event", () => {
|
|
5
|
-
const aggregateId = "d99810a4-a453-45b9-acc9-71896651e641";
|
|
6
|
-
|
|
7
|
-
const domainEvent = sut({ aggregateId });
|
|
8
|
-
|
|
9
|
-
expect(domainEvent.aggregateId).toBe(aggregateId);
|
|
10
|
-
expect(domainEvent.name).toBe(CHECKOUT_BOOKING_BLOCKED);
|
|
11
|
-
});
|
|
12
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { domainEvent, DomainEvent } from "@lookiero/messaging";
|
|
2
|
-
|
|
3
|
-
const CHECKOUT_BOOKING_BLOCKED = "checkout_booking_blocked";
|
|
4
|
-
|
|
5
|
-
interface CheckoutBookingBlokedPaylcoad {
|
|
6
|
-
readonly aggregateId: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface CheckoutBookingBlocked extends DomainEvent<typeof CHECKOUT_BOOKING_BLOCKED>, CheckoutBookingBlokedPaylcoad {}
|
|
10
|
-
|
|
11
|
-
interface CheckoutBookingBlokedFunctcion {
|
|
12
|
-
(payload: CheckoutBookingBlokedPaylcoad): CheckoutBookingBlocked;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const checkoutBookingBlocked: CheckoutBookingBlokedFunctcion = ({ aggregateId }) =>
|
|
16
|
-
domainEvent({ aggregateId, name: CHECKOUT_BOOKING_BLOCKED });
|
|
17
|
-
|
|
18
|
-
export type { CheckoutBookingBlocked };
|
|
19
|
-
export { CHECKOUT_BOOKING_BLOCKED, checkoutBookingBlocked };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { DomainEvent, MessageName } from "@lookiero/messaging";
|
|
2
|
-
import { HttpPostFunction } from "@lookiero/sty-psp-http";
|
|
3
|
-
import { CheckoutBooking } from "../../../../domain/checkoutBooking/model/checkoutBooking";
|
|
4
|
-
import { checkoutBookingBlocked } from "../../../../domain/checkoutBooking/model/checkoutBookingBlocked";
|
|
5
|
-
import { httpCheckoutBookingsBlock as sut } from "./httpCheckoutBookingsBlock";
|
|
6
|
-
|
|
7
|
-
const checkoutBookingId = "808fe42d-71da-4ad8-8790-5468103b2405";
|
|
8
|
-
|
|
9
|
-
const checkoutBookingWithDomainEvent = (domainEvents: DomainEvent<MessageName>[]): CheckoutBooking => ({
|
|
10
|
-
aggregateId: checkoutBookingId,
|
|
11
|
-
checkoutItemIds: [],
|
|
12
|
-
isExpired: false,
|
|
13
|
-
domainEvents,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const httpPostMock = jest.fn(() => Promise.resolve());
|
|
17
|
-
|
|
18
|
-
afterEach(() => httpPostMock.mockClear());
|
|
19
|
-
|
|
20
|
-
describe("httpCheckoutBookingsBlock", () => {
|
|
21
|
-
it("saves a checkout when checkoutBookingBlocked", async () => {
|
|
22
|
-
const checkout = checkoutBookingWithDomainEvent([checkoutBookingBlocked({ aggregateId: checkoutBookingId })]);
|
|
23
|
-
|
|
24
|
-
await sut({ httpPost: httpPostMock as HttpPostFunction })(checkout);
|
|
25
|
-
|
|
26
|
-
expect(httpPostMock).toHaveBeenCalledWith({
|
|
27
|
-
endpoint: "/block-checkout-booking",
|
|
28
|
-
body: {
|
|
29
|
-
checkoutBookingId,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("does nothing if not checkoutBookingBlocked", async () => {
|
|
35
|
-
const checkout = checkoutBookingWithDomainEvent([]);
|
|
36
|
-
|
|
37
|
-
await sut({ httpPost: httpPostMock as HttpPostFunction })(checkout);
|
|
38
|
-
|
|
39
|
-
expect(httpPostMock).not.toHaveBeenCalled();
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { DomainEvent, MessageName } from "@lookiero/messaging";
|
|
2
|
-
import {
|
|
3
|
-
CheckoutBookingBlocked,
|
|
4
|
-
CHECKOUT_BOOKING_BLOCKED,
|
|
5
|
-
} from "../../../../domain/checkoutBooking/model/checkoutBookingBlocked";
|
|
6
|
-
import { HttpCheckoutBookingsSaveFunction } from "./httpCheckoutBookings";
|
|
7
|
-
|
|
8
|
-
interface HttpCheckoutBookingsBlockFunction extends HttpCheckoutBookingsSaveFunction {}
|
|
9
|
-
|
|
10
|
-
const isCheckoutBookingBlocked = (event: DomainEvent<MessageName>): event is CheckoutBookingBlocked =>
|
|
11
|
-
event.name === CHECKOUT_BOOKING_BLOCKED;
|
|
12
|
-
|
|
13
|
-
const httpCheckoutBookingsBlock: HttpCheckoutBookingsBlockFunction =
|
|
14
|
-
({ httpPost }) =>
|
|
15
|
-
async ({ aggregateId, domainEvents }) => {
|
|
16
|
-
const checkoutBookingBlocked = domainEvents.find(isCheckoutBookingBlocked);
|
|
17
|
-
|
|
18
|
-
if (!checkoutBookingBlocked) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
await httpPost({
|
|
23
|
-
endpoint: "/block-checkout-booking",
|
|
24
|
-
body: {
|
|
25
|
-
checkoutBookingId: aggregateId,
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export { httpCheckoutBookingsBlock };
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { act, renderHook, waitFor } from "@testing-library/react-native";
|
|
2
|
-
import { mock } from "jest-mock-extended";
|
|
3
|
-
import { bootstrap, CommandStatus } from "@lookiero/messaging-react";
|
|
4
|
-
import { Logger } from "@lookiero/sty-psp-logging";
|
|
5
|
-
import { BLOCK_CHECKOUT_BOOKING } from "../../../../domain/checkoutBooking/command/blockCheckoutBooking";
|
|
6
|
-
import { CheckoutBooking } from "../../../../domain/checkoutBooking/model/checkoutBooking";
|
|
7
|
-
import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
|
|
8
|
-
import { useBlockCheckoutBooking as sut } from "./useBlockCheckoutBooking";
|
|
9
|
-
|
|
10
|
-
const mockCreateToastNotification = jest.fn();
|
|
11
|
-
jest.mock("@lookiero/sty-psp-notifications", () => ({
|
|
12
|
-
...jest.requireActual("@lookiero/sty-psp-notifications"),
|
|
13
|
-
useCreateToastNotification: () => [mockCreateToastNotification],
|
|
14
|
-
}));
|
|
15
|
-
|
|
16
|
-
const checkoutBookingId = "4cffd8ab-e6a5-4ef8-9388-52672cb32bb8";
|
|
17
|
-
const checkoutBooking: CheckoutBooking = {
|
|
18
|
-
aggregateId: checkoutBookingId,
|
|
19
|
-
checkoutItemIds: [],
|
|
20
|
-
isExpired: false,
|
|
21
|
-
domainEvents: [],
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const logger = mock<Logger>();
|
|
25
|
-
|
|
26
|
-
const getMock = jest.fn(() => Promise.resolve(checkoutBooking));
|
|
27
|
-
const get = jest.fn(() => getMock);
|
|
28
|
-
const saveMock = jest.fn();
|
|
29
|
-
const save = jest.fn(() => saveMock);
|
|
30
|
-
const mockBlockCheckoutBookingHandler = jest.fn();
|
|
31
|
-
const { Component: Messaging } = bootstrap({ id: MESSAGING_CONTEXT_ID })
|
|
32
|
-
.command(
|
|
33
|
-
BLOCK_CHECKOUT_BOOKING,
|
|
34
|
-
mockBlockCheckoutBookingHandler,
|
|
35
|
-
{},
|
|
36
|
-
)(get, save)
|
|
37
|
-
.build();
|
|
38
|
-
|
|
39
|
-
beforeEach(() => {
|
|
40
|
-
logger.captureException.mockClear();
|
|
41
|
-
mockCreateToastNotification.mockClear();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe("useBlockCheckoutBooking integration hook", () => {
|
|
45
|
-
it("returns success as the status when 'block' succeeds", async () => {
|
|
46
|
-
mockBlockCheckoutBookingHandler.mockImplementation(() => () => ({ domainEvents: [] }));
|
|
47
|
-
const { result } = renderHook(() => sut({ checkoutBookingId, logger }), {
|
|
48
|
-
wrapper: Messaging,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
await act(() => {
|
|
52
|
-
const [blockCheckoutBooking] = result.current;
|
|
53
|
-
blockCheckoutBooking();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
await waitFor(() => {
|
|
57
|
-
const [, status] = result.current;
|
|
58
|
-
expect(status).toBe(CommandStatus.SUCCESS);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("calls logger.captureException and createNotification when 'block' fails", async () => {
|
|
63
|
-
const error = new Error("Some error");
|
|
64
|
-
mockBlockCheckoutBookingHandler.mockImplementation(() => () => {
|
|
65
|
-
throw error;
|
|
66
|
-
});
|
|
67
|
-
const { result } = renderHook(() => sut({ checkoutBookingId, logger }), {
|
|
68
|
-
wrapper: Messaging,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const [blockCheckoutBooking] = result.current;
|
|
72
|
-
|
|
73
|
-
expect(async () => blockCheckoutBooking()).rejects.toThrow();
|
|
74
|
-
|
|
75
|
-
await waitFor(() => {
|
|
76
|
-
const [, status] = result.current;
|
|
77
|
-
|
|
78
|
-
expect(status).toBe(CommandStatus.ERROR);
|
|
79
|
-
expect(logger.captureException).toHaveBeenCalledWith(error);
|
|
80
|
-
expect(mockCreateToastNotification).toHaveBeenCalled();
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
2
|
-
import invariant from "tiny-invariant";
|
|
3
|
-
import { CommandStatus, useCommand } from "@lookiero/messaging-react";
|
|
4
|
-
import { Logger } from "@lookiero/sty-psp-logging";
|
|
5
|
-
import { NotificationLevel, useCreateToastNotification } from "@lookiero/sty-psp-notifications";
|
|
6
|
-
import { blockCheckoutBooking as blockCheckoutBookingCommand } from "../../../../domain/checkoutBooking/command/blockCheckoutBooking";
|
|
7
|
-
import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
|
|
8
|
-
import { I18nMessages } from "../../../ui/i18n/i18n";
|
|
9
|
-
|
|
10
|
-
interface BlockCheckoutBookingFunction {
|
|
11
|
-
(): Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type UseBlockCheckoutBooking = [blockCheckoutBooking: BlockCheckoutBookingFunction, status: CommandStatus];
|
|
15
|
-
|
|
16
|
-
interface UseBlockCheckoutBookingFunctionArgs {
|
|
17
|
-
readonly checkoutBookingId: string | undefined;
|
|
18
|
-
readonly logger: Logger;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
interface UseBlockCheckoutBookingFunction {
|
|
22
|
-
(args: UseBlockCheckoutBookingFunctionArgs): UseBlockCheckoutBooking;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const useBlockCheckoutBooking: UseBlockCheckoutBookingFunction = ({ checkoutBookingId, logger }) => {
|
|
26
|
-
const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
|
|
27
|
-
const [createNotification] = useCreateToastNotification({ contextId: MESSAGING_CONTEXT_ID, logger });
|
|
28
|
-
|
|
29
|
-
const blockCheckoutBooking = useCallback(async () => {
|
|
30
|
-
invariant(checkoutBookingId, "checkoutBookingId is required");
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
await commandBus(
|
|
34
|
-
blockCheckoutBookingCommand({
|
|
35
|
-
aggregateId: checkoutBookingId,
|
|
36
|
-
}),
|
|
37
|
-
);
|
|
38
|
-
} catch (error) {
|
|
39
|
-
logger.captureException(error as Error);
|
|
40
|
-
createNotification({
|
|
41
|
-
level: NotificationLevel.ERROR,
|
|
42
|
-
bodyI18nKey: I18nMessages.TOAST_GENERIC_ERROR,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
}, [checkoutBookingId, commandBus, createNotification, logger]);
|
|
48
|
-
|
|
49
|
-
return [blockCheckoutBooking, status];
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export { useBlockCheckoutBooking };
|