palbaseDocs

Palbase IAP · API

POST/iap/customers/{customer_id}/spend

Spend credits or a quota

Takes a customer's credits (credits, a credit of the catalog) or units of a quota (limit) in one step. Credits go from the lots that expire first, bought ones last. A quota counts in its current window, up to the most any product the customer holds gives (the limit's free tier otherwise); past it, a limit with overflow takes credits instead, and one without is refused (409 limit_reached). The Idempotency-Key names the spend for good: sent again — a minute or a month later — it is the same spend (200, Idempotent-Replayed), never a second. A customer not seen before is made. Emits the credits' and quota's events when a balance crosses its low mark or runs out and when a window reaches 80% or 100%, and iap.customer.changed.

Called by your server, with the project's secret key.

Path

customer_idstring · requiredThe customer: the user's id (a guest merged into an account names the account).

Headers

Idempotency-Keystring · requiredNames the operation for good (1 to 255 characters): sent again — a minute or a month later — with the same request, it is the same one, never a second; with a different request it is refused (422 `idempotency_key_reused`). Required. The key is the project's, not the customer's: the same key on two customers names one operation (the second is refused as a different request), so put the customer's id in it.
curl
curl -X POST "https://<your-ref>.palbase.studio/iap/customers/<customer_id>/spend" \
  -H "apikey: $PALBASE_SECRET_KEY" \
  -H "content-type: application/json" \
  -d '{"amount":1,"credits":"string"}'

Responses

200The one this Idempotency-Key made before, as it stands

201The spend

400Neither or both of `credits` and `limit` (`credits_or_limit`), no Idempotency-Key (`idempotency_key_required`), `ttl_seconds` on a spend in one step (`ttl_for_holds`), or a field out of its bounds (`invalid_<field>`)

401No key, not a key of this project, or a token that is not valid (the edge's answer)

403Not the project's secret key (`secret_key_required`)

404The catalog defines no such limit (`limit_not_found`)

409Not enough credits available (`credits_insufficient`), or the window's limit is used and it has no overflow (`limit_reached`); or a request with this Idempotency-Key is still running (`idempotency_key_in_use`, Retry-After) With `limit_reached`, `upgrades` names what would give the customer more of the limit.

410The user was deleted (`customer_erased`): their id is no customer's again

413The request body is too large (`request_too_large`)

422The Idempotency-Key was sent with a different request (`idempotency_key_reused`)

429Over the project's request limit; Retry-After says when to try again

503Another change to this customer is in progress (`customer_busy`), or the platform could not answer now; retrying is safe after Retry-After

defaultAn error: the envelope names it (`error`) and explains it (`error_description`).

Operation Spend of iap's contract.