Let customers prepay with credits
Customer buys credits -> Credits are added
Feature use -> Credits are debited
Balance reaches zero -> Access is blocked until they buy more
- TypeScript
- Python
- Go
- cURL
const checkout = await accend.checkout.createSession({
mode: "credits",
customerId: "cus_123",
amount: "50.00",
currency: "USDC"
});
const access = await accend.access.check({
customerId: "cus_123",
meterId: "meter_123",
quantity: 1
});
if (!access.data.allowed && access.data.reason === "insufficient_credits") {
return { error: "not_enough_credits", buyMoreUrl: access.data.paymentUrl };
}
checkout = accend.checkout.create_session({
"mode": "credits",
"customerId": "cus_123",
"amount": "50.00",
"currency": "USDC",
})
access = accend.access.check({
"customerId": "cus_123",
"meterId": "meter_123",
"quantity": 1,
})
client.CreateCheckoutSession(ctx, map[string]any{
"mode": "credits",
"customerId": "cus_123",
"amount": "50.00",
"currency": "USDC",
})
client.CheckAccess(ctx, map[string]any{
"customerId": "cus_123",
"meterId": "meter_123",
"quantity": 1,
})
curl -X POST "https://api.accend.now/v1/checkout/sessions" \
-H "Authorization: Bearer $ACCEND_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"mode":"credits","customerId":"cus_123","amount":"50.00","currency":"USDC"}'