openemail.billing
Çdo metodë në këtë hapësirë emrash: nënshkrimi, parametrat, çfarë kthen dhe një shembull.
Metodat
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()billing.list_plans()billing.get_usage()billing.list_alerts()billing.list_countries()billing.get_pay_as_you_go()billing.set_pay_as_you_go()billing.set_pay_as_you_go_limit()billing.confirm_pay_as_you_go()billing.start_checkout()billing.open_portal()billing.list_invoices()billing.get_invoice()billing.save_invoice_details()
billing.get()
Read the plan
def get(*, api_key: str | None = None, timeout: float | None = None) -> BillingResourceReturns 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.
Parametrat
api_keystrOverrides the client's API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Kthen
BillingResource with plan, interval, renewsAt, nextCharge, domains, usage and payAsYouGo.
Shembull
from openemail import openemail billing = openemail.billing.get()sends = billing['usage']['sends']limit = 'no limit' if sends['limit'] is None else sends['limit'] print(billing['planName'], sends['used'], limit)Shënime
A limit of
Nonemeans the plan has none.
E disponueshme edhe në
- API
GET /billing- TypeScript
billing.get()- Ruby
billing.get- CLI
openemail billing get
billing.list_plans()
List the plans
def list_plans( *, api_key: str | None = None, timeout: float | None = None,) -> BillingPlanListResourceReturns 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.
Parametrat
api_keystrOverrides the client's API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Kthen
BillingPlanListResource, a dict with one BillingPlanResource per plan in data.
Shembull
from openemail import openemail plans = openemail.billing.list_plans() for plan in plans['data']: if plan['available']: print(plan['name'], plan['monthlyPriceCents'] / 100, plan['intervals'])E disponueshme edhe në
billing.get_usage()
Read the usage history
def get_usage( *, days: BillingUsageWindow | None = None, api_key: str | None = None, timeout: float | None = None,) -> BillingUsageResourceReturns 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.
Parametrat
daysBillingUsageWindowHow many days back to go, an
intfrom 1 to 3,660, or'all'for every day since the workspace was made. The server defaults to 30.api_keystrOverrides the client's API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Kthen
BillingUsageResource with days, months, dailyAiActions and monthlySends.
Shembull
from openemail import openemail usage = openemail.billing.get_usage(days=90) sent = sum(day['sends'] for day in usage['days']) print(sent, 'sends in the last 90 days')E disponueshme edhe në
- API
GET /billing/usage- TypeScript
billing.getUsage()- Ruby
billing.get_usage- CLI
openemail billing get-usage
billing.list_alerts()
List the billing alerts
def list_alerts( *, api_key: str | None = None, timeout: float | None = None,) -> BillingAlertListResourceReturns 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 data 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.
Parametrat
api_keystrOverrides the client's API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Kthen
BillingAlertListResource, a dict with one BillingAlertResource per alert in data.
Shembull
from openemail import openemail alerts = openemail.billing.list_alerts() for alert in alerts['data']: if alert['severity'] == 'blocked': print(alert['kind'], alert['target'], alert['at'])Shënime
An alert keeps its
idwhile the same thing is true, so one that was dismissed can stay dismissed.
E disponueshme edhe në
billing.list_countries()
List the billing countries
def list_countries( *, api_key: str | None = None, timeout: float | None = None,) -> BillingCountryListResourceReturns 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.
Parametrat
api_keystrOverrides the client's API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Kthen
BillingCountryListResource, a dict with the codes in data.
Shembull
from openemail import openemail countries = openemail.billing.list_countries() print('DE' in countries['data'], len(countries['data']))E disponueshme edhe në
billing.get_pay_as_you_go()
Read pay as you go
def get_pay_as_you_go( *, api_key: str | None = None, timeout: float | None = None,) -> PayAsYouGoResourceReturns 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.
Parametrat
api_keystrOverrides the client's API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Kthen
PayAsYouGoResource with the state, limits, prices and period.
Shembull
from openemail import openemail pay_as_you_go = openemail.billing.get_pay_as_you_go() print(pay_as_you_go['enabled'], pay_as_you_go['spentCents'], pay_as_you_go['limitCents'])Shënime
Amounts are in US cents.
E disponueshme edhe në
billing.set_pay_as_you_go()
Turn pay as you go on or off
def set_pay_as_you_go( body: PayAsYouGoSet, *, api_key: str | None = None, timeout: float | None = None,) -> PayAsYouGoSwitchResourceTurns 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.
Parametrat
body['enabled']boolE detyrueshmeTrueto turn it on,Falseto turn it off.body['theme']BillingTheme'light'or'dark', for the page the link opens.body['locale']strA language tag such as
'de'or'pt-PT', for the page the link opens.api_keystrOverrides the client's API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Kthen
PayAsYouGoSwitchResource with enabled, suspended, activating and checkoutUrl.
Shembull
from openemail import openemail switch = openemail.billing.set_pay_as_you_go({'enabled': True}) if switch['checkoutUrl']: print('Add a card here:', switch['checkoutUrl'])else: print('Pay as you go is on:', switch['enabled'])Shënime
With an OAuth access token it asks for a verification code: until the app has verified one, it raises
OpenEmailApiErrorwith status 403, codestep_up_requiredandis_step_up_requiredset. 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.
E disponueshme edhe në
billing.set_pay_as_you_go_limit()
Set the pay as you go limit
def set_pay_as_you_go_limit( body: PayAsYouGoLimitSet, *, api_key: str | None = None, timeout: float | None = None,) -> PayAsYouGoLimitResourceSets 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.
Parametrat
body['limitCents']intE detyrueshmeThe limit in US cents: 1,000, 2,500, 5,000, 10,000, 25,000, 50,000, 100,000, 250,000 or 500,000, the values in
PAY_AS_YOU_GO_LIMITS_CENTS.api_keystrOverrides the client's API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Kthen
PayAsYouGoLimitResource with limitCents.
Shembull
from openemail import openemail saved = openemail.billing.set_pay_as_you_go_limit({'limitCents': 10_000}) print(saved['limitCents'] / 100, 'US dollars a month at most')Shënime
With an OAuth access token it asks for a verification code: until the app has verified one, it raises
OpenEmailApiErrorwith status 403, codestep_up_requiredandis_step_up_requiredset. 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.
E disponueshme edhe në
billing.confirm_pay_as_you_go()
Confirm pay as you go
def confirm_pay_as_you_go( *, api_key: str | None = None, timeout: float | None = None,) -> PayAsYouGoConfirmationResourceChecks 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.
Parametrat
api_keystrOverrides the client's API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Kthen
PayAsYouGoConfirmationResource with enabled.
Shembull
from openemail import openemail confirmation = openemail.billing.confirm_pay_as_you_go() print('Pay as you go is on' if confirmation['enabled'] else 'No card was saved')Shënime
With an OAuth access token it asks for a verification code: until the app has verified one, it raises
OpenEmailApiErrorwith status 403, codestep_up_requiredandis_step_up_requiredset. An API key is never asked.It is safe to call again.
The SDK does not retry it.
E disponueshme edhe në
billing.start_checkout()
Start a checkout
def start_checkout( body: BillingCheckoutCreate, *, api_key: str | None = None, timeout: float | None = None,) -> BillingCheckoutResourceStarts 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.
Parametrat
body['plan']PaidPlanIdE detyrueshme'starter','business'or'enterprise'.body['interval']BillingInterval'month'or'year'. Defaults to'month'.body['theme']BillingTheme'light'or'dark', for the page the link opens.body['locale']strA language tag such as
'de'or'pt-PT', for the page the link opens.api_keystrOverrides the client's API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Kthen
BillingCheckoutResource with url.
Shembull
from openemail import openemail checkout = openemail.billing.start_checkout({'plan': 'business', 'interval': 'year'}) print('Pay here:', checkout['url'])Shënime
With an OAuth access token it asks for a verification code: until the app has verified one, it raises
OpenEmailApiErrorwith status 403, codestep_up_requiredandis_step_up_requiredset. 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 422plan_unavailable.The SDK does not retry it.
E disponueshme edhe në
billing.open_portal()
Open the billing portal
def open_portal( body: BillingHandoff | None = None, *, api_key: str | None = None, timeout: float | None = None,) -> BillingPortalResourceReturns 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. The body is optional.
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.
Parametrat
body['theme']BillingTheme'light'or'dark', for the page the link opens.body['locale']strA language tag such as
'de'or'pt-PT', for the page the link opens.api_keystrOverrides the client's API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Kthen
BillingPortalResource with url.
Shembull
from openemail import openemail portal = openemail.billing.open_portal({'theme': 'dark'}) print('Manage the plan here:', portal['url'])Shënime
With an OAuth access token it asks for a verification code: until the app has verified one, it raises
OpenEmailApiErrorwith status 403, codestep_up_requiredandis_step_up_requiredset. An API key is never asked.The SDK does not retry it.
E disponueshme edhe në
billing.list_invoices()
List the charges
def list_invoices( *, page: int | None = None, limit: int | None = None, sort: BillingInvoiceSort | None = None, search: str | None = None, api_key: str | None = None, timeout: float | None = None,) -> BillingInvoiceListResourceReturns every charge of the workspace with the state of its invoice, a page at a time, as History on Plans & Billing lists them. Pages are numbered rather than cursored: ask for the next one with page= while hasMore is True. 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.
Parametrat
pageintWhich page, from 1.
limitintCharges per page, from 1 to 100. The server defaults to 25.
sortBillingInvoiceSort'newest', the default, or'oldest'.searchstrWords to look for, up to 120 characters.
api_keystrOverrides the client's API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Kthen
BillingInvoiceListResource, a dict with data, total, page, limit, hasMore and metered.
Shembull
from openemail import openemail charges = openemail.billing.list_invoices(limit=10) for charge in charges['data']: if not charge['paid']: print(charge['id'], charge['amountCents'], charge['currency'], charge['status'])Shënime
A provider that does not answer is 502
billing_unreachable.
E disponueshme edhe në
billing.get_invoice()
Get the invoice of a charge
def get_invoice( order_id: str, *, api_key: str | None = None, timeout: float | None = None,) -> BillingInvoiceLinkResourceReturns 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.
Parametrat
order_idstrE detyrueshmeThe charge id, the
idof a charge inlist_invoices.api_keystrOverrides the client's API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Kthen
BillingInvoiceLinkResource with url and fileName.
Shembull
from openemail import openemail charges = openemail.billing.list_invoices(limit=1) for charge in charges['data']: invoice = openemail.billing.get_invoice(charge['id']) print(invoice['fileName'], invoice['url'])Shënime
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.
E disponueshme edhe në
billing.save_invoice_details()
Save the billing details of a charge
def save_invoice_details( order_id: str, body: BillingDetailsSet, *, api_key: str | None = None, timeout: float | None = None,) -> BillingInvoiceDetailsResourceSaves 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.
Parametrat
order_idstrE detyrueshmeThe charge id, the
idof a charge inlist_invoices.body['name']strE detyrueshmeWho is billed, up to 200 characters.
body['line1']strE detyrueshmeThe street address, up to 200 characters.
body['line2']strA flat, suite or building, up to 200 characters.
body['city']strE detyrueshmeUp to 120 characters.
body['postalCode']strUp to 40 characters.
body['state']strThe state or region, up to 60 characters. In the US and Canada, its two-letter code.
body['country']strE detyrueshmeA two-letter ISO 3166 code, one of those
list_countriesreturns.api_keystrOverrides the client's API key for this call only.
timeoutfloatSeconds this call may take, the response included, before it raises
OpenEmailNetworkErrorwithis_timeout. It overrides the client'stimeoutfor this call, and0turns the limit off.
Kthen
BillingInvoiceDetailsResource with invoice and message.
Shembull
from openemail import openemail details = openemail.billing.save_invoice_details( '3f6c2a9e-8b1d-4e7a-9c35-2d4f1b8e6a07', { 'name': 'Acme Ltd', 'line1': '1 Market Street', 'city': 'London', 'postalCode': 'EC1A 1AA', 'country': 'GB', },) print(details['invoice'], details['message'])Shënime
With an OAuth access token it asks for a verification code: until the app has verified one, it raises
OpenEmailApiErrorwith status 403, codestep_up_requiredandis_step_up_requiredset. An API key is never asked.An address the billing provider refuses is 422
billing_address_rejected.The SDK does not retry it.