email to complete payment on sign up
parent
ec879241c1
commit
617f521708
|
@ -109,10 +109,7 @@ export async function CreateCheckoutSession(priceId: string, userId: string) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cachedPrices.length === 0) {
|
await loadPrices();
|
||||||
logger.info("Loading prices from Stripe API");
|
|
||||||
await loadPrices();
|
|
||||||
}
|
|
||||||
|
|
||||||
const session = await stripe.checkout.sessions.create({
|
const session = await stripe.checkout.sessions.create({
|
||||||
payment_method_types: ["card"],
|
payment_method_types: ["card"],
|
||||||
|
@ -133,6 +130,7 @@ export async function CreateCheckoutSession(priceId: string, userId: string) {
|
||||||
await UserPendingPayment.create({
|
await UserPendingPayment.create({
|
||||||
payment_session_id: session.id,
|
payment_session_id: session.id,
|
||||||
user_id: userId,
|
user_id: userId,
|
||||||
|
payment_session_url: session.url as string,
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.info(`CreateCheckoutSession: ${session.id}`);
|
logger.info(`CreateCheckoutSession: ${session.id}`);
|
||||||
|
|
|
@ -43,6 +43,7 @@ import verifyCaptcha from "../utils/recaptcha";
|
||||||
import EmailVerification from "../models/emailVerification";
|
import EmailVerification from "../models/emailVerification";
|
||||||
import UserPendingEmailChange from "../models/userPendingEmailChange";
|
import UserPendingEmailChange from "../models/userPendingEmailChange";
|
||||||
import { CreateCheckoutSession, getPriceId } from "./paymentController";
|
import { CreateCheckoutSession, getPriceId } from "./paymentController";
|
||||||
|
import UserPendingPayment from "../models/userPendingPayment";
|
||||||
|
|
||||||
export async function SignUp(req: Request, res: Response) {
|
export async function SignUp(req: Request, res: Response) {
|
||||||
try {
|
try {
|
||||||
|
@ -217,6 +218,36 @@ export async function Login(req: Request, res: Response) {
|
||||||
// and only needs to enter their email to get the user state to know what to do next
|
// and only needs to enter their email to get the user state to know what to do next
|
||||||
|
|
||||||
if (password === undefined) {
|
if (password === undefined) {
|
||||||
|
// user has signed up but not completed payment
|
||||||
|
// happens when user closed stripe checkout before completing payment
|
||||||
|
// and then tries to login
|
||||||
|
if (user.state === ACCOUNT_STATE.INIT_PAYMENT) {
|
||||||
|
const userPendingPayment = await UserPendingPayment.findOne({
|
||||||
|
where: {
|
||||||
|
user_id: user.user_id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (
|
||||||
|
userPendingPayment &&
|
||||||
|
userPendingPayment.payment_session_url !== ""
|
||||||
|
) {
|
||||||
|
userLogger.info(
|
||||||
|
user.user_id,
|
||||||
|
"Sent email to complete init payment from signup"
|
||||||
|
);
|
||||||
|
|
||||||
|
rabbitmq.sendEmail(
|
||||||
|
email,
|
||||||
|
"dashboardSignUpUrlToCompletePayment",
|
||||||
|
user.language,
|
||||||
|
{
|
||||||
|
paymentSessionUrl: userPendingPayment.payment_session_url,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return res.status(200).send({ state: user.state });
|
return res.status(200).send({ state: user.state });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import sequelize from "../database/database";
|
||||||
interface UserPendingPaymentAttributes {
|
interface UserPendingPaymentAttributes {
|
||||||
payment_session_id: string;
|
payment_session_id: string;
|
||||||
user_id: string;
|
user_id: string;
|
||||||
|
payment_session_url?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserPendingPayment
|
class UserPendingPayment
|
||||||
|
@ -12,6 +13,7 @@ class UserPendingPayment
|
||||||
{
|
{
|
||||||
declare payment_session_id: string;
|
declare payment_session_id: string;
|
||||||
declare user_id: string;
|
declare user_id: string;
|
||||||
|
declare payment_session_url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserPendingPayment.init(
|
UserPendingPayment.init(
|
||||||
|
@ -25,6 +27,10 @@ UserPendingPayment.init(
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
|
payment_session_url: {
|
||||||
|
type: DataTypes.STRING, // varchar(1000) needs to be set manually
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
|
|
Loading…
Reference in New Issue