Portal
Update Payment Method
Update the logged-in customer’s vaulted payment method
PUT
/
portal
/
api
/
payment-method
Update the logged-in customer's payment method
curl --request PUT \
--url https://billing.example.com/portal/api/payment-method \
--header 'Content-Type: application/json' \
--cookie portal_session= \
--data '
{
"card_brand": "visa",
"card_last4": "4242",
"card_exp_month": 6,
"card_exp_year": 2021
}
'import requests
url = "https://billing.example.com/portal/api/payment-method"
payload = {
"card_brand": "visa",
"card_last4": "4242",
"card_exp_month": 6,
"card_exp_year": 2021
}
headers = {
"cookie": "portal_session=",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {cookie: 'portal_session=', 'Content-Type': 'application/json'},
body: JSON.stringify({card_brand: 'visa', card_last4: '4242', card_exp_month: 6, card_exp_year: 2021})
};
fetch('https://billing.example.com/portal/api/payment-method', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://billing.example.com/portal/api/payment-method",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'card_brand' => 'visa',
'card_last4' => '4242',
'card_exp_month' => 6,
'card_exp_year' => 2021
]),
CURLOPT_COOKIE => "portal_session=",
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://billing.example.com/portal/api/payment-method"
payload := strings.NewReader("{\n \"card_brand\": \"visa\",\n \"card_last4\": \"4242\",\n \"card_exp_month\": 6,\n \"card_exp_year\": 2021\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("cookie", "portal_session=")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://billing.example.com/portal/api/payment-method")
.header("cookie", "portal_session=")
.header("Content-Type", "application/json")
.body("{\n \"card_brand\": \"visa\",\n \"card_last4\": \"4242\",\n \"card_exp_month\": 6,\n \"card_exp_year\": 2021\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/portal/api/payment-method")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["cookie"] = 'portal_session='
request["Content-Type"] = 'application/json'
request.body = "{\n \"card_brand\": \"visa\",\n \"card_last4\": \"4242\",\n \"card_exp_month\": 6,\n \"card_exp_year\": 2021\n}"
response = http.request(request)
puts response.read_body{
"status": "ok"
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}Portal endpoints authenticate via the
portal_session cookie issued by magic-link verification — not a Bearer API key. State-changing portal calls must additionally echo the portal_csrf cookie’s value in the X-CSRF-Token header (double-submit CSRF).Request body
| Parameter | Type | Required | Description |
|---|---|---|---|
card_brand | string | Yes | Card brand from tokenization, e.g. visa. |
card_last4 | string | Yes | Last four digits (exactly 4 characters). |
card_exp_month | integer | Yes | Expiry month, 1–12. |
card_exp_year | integer | Yes | Expiry year (2020 or later). |
Example Request
curl -X PUT "https://api.recurso.dev/portal/api/payment-method" \
-b "portal_session=$PORTAL_SESSION; portal_csrf=$CSRF_TOKEN" \
-H "X-CSRF-Token: $CSRF_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"card_brand": "visa",
"card_last4": "4242",
"card_exp_month": 11,
"card_exp_year": 2028
}'
Response
{
"status": "ok"
}
To collect a new card through Stripe first, start with Start Card Update; for US bank accounts use Start Bank Account Setup.
Authorizations
Customer-portal session cookie issued by GET /portal/auth/verify.
Body
application/json
Response
Payment method updated.
Example:
"ok"
⌘I
Update the logged-in customer's payment method
curl --request PUT \
--url https://billing.example.com/portal/api/payment-method \
--header 'Content-Type: application/json' \
--cookie portal_session= \
--data '
{
"card_brand": "visa",
"card_last4": "4242",
"card_exp_month": 6,
"card_exp_year": 2021
}
'import requests
url = "https://billing.example.com/portal/api/payment-method"
payload = {
"card_brand": "visa",
"card_last4": "4242",
"card_exp_month": 6,
"card_exp_year": 2021
}
headers = {
"cookie": "portal_session=",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {cookie: 'portal_session=', 'Content-Type': 'application/json'},
body: JSON.stringify({card_brand: 'visa', card_last4: '4242', card_exp_month: 6, card_exp_year: 2021})
};
fetch('https://billing.example.com/portal/api/payment-method', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://billing.example.com/portal/api/payment-method",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'card_brand' => 'visa',
'card_last4' => '4242',
'card_exp_month' => 6,
'card_exp_year' => 2021
]),
CURLOPT_COOKIE => "portal_session=",
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://billing.example.com/portal/api/payment-method"
payload := strings.NewReader("{\n \"card_brand\": \"visa\",\n \"card_last4\": \"4242\",\n \"card_exp_month\": 6,\n \"card_exp_year\": 2021\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("cookie", "portal_session=")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://billing.example.com/portal/api/payment-method")
.header("cookie", "portal_session=")
.header("Content-Type", "application/json")
.body("{\n \"card_brand\": \"visa\",\n \"card_last4\": \"4242\",\n \"card_exp_month\": 6,\n \"card_exp_year\": 2021\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/portal/api/payment-method")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["cookie"] = 'portal_session='
request["Content-Type"] = 'application/json'
request.body = "{\n \"card_brand\": \"visa\",\n \"card_last4\": \"4242\",\n \"card_exp_month\": 6,\n \"card_exp_year\": 2021\n}"
response = http.request(request)
puts response.read_body{
"status": "ok"
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}