Skip to main content

POST /api/subscription/create-portal-session

Creates a Stripe Customer Portal session where users can manage their subscription, update payment methods, view invoices, and cancel their subscription. Only available for users with paid plans (BASIC or PRO).

Authentication

This endpoint requires authentication. Include your access token in the request cookies.

Response

url
string
required
URL to redirect the user to the Stripe Customer Portal
message
string
required
Success message

Example Request

curl -X POST "https://api.contafy.com/api/subscription/create-portal-session" \
  -H "Cookie: access_token=your_access_token"

Example Response

{
  "url": "https://billing.stripe.com/p/session/test_YWNjdF8xMjM0NTY3ODk",
  "message": "Portal session created successfully"
}

Customer Portal Features

The Stripe Customer Portal allows users to:
  • View current subscription details
  • Update payment methods
  • View billing history and download invoices
  • Change subscription plan
  • Cancel subscription
  • Update billing information

Usage Flow

  1. Call this endpoint to create a portal session
  2. Redirect the user to the returned url
  3. User manages their subscription on Stripe’s hosted portal
  4. User is redirected back to your return URL
  5. Stripe webhooks update subscription changes automatically

Error Responses

401 Unauthorized
error
Authentication required or token expired
{
  "error": "Unauthorized",
  "message": "Authentication required"
}
403 Forbidden
error
User does not have a paid subscription
{
  "error": "Forbidden",
  "message": "Customer portal is only available for paid subscriptions"
}
404 Not Found
error
Stripe customer not found
{
  "error": "Not Found",
  "message": "Stripe customer not found"
}
500 Internal Server Error
error
Server or Stripe error occurred
{
  "error": "Internal Server Error",
  "message": "Failed to create portal session"
}
This endpoint is only available for users with BASIC or PRO subscriptions. FREE plan users will receive a 403 Forbidden error.
The portal session URL is single-use and expires after the user leaves the portal or after a certain period of inactivity.