Customer portal

Sign a customer in to your customer portal from your own site, so they see their orders, receipts and invoices with you without asking for a code.

On this page

How it works

Your customer portal is one page where each of your customers sees what they bought from you: their orders with a receipt for each one paid, their invoices with Pay, and their own contact details. A customer signs in there with a code emailed to the address they bought with. Turn it on in the dashboard under Customers → Customer portal.

When the customer is already signed in to your own site, skip the code: your server asks for a customer portal session and sends the customer to its url.

  1. Your server calls Create a customer portal session with the customer's id or email.
  2. Redirect the customer's browser to url straight away.
  3. The portal opens signed in, for an hour. Its Back link goes to your return_url.

The url opens once and only for 5 minutes. Make a new one each time the customer asks for their portal, never ahead of time, and never put one in an email or a page another person could see: whoever opens it first is signed in as that customer.

Retrieve the customer portal

GET /v1/customer_portal

Returns your portal's settings as they stand in the key's mode: whether it's on, its address, its words, which sections customers see and the links it shows. Check enabled before offering customers a link to it. The settings are changed in the dashboard, under Customers → Customer portal.

cURL
curl https://pay.railbed.io/v1/customer_portal \
  -H "Authorization: Bearer $RAILBED_SECRET_KEY"
Response
{
  "object": "customer_portal",
  "enabled": true,
  "url": "https://pay.railbed.io/portal/northwind-studio-k7rq",
  "headline": null,
  "welcome": "Your orders, receipts and invoices from Northwind Studio.",
  "help_text": "Refunds within 30 days of purchase.",
  "receipt_details": null,
  "sections": {
    "invoices": true,
    "receipts": true,
    "edit_details": true,
    "marketing": false,
    "preferred_provider": true,
    "subscriptions": true
  },
  "links": {
    "support_email": "help@northwind.example",
    "support_url": null,
    "refund_policy_url": "https://northwind.example/refunds",
    "terms_url": null,
    "privacy_url": null,
    "website_url": "https://northwind.example"
  }
}
200 OK
FieldTypeDescription
enabledbooleantrue while the portal is on. Portal sessions need it on
urlstring or nullWhere customers sign in with a code sent to their email. null while the portal is off
headline, welcome, help_text, receipt_detailsstring or nullThe words you set, or null for the portal's own
sectionsobjectinvoices, receipts, edit_details, marketing, preferred_provider and subscriptions, each true when customers see it
linksobjectsupport_email, support_url, refund_policy_url, terms_url, privacy_url and website_url, or null

It needs the customers:read scope, which Read only keys have.

The customer portal session object

FieldTypeDescription
objectstring"customer_portal_session"
customerstringThe customer it signs in, cus_…
livemodebooleanfalse for Test mode, true for Live mode: the key's mode
urlstringSend the customer here. It opens once, then signs them in for an hour
return_urlstring or nullWhere the portal's Back link goes, as you sent it
expires_atintegerWhen url stops opening, in Unix seconds: 5 minutes after it was made
A customer portal session
{
  "object": "customer_portal_session",
  "customer": "cus_Hc7nQ2wVz9KpT4mRb1Ye",
  "livemode": true,
  "url": "https://pay.railbed.io/portal/northwind-studio-k7rq#t=Qm9KcW1xV3pYcjRkTjhwTGs2SnRZdjNiSGY1Uw2RzAx",
  "return_url": "https://northwind.example/account",
  "expires_at": 1790380825
}
201 Created

Create a customer portal session

POST /v1/customer_portal/sessions

Makes a single-use link to your customer portal for one customer, in the key's mode. Name the customer with customer or email, not both.

ParameterTypeDescription
customerstringThe customer's id, cus_…
emailstringTheir email, in any letter case, when you don't keep their id
return_urlstringOptional. Where the portal's Back link goes, such as your account page. A full https:// address in Live mode; Test mode also allows http://localhost. Left out, the portal shows the website from its settings, if any
curl https://pay.railbed.io/v1/customer_portal/sessions \
  -H "Authorization: Bearer $RAILBED_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customer": "cus_Hc7nQ2wVz9KpT4mRb1Ye", "return_url": "https://northwind.example/account"}'
Response
{
  "object": "customer_portal_session",
  "customer": "cus_Hc7nQ2wVz9KpT4mRb1Ye",
  "livemode": true,
  "url": "https://pay.railbed.io/portal/northwind-studio-k7rq#t=Qm9KcW1xV3pYcjRkTjhwTGs2SnRZdjNiSGY1Uw2RzAx",
  "return_url": "https://northwind.example/account",
  "expires_at": 1790380825
}
201 Created

It needs the orders:write scope, so a Read only key can't sign customers in. Each call makes a new link: a call that failed is safe to send again, and a link nobody opened expires by itself.

ResponseCause
404 not_foundNo customer of yours has that id or email in this key's mode, or you deleted their details
409 portal_offThe customer portal is off. Turn it on in the dashboard first
400 invalid_customerNeither customer nor email was sent, or both were, or customer isn't a customer id
400 invalid_urlreturn_url isn't an address the portal may use, by the rules of a session's success_url

A link opened after it was used or expired shows the portal's sign-in card, where the customer gets a code by email instead.

Updated · This page as Markdown