From 8c11044e6b616db6e282fb509eeea9a94fea2c90 Mon Sep 17 00:00:00 2001 From: delemeator Date: Tue, 10 Sep 2024 19:03:10 +0200 Subject: [PATCH 1/5] Create dummyComponent.tsx --- .../PaymentSection/Dummy/dummyComponent.tsx | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/checkout/sections/PaymentSection/Dummy/dummyComponent.tsx diff --git a/src/checkout/sections/PaymentSection/Dummy/dummyComponent.tsx b/src/checkout/sections/PaymentSection/Dummy/dummyComponent.tsx new file mode 100644 index 000000000..e6a92c0a1 --- /dev/null +++ b/src/checkout/sections/PaymentSection/Dummy/dummyComponent.tsx @@ -0,0 +1,57 @@ +"use client"; + +import { useState } from "react"; +import { apiErrorMessages } from "../errorMessages"; +import { dummyGatewayId } from "./types"; +import { useTransactionInitializeMutation } from "@/checkout/graphql"; + +import { useAlerts } from "@/checkout/hooks/useAlerts"; +import { useErrorMessages } from "@/checkout/hooks/useErrorMessages"; +import { useCheckout } from "@/checkout/hooks/useCheckout"; +import { Button } from "@/checkout/components"; +import { useCheckoutComplete } from "@/checkout/hooks/useCheckoutComplete"; + +export const DummyComponent = () => { + const [loading, setLoading] = useState(false); + const { checkout } = useCheckout(); + const { deliveryMethod } = checkout; + + const { showCustomErrors } = useAlerts(); + const [, transactionInitialize] = useTransactionInitializeMutation(); + const { errorMessages: commonErrorMessages } = useErrorMessages(apiErrorMessages); + const { onCheckoutComplete, completingCheckout } = useCheckoutComplete(); + + const pay = async () => { + setLoading(true); + + transactionInitialize({ + checkoutId: checkout.id, + paymentGateway: { + id: dummyGatewayId, + data: { + event: { + type: "CHARGE_SUCCESS", + includePspReference: true, + }, + }, + }, + }).catch((err) => { + console.error(err); + showCustomErrors([{ message: commonErrorMessages.somethingWentWrong }]); + }); + + void onCheckoutComplete(); + + setLoading(false); + }; + + if (!deliveryMethod) { + return null; + } + + if (loading || completingCheckout) { + return

Przetwarzanie płatności...

; + } + + return