Stock Oversell in ExpressJs

Viewed 56

I have been building authentication software for group owners for over a year now, and it is purpose is to add stock to the product and release a drop that a lot of people would try to cop it before it gets OOS (Out Of Stock) I have tried express-queue, express-enqueue and many more like it to ensure only certain people gets the product and not oversell but nothing have worked for me as it either oversell or just loops around using those modules and never goes to the checkout page, what is the best way to do like a stock management tool where it only sells what is set and doesn't oversell, keep in mind i use Stripe Checkout

app.post("/chargestripe", queueStock.getMiddleware(), urlEncoded, async (req, res) => {
  sql.query(`SELECT * FROM admins;`, (errMysql, resMysql) => {
    (async () => {
    const session = await stripe.checkout.sessions.create({
      payment_method_types: ['card'],
      subscription_data: {
        items: [{
          plan: resMysql[0].plan_id,
        }],
        trial_from_plan: true,
      },
      billing_address_collection: 'required',
      success_url: `http://localhost/success?session_id={CHECKOUT_SESSION_ID}`,
      cancel_url: `http://localhost/cancel`,
    });
    io.of('/dashboard').emit('valid', {
        session: session.id
    });
    })();
  });
});

The point of this is once someone click purchase it creates a session and then redirects him to the purchase page if it was successful it redirects him to the success page and proceed by giving him his membership else it will just go to the /cancel page, my Database has a column called key_stock which is basically an INT that represents the stock and if there is a way to fix such issue i would really appreciate it as it has been like this all the time and I couldn't find a solution what-so-ever thank you.

0 Answers
Related