I am trying to connect my react app to stripe so that users can manage their subscriptions and payments.
I am getting a little confused with the backend side of this to actually make the backend call and open the customer portal.
I'm not sure I have the backend server set up correctly. This is how I have things setup in the app.
I have a button which is intended to go to the customer portal:
<form method="POST" action="/create-customer-portal-session">
<button type="submit">Manage billing</button>
</form>
I then have this to create the customer portal session:
const stripe = require('stripe')(Secret Key);
const express = require('express');
export const app = express();
app.use(express.static('public'));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.post('/create-customer-portal-session', async (req, res) => {
// Authenticate your user.
const session = await stripe.billingPortal.sessions.create({
customer: 'cus_MIx5hmhlXwCOzk',
});
res.redirect(session.url);
});
app.listen(3001, () => console.log('Running on port :3001'));
Then in package.json I have the following:
"proxy": "http://localhost:3001/"
That is everything I have set up to do this currently, it returns the error:
Proxy error: Could not proxy request /create-customer-portal-session from localhost:3000 to http://localhost:3001/. See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).
I'm getting a little lost with the proxy server side of things as it's quite new to me and I am not sure how to approach this.