* Build HitPay app * Deleted a lint comment * Add redirect for iframe * Fix type check error * Fixed issue of payment pending * Update hitpay package.json * fix: fix lint issue in KeyInput and update zod * fix: fix issue of parsing string to number * fix: add default hitpay API links * fix: resolve atoms build error --------- Co-authored-by: kutsaniuk <kutsaniuk@gmail.com>
44 lines
966 B
TypeScript
44 lines
966 B
TypeScript
import { useEffect } from "react";
|
|
import { z } from "zod";
|
|
|
|
const PaymentHitpayDataSchema = z.object({
|
|
url: z.string(),
|
|
});
|
|
|
|
interface IPaymentComponentProps {
|
|
payment: {
|
|
data: unknown;
|
|
};
|
|
}
|
|
|
|
export const HitpayPaymentComponent = (props: IPaymentComponentProps) => {
|
|
const { payment } = props;
|
|
const { data } = payment;
|
|
const wrongUrl = (
|
|
<>
|
|
<p className="mt-3 text-center">Couldn't obtain payment URL</p>
|
|
</>
|
|
);
|
|
|
|
const parsedData = PaymentHitpayDataSchema.safeParse(data);
|
|
|
|
useEffect(() => {
|
|
if (window) {
|
|
if (parsedData.success) {
|
|
if (window.self !== window.top && window.top) {
|
|
window.top.open(parsedData.data.url, "_blank");
|
|
} else {
|
|
window.location.href = parsedData.data.url;
|
|
}
|
|
}
|
|
}
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, []);
|
|
|
|
if (!parsedData.success || !parsedData.data?.url) {
|
|
return wrongUrl;
|
|
}
|
|
|
|
return <div />;
|
|
};
|