Updating the user controller
We will create a new, or update an existing, Stripe Customer when the user places an order after entering their credit card details. To implement this, we will update the user controllers with a stripeCustomer method that will be called before the order is created when our server receives a request to the create order API (as discussed in the Creating a new order section).
In the stripeCustomer controller method, we will need to use the stripe node module, which can be installed with the following command:
yarn add stripe
After installing the stripe module, it needs to be imported into the user controller file. Then, the stripe instance needs to be initialized with the application's Stripe secret key.
mern-marketplace/server/controllers/user.controller.js ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access