diff --git a/src/components/UserSubscription/ProcessedPayment.jsx b/src/components/UserSubscription/ProcessedPayment.jsx
index a27a044c..b86a00d5 100644
--- a/src/components/UserSubscription/ProcessedPayment.jsx
+++ b/src/components/UserSubscription/ProcessedPayment.jsx
@@ -54,12 +54,12 @@ const ProcessedPayment = ({
const { mutate: MakePayment, isPending } = useMakePayment(
(response) => {
- debugger
+
unblockUI();
onNext(response);
},
(fail) => {
- debu
+
unblockUI();
setFailPayment(fail);
onNext(fail);
diff --git a/src/components/UserSubscription/SubscriptionForm.jsx b/src/components/UserSubscription/SubscriptionForm.jsx
index 73353f1e..bada7426 100644
--- a/src/components/UserSubscription/SubscriptionForm.jsx
+++ b/src/components/UserSubscription/SubscriptionForm.jsx
@@ -237,7 +237,7 @@ const SubscriptionForm = ({ currentStep, setCurrentStep, setStepStatus }) => {
className="btn btn-label-primary d-flex align-items-center me-2"
>
{isPending ? (
- Please Wait...
+ Please Wait...
) : (
<>
Next
diff --git a/src/hooks/usePayment.jsx b/src/hooks/usePayment.jsx
index b1699526..bfe19fe8 100644
--- a/src/hooks/usePayment.jsx
+++ b/src/hooks/usePayment.jsx
@@ -2,7 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { PaymentRepository } from "../repositories/PaymentRepository";
import showToast from "../services/toastService";
import { useSelector } from "react-redux";
-import { blockUI } from "../utils/blockUI";
+import { blockUI, unblockUI } from "../utils/blockUI";
export const removeRazorpayArtifacts=()=> {
try {
@@ -85,13 +85,10 @@ export const useMakePayment = (
const { tenantEnquireId, planId } = useSelector(
(store) => store.localVariables.selfTenant
);
+
const { mutate: verifyPayment } = useVerifyPayment(
- (response) => {
- if (onSuccessCallBack) onSuccessCallBack(response);
- },
- (error) => {
- if (onFailureCallBack) onFailureCallBack(error);
- }
+ (response) => onSuccessCallBack?.(response),
+ (error) => onFailureCallBack?.(error)
);
return useMutation({
@@ -106,6 +103,8 @@ export const useMakePayment = (
return;
}
+ let manuallyClosed = false;
+
const options = {
key,
amount: (currentPlan?.amount ?? 1) * 100,
@@ -114,10 +113,15 @@ export const useMakePayment = (
order_id: orderId,
handler: async (response) => {
+ if (manuallyClosed) {
+ unblockUI()
+ return;
+ }
+
try {
const payload = {
- tenantEnquireId: tenantEnquireId,
- planId: planId,
+ tenantEnquireId,
+ planId,
orderId: response.razorpay_order_id,
paymentId: response.razorpay_payment_id,
signature: response.razorpay_signature,
@@ -138,42 +142,29 @@ export const useMakePayment = (
modal: {
ondismiss: () => {
- if (onFailureCallBack) {
- onFailureCallBack({
- status: "failed",
- message: "Payment was cancelled before completion.",
- reason: "popup_closed",
- });
- }
+ manuallyClosed = true;
+ unblockUI();
closeRazorpayPopup();
},
},
};
try {
- setTimeout(() => {
- const razorpay = new window.Razorpay(options);
+ const razorpay = new window.Razorpay(options);
- razorpay.on("payment.failed", (response) => {
- if (onFailureCallBack) {
- onFailureCallBack({
- status: "failed",
- message: response.error?.description || "Payment failed.",
- error: response.error,
- reason: "transaction_failed",
- });
- }
- closeRazorpayPopup();
+ razorpay.on("payment.failed", (response) => {
+ if (manuallyClosed) return;
+ onFailureCallBack?.({
+ status: "failed",
+ message: response.error?.description || "Payment failed.",
+ error: response.error,
+ reason: "transaction_failed",
});
+ closeRazorpayPopup();
+ });
- try {
- blockUI("Please Wait...")
- razorpay.open();
- } catch (err) {
- alert("This browser is not supported. Please try another browser.");
- closeRazorpayPopup();
- }
- }, 300);
+ blockUI("Please Wait...");
+ razorpay.open();
} catch (err) {
alert("This browser is not supported. Please try another browser.");
closeRazorpayPopup();
diff --git a/src/pages/Home/MakeSubscription.jsx b/src/pages/Home/MakeSubscription.jsx
index 609dbd0b..1a610872 100644
--- a/src/pages/Home/MakeSubscription.jsx
+++ b/src/pages/Home/MakeSubscription.jsx
@@ -8,7 +8,7 @@ import SelectPlan from "../../components/UserSubscription/SelectPlan";
import Review from "../../components/UserSubscription/Review";
const MakeSubscription = () => {
- const [currentStep, setCurrentStep] = useState(4);
+ const [currentStep, setCurrentStep] = useState(1);
const [responsePayment, setResponsePayment] = useState(null);
const [stepStatus, setStepStatus] = useState({
@@ -22,19 +22,21 @@ const MakeSubscription = () => {
const handleVerification = (resp) => {
setResponsePayment(resp);
if (resp?.success) {
- setStepStatus((prev) => ({ ...prev, 4: "success" }));
- setCurrentStep(3);
+ setStepStatus((prev) => ({ ...prev, 4: "success" }));
+ setCurrentStep(5);
} else {
setStepStatus((prev) => ({ ...prev, 4: "failed" }));
}
};
-const handleNext = () => {
- setStepStatus((prev) => ({
- ...prev,
- [currentStep + 1]: "pending",
- }));
- setCurrentStep((prev) => prev + 1);
-};
+ const handleNext = () => {
+ setStepStatus((prev) => ({
+ ...prev,
+ [currentStep]: "success",
+ [currentStep + 1]: "pending",
+ }));
+
+ setCurrentStep((prev) => prev + 1);
+ };
const checkOut_Steps = [
{
@@ -53,7 +55,7 @@ const handleNext = () => {
),
},
@@ -62,7 +64,6 @@ const handleNext = () => {
component: () => (
handleVerification(resp)}
-
resetPaymentStep={() =>
setStepStatus((prev) => ({ ...prev, 4: "pending" }))
}
@@ -78,9 +79,8 @@ const handleNext = () => {
{
name: "Payment",
component: () => (
- handleVerification(resp)}
-
resetPaymentStep={() =>
setStepStatus((prev) => ({ ...prev, 4: "pending" }))
}
@@ -97,7 +97,9 @@ const handleNext = () => {
name: "Verified",
component: () => (
({ ...prev, 4: "success" })}
+ onNext={() => {
+ setStepStatus((prev) => ({ ...prev, 5: "success" }))
+ }}
responsePayment={responsePayment}
/>
),