integrated partiallly payment gatway , in this changes handle if payment suucess, fail and close - response
This commit is contained in:
parent
3c89a78034
commit
0dba21fe0d
@ -54,12 +54,12 @@ const ProcessedPayment = ({
|
|||||||
|
|
||||||
const { mutate: MakePayment, isPending } = useMakePayment(
|
const { mutate: MakePayment, isPending } = useMakePayment(
|
||||||
(response) => {
|
(response) => {
|
||||||
debugger
|
|
||||||
unblockUI();
|
unblockUI();
|
||||||
onNext(response);
|
onNext(response);
|
||||||
},
|
},
|
||||||
(fail) => {
|
(fail) => {
|
||||||
debu
|
|
||||||
unblockUI();
|
unblockUI();
|
||||||
setFailPayment(fail);
|
setFailPayment(fail);
|
||||||
onNext(fail);
|
onNext(fail);
|
||||||
|
|||||||
@ -237,7 +237,7 @@ const SubscriptionForm = ({ currentStep, setCurrentStep, setStepStatus }) => {
|
|||||||
className="btn btn-label-primary d-flex align-items-center me-2"
|
className="btn btn-label-primary d-flex align-items-center me-2"
|
||||||
>
|
>
|
||||||
{isPending ? (
|
{isPending ? (
|
||||||
<span><i class='bx bx-loader-alt bx-md bx-spin me-2'></i>Please Wait...</span>
|
<span><i className='bx bx-loader-alt bx-md bx-spin me-2'></i>Please Wait...</span>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<span className="me-1">Next</span>
|
<span className="me-1">Next</span>
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|||||||
import { PaymentRepository } from "../repositories/PaymentRepository";
|
import { PaymentRepository } from "../repositories/PaymentRepository";
|
||||||
import showToast from "../services/toastService";
|
import showToast from "../services/toastService";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { blockUI } from "../utils/blockUI";
|
import { blockUI, unblockUI } from "../utils/blockUI";
|
||||||
|
|
||||||
export const removeRazorpayArtifacts=()=> {
|
export const removeRazorpayArtifacts=()=> {
|
||||||
try {
|
try {
|
||||||
@ -85,13 +85,10 @@ export const useMakePayment = (
|
|||||||
const { tenantEnquireId, planId } = useSelector(
|
const { tenantEnquireId, planId } = useSelector(
|
||||||
(store) => store.localVariables.selfTenant
|
(store) => store.localVariables.selfTenant
|
||||||
);
|
);
|
||||||
|
|
||||||
const { mutate: verifyPayment } = useVerifyPayment(
|
const { mutate: verifyPayment } = useVerifyPayment(
|
||||||
(response) => {
|
(response) => onSuccessCallBack?.(response),
|
||||||
if (onSuccessCallBack) onSuccessCallBack(response);
|
(error) => onFailureCallBack?.(error)
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
if (onFailureCallBack) onFailureCallBack(error);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
@ -106,6 +103,8 @@ export const useMakePayment = (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let manuallyClosed = false;
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
key,
|
key,
|
||||||
amount: (currentPlan?.amount ?? 1) * 100,
|
amount: (currentPlan?.amount ?? 1) * 100,
|
||||||
@ -114,10 +113,15 @@ export const useMakePayment = (
|
|||||||
order_id: orderId,
|
order_id: orderId,
|
||||||
|
|
||||||
handler: async (response) => {
|
handler: async (response) => {
|
||||||
|
if (manuallyClosed) {
|
||||||
|
unblockUI()
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const payload = {
|
const payload = {
|
||||||
tenantEnquireId: tenantEnquireId,
|
tenantEnquireId,
|
||||||
planId: planId,
|
planId,
|
||||||
orderId: response.razorpay_order_id,
|
orderId: response.razorpay_order_id,
|
||||||
paymentId: response.razorpay_payment_id,
|
paymentId: response.razorpay_payment_id,
|
||||||
signature: response.razorpay_signature,
|
signature: response.razorpay_signature,
|
||||||
@ -138,46 +142,33 @@ export const useMakePayment = (
|
|||||||
|
|
||||||
modal: {
|
modal: {
|
||||||
ondismiss: () => {
|
ondismiss: () => {
|
||||||
if (onFailureCallBack) {
|
manuallyClosed = true;
|
||||||
onFailureCallBack({
|
unblockUI();
|
||||||
status: "failed",
|
|
||||||
message: "Payment was cancelled before completion.",
|
|
||||||
reason: "popup_closed",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
closeRazorpayPopup();
|
closeRazorpayPopup();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setTimeout(() => {
|
|
||||||
const razorpay = new window.Razorpay(options);
|
const razorpay = new window.Razorpay(options);
|
||||||
|
|
||||||
razorpay.on("payment.failed", (response) => {
|
razorpay.on("payment.failed", (response) => {
|
||||||
if (onFailureCallBack) {
|
if (manuallyClosed) return;
|
||||||
onFailureCallBack({
|
onFailureCallBack?.({
|
||||||
status: "failed",
|
status: "failed",
|
||||||
message: response.error?.description || "Payment failed.",
|
message: response.error?.description || "Payment failed.",
|
||||||
error: response.error,
|
error: response.error,
|
||||||
reason: "transaction_failed",
|
reason: "transaction_failed",
|
||||||
});
|
});
|
||||||
}
|
|
||||||
closeRazorpayPopup();
|
closeRazorpayPopup();
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
blockUI("Please Wait...");
|
||||||
blockUI("Please Wait...")
|
|
||||||
razorpay.open();
|
razorpay.open();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert("This browser is not supported. Please try another browser.");
|
alert("This browser is not supported. Please try another browser.");
|
||||||
closeRazorpayPopup();
|
closeRazorpayPopup();
|
||||||
}
|
}
|
||||||
}, 300);
|
|
||||||
} catch (err) {
|
|
||||||
alert("This browser is not supported. Please try another browser.");
|
|
||||||
closeRazorpayPopup();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import SelectPlan from "../../components/UserSubscription/SelectPlan";
|
|||||||
import Review from "../../components/UserSubscription/Review";
|
import Review from "../../components/UserSubscription/Review";
|
||||||
|
|
||||||
const MakeSubscription = () => {
|
const MakeSubscription = () => {
|
||||||
const [currentStep, setCurrentStep] = useState(4);
|
const [currentStep, setCurrentStep] = useState(1);
|
||||||
const [responsePayment, setResponsePayment] = useState(null);
|
const [responsePayment, setResponsePayment] = useState(null);
|
||||||
|
|
||||||
const [stepStatus, setStepStatus] = useState({
|
const [stepStatus, setStepStatus] = useState({
|
||||||
@ -23,18 +23,20 @@ const MakeSubscription = () => {
|
|||||||
setResponsePayment(resp);
|
setResponsePayment(resp);
|
||||||
if (resp?.success) {
|
if (resp?.success) {
|
||||||
setStepStatus((prev) => ({ ...prev, 4: "success" }));
|
setStepStatus((prev) => ({ ...prev, 4: "success" }));
|
||||||
setCurrentStep(3);
|
setCurrentStep(5);
|
||||||
} else {
|
} else {
|
||||||
setStepStatus((prev) => ({ ...prev, 4: "failed" }));
|
setStepStatus((prev) => ({ ...prev, 4: "failed" }));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const handleNext = () => {
|
const handleNext = () => {
|
||||||
setStepStatus((prev) => ({
|
setStepStatus((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
|
[currentStep]: "success",
|
||||||
[currentStep + 1]: "pending",
|
[currentStep + 1]: "pending",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
setCurrentStep((prev) => prev + 1);
|
setCurrentStep((prev) => prev + 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkOut_Steps = [
|
const checkOut_Steps = [
|
||||||
{
|
{
|
||||||
@ -62,7 +64,6 @@ const handleNext = () => {
|
|||||||
component: () => (
|
component: () => (
|
||||||
<ProcessedPayment
|
<ProcessedPayment
|
||||||
onNext={(resp) => handleVerification(resp)}
|
onNext={(resp) => handleVerification(resp)}
|
||||||
|
|
||||||
resetPaymentStep={() =>
|
resetPaymentStep={() =>
|
||||||
setStepStatus((prev) => ({ ...prev, 4: "pending" }))
|
setStepStatus((prev) => ({ ...prev, 4: "pending" }))
|
||||||
}
|
}
|
||||||
@ -80,7 +81,6 @@ const handleNext = () => {
|
|||||||
component: () => (
|
component: () => (
|
||||||
<ProcessedPayment
|
<ProcessedPayment
|
||||||
onNext={(resp) => handleVerification(resp)}
|
onNext={(resp) => handleVerification(resp)}
|
||||||
|
|
||||||
resetPaymentStep={() =>
|
resetPaymentStep={() =>
|
||||||
setStepStatus((prev) => ({ ...prev, 4: "pending" }))
|
setStepStatus((prev) => ({ ...prev, 4: "pending" }))
|
||||||
}
|
}
|
||||||
@ -97,7 +97,9 @@ const handleNext = () => {
|
|||||||
name: "Verified",
|
name: "Verified",
|
||||||
component: () => (
|
component: () => (
|
||||||
<VerifiedPayment
|
<VerifiedPayment
|
||||||
onNext={(prev) => ({ ...prev, 4: "success" })}
|
onNext={() => {
|
||||||
|
setStepStatus((prev) => ({ ...prev, 5: "success" }))
|
||||||
|
}}
|
||||||
responsePayment={responsePayment}
|
responsePayment={responsePayment}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user