Problem Explanation
I have 3rd party (Stripe) form in my app that users submit. I would like to be able to count number of submits and display it on the front end.
Code Explanation
This is my route for form submit (works fine)
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
const stripeChargeCallback = (res) => (stripeErr, stripeRes) => {
if (stripeErr) {
res.status(500).send({ error: stripeErr });
} else {
res.status(200).send({ success: stripeRes });
}
};
const paymentApi = (app) => {
app.get('/payment', (req, res) => {
res.send({
message: 'Hello Stripe checkout server!',
timestamp: new Date().toISOString(),
});
});
app.post('/payment', (req, res) => {
const body = {
source: req.body.token.id,
amount: req.body.amount,
currency: 'dkk',
};
stripe.charges.create(body, stripeChargeCallback(res));
});
return app;
};
I am not sure if I can just add to this routing logic for counting submits or it should new route.
This is a (useless) solution on frontend I would like to replace and connect with Express: (ProgressBar is bootstrap component)
const addOneLocalStorage = JSON.parse(localStorage.getItem('sold') || 0);
const [addOne, setAddOne] = useState(addOneLocalStorage);
const handleAdd = () => {
setAddOne(addOne + 1);
localStorage.setItem('sold', addOne);
};
<ProgressBar animated now={addOne} min={0} max={100} />;
I tried to Google how to handle such a thing (since I am not a backend developer), but I can't find any resource, would appreciate any help here.