fix: add timeout createSubscriptionReceipt stripe
This commit is contained in:
parent
e67bb75739
commit
59783fb846
@ -1,6 +1,6 @@
|
|||||||
import { useApi } from "@/api";
|
import { useApi } from "@/api";
|
||||||
import Loader from "@/components/Loader";
|
import Loader from "@/components/Loader";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { Stripe, loadStripe } from "@stripe/stripe-js";
|
import { Stripe, loadStripe } from "@stripe/stripe-js";
|
||||||
import { Elements } from "@stripe/react-stripe-js";
|
import { Elements } from "@stripe/react-stripe-js";
|
||||||
import CheckoutForm from "../PaymentPage/methods/Stripe/CheckoutForm";
|
import CheckoutForm from "../PaymentPage/methods/Stripe/CheckoutForm";
|
||||||
@ -31,6 +31,7 @@ export function StripePage(): JSX.Element {
|
|||||||
if (!activeSubPlan) {
|
if (!activeSubPlan) {
|
||||||
navigate(routes.client.priceList());
|
navigate(routes.client.priceList());
|
||||||
}
|
}
|
||||||
|
const timeoutRef = useRef<NodeJS.Timeout>();
|
||||||
|
|
||||||
// const appleReceipt = async () => {
|
// const appleReceipt = async () => {
|
||||||
// const { subscription_receipt } = await api.createSubscriptionReceipt({
|
// const { subscription_receipt } = await api.createSubscriptionReceipt({
|
||||||
@ -58,7 +59,7 @@ export function StripePage(): JSX.Element {
|
|||||||
}, [activeSubPlan, api, locale, navigate]);
|
}, [activeSubPlan, api, locale, navigate]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
timeoutRef.current = setTimeout(async () => {
|
||||||
const { subscription_receipt } = await api.createSubscriptionReceipt({
|
const { subscription_receipt } = await api.createSubscriptionReceipt({
|
||||||
token,
|
token,
|
||||||
way: "stripe",
|
way: "stripe",
|
||||||
@ -69,7 +70,12 @@ export function StripePage(): JSX.Element {
|
|||||||
const { client_secret } = subscription_receipt.data;
|
const { client_secret } = subscription_receipt.data;
|
||||||
setClientSecret(client_secret);
|
setClientSecret(client_secret);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
})();
|
}, 4000);
|
||||||
|
return () => {
|
||||||
|
if (timeoutRef.current) {
|
||||||
|
clearTimeout(timeoutRef.current);
|
||||||
|
}
|
||||||
|
};
|
||||||
}, [api, token]);
|
}, [api, token]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user