Skip to content

Paying through the API

What an API call can buy, how it's paid, and what happens when a payment needs you.

3 min read Updated

Some operations cost money. They're paid like the same purchase in the panel, from the account's wallet and its saved cards, without a browser. They're marked Spends money in the reference:

OperationRequest
Create a server POST /v1/servers
Resize a server POST /v1/servers/{serverId}/actions/resize
Turn on a site's malware protection POST /v1/sites/{siteId}/malware-protection/actions/enable
Choose where and how often a site is backed up PUT /v1/sites/{siteId}/backup/settings
Turn on Media Offload for a site POST /v1/sites/{siteId}/media-offload/actions/enable

Each one needs an Idempotency-Key, so that sending it again after a timeout never pays twice (see Idempotency).

How it's paid

  1. The wallet first: its balance pays as much as it can.
  2. Then a card: the account's default card, set in the panel's Billing. Leave paymentMethodId out to pay with it.

A server is billed every month as one ordered in the panel, and a resize charges the difference for the rest of the month at once. Free trial servers can't be made through the API.

Agree to card charges once

Before the API can charge a card, the account agrees once, in the panel, to card charges: the agreement shown in Billing when a card is added or paid with. Until then, an operation that spends money answers 403 charges_not_authorized: In the panel, open Billing and accept the terms once. Then try again.

When the bank asks for a confirmation

Some banks ask the card's owner to confirm a payment (3-D Secure). Code can't do that, so the answer is 402 payment_action_required and nothing is bought. Two ways forward:

  • Add funds to the wallet in the panel (how), then send the request again with a new Idempotency-Key: wallet payments need no confirmation.
  • Make this purchase in the panel instead, where the bank can ask.

When a payment is refused

A 402 means nothing was bought: nothing is created or changed, so there's never a half-made server to clean up, and no event announces one. A server bought through the API is announced (server.created, and site.created for a first site ordered with it) once it's paid for, by webhooks and in the account's events. The refusal is kept with its Idempotency-Key, so once you've fixed the cause, send the request again with a new key.

CodeStatusWhat it meansWhat to do
payment_method_required 402 There's no money in the wallet and no saved card to pay with. Add funds to the wallet or save a card in the panel.
card_declined 402 The card was declined. message gives the bank's reason. Nothing was created. Use another card, or add funds to the wallet.
payment_action_required 402 The bank wants the customer to confirm this payment, which can't happen through the API. Nothing was created. Add funds to the wallet in the panel (wallet payments need no confirmation), or make this purchase in the panel.
payment_required 402 An unpaid bill must be settled first (for example, the Own servers plan's). Pay the open bill on the panel's Billing page, then try again.
payment_failed 402 The payment didn't go through. message gives the reason. Nothing was changed. Use another card, or add funds to the wallet, then try again.
card_needed 402 Servers on this cloud need a saved card: data transfer beyond what the plan includes is charged to it. Save a card in the panel, or pass paymentMethodId.
transfer_unpaid 402 An earlier data transfer bill is unpaid. Pay it on the panel's Billing page, then try again.
billing_error 402, 409, 502 The payment couldn't be made or set up. message gives the reason. Check the card in the panel, then try again. A 502 can be tried again in a minute.
license_required 402 The site is on a server of your own, so RabbitPress Cache needs one of your licences there. Buy a RabbitPress Cache licence in the panel, then install again with its licenseId.
unpaid 402 A Media Offload bill is unpaid, so it can't be turned on for a site. Pay the bill on the panel's Billing page, then try again.
charges_not_authorized 403 The account hasn't agreed to card charges yet. In the panel, open Billing and accept the terms once. Then try again.
card_not_found 404 The card in paymentMethodId isn't one of this account's saved cards. Leave paymentMethodId out to pay with the default card, set in the panel's Billing.
paypal_billed 409 This server is paid through PayPal, so price changes are approved on PayPal's site. Make this change in the panel.

When the payment service fails

A 502 billing_error means the payment service failed while the request ran, and the payment may have gone through. These operations answer it, and for them sending the same request again with the same key is safe: a payment that went through is found, never made twice.

OperationRequest
Create a server POST /v1/servers
Resize a server POST /v1/servers/{serverId}/actions/resize
Turn on a site's malware protection POST /v1/sites/{siteId}/malware-protection/actions/enable
Choose where and how often a site is backed up PUT /v1/sites/{siteId}/backup/settings
Turn on Media Offload for a site POST /v1/sites/{siteId}/media-offload/actions/enable

Every other operation that spends money answers a payment error with 500 internal_error instead, kept with its key: the payment may have gone through. Any operation that spends money, those above included, can also answer 500 when it can't tell what happened, a purchase that ended without what it bought for one (the message says what to look at). After a 500, look at what the request would have bought, and the account's billing, before you try again, with a new key.

PayPal

PayPal can't pay through the API. A server paid through PayPal keeps working with every other operation, but changing its price, like resizing it, answers 409 paypal_billed: do it in the panel.

Still have a question?

Our team answers support tickets about the API, and other developers answer in the community.

Contact support

Popular

API docs