Customers
Update Payment Method
Update a customer’s payment method
PUT
/
v1
/
customers
/
{id}
/
payment-method
Update a customer's card on file
curl --request PUT \
--url https://billing.example.com/v1/customers/{id}/payment-method \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"card_brand": "visa",
"card_last4": "<string>",
"card_exp_month": 6,
"card_exp_year": 2021
}
'import requests
url = "https://billing.example.com/v1/customers/{id}/payment-method"
payload = {
"card_brand": "visa",
"card_last4": "<string>",
"card_exp_month": 6,
"card_exp_year": 2021
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
card_brand: 'visa',
card_last4: '<string>',
card_exp_month: 6,
card_exp_year: 2021
})
};
fetch('https://billing.example.com/v1/customers/{id}/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/v1/customers/{id}/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' => '<string>',
'card_exp_month' => 6,
'card_exp_year' => 2021
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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/v1/customers/{id}/payment-method"
payload := strings.NewReader("{\n \"card_brand\": \"visa\",\n \"card_last4\": \"<string>\",\n \"card_exp_month\": 6,\n \"card_exp_year\": 2021\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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/v1/customers/{id}/payment-method")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"card_brand\": \"visa\",\n \"card_last4\": \"<string>\",\n \"card_exp_month\": 6,\n \"card_exp_year\": 2021\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/v1/customers/{id}/payment-method")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"card_brand\": \"visa\",\n \"card_last4\": \"<string>\",\n \"card_exp_month\": 6,\n \"card_exp_year\": 2021\n}"
response = http.request(request)
puts response.read_body{
"status": "ok"
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The customer ID |
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
gateway | string | Yes | Payment gateway: razorpay or stripe |
gateway_payment_method_id | string | Yes | Payment method ID from the gateway |
type | string | Yes | Payment method type: card, upi, or bank_transfer |
set_default | boolean | No | Set as default payment method (default: false) |
Example Request
curl -X PUT https://api.recurso.dev/v1/customers/cust_abc123/payment-method \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"gateway": "razorpay",
"gateway_payment_method_id": "pay_method_rzp_9k2m",
"type": "card",
"set_default": true
}'
Response
{
"id": "pm_7xq9r2",
"object": "payment_method",
"customer_id": "cust_abc123",
"gateway": "razorpay",
"gateway_payment_method_id": "pay_method_rzp_9k2m",
"type": "card",
"card": {
"brand": "visa",
"last4": "4242",
"exp_month": 12,
"exp_year": 2026
},
"is_default": true,
"created_at": "2024-02-10T08:15:00Z",
"updated_at": "2024-03-05T11:45:00Z"
}
When
set_default is true, this payment method will be used for all future automatic charges on the customer’s subscriptions.Authorizations
Tenant API key obtained from POST /auth/register or POST /v1/developer/keys.
Path Parameters
Body
application/json
Response
Payment method updated.
Allowed value:
"ok"⌘I
Update a customer's card on file
curl --request PUT \
--url https://billing.example.com/v1/customers/{id}/payment-method \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"card_brand": "visa",
"card_last4": "<string>",
"card_exp_month": 6,
"card_exp_year": 2021
}
'import requests
url = "https://billing.example.com/v1/customers/{id}/payment-method"
payload = {
"card_brand": "visa",
"card_last4": "<string>",
"card_exp_month": 6,
"card_exp_year": 2021
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
card_brand: 'visa',
card_last4: '<string>',
card_exp_month: 6,
card_exp_year: 2021
})
};
fetch('https://billing.example.com/v1/customers/{id}/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/v1/customers/{id}/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' => '<string>',
'card_exp_month' => 6,
'card_exp_year' => 2021
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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/v1/customers/{id}/payment-method"
payload := strings.NewReader("{\n \"card_brand\": \"visa\",\n \"card_last4\": \"<string>\",\n \"card_exp_month\": 6,\n \"card_exp_year\": 2021\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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/v1/customers/{id}/payment-method")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"card_brand\": \"visa\",\n \"card_last4\": \"<string>\",\n \"card_exp_month\": 6,\n \"card_exp_year\": 2021\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/v1/customers/{id}/payment-method")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"card_brand\": \"visa\",\n \"card_last4\": \"<string>\",\n \"card_exp_month\": 6,\n \"card_exp_year\": 2021\n}"
response = http.request(request)
puts response.read_body{
"status": "ok"
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}{
"error": {
"code": "BAD_REQUEST",
"message": "<string>"
}
}