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.
- Your server calls Create a customer portal session with the customer's id or email.
- Redirect the customer's browser to
urlstraight away. - 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 https://pay.railbed.io/v1/customer_portal \
-H "Authorization: Bearer $RAILBED_SECRET_KEY"{
"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"
}
}| Field | Type | Description |
|---|---|---|
enabled | boolean | true while the portal is on. Portal sessions need it on |
url | string or null | Where customers sign in with a code sent to their email. null while the portal is off |
headline, welcome, help_text, receipt_details | string or null | The words you set, or null for the portal's own |
sections | object | invoices, receipts, edit_details, marketing, preferred_provider and subscriptions, each true when customers see it |
links | object | support_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
| Field | Type | Description |
|---|---|---|
object | string | "customer_portal_session" |
customer | string | The customer it signs in, cus_… |
livemode | boolean | false for Test mode, true for Live mode: the key's mode |
url | string | Send the customer here. It opens once, then signs them in for an hour |
return_url | string or null | Where the portal's Back link goes, as you sent it |
expires_at | integer | When url stops opening, in Unix seconds: 5 minutes after it was made |
{
"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
}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.
| Parameter | Type | Description |
|---|---|---|
customer | string | The customer's id, cus_… |
email | string | Their email, in any letter case, when you don't keep their id |
return_url | string | Optional. 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"}'// In your "Orders and receipts" route, for the signed-in customer.
const session = await fetch('https://pay.railbed.io/v1/customer_portal/sessions', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.RAILBED_SECRET_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ customer: user.railbedCustomerId, return_url: 'https://northwind.example/account' }),
}).then((r) => r.json());
res.redirect(303, session.url);session = requests.post(
"https://pay.railbed.io/v1/customer_portal/sessions",
headers={"Authorization": f"Bearer {os.environ['RAILBED_SECRET_KEY']}"},
json={"email": user.email, "return_url": "https://northwind.example/account"},
timeout=15,
).json()
return redirect(session["url"], code=303)<?php
$ch = curl_init('https://pay.railbed.io/v1/customer_portal/sessions');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RAILBED_SECRET_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode(['email' => $user['email'], 'return_url' => 'https://northwind.example/account']),
]);
$session = json_decode(curl_exec($ch), true);
header('Location: ' . $session['url'], true, 303);{
"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
}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.
| Response | Cause |
|---|---|
404 not_found | No customer of yours has that id or email in this key's mode, or you deleted their details |
409 portal_off | The customer portal is off. Turn it on in the dashboard first |
400 invalid_customer | Neither customer nor email was sent, or both were, or customer isn't a customer id |
400 invalid_url | return_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.