curl --request POST 'https://api.integrateledger.com/v1/customers/redemptions?customerId=user_123' \
-H "Authorization: Bearer $LEDGER_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"code":"LAUNCH20"}'import ledger from "integrateledger";
const client = new ledger({ apiKey: process.env.LEDGER_API_KEY ?? "" });
await client.redeemPromotionCode({ customerId: "user_123", body: { code: "LAUNCH20" } });import os
from integrateledger import ledger
client = ledger(api_key=os.environ["LEDGER_API_KEY"])
client.redeem_promotion_code(customer_id="user_123", code="LAUNCH20"){
"referral": {
"referralId": 123,
"programId": "<string>",
"referrerId": "<string>",
"refereeId": "<string>",
"status": "pending",
"refusedReason": "same_payment_method",
"rewardedAt": "<string>",
"createdAt": "<string>"
},
"redemptionId": 123,
"rewardId": "<string>",
"kind": "coupon",
"code": "<string>",
"status": "pending",
"appliesFrom": "next_invoice",
"subscriptionId": 123,
"discount": {
"percentOff": 123,
"amountOffCents": 123,
"currency": "<string>",
"duration": "once",
"durationMonths": 123
},
"grants": [
{
"featureId": "<string>",
"amount": 123,
"expiresAt": "<string>"
}
],
"endsAt": "<string>",
"endedReason": "duration",
"createdAt": "<string>"
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment.",
"issues": [
{
"path": "<string>",
"message": "<string>"
}
]
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment.",
"issues": [
{
"path": "<string>",
"message": "<string>"
}
]
}{
"error": "insufficient_permissions",
"requiredScope": "customers:read",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment.",
"issues": [
{
"path": "<string>",
"message": "<string>"
}
]
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment.",
"issues": [
{
"path": "<string>",
"message": "<string>"
}
]
}{
"error": "payload_too_large",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment.",
"issues": [
{
"path": "<string>",
"message": "<string>"
}
]
}{
"error": "rate_limited",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}Redeem a promotion code
Give a customer a coupon or a grant from a code they typed in your app.
curl --request POST 'https://api.integrateledger.com/v1/customers/redemptions?customerId=user_123' \
-H "Authorization: Bearer $LEDGER_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"code":"LAUNCH20"}'import ledger from "integrateledger";
const client = new ledger({ apiKey: process.env.LEDGER_API_KEY ?? "" });
await client.redeemPromotionCode({ customerId: "user_123", body: { code: "LAUNCH20" } });import os
from integrateledger import ledger
client = ledger(api_key=os.environ["LEDGER_API_KEY"])
client.redeem_promotion_code(customer_id="user_123", code="LAUNCH20"){
"referral": {
"referralId": 123,
"programId": "<string>",
"referrerId": "<string>",
"refereeId": "<string>",
"status": "pending",
"refusedReason": "same_payment_method",
"rewardedAt": "<string>",
"createdAt": "<string>"
},
"redemptionId": 123,
"rewardId": "<string>",
"kind": "coupon",
"code": "<string>",
"status": "pending",
"appliesFrom": "next_invoice",
"subscriptionId": 123,
"discount": {
"percentOff": 123,
"amountOffCents": 123,
"currency": "<string>",
"duration": "once",
"durationMonths": 123
},
"grants": [
{
"featureId": "<string>",
"amount": 123,
"expiresAt": "<string>"
}
],
"endsAt": "<string>",
"endedReason": "duration",
"createdAt": "<string>"
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment.",
"issues": [
{
"path": "<string>",
"message": "<string>"
}
]
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment.",
"issues": [
{
"path": "<string>",
"message": "<string>"
}
]
}{
"error": "insufficient_permissions",
"requiredScope": "customers:read",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment.",
"issues": [
{
"path": "<string>",
"message": "<string>"
}
]
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment.",
"issues": [
{
"path": "<string>",
"message": "<string>"
}
]
}{
"error": "payload_too_large",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}{
"error": "<string>",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment.",
"issues": [
{
"path": "<string>",
"message": "<string>"
}
]
}{
"error": "rate_limited",
"message": "No customer \"user_123\" exists in this environment. Create it with POST /v1/customers, or check that the API key is for the right environment."
}active, with what it gave in grants. For a coupon code, on a current paid plan the coupon covers, Ledger puts it on the customer’s subscription and it discounts from their next invoice (appliesFrom: "next_invoice"). Otherwise it waits for their next attach of a plan it covers (next_attach). A subscription carries one Ledger coupon at a time: a second one is queued and starts when the first ends.
Refusals, in the order Ledger checks: 404 promotion_code_not_found, 409 promotion_code_expired, 409 promotion_code_not_for_customer, 409 promotion_code_first_time_only (the customer has paid for a plan or pack), 409 promotion_code_already_redeemed, 409 promotion_code_exhausted. Send an Idempotency-Key header to retry safely: a retry returns the first redemption. Needs the Billing permission.Authorizations
Body
Response
Redeemed. A grant code's credits and units are the customer's at once (grants). On a current plan a coupon covers, Ledger puts it on the customer's subscription and it discounts from the next invoice; otherwise it waits for their next attach of a covered plan. A repeat with the same Idempotency-Key returns the first redemption.
pending: waiting for a bill (the customer's next attach of a covered plan, or Ledger putting it on their current one). queued: their bill already has a Ledger discount; it starts when that one ends. active: on the bill, or a grant's credits and units granted. ended: used up, or the bill ended. void: never applied, such as an abandoned Checkout; its use was given back.
pending, queued, active, ended, void