@@ -26,10 +26,10 @@ const Login = () => {
|
|||||||
email,
|
email,
|
||||||
password
|
password
|
||||||
);
|
);
|
||||||
|
|
||||||
// Signed in
|
// Signed in
|
||||||
userCredential?.user && navigate("/dashboard");
|
userCredential?.user && navigate("/dashboard");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log("error", error);
|
||||||
if (
|
if (
|
||||||
["auth/invalid-login-credentials", "auth/invalid-email"].includes(
|
["auth/invalid-login-credentials", "auth/invalid-email"].includes(
|
||||||
error.code
|
error.code
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ const SignupPage = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveUserData(authId, dataValues) {
|
async function saveUserData(authId, dataValues, customerId, subscriptionId) {
|
||||||
const appUserId = uuidv4();
|
const appUserId = uuidv4();
|
||||||
const firmId = uuidv4();
|
const firmId = uuidv4();
|
||||||
const fbAuthUid = authId;
|
const fbAuthUid = authId;
|
||||||
@@ -167,10 +167,11 @@ const SignupPage = () => {
|
|||||||
practiceArea,
|
practiceArea,
|
||||||
email,
|
email,
|
||||||
} = dataValues;
|
} = dataValues;
|
||||||
|
console.log(
|
||||||
const subscriptionId = dataValues?.subscriptionId;
|
"customerId, subscriptionId in saveUserData",
|
||||||
const customerId = dataValues?.customerId;
|
customerId,
|
||||||
|
subscriptionId
|
||||||
|
);
|
||||||
const userData = {
|
const userData = {
|
||||||
docsAllowed,
|
docsAllowed,
|
||||||
docsGenerated,
|
docsGenerated,
|
||||||
@@ -188,8 +189,8 @@ const SignupPage = () => {
|
|||||||
barNumber,
|
barNumber,
|
||||||
practiceArea,
|
practiceArea,
|
||||||
email,
|
email,
|
||||||
//subscriptionId,
|
customerId: customerId,
|
||||||
//customerId,
|
subscriptionId: subscriptionId,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -241,7 +242,6 @@ const SignupPage = () => {
|
|||||||
|
|
||||||
// ******************** STRIPE PAY API CALL ******************** //
|
// ******************** STRIPE PAY API CALL ******************** //
|
||||||
async function handleStripeAuthorization(
|
async function handleStripeAuthorization(
|
||||||
user,
|
|
||||||
paymentDataValues,
|
paymentDataValues,
|
||||||
customerDataValues
|
customerDataValues
|
||||||
) {
|
) {
|
||||||
@@ -267,7 +267,7 @@ const SignupPage = () => {
|
|||||||
|
|
||||||
const type = selectedPlan[0].value ? selectedPlan[0].value : null;
|
const type = selectedPlan[0].value ? selectedPlan[0].value : null;
|
||||||
try {
|
try {
|
||||||
let response = await fetch(`${apiUrl}/create-subscription`, {
|
const response = await fetch(`${apiUrl}/create-subscription`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -284,14 +284,14 @@ const SignupPage = () => {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
response = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
subscriptionId = response.subscriptionId;
|
console.log("data in stripe auth call -------------++++++++++++++", data);
|
||||||
customerId = response.customerId;
|
//subscriptionId = response.subscriptionId;
|
||||||
|
//customerId = response.customerId;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
subscriptionId,
|
data,
|
||||||
//customerId,
|
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
@@ -326,6 +326,19 @@ const SignupPage = () => {
|
|||||||
setIsBusy(true);
|
setIsBusy(true);
|
||||||
if (paymentDataValues && dataValues) {
|
if (paymentDataValues && dataValues) {
|
||||||
try {
|
try {
|
||||||
|
const data = await handleStripeAuthorization(
|
||||||
|
paymentDataValues,
|
||||||
|
dataValues
|
||||||
|
);
|
||||||
|
console.log("----------------------------->>>>>>>>>>>>>>>>>data", data);
|
||||||
|
const customerId = data.data.customerId;
|
||||||
|
const subscriptionId = data.data.subscriptionId;
|
||||||
|
|
||||||
|
if (data === undefined) {
|
||||||
|
setIsBusy(false);
|
||||||
|
setNotice("Sorry, something went wrong. Please try again.");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
const userCredential = await createUserWithEmailAndPassword(
|
const userCredential = await createUserWithEmailAndPassword(
|
||||||
auth,
|
auth,
|
||||||
dataValues.email,
|
dataValues.email,
|
||||||
@@ -333,24 +346,14 @@ const SignupPage = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const user = userCredential.user;
|
const user = userCredential.user;
|
||||||
|
dataValues = { ...dataValues, ...data };
|
||||||
const paymentResponse = await handleStripeAuthorization(
|
|
||||||
user,
|
|
||||||
paymentDataValues,
|
|
||||||
dataValues
|
|
||||||
);
|
|
||||||
console.log(
|
console.log(
|
||||||
"----------------------------->>>>>>>>>>>>>>>>>paymentResponse",
|
"customerId, subscriptionId in handleSignup right before saveUserData",
|
||||||
paymentResponse
|
customerId,
|
||||||
|
subscriptionId
|
||||||
);
|
);
|
||||||
if (paymentResponse === false) {
|
await saveUserData(user.uid, dataValues, customerId, subscriptionId);
|
||||||
setIsBusy(false);
|
navigate("/dashboard");
|
||||||
setNotice("Sorry, something went wrong. Please try again.");
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
dataValues = { ...dataValues, ...paymentResponse };
|
|
||||||
await saveUserData(user.uid, dataValues);
|
|
||||||
navigate("/");
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setIsBusy(false);
|
setIsBusy(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user