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 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.getbilling.list_plansbilling.get_usagebilling.list_alertsbilling.list_countriesbilling.get_pay_as_you_gobilling.set_pay_as_you_gobilling.set_pay_as_you_go_limitbilling.confirm_pay_as_you_gobilling.start_checkoutbilling.open_portalbilling.list_invoicesbilling.get_invoicebilling.save_invoice_detailsbilling.list_add_onsbilling.start_add_on_checkoutbilling.cancel_add_on
billing.get
Read the plan
get(api_key: nil) -> HashReturns the plan of the workspace and what it includes, as 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 while billing is switched off, 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.
Parameters
api_keyStringOverrides the client's API key for this call only.
Returns
A Hash with plan, planName, interval, renewsAt, nextCharge, domains, usage and payAsYouGo.
Example
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- TypeScript
nextmail.billing.get()- Python
billing.get()- PHP
billing->get- Go
Billing.Get- Java
billing().get- C#
Billing.GetAsync- CLI
nextmail billing get
billing.list_plans
List the plans
list_plans(api_key: nil) -> HashReturns every plan, cheapest first, with its price in US cents and what it includes. available says whether it is on sale, 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.
Parameters
api_keyStringOverrides the client's API key for this call only.
Returns
A Hash with data, an Array with one Hash per plan.
Example
plans = client.billing.list_plans sold = plans[:data].select { |plan| plan[:available] }sold.each { |plan| puts plan[:name] }Also available in
billing.get_usage
Read the usage history
get_usage(days: nil, api_key: nil) -> HashReturns 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.
Parameters
daysInteger or StringHow many days back to go, from 1 to 3,660, or
allfor every day since the workspace was made. The server defaults to 30.api_keyStringOverrides the client's API key for this call only.
Returns
A Hash with days, months, dailyAiActions and monthlySends.
Example
usage = client.billing.get_usage(days: 90) sent = usage[:days].sum { |day| day[:sends] }puts sentAlso available in
billing.list_alerts
List the billing alerts
list_alerts(api_key: nil) -> HashReturns 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.
Parameters
api_keyStringOverrides the client's API key for this call only.
Returns
A Hash with data, an Array with one Hash per alert.
Example
alerts = client.billing.list_alerts blocked = alerts[:data].select { |alert| alert[:severity] == "blocked" }blocked.each { |alert| puts alert[:kind] }Notes
An alert keeps its
idwhile the same thing is true, so one that was dismissed can stay dismissed.
Also available in
billing.list_countries
List the billing countries
list_countries(api_key: nil) -> HashReturns 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.
Parameters
api_keyStringOverrides the client's API key for this call only.
Returns
A Hash with the codes in data, an Array of Strings.
Example
countries = client.billing.list_countries puts countries[:data].include?("DE")Also available in
billing.get_pay_as_you_go
Read pay as you go
get_pay_as_you_go(api_key: nil) -> HashReturns 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.
Parameters
api_keyStringOverrides the client's API key for this call only.
Returns
A Hash with the state, limits, prices and period.
Example
payg = client.billing.get_pay_as_you_go puts payg[:enabled], payg[:spentCents], payg[:limitCents]Notes
Amounts are in US cents.
Also available in
billing.set_pay_as_you_go
Turn pay as you go on or off
set_pay_as_you_go(body = nil, api_key: nil, **fields) -> HashTurns pay as you go on or off, as the switch on 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.
Parameters
enabledBooleanRequiredtrueto turn it on,falseto turn it off.themeStringlightordark, for the page the link opens.api_keyStringOverrides the client's API key for this call only.
Returns
A Hash with enabled, suspended, activating and checkoutUrl.
Example
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 while pay as you go is unavailable is 503
billing_not_configured.The SDK does not retry it.
Also available in
billing.set_pay_as_you_go_limit
Set the pay as you go limit
set_pay_as_you_go_limit(body = nil, api_key: nil, **fields) -> HashSets 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.
Parameters
limitCentsIntegerRequiredThe limit in US cents: 1,000, 2,500, 5,000, 10,000, 25,000, 50,000, 100,000, 250,000 or 500,000.
api_keyStringOverrides the client's API key for this call only.
Returns
A Hash with limitCents.
Example
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
billing.confirm_pay_as_you_go
Confirm pay as you go
confirm_pay_as_you_go(api_key: nil) -> HashChecks 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.
Parameters
api_keyStringOverrides the client's API key for this call only.
Returns
A Hash with enabled.
Example
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
billing.start_checkout
Start a checkout
start_checkout(body = nil, api_key: nil, **fields) -> HashStarts 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.
Parameters
planStringRequiredstarter,businessorenterprise.intervalStringmonthoryear. Defaults tomonth.themeStringlightordark, for the page the link opens.api_keyStringOverrides the client's API key for this call only.
Returns
A Hash with url.
Example
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 that is not on sale is 422plan_unavailable.The SDK does not retry it.
Also available in
billing.open_portal
Open the billing portal
open_portal(body = nil, api_key: nil, **fields) -> HashReturns 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.
Parameters
themeStringlightordark, for the page the link opens.api_keyStringOverrides the client's API key for this call only.
Returns
A Hash with url.
Example
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
billing.list_invoices
List the charges
list_invoices(page: nil, limit: nil, sort: nil, search: nil, api_key: nil) -> HashReturns every charge of the workspace with the state of its invoice, a page at a time, as History on 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.
Parameters
pageIntegerWhich page, from 1.
limitIntegerCharges per page, from 1 to 100. The server defaults to 25.
sortStringnewest, the default, oroldest.searchStringWords to look for, up to 120 characters.
api_keyStringOverrides the client's API key for this call only.
Returns
A Hash with data, total, page, limit, hasMore and metered.
Example
invoices = client.billing.list_invoices(limit: 10) unpaid = invoices[:data].reject { |charge| charge[:paid] }puts unpaid.lengthNotes
A provider that does not answer is 502
billing_unreachable.
Also available in
billing.get_invoice
Get the invoice of a charge
get_invoice(order_id, api_key: nil) -> HashReturns 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.
Parameters
order_idStringRequiredThe charge id, as
list_invoicesreturns it.api_keyStringOverrides the client's API key for this call only.
Returns
A Hash with url and fileName.
Example
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 withsave_invoice_details. A draft or void charge is 409invoice_unavailable, and an invoice still being written is 504invoice_not_ready.
Also available in
billing.save_invoice_details
Save the billing details of a charge
save_invoice_details(order_id, body = nil, api_key: nil, **fields) -> HashSaves 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.
Parameters
order_idStringRequiredThe charge id, as
list_invoicesreturns it.nameStringRequiredWho is billed, up to 200 characters.
line1StringRequiredThe street address, up to 200 characters.
line2StringA flat, suite or building, up to 200 characters.
cityStringRequiredUp to 120 characters.
postalCodeStringUp to 40 characters.
stateStringThe state or region, up to 60 characters. In the US and Canada, its two-letter code.
countryStringRequiredA two-letter ISO 3166 code, one of those
list_countriesreturns.api_keyStringOverrides the client's API key for this call only.
Returns
A Hash with invoice and message.
Example
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
billing.list_add_ons
List add-ons
list_add_ons(api_key: nil) -> HashReturns what can be bought on top of the plan, today the dedicated sending IP: whether it is for sale, its price per IP a month in priceCents, whether the workspace has it and when it ends, the IPs it brought, and eligibility, which says whether the workspace qualifies. A dedicated IP needs the Business or Enterprise plan and at least 100,000 emails sent in a month, because below that volume it delivers worse than the shared IPs.
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.
Parameters
api_keyStringOverrides the client's API key for this call only.
Returns
A Hash with one Hash per add-on in data: addOn, available, status, priceCents, endsAt, eligibility and ips.
Example
add_ons = client.billing.list_add_ons add_ons[:data].each do |add_on| puts "#{add_on[:addOn]} #{add_on[:eligibility][:eligible]} #{add_on[:eligibility][:reason]}"endNotes
statusisniluntil the workspace has the add-on.pendingis paid and being set up,warmingandactivesend through the dedicated IP, andreleasingis being taken down.A GET is retried automatically on network failure and on 408, 500, 502, 503 and 504 responses, up to the client's
max_retries:, and on a 429 only when it carries aRetry-Afterof a minute or less.
Also available in
billing.start_add_on_checkout
Start a checkout for an add-on
start_add_on_checkout(body = nil, api_key: nil, **fields) -> HashStarts buying an add-on, as the button under Billing does, and returns the link to the checkout. Nothing is charged until the person pays there. Once it is paid the dedicated IP is set up and warmed up, which sending.list_dedicated_ips shows.
Nothing is paid through the API: the person pays 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.
Parameters
addOnStringRequiredThe add-on to buy:
dedicated-ip.themeStringlightordark, for the page the link opens.api_keyStringOverrides the client's API key for this call only.
Returns
A Hash with addOn and url.
Example
checkout = client.billing.start_add_on_checkout(addOn: "dedicated-ip") 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 has the add-on is 409
add_on_already_active, one that does not qualify is 409add_on_not_eligible, and when every IP is taken it is 409add_on_sold_out. While add-ons are not on sale it is 503add_on_unavailable.The SDK does not retry it.
Also available in
billing.cancel_add_on
Cancel an add-on
cancel_add_on(add_on, api_key: nil) -> HashCancels an add-on. It stays until the end of the month already paid for, which endsAt gives. Then the dedicated IP is released and mail leaves through the shared IPs again.
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.
Parameters
add_onStringRequiredThe add-on to cancel:
dedicated-ip.api_keyStringOverrides the client's API key for this call only.
Returns
A Hash with the add-on, now with endsAt set.
Example
add_on = client.billing.cancel_add_on("dedicated-ip") puts "Ends at #{add_on[:endsAt]}"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 does not have the add-on, or whose add-on is already ending, is 409
add_on_not_active.The SDK does not retry a delete.
Google Workspace