@lookiero/checkout 0.7.2 → 0.8.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/dist/index.d.ts CHANGED
@@ -20,8 +20,8 @@ interface FirstAvailableCheckoutByCustomerIdFunction {
20
20
  interface BootstrapFunctionArgs {
21
21
  readonly getAuthToken: () => Promise<string>;
22
22
  readonly apiUrl: string;
23
- readonly translations: EndpointFunction;
24
23
  readonly sentry: SentryLoggerFunctionArgs;
24
+ readonly translations: EndpointFunction[];
25
25
  }
26
26
  interface BootstrapFunctionReturn {
27
27
  readonly Root: ComponentType<RootProps>;
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
- import { fetchFetchTranslation } from "@lookiero/i18n";
2
1
  import { i18n } from "@lookiero/i18n-react";
3
2
  import { CheckoutStatus } from "./domain/checkout/model/checkout";
4
3
  import { bootstrap as checkoutBootstrap } from "./infrastructure/delivery/bootstrap";
5
4
  import { root } from "./infrastructure/ui/Root";
5
+ import { fetchTranslations } from "./infrastructure/ui/i18n/fetchTranslations";
6
6
  import { viewFirstAvailableCheckoutByCustomerId } from "./projection/checkout/viewFirstAvailableCheckoutByCustomerId";
7
7
  import { viewIsCheckoutAccessibleByCustomerId, } from "./projection/checkout/viewIsCheckoutAccessibleByCustomerId";
8
8
  const bootstrap = ({ apiUrl, getAuthToken, translations, sentry }) => {
9
9
  const { Component: Messaging, queryBus } = checkoutBootstrap({ apiUrl, getAuthToken });
10
10
  const I18n = i18n({
11
- fetchTranslation: fetchFetchTranslation({ endpoint: translations }),
11
+ fetchTranslation: fetchTranslations({ translations }),
12
12
  contextId: "CheckoutI18n",
13
13
  });
14
14
  const Root = root({ Messaging, I18n, getAuthToken, sentry });
@@ -20,29 +20,22 @@ const useSubmitCheckout = ({ checkoutId, checkoutBookingId, paymentFlowRef, onEr
20
20
  paymentFlowRef.current?.startLegacyBoxCheckout(
21
21
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
22
22
  // @ts-ignore
23
- paymentFlowPayload, async ({ status }) => {
23
+ paymentFlowPayload, async ({ status, toaster }) => {
24
24
  setStartLegacyBoxCheckoutStatus("loading");
25
- if (status === ChargeStatus.REJECTED) {
26
- createNotification({
27
- level: NotificationLevel.ERROR,
28
- bodyI18nKey: I18nMessages.CHECKOUT_TOAST_PAYMENT_REJECTED,
29
- });
30
- setStartLegacyBoxCheckoutStatus("error");
31
- }
32
- else if (status === ChargeStatus.ERROR) {
33
- createNotification({
34
- level: NotificationLevel.ERROR,
35
- bodyI18nKey: I18nMessages.CHECKOUT_TOAST_PAYMENT_ERROR,
36
- });
37
- setStartLegacyBoxCheckoutStatus("error");
38
- }
39
- else if (status === ChargeStatus.EXECUTED) {
25
+ if (status === ChargeStatus.EXECUTED) {
40
26
  setStartLegacyBoxCheckoutStatus("success");
41
27
  try {
42
28
  await submitCheckoutCommand();
43
29
  }
44
30
  catch (error) { }
45
31
  }
32
+ else {
33
+ createNotification({
34
+ level: NotificationLevel.ERROR,
35
+ bodyI18nKey: toaster?.id || I18nMessages.CHECKOUT_TOAST_PAYMENT_ERROR,
36
+ });
37
+ setStartLegacyBoxCheckoutStatus("error");
38
+ }
46
39
  });
47
40
  }, [blockCheckoutBooking, createNotification, submitCheckoutCommand, paymentFlowRef]);
48
41
  const status = useMemo(() => {
@@ -0,0 +1,9 @@
1
+ import { EndpointFunction, FetchTranslationFuction } from "@lookiero/i18n";
2
+ interface FetchTranslationsFuntionArgs {
3
+ readonly translations: EndpointFunction[];
4
+ }
5
+ interface FetchTranslationsFuntion {
6
+ (args: FetchTranslationsFuntionArgs): FetchTranslationFuction;
7
+ }
8
+ declare const fetchTranslations: FetchTranslationsFuntion;
9
+ export { fetchTranslations };
@@ -0,0 +1,9 @@
1
+ import { fetchFetchTranslation } from "@lookiero/i18n";
2
+ const fetchTranslations = ({ translations }) => async ({ locale }) => {
3
+ const translationsMessages = await Promise.all(translations.map((endpoint) => fetchFetchTranslation({ endpoint })({ locale })));
4
+ return translationsMessages.reduce((acc, translationMessages) => ({
5
+ ...acc,
6
+ ...translationMessages,
7
+ }), {});
8
+ };
9
+ export { fetchTranslations };
@@ -42,7 +42,6 @@ declare enum I18nMessages {
42
42
  PRODUCT_VARIANT_SIZE_CHANGE = "product_variant.size_change",
43
43
  CHECKOUT_TITLE = "checkout.title",
44
44
  CHECKOUT_PAY_BUTTON = "checkout.pay_button",
45
- CHECKOUT_TOAST_PAYMENT_REJECTED = "checkout.toast_payment_rejected",
46
45
  CHECKOUT_TOAST_PAYMENT_ERROR = "checkout.toast_payment_error",
47
46
  CHECKOUT_SUCCESS_MODAL_TITLE = "checkout.success_modal_title",
48
47
  CHECKOUT_SUCCESS_MODAL_DESCRIPTION = "checkout.success_modal_description",
@@ -43,7 +43,6 @@ var I18nMessages;
43
43
  I18nMessages["PRODUCT_VARIANT_SIZE_CHANGE"] = "product_variant.size_change";
44
44
  I18nMessages["CHECKOUT_TITLE"] = "checkout.title";
45
45
  I18nMessages["CHECKOUT_PAY_BUTTON"] = "checkout.pay_button";
46
- I18nMessages["CHECKOUT_TOAST_PAYMENT_REJECTED"] = "checkout.toast_payment_rejected";
47
46
  I18nMessages["CHECKOUT_TOAST_PAYMENT_ERROR"] = "checkout.toast_payment_error";
48
47
  I18nMessages["CHECKOUT_SUCCESS_MODAL_TITLE"] = "checkout.success_modal_title";
49
48
  I18nMessages["CHECKOUT_SUCCESS_MODAL_DESCRIPTION"] = "checkout.success_modal_description";
@@ -0,0 +1,10 @@
1
+ import { EndpointFunction } from "@lookiero/i18n";
2
+ interface TranslationEndpointFunctionArgs {
3
+ readonly translationsUrl: string;
4
+ readonly translationsApiKey: string;
5
+ }
6
+ interface TranslationEndpointFunction {
7
+ (args: TranslationEndpointFunctionArgs): EndpointFunction;
8
+ }
9
+ declare const translationEndpoint: TranslationEndpointFunction;
10
+ export { translationEndpoint };
@@ -0,0 +1,2 @@
1
+ const translationEndpoint = ({ translationsUrl, translationsApiKey }) => (locale) => `${translationsUrl}/${locale}?key=${translationsApiKey}&no-folding=true`;
2
+ export { translationEndpoint };
@@ -29,7 +29,7 @@ interface PaymentFlowPayloadReplacedItem extends PaymentFlowPayloadItem {
29
29
  interface PaymentFlowPayloadKeptItem extends PaymentFlowPayloadItem {
30
30
  }
31
31
  interface PaymentFlowPayloadProjection {
32
- readonly bookingId: string;
32
+ readonly bookingId: string | undefined;
33
33
  readonly orderId: string;
34
34
  readonly comment: string;
35
35
  readonly items: (PaymentFlowPayloadKeptItem | PaymentFlowPayloadReplacedItem | PaymentFlowPayloadReturnedItem)[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lookiero/checkout",
3
- "version": "0.7.2",
3
+ "version": "0.8.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [