cURL
curl --request POST 'https://api.integrateledger.com/v1/billing/upgrade' \
-H "Authorization: Bearer $LEDGER_API_KEY" \
-H 'Idempotency-Key: upgrade_123' \
-H 'Content-Type: application/json' \
--data '{"customerId":"user_123","planId":"pro"}'import os
from ledger_sdk import Ledger
ledger = Ledger(api_key=os.environ["LEDGER_API_KEY"])
ledger.upgrade_paid_plan(customer_id="user_123", plan_id="pro", idempotency_key="upgrade_123")import { Ledger } from "@ledger/sdk";
const ledger = new Ledger({ apiKey: process.env.LEDGER_API_KEY ?? "" });
await ledger.upgradePaidPlan({ idempotencyKey: "upgrade_123", body: { customerId: "user_123", planId: "pro" } });const options = {
method: 'POST',
headers: {
'idempotency-key': '<idempotency-key>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({customerId: '<string>', planId: '<string>'})
};
fetch('https://api.integrateledger.com/v1/billing/upgrade', 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://api.integrateledger.com/v1/billing/upgrade",
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([
'customerId' => '<string>',
'planId' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"idempotency-key: <idempotency-key>"
],
]);
$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://api.integrateledger.com/v1/billing/upgrade"
payload := strings.NewReader("{\n \"customerId\": \"<string>\",\n \"planId\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("idempotency-key", "<idempotency-key>")
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.post("https://api.integrateledger.com/v1/billing/upgrade")
.header("idempotency-key", "<idempotency-key>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customerId\": \"<string>\",\n \"planId\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.integrateledger.com/v1/billing/upgrade")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["idempotency-key"] = '<idempotency-key>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customerId\": \"<string>\",\n \"planId\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"upgradeId": 123,
"status": "applied",
"paymentUrl": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>",
"upgradeId": 123
}Billing
Upgrade a paid plan
Start an idempotent paid plan upgrade for an existing subscription.
POST
/
v1
/
billing
/
upgrade
cURL
curl --request POST 'https://api.integrateledger.com/v1/billing/upgrade' \
-H "Authorization: Bearer $LEDGER_API_KEY" \
-H 'Idempotency-Key: upgrade_123' \
-H 'Content-Type: application/json' \
--data '{"customerId":"user_123","planId":"pro"}'import os
from ledger_sdk import Ledger
ledger = Ledger(api_key=os.environ["LEDGER_API_KEY"])
ledger.upgrade_paid_plan(customer_id="user_123", plan_id="pro", idempotency_key="upgrade_123")import { Ledger } from "@ledger/sdk";
const ledger = new Ledger({ apiKey: process.env.LEDGER_API_KEY ?? "" });
await ledger.upgradePaidPlan({ idempotencyKey: "upgrade_123", body: { customerId: "user_123", planId: "pro" } });const options = {
method: 'POST',
headers: {
'idempotency-key': '<idempotency-key>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({customerId: '<string>', planId: '<string>'})
};
fetch('https://api.integrateledger.com/v1/billing/upgrade', 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://api.integrateledger.com/v1/billing/upgrade",
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([
'customerId' => '<string>',
'planId' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"idempotency-key: <idempotency-key>"
],
]);
$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://api.integrateledger.com/v1/billing/upgrade"
payload := strings.NewReader("{\n \"customerId\": \"<string>\",\n \"planId\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("idempotency-key", "<idempotency-key>")
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.post("https://api.integrateledger.com/v1/billing/upgrade")
.header("idempotency-key", "<idempotency-key>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"customerId\": \"<string>\",\n \"planId\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.integrateledger.com/v1/billing/upgrade")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["idempotency-key"] = '<idempotency-key>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customerId\": \"<string>\",\n \"planId\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"upgradeId": 123,
"status": "applied",
"paymentUrl": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>",
"upgradeId": 123
}Starts an upgrade for a customer with an active Stripe-backed monthly subscription. Send
customerId and the target planId, plus a client-generated Idempotency-Key header. The target must be an active paid plan with a synced Stripe Price and a higher monthly price than the customer’s current plan.
The Stripe connection must have a stored signed webhook endpoint. Ledger returns 502 stripe_not_configured before starting an upgrade when that setup is incomplete.
The response reports an upgradeId, a status (applied, pending_payment, processing, or closed), and a nullable paymentUrl. If paymentUrl is present, send the customer to Stripe’s hosted invoice page. Ledger applies the new plan and its credits after Stripe confirms payment; processing means the result is still being reconciled. A verified upgrade starts a new full-price monthly billing cycle. Ledger expires the previous plan’s unspent allowance and grants the new plan’s allowance; separately purchased credit-pack credits remain available. If payment fails or expires, the existing plan and allowance remain in place.
Reuse the same idempotency key when retrying this intended upgrade. Reusing it for a different target returns 409 idempotency_key_mismatch; starting another upgrade while one is pending returns 409 upgrade_pending. An ineligible subscription, unsynced or non-higher target, or incompatible Stripe billing state returns 400. If Stripe reconciliation needs another attempt (503) or a Stripe request fails (502), retry with the same key rather than starting a second upgrade.
See Billing and Checkout for payment timing and Customers for plan attachment. The API key selects the environment; live upgrades require live activation and Ledger’s live-charge gate.Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Headers
Required string length:
1 - 255Body
application/json