Update subscription payment method
curl --request POST \
--url {protocol}://{host}/wp-json/cocart/preview/my-account/subscriptions/{id}/payment-method \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"payment_method": "stripe",
"token_id": 123
}
'import requests
url = "{protocol}://{host}/wp-json/cocart/preview/my-account/subscriptions/{id}/payment-method"
payload = {
"payment_method": "stripe",
"token_id": 123
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
body: JSON.stringify({payment_method: 'stripe', token_id: 123})
};
fetch('{protocol}://{host}/wp-json/cocart/preview/my-account/subscriptions/{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 => "{protocol}://{host}/wp-json/cocart/preview/my-account/subscriptions/{id}/payment-method",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'payment_method' => 'stripe',
'token_id' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"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 := "{protocol}://{host}/wp-json/cocart/preview/my-account/subscriptions/{id}/payment-method"
payload := strings.NewReader("{\n \"payment_method\": \"stripe\",\n \"token_id\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
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.post("{protocol}://{host}/wp-json/cocart/preview/my-account/subscriptions/{id}/payment-method")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"payment_method\": \"stripe\",\n \"token_id\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("{protocol}://{host}/wp-json/cocart/preview/my-account/subscriptions/{id}/payment-method")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"payment_method\": \"stripe\",\n \"token_id\": 123\n}"
response = http.request(request)
puts response.read_body{
"subscription_id": 123,
"subscription_status": "<string>",
"requires_payment": true,
"payment_processed": true,
"payment_method": "<string>",
"is_manual": "true",
"payment_token": {
"id": 123,
"token": "<string>",
"type": "cc",
"gateway_id": "<string>",
"is_default": true,
"expires": "12/2025"
},
"available_tokens": [
{
"id": 123,
"token": "<string>",
"type": "cc",
"gateway_id": "<string>",
"is_default": true,
"expires": "12/2025"
}
],
"can_use_token": true,
"checkout_url": "<string>",
"order_id": 123,
"order_key": "<string>",
"order_total": "<string>",
"message": "<string>"
}{
"code": "<string>",
"message": "<string>",
"data": {
"status": 123
}
}{
"code": "<string>",
"message": "<string>",
"data": {
"status": 123
}
}{
"code": "<string>",
"message": "<string>",
"data": {
"status": 123
}
}Update Subscription Payment Method
Update the payment method for a subscription using a saved payment token
POST
/
my-account
/
subscriptions
/
{id}
/
payment-method
Update subscription payment method
curl --request POST \
--url {protocol}://{host}/wp-json/cocart/preview/my-account/subscriptions/{id}/payment-method \
--header 'Authorization: Basic <encoded-value>' \
--header 'Content-Type: application/json' \
--data '
{
"payment_method": "stripe",
"token_id": 123
}
'import requests
url = "{protocol}://{host}/wp-json/cocart/preview/my-account/subscriptions/{id}/payment-method"
payload = {
"payment_method": "stripe",
"token_id": 123
}
headers = {
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Basic <encoded-value>', 'Content-Type': 'application/json'},
body: JSON.stringify({payment_method: 'stripe', token_id: 123})
};
fetch('{protocol}://{host}/wp-json/cocart/preview/my-account/subscriptions/{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 => "{protocol}://{host}/wp-json/cocart/preview/my-account/subscriptions/{id}/payment-method",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'payment_method' => 'stripe',
'token_id' => 123
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"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 := "{protocol}://{host}/wp-json/cocart/preview/my-account/subscriptions/{id}/payment-method"
payload := strings.NewReader("{\n \"payment_method\": \"stripe\",\n \"token_id\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Basic <encoded-value>")
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.post("{protocol}://{host}/wp-json/cocart/preview/my-account/subscriptions/{id}/payment-method")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"payment_method\": \"stripe\",\n \"token_id\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("{protocol}://{host}/wp-json/cocart/preview/my-account/subscriptions/{id}/payment-method")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"payment_method\": \"stripe\",\n \"token_id\": 123\n}"
response = http.request(request)
puts response.read_body{
"subscription_id": 123,
"subscription_status": "<string>",
"requires_payment": true,
"payment_processed": true,
"payment_method": "<string>",
"is_manual": "true",
"payment_token": {
"id": 123,
"token": "<string>",
"type": "cc",
"gateway_id": "<string>",
"is_default": true,
"expires": "12/2025"
},
"available_tokens": [
{
"id": 123,
"token": "<string>",
"type": "cc",
"gateway_id": "<string>",
"is_default": true,
"expires": "12/2025"
}
],
"can_use_token": true,
"checkout_url": "<string>",
"order_id": 123,
"order_key": "<string>",
"order_total": "<string>",
"message": "<string>"
}{
"code": "<string>",
"message": "<string>",
"data": {
"status": 123
}
}{
"code": "<string>",
"message": "<string>",
"data": {
"status": 123
}
}{
"code": "<string>",
"message": "<string>",
"data": {
"status": 123
}
}This endpoint is currently shown as a preview of what’s currently in development and is subject to change.
This endpoint supports only the official WooCommerce Subscriptions extension.
Body
application/json
Payment method details
Response
Payment method updated successfully