April 2020
Intermediate to advanced
716 pages
18h 55m
English
If the current user does not have a corresponding Stripe Customer – in other words, a value is not stored for the stripe_customer field – we will use the create a customer API (https://stripe.com/docs/api#create_customer) from Stripe, as follows.
mern-marketplace/server/controllers/user.controller.js:
myStripe.customers.create({ email: req.profile.email, source: req.body.token }).then((customer) => { User.update({'_id':req.profile._id}, {'$set': { 'stripe_customer': customer.id }}, (err, order) => { if (err) { return res.status(400).send({ error: errorHandler.getErrorMessage(err) }) } req.body.order.payment_id = customer.id next() })})
If the Stripe Customer is successfully created, we will update the current ...
Read now
Unlock full access