Integrate Stripe Customer Portal via POST request to create a portal session

I am trying to integrate the Stripe Customer Portal via a portal session on our Webflow Member page. A portal session is the entry point into the customer portal. It provides a unique, temporary link to the portal.

I know third-party tools can do that as well, but I don’t see the point of paying $300+ for that when it’s possible with some lines of code, and I don’t need subscription management.

The Stripe documentation (Integrate the customer portal with the API | Stripe Documentation) states:

  1. Add a button that customers can click to enter the portal. Use a POST request to create a portal session:
<form method="POST" action="/create-customer-portal-session">
  <button type="submit">Manage billing</button>
  1. Add an endpoint that creates a portal session and redirects your customers. Make sure to authenticate customers on your site before creating sessions for them. To create a session, you need the customer’s ID (already added as a custom field to each WF Member account) and a return_url (in our case domain[dot]com/user-account) , which is required if a default return URL isn’t set in the Dashboard configuration.

When we create a portal session, Stripe returns the portal session object , which contains the session’s short-lived URL that our customers use to access the customer portal.

And then follows a code block to initiate the session:

curl \
  -u sk_test_XXXXX: \
  -d "customer"="{{CUSTOMER_ID}}" \
  -d "return_url"=""

Adding a button to the page is straightforward. What I am struggling with the most is how I can initiate the session and how I can integrate the code block to authenticate the portal session.

Thank you a lot for your help on this. Really appreciate everyone who takes the time to answer this post.

Hi @felixz :wave: gosh, that’s a lot to follow :smile:

But it looks like the crux of your problem is that once a Webflow Memberships user is logged in, you need access to their unique user id so that you can create a valid Stripe portal session.

Is that a correct understanding?

If so, there are solutions, but I want to make sure I’m understanding you, first.

Hi Chris,

Yes, that’s correct. The unique Stripe customer ID {CUSTOMER_ID} is filled in each member profile as a custom field, so my assumption is that we can fill that value when necessary in other elements (hopefully code blocks as well).

Hi @ChrisDrit, did you have a chance to figure it out?

@felixz you can get that from the API through Webhooks. You also have access to it if you use Webflow Logic.

You can use it from those sources to populate your Stripe API call.

Hi @felixz, I am looking to implement the same functionality. Did you manage to make it work with @ChrisDrit’s help? Thanks!