Updating an existing Stripe Customer

For an existing Stripe Customer – in other words, where the current user already has a value stored for the stripe_customer field – we will use the Stripe API to update a Stripe Customer, as follows.

mern-marketplace/server/controllers/user.controller.js:

  myStripe.customers.update(req.profile.stripe_customer, {
source: req.body.token
},
(err, customer) => {
if(err){
return res.status(400).send({
error: "Could not update charge details"
})
}
req.body.order.payment_id = customer.id
next()
})

Once the Stripe Customer has been successfully updated, we will add the Customer ID to the order being created in the next() call. Though not covered here, the Stripe Customer feature can be used to allow users to store and update their credit card information from the application. With the user's payment information securely stored and accessible, we can look into how to use this information to process a payment when an ordered product is processed by the seller.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset