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