@lookiero/checkout 0.8.3-beta.0 → 0.8.3-beta.2

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.
@@ -1,37 +1,37 @@
1
1
  import { useEvent } from "@lookiero/event";
2
- import { useEffect } from "react";
2
+ import { useCallback, useEffect } from "react";
3
3
  import { useCreateNotification } from "../../../shared/notifications";
4
4
  import { NotificationLevel } from "../../../shared/notifications/domain/notification/model/notification";
5
5
  import { MESSAGING_CONTEXT_ID } from "../../delivery/baseBootstrap";
6
6
  import { I18nMessages } from "../i18n/i18n";
7
+ const PAYMENT_ERROR = "ERROR";
8
+ const PAYMENT_SUCCESS = "PAYMENT_INSTRUMENT_UPDATED";
7
9
  const usePaymentInstrumentUpdateEvents = () => {
8
10
  const { subscribe, unsubscribe } = useEvent();
9
11
  const [createNotification] = useCreateNotification({ contextId: MESSAGING_CONTEXT_ID });
12
+ const onSuccess = useCallback(({ message }) => {
13
+ console.log({ message });
14
+ createNotification({
15
+ level: NotificationLevel.SUCCESS,
16
+ bodyI18nKey: message.id,
17
+ });
18
+ }, [createNotification]);
19
+ const onError = useCallback(({ error }) => {
20
+ console.log({ error });
21
+ createNotification({
22
+ level: NotificationLevel.ERROR,
23
+ bodyI18nKey: error.toaster?.id || I18nMessages.CHECKOUT_TOAST_PAYMENT_ERROR,
24
+ });
25
+ }, [createNotification]);
10
26
  useEffect(() => {
11
- // if (disabled) return;
12
- const onSuccess = ({ message }) => {
13
- // if (notifySuccess) {
14
- createNotification({
15
- level: NotificationLevel.SUCCESS,
16
- bodyI18nKey: message.id || I18nMessages.CHECKOUT_TOAST_PAYMENT_ERROR,
17
- });
18
- // }
19
- };
20
- const onError = ({ error }) => {
21
- console.log({ error });
22
- createNotification({
23
- level: NotificationLevel.ERROR,
24
- bodyI18nKey: error.toaster?.id || I18nMessages.CHECKOUT_TOAST_PAYMENT_ERROR,
25
- });
26
- };
27
27
  console.log("subscribe");
28
- subscribe({ event: "ERROR" }, onError);
29
- subscribe({ event: "PAYMENT_INSTRUMENT_UPDATED" }, onSuccess);
28
+ subscribe({ event: PAYMENT_ERROR }, onError);
29
+ subscribe({ event: PAYMENT_SUCCESS }, onSuccess);
30
30
  return () => {
31
31
  console.log("unsubscribe");
32
- unsubscribe({ event: "ERROR" }, onError);
33
- unsubscribe({ event: "PAYMENT_INSTRUMENT_UPDATED" }, onSuccess);
32
+ unsubscribe({ event: PAYMENT_ERROR }, onError);
33
+ unsubscribe({ event: PAYMENT_SUCCESS }, onSuccess);
34
34
  };
35
- }, [subscribe, unsubscribe, createNotification]);
35
+ }, [subscribe, unsubscribe, createNotification, onError, onSuccess]);
36
36
  };
37
37
  export { usePaymentInstrumentUpdateEvents };
@@ -1,8 +1,7 @@
1
1
  import { Text } from "@lookiero/aurora-next/build/components/primitives/Text/Text";
2
2
  import { useI18nMessage } from "@lookiero/i18n-react";
3
3
  import { QueryStatus } from "@lookiero/messaging-react";
4
- import { PaymentInstrumentSelect, PaymentMethod, Section } from "@lookiero/payments-front";
5
- import React, { useCallback, useMemo, useRef } from "react";
4
+ import React, { useCallback, useMemo } from "react";
6
5
  import { Platform, View } from "react-native";
7
6
  import { useNavigate } from "react-router-native";
8
7
  import { CheckoutItemStatus } from "../../../../domain/checkoutItem/model/checkoutItem";
@@ -13,7 +12,6 @@ import { useViewPricingByCheckoutId } from "../../../projection/pricing/react/us
13
12
  import { TrackingPage } from "../../../tracking/tracking";
14
13
  import { Body } from "../../components/layouts/body/Body";
15
14
  import { SafeAreaScrollView } from "../../components/templates/SafeAreaScrollView";
16
- import { usePaymentInstrumentUpdateEvents } from "../../hooks/usePaymentInstrumentUpdateEvents";
17
15
  import { I18nMessages } from "../../i18n/i18n";
18
16
  import { Routes } from "../../routing/routes";
19
17
  import { useBasePath } from "../../routing/useBasePath";
@@ -22,9 +20,9 @@ import { HEADER_HEIGHT } from "../navigation/components/header/Header.style";
22
20
  import { Pricing } from "../summary/components/pricing/Pricing";
23
21
  import { style } from "./Checkout.style";
24
22
  import { DeliveryBanner } from "./components/deliveryBanner/DeliveryBanner";
23
+ import { PaymentInstrument } from "./components/paymentInstrument/PaymentInstrument";
25
24
  const Checkout = ({ children, customerId, country, useRedirect }) => {
26
25
  const titleText = useI18nMessage({ id: I18nMessages.CHECKOUT_TITLE });
27
- const paymentInstrumentSelectRef = useRef(null);
28
26
  const [checkout, checkoutStatus] = useViewFirstAvailableCheckoutByCustomerId({ customerId });
29
27
  const [pricing, pricingStatus] = useViewPricingByCheckoutId({ checkoutId: checkout?.id });
30
28
  usePageView({
@@ -32,10 +30,8 @@ const Checkout = ({ children, customerId, country, useRedirect }) => {
32
30
  country,
33
31
  checkoutId: checkout?.id,
34
32
  });
35
- usePaymentInstrumentUpdateEvents();
36
33
  const navigate = useNavigate();
37
34
  const basePath = useBasePath();
38
- const { returnUrl } = useRedirect();
39
35
  const handleOnSubmit = useCallback(() => {
40
36
  navigate(`${basePath}/${Routes.CHECKOUT}/${Routes.CHECKOUT_PAYMENT}`);
41
37
  }, [basePath, navigate]);
@@ -51,7 +47,7 @@ const Checkout = ({ children, customerId, country, useRedirect }) => {
51
47
  React.createElement(Body, { style: { column: style.bodyColumn } },
52
48
  hasReplacedCheckoutItem && (React.createElement(View, { style: style.deliveryBannerContainer },
53
49
  React.createElement(DeliveryBanner, null))),
54
- React.createElement(PaymentInstrumentSelect, { ref: paymentInstrumentSelectRef, beforeRedirect: returnUrl ? () => Promise.resolve(returnUrl) : undefined, hasError: false, hidePaymentMethods: [PaymentMethod.GOOGLE_PAY], section: Section.BOX_CHECKOUT }),
50
+ React.createElement(PaymentInstrument, { useRedirect: useRedirect }),
55
51
  React.createElement(Text, { level: 3, style: style.title, heading: true }, titleText),
56
52
  checkoutItemsKept?.map((checkoutItem) => (React.createElement(View, { key: checkoutItem.id, style: style.checkoutItemKept, testID: "checkout-items-kept" },
57
53
  React.createElement(ProductVariant, { brand: checkoutItem.productVariant.brand, color: checkoutItem.productVariant.color, country: country, media: checkoutItem.productVariant.media, name: checkoutItem.productVariant.name, price: checkoutItem.price, status: checkoutItem.status, size: checkoutItem.status === CheckoutItemStatus.REPLACED && checkoutItem.replacedFor
@@ -0,0 +1,6 @@
1
+ import { FC } from "react";
2
+ interface PaymentInstrumentProps {
3
+ readonly useRedirect: () => Record<string, string>;
4
+ }
5
+ declare const PaymentInstrument: FC<PaymentInstrumentProps>;
6
+ export { PaymentInstrument };
@@ -0,0 +1,10 @@
1
+ import { PaymentInstrumentSelect, PaymentMethod, Section } from "@lookiero/payments-front";
2
+ import React, { useRef } from "react";
3
+ import { usePaymentInstrumentUpdateEvents } from "../../../../hooks/usePaymentInstrumentUpdateEvents";
4
+ const PaymentInstrument = ({ useRedirect }) => {
5
+ const paymentInstrumentSelectRef = useRef(null);
6
+ const { returnUrl } = useRedirect();
7
+ usePaymentInstrumentUpdateEvents();
8
+ return (React.createElement(PaymentInstrumentSelect, { ref: paymentInstrumentSelectRef, beforeRedirect: returnUrl ? () => Promise.resolve(returnUrl) : undefined, hasError: false, hidePaymentMethods: [PaymentMethod.GOOGLE_PAY], section: Section.BOX_CHECKOUT }));
9
+ };
10
+ export { PaymentInstrument };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lookiero/checkout",
3
- "version": "0.8.3-beta.0",
3
+ "version": "0.8.3-beta.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [