---
title: "client.billing"
description: "Every method in this namespace: its signature, its parameters, what it returns and an example."
url: "https://openemail.uk/docs/ruby/reference/billing"
area: "Ruby"
category: "Reference"
---

# client.billing

Every method in this namespace: its signature, its parameters, what it returns and an example.

## Methods

The plan of the workspace and what it costs, as Plans & Billing shows them: the plan and its usage, the plans on sale, pay as you go, every charge with its invoice, and the links that start a checkout or open the billing portal. Only the workspace owner reaches it, and nothing is paid through the API.

### `billing.get`

Read the plan

```ruby
get(api_key: nil) -> Hash
```

Returns the plan of the workspace and what it includes, as Plans & Billing shows it: how it is billed, when it renews or ends and the next charge, how many domains it holds, how much of this month's sends and today's AI actions are used, and pay as you go. `metered` is false when billing is off on the install, and then nothing is capped.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 `owner_only`, and a key or token limited to particular addresses or domains is 422 `capability_unsupported`.

Scopes: `billing:read`.

**Parameters**

- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with `plan`, `planName`, `interval`, `renewsAt`, `nextCharge`, `domains`, `usage` and `payAsYouGo`.

**Example**

```ruby
billing = client.billing.get

puts billing[:planName], billing.dig(:usage, :sends, :used), billing.dig(:usage, :sends, :limit)
```

**Notes**

- A limit of nil means the plan has none.

Also available in: API [`GET /billing`](https://openemail.uk/docs/api/reference/billing#get-billing); TypeScript [`billing.get()`](https://openemail.uk/docs/sdk/reference/billing#get); Python [`billing.get()`](https://openemail.uk/docs/python/reference/billing#get); CLI [`openemail billing get`](https://openemail.uk/docs/cli/reference/billing#billing-get).

### `billing.list_plans`

List the plans

```ruby
list_plans(api_key: nil) -> Hash
```

Returns every plan, cheapest first, with its price in US cents and what it includes. `available` says whether it is sold on the install, and `intervals` the billing intervals it is sold at.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 `owner_only`, and a key or token limited to particular addresses or domains is 422 `capability_unsupported`.

Scopes: `billing:read`.

**Parameters**

- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with `data`, an Array with one Hash per plan.

**Example**

```ruby
plans = client.billing.list_plans

sold = plans[:data].select { |plan| plan[:available] }
sold.each { |plan| puts plan[:name] }
```

Also available in: API [`GET /billing/plans`](https://openemail.uk/docs/api/reference/billing#get-billing-plans); TypeScript [`billing.listPlans()`](https://openemail.uk/docs/sdk/reference/billing#listPlans); Python [`billing.list_plans()`](https://openemail.uk/docs/python/reference/billing#listPlans); CLI [`openemail billing list-plans`](https://openemail.uk/docs/cli/reference/billing#billing-list-plans).

### `billing.get_usage`

Read the usage history

```ruby
get_usage(days: nil, api_key: nil) -> Hash
```

Returns the sends and AI actions of each day, and what pay as you go extras cost each month, as the Usage charts show them.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 `owner_only`, and a key or token limited to particular addresses or domains is 422 `capability_unsupported`.

Scopes: `billing:read`.

**Parameters**

- `days` (`Integer or String`): How many days back to go, from 1 to 3,660, or `all` for every day since the workspace was made. The server defaults to 30.
- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with `days`, `months`, `dailyAiActions` and `monthlySends`.

**Example**

```ruby
usage = client.billing.get_usage(days: 90)

sent = usage[:days].sum { |day| day[:sends] }
puts sent
```

Also available in: API [`GET /billing/usage`](https://openemail.uk/docs/api/reference/billing#get-billing-usage); TypeScript [`billing.getUsage()`](https://openemail.uk/docs/sdk/reference/billing#getUsage); Python [`billing.get_usage()`](https://openemail.uk/docs/python/reference/billing#getUsage); CLI [`openemail billing get-usage`](https://openemail.uk/docs/cli/reference/billing#billing-get-usage).

### `billing.list_alerts`

List the billing alerts

```ruby
list_alerts(api_key: nil) -> Hash
```

Returns what the billing banner of the app would say now, most urgent first: a failed payment, paused pay as you go, sending or AI paused at a limit, a plan about to end, an allowance nearly used and a charge coming soon. An empty list means there is nothing to say.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 `owner_only`, and a key or token limited to particular addresses or domains is 422 `capability_unsupported`.

Scopes: `billing:read`.

**Parameters**

- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with `data`, an Array with one Hash per alert.

**Example**

```ruby
alerts = client.billing.list_alerts

blocked = alerts[:data].select { |alert| alert[:severity] == "blocked" }
blocked.each { |alert| puts alert[:kind] }
```

**Notes**

- An alert keeps its `id` while the same thing is true, so one that was dismissed can stay dismissed.

Also available in: API [`GET /billing/alerts`](https://openemail.uk/docs/api/reference/billing#get-billing-alerts); TypeScript [`billing.listAlerts()`](https://openemail.uk/docs/sdk/reference/billing#listAlerts); Python [`billing.list_alerts()`](https://openemail.uk/docs/python/reference/billing#listAlerts); CLI [`openemail billing list-alerts`](https://openemail.uk/docs/cli/reference/billing#billing-list-alerts).

### `billing.list_countries`

List the billing countries

```ruby
list_countries(api_key: nil) -> Hash
```

Returns every country a billing address can be in, as the two-letter ISO 3166 codes `save_invoice_details` takes as `country`.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 `owner_only`, and a key or token limited to particular addresses or domains is 422 `capability_unsupported`.

Scopes: `billing:read`.

**Parameters**

- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with the codes in `data`, an Array of Strings.

**Example**

```ruby
countries = client.billing.list_countries

puts countries[:data].include?("DE")
```

Also available in: API [`GET /billing/countries`](https://openemail.uk/docs/api/reference/billing#get-billing-countries); TypeScript [`billing.listCountries()`](https://openemail.uk/docs/sdk/reference/billing#listCountries); Python [`billing.list_countries()`](https://openemail.uk/docs/python/reference/billing#listCountries); CLI [`openemail billing list-countries`](https://openemail.uk/docs/cli/reference/billing#billing-list-countries).

### `billing.get_pay_as_you_go`

Read pay as you go

```ruby
get_pay_as_you_go(api_key: nil) -> Hash
```

Returns pay as you go on the workspace: whether usage past the allowances is billed, the monthly limit and what extras cost so far, the current billing period once it is set up, the limits that can be chosen and the prices.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 `owner_only`, and a key or token limited to particular addresses or domains is 422 `capability_unsupported`.

Scopes: `billing:read`.

**Parameters**

- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with the state, `limits`, `prices` and `period`.

**Example**

```ruby
payg = client.billing.get_pay_as_you_go

puts payg[:enabled], payg[:spentCents], payg[:limitCents]
```

**Notes**

- Amounts are in US cents.

Also available in: API [`GET /billing/pay-as-you-go`](https://openemail.uk/docs/api/reference/billing#get-billing-pay-as-you-go); TypeScript [`billing.getPayAsYouGo()`](https://openemail.uk/docs/sdk/reference/billing#getPayAsYouGo); Python [`billing.get_pay_as_you_go()`](https://openemail.uk/docs/python/reference/billing#getPayAsYouGo); CLI [`openemail billing get-pay-as-you-go`](https://openemail.uk/docs/cli/reference/billing#billing-get-pay-as-you-go).

### `billing.set_pay_as_you_go`

Turn pay as you go on or off

```ruby
set_pay_as_you_go(body = nil, api_key: nil, **fields) -> Hash
```

Turns pay as you go on or off, as the switch on Plans & Billing does. Off takes effect at once, and usage stops at the allowances. On takes effect at once when a card is already saved. The first time, `checkoutUrl` is a link where the person adds a card, and pay as you go starts once they have: call `confirm_pay_as_you_go` after they return.

Nothing is paid through the API: the person pays, changes the card or cancels on the billing provider's page the link opens, as they do from the app.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 `owner_only`, and a key or token limited to particular addresses or domains is 422 `capability_unsupported`.

Scopes: `billing:write`.

**Parameters**

- `enabled` (`Boolean`, required): `true` to turn it on, `false` to turn it off.
- `theme` (`String`): `light` or `dark`, for the page the link opens.
- `locale` (`String`): A language tag such as `de` or `pt-PT`, for the page the link opens.
- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with `enabled`, `suspended`, `activating` and `checkoutUrl`.

**Example**

```ruby
result = client.billing.set_pay_as_you_go(enabled: true)

puts "Add a card here: #{result[:checkoutUrl]}" if result[:checkoutUrl]
```

**Notes**

- With an OAuth access token it asks for a verification code: until the app has verified one, it is refused with 403 `step_up_required`. An API key is never asked.
- Turning it on where pay as you go is not set up on the install is 503 `billing_not_configured`.
- The SDK does not retry it.

Also available in: API [`PATCH /billing/pay-as-you-go`](https://openemail.uk/docs/api/reference/billing#patch-billing-pay-as-you-go); TypeScript [`billing.setPayAsYouGo()`](https://openemail.uk/docs/sdk/reference/billing#setPayAsYouGo); Python [`billing.set_pay_as_you_go()`](https://openemail.uk/docs/python/reference/billing#setPayAsYouGo); CLI [`openemail billing set-pay-as-you-go`](https://openemail.uk/docs/cli/reference/billing#billing-set-pay-as-you-go).

### `billing.set_pay_as_you_go_limit`

Set the pay as you go limit

```ruby
set_pay_as_you_go_limit(body = nil, api_key: nil, **fields) -> Hash
```

Sets the monthly spending limit of pay as you go, in US cents, one of the amounts `get_pay_as_you_go` lists in `limits`. Extras stop for the rest of a calendar month once it is reached.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 `owner_only`, and a key or token limited to particular addresses or domains is 422 `capability_unsupported`.

Scopes: `billing:write`.

**Parameters**

- `limitCents` (`Integer`, required): The limit in US cents: 1,000, 2,500, 5,000, 10,000, 25,000, 50,000, 100,000, 250,000 or 500,000.
- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with `limitCents`.

**Example**

```ruby
client.billing.set_pay_as_you_go_limit(limitCents: 10_000)
```

**Notes**

- With an OAuth access token it asks for a verification code: until the app has verified one, it is refused with 403 `step_up_required`. An API key is never asked.
- A workspace where pay as you go was never set up is 409 `pay_as_you_go_not_enrolled`.
- The SDK does not retry it.

Also available in: API [`PUT /billing/pay-as-you-go/limit`](https://openemail.uk/docs/api/reference/billing#put-billing-pay-as-you-go-limit); TypeScript [`billing.setPayAsYouGoLimit()`](https://openemail.uk/docs/sdk/reference/billing#setPayAsYouGoLimit); Python [`billing.set_pay_as_you_go_limit()`](https://openemail.uk/docs/python/reference/billing#setPayAsYouGoLimit); CLI [`openemail billing set-pay-as-you-go-limit`](https://openemail.uk/docs/cli/reference/billing#billing-set-pay-as-you-go-limit).

### `billing.confirm_pay_as_you_go`

Confirm pay as you go

```ruby
confirm_pay_as_you_go(api_key: nil) -> Hash
```

Checks with the billing provider whether the card from a pay as you go checkout was saved, and records it, as the app does when the person comes back from the checkout. `enabled` says whether pay as you go is on now.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 `owner_only`, and a key or token limited to particular addresses or domains is 422 `capability_unsupported`.

Scopes: `billing:write`.

**Parameters**

- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with `enabled`.

**Example**

```ruby
confirmation = client.billing.confirm_pay_as_you_go

puts confirmation[:enabled]
```

**Notes**

- With an OAuth access token it asks for a verification code: until the app has verified one, it is refused with 403 `step_up_required`. An API key is never asked.
- It is safe to call again.
- The SDK does not retry it.

Also available in: API [`POST /billing/pay-as-you-go/confirm`](https://openemail.uk/docs/api/reference/billing#post-billing-pay-as-you-go-confirm); TypeScript [`billing.confirmPayAsYouGo()`](https://openemail.uk/docs/sdk/reference/billing#confirmPayAsYouGo); Python [`billing.confirm_pay_as_you_go()`](https://openemail.uk/docs/python/reference/billing#confirmPayAsYouGo); CLI [`openemail billing confirm-pay-as-you-go`](https://openemail.uk/docs/cli/reference/billing#billing-confirm-pay-as-you-go).

### `billing.start_checkout`

Start a checkout

```ruby
start_checkout(body = nil, api_key: nil, **fields) -> Hash
```

Starts buying a paid plan for a workspace on Free, as choosing a plan in the app does, and returns the link to the checkout. Nothing is charged until the person pays there, and the plan starts once they have. A workspace that already pays for a plan changes it with `open_portal` instead.

Nothing is paid through the API: the person pays, changes the card or cancels on the billing provider's page the link opens, as they do from the app.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 `owner_only`, and a key or token limited to particular addresses or domains is 422 `capability_unsupported`.

Scopes: `billing:write`.

**Parameters**

- `plan` (`String`, required): `starter`, `business` or `enterprise`.
- `interval` (`String`): `month` or `year`. Defaults to `month`.
- `theme` (`String`): `light` or `dark`, for the page the link opens.
- `locale` (`String`): A language tag such as `de` or `pt-PT`, for the page the link opens.
- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with `url`.

**Example**

```ruby
checkout = client.billing.start_checkout(plan: "business", interval: "year")

puts "Pay here: #{checkout[:url]}"
```

**Notes**

- With an OAuth access token it asks for a verification code: until the app has verified one, it is refused with 403 `step_up_required`. An API key is never asked.
- A workspace that already pays for a plan is 409 `plan_conflict`, and a plan or interval not sold on the install is 422 `plan_unavailable`.
- The SDK does not retry it.

Also available in: API [`POST /billing/checkout`](https://openemail.uk/docs/api/reference/billing#post-billing-checkout); TypeScript [`billing.startCheckout()`](https://openemail.uk/docs/sdk/reference/billing#startCheckout); Python [`billing.start_checkout()`](https://openemail.uk/docs/python/reference/billing#startCheckout); CLI [`openemail billing start-checkout`](https://openemail.uk/docs/cli/reference/billing#billing-start-checkout).

### `billing.open_portal`

Open the billing portal

```ruby
open_portal(body = nil, api_key: nil, **fields) -> Hash
```

Returns a link to the billing portal, where the person changes or cancels the plan, updates the card and downloads past invoices, as Manage does in the app.

Nothing is paid through the API: the person pays, changes the card or cancels on the billing provider's page the link opens, as they do from the app.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 `owner_only`, and a key or token limited to particular addresses or domains is 422 `capability_unsupported`.

Scopes: `billing:write`.

**Parameters**

- `theme` (`String`): `light` or `dark`, for the page the link opens.
- `locale` (`String`): A language tag such as `de` or `pt-PT`, for the page the link opens.
- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with `url`.

**Example**

```ruby
portal = client.billing.open_portal(theme: "dark")

puts portal[:url]
```

**Notes**

- With an OAuth access token it asks for a verification code: until the app has verified one, it is refused with 403 `step_up_required`. An API key is never asked.
- The SDK does not retry it.

Also available in: API [`POST /billing/portal`](https://openemail.uk/docs/api/reference/billing#post-billing-portal); TypeScript [`billing.openPortal()`](https://openemail.uk/docs/sdk/reference/billing#openPortal); Python [`billing.open_portal()`](https://openemail.uk/docs/python/reference/billing#openPortal); CLI [`openemail billing open-portal`](https://openemail.uk/docs/cli/reference/billing#billing-open-portal).

### `billing.list_invoices`

List the charges

```ruby
list_invoices(page: nil, limit: nil, sort: nil, search: nil, api_key: nil) -> Hash
```

Returns every charge of the workspace with the state of its invoice, a page at a time, as History on Plans & Billing lists them. `search:` matches the plan, the invoice number, the charge id and the name billed.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 `owner_only`, and a key or token limited to particular addresses or domains is 422 `capability_unsupported`.

Scopes: `billing:read`.

**Parameters**

- `page` (`Integer`): Which page, from 1.
- `limit` (`Integer`): Charges per page, from 1 to 100. The server defaults to 25.
- `sort` (`String`): `newest`, the default, or `oldest`.
- `search` (`String`): Words to look for, up to 120 characters.
- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with `data`, `total`, `page`, `limit`, `hasMore` and `metered`.

**Example**

```ruby
invoices = client.billing.list_invoices(limit: 10)

unpaid = invoices[:data].reject { |charge| charge[:paid] }
puts unpaid.length
```

**Notes**

- A provider that does not answer is 502 `billing_unreachable`.

Also available in: API [`GET /billing/invoices`](https://openemail.uk/docs/api/reference/billing#get-billing-invoices); TypeScript [`billing.listInvoices()`](https://openemail.uk/docs/sdk/reference/billing#listInvoices); Python [`billing.list_invoices()`](https://openemail.uk/docs/python/reference/billing#listInvoices); CLI [`openemail billing list-invoices`](https://openemail.uk/docs/cli/reference/billing#billing-list-invoices).

### `billing.get_invoice`

Get the invoice of a charge

```ruby
get_invoice(order_id, api_key: nil) -> Hash
```

Returns the link to the invoice of one charge, as a PDF, and its file name. An invoice that was not written yet is written first, which can take a few seconds. The link is signed by the billing provider, downloads the PDF and stops working after a while, so fetch it again rather than keeping it.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 `owner_only`, and a key or token limited to particular addresses or domains is 422 `capability_unsupported`.

Scopes: `billing:read`.

**Parameters**

- `order_id` (`String`, required): The charge id, as `list_invoices` returns it.
- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with `url` and `fileName`.

**Example**

```ruby
latest = client.billing.list_invoices(limit: 1)[:data].first

invoice = client.billing.get_invoice(latest[:id])

puts invoice[:fileName], invoice[:url]
```

**Notes**

- A charge with no billing name and address is 409 `billing_details_required`: save them with `save_invoice_details`. A draft or void charge is 409 `invoice_unavailable`, and an invoice still being written is 504 `invoice_not_ready`.

Also available in: API [`GET /billing/invoices/{orderId}`](https://openemail.uk/docs/api/reference/billing#get-billing-invoices-orderid); TypeScript [`billing.getInvoice()`](https://openemail.uk/docs/sdk/reference/billing#getInvoice); Python [`billing.get_invoice()`](https://openemail.uk/docs/python/reference/billing#getInvoice); CLI [`openemail billing get-invoice`](https://openemail.uk/docs/cli/reference/billing#billing-get-invoice).

### `billing.save_invoice_details`

Save the billing details of a charge

```ruby
save_invoice_details(order_id, body = nil, api_key: nil, **fields) -> Hash
```

Saves the name and address billed on a charge, as the Billing address dialog does, keeps the address for later charges, and starts writing its invoice. `invoice` is `ready` when the charge already had one, `started` when it is being written, and `refused` with the reason in `message`.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 `owner_only`, and a key or token limited to particular addresses or domains is 422 `capability_unsupported`.

Scopes: `billing:write`.

**Parameters**

- `order_id` (`String`, required): The charge id, as `list_invoices` returns it.
- `name` (`String`, required): Who is billed, up to 200 characters.
- `line1` (`String`, required): The street address, up to 200 characters.
- `line2` (`String`): A flat, suite or building, up to 200 characters.
- `city` (`String`, required): Up to 120 characters.
- `postalCode` (`String`): Up to 40 characters.
- `state` (`String`): The state or region, up to 60 characters. In the US and Canada, its two-letter code.
- `country` (`String`, required): A two-letter ISO 3166 code, one of those `list_countries` returns.
- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash with `invoice` and `message`.

**Example**

```ruby
charge_id = "3b9f2c4e-7a1d-4e8b-9c0f-5d6a7b8c9d0e"

client.billing.save_invoice_details(
  charge_id,
  name: "Acme Ltd",
  line1: "1 Market Street",
  city: "London",
  postalCode: "EC1A 1AA",
  country: "GB"
)
```

**Notes**

- With an OAuth access token it asks for a verification code: until the app has verified one, it is refused with 403 `step_up_required`. An API key is never asked.
- An address the billing provider refuses is 422 `billing_address_rejected`.
- The SDK does not retry it.

Also available in: API [`PUT /billing/invoices/{orderId}/details`](https://openemail.uk/docs/api/reference/billing#put-billing-invoices-orderid-details); TypeScript [`billing.saveInvoiceDetails()`](https://openemail.uk/docs/sdk/reference/billing#saveInvoiceDetails); Python [`billing.save_invoice_details()`](https://openemail.uk/docs/python/reference/billing#saveInvoiceDetails); CLI [`openemail billing save-invoice-details`](https://openemail.uk/docs/cli/reference/billing#billing-save-invoice-details).
