added subscription id and customer id to the user data

This commit is contained in:
Jacob
2024-01-23 14:42:57 -05:00
parent d9e49487a3
commit b48c8212d3

View File

@@ -94,6 +94,9 @@ const SignupPage = () => {
email,
} = dataValues;
const subscriptionId = dataValues?.subscriptionId;
const customerId = dataValues?.customerId;
const userData = {
appUserId,
fbAuthUid,
@@ -109,6 +112,8 @@ const SignupPage = () => {
barNumber,
practiceArea,
email,
subscriptionId,
customerId,
};
try {
@@ -134,12 +139,14 @@ const SignupPage = () => {
setShowPaymentModal(true);
};
async function handleStripeAuthorization(paymentDataValues, customerDataValues) {
async function handleStripeAuthorization(user, paymentDataValues, customerDataValues) {
// Do: calls to Stripe API
// if success, return some truthy value or
// handle failure in handleSignup
let error = false;
let subscriptionId = null;
let customerId = null;
const token = await stripe.tokens.create({
card: {
@@ -166,12 +173,32 @@ const SignupPage = () => {
token,
}),
})
response = await response.json()
subscriptionId = response.subscriptionId;
customerId = response.customerId;
console.log('response', response);
return {
subscriptionId,
customerId,
}
}
catch (error) {
console.log(error)
error = true;
}
if(error) {
return false
}
return {
subscriptionId,
customerId,
}
return !error;
}
@@ -182,7 +209,7 @@ const SignupPage = () => {
return;
}
const dataValues = validateData();
let dataValues = validateData();
if (dataValues === null) {
return;
}
@@ -197,14 +224,21 @@ const SignupPage = () => {
);
const user = userCredential.user;
const paymentSuccess = await handleStripeAuthorization(paymentDataValues, dataValues);
const paymentResponse = await handleStripeAuthorization(user, paymentDataValues, dataValues);
if(paymentSuccess) {
await saveUserData(user.uid, dataValues);
navigate("/");
if(paymentResponse === false) {
// handle payment failure
setIsBusy(false);
setNotice(
"Sorry, something went wrong. Please try again."
);
return;
}
else {
// handle payment failure
dataValues = {...dataValues, ...paymentResponse};
await saveUserData(user.uid, dataValues);
navigate("/");
}
} catch (error) {
setIsBusy(false);