Elixir SDK and client for the Polar API.
Configuration
Add your PolarExpress credentials to your application config:
# config/runtime.exs
config :polar_express,
api_key: System.fetch_env!("POLAR_ACCESS_TOKEN"),
webhook_secret: System.fetch_env!("POLAR_WEBHOOK_SECRET")Then create a client — it picks up your config automatically:
client = PolarExpress.client()
{:ok, customer} = PolarExpress.Services.CustomersService.create_customer(client, %{
email: "jane@example.com"
})Per-Client Overrides
Override any config option when creating a client:
# Use sandbox environment
client = PolarExpress.client(server: :sandbox)
# Explicit key (ignores config)
client = PolarExpress.client("pk_test_other", max_retries: 5)Config Precedence
Options are resolved in this order (highest wins):
- Explicit arguments to
client/1orclient/2 - Application config (
config :polar_express, ...) - Struct defaults (e.g.
max_retries: 2)
Supported Config Keys
Client options (used by PolarExpress.client/0,1,2):
:api_key- Polar API key (required):server- API environment::productionor:sandbox(default::production):max_retries- Maximum retry attempts (default: 2):timeout_ms- Request timeout in ms (default: 30_000):finch- Custom Finch instance name (default:PolarExpress.Finch)
Non-client options (used by other modules):
:webhook_secret- Webhook signing secret (used byPolarExpress.WebhookPlug)
Summary
Functions
Get BenefitGrantsService module
Get BenefitsService module
Get CheckoutLinksService module
Get CheckoutsService module
Create a new PolarExpress client from application config.
Create a new PolarExpress client with overrides.
Create a new PolarExpress client with an explicit API key.
Get CustomFieldsService module
Get CustomerMetersService module
Get CustomerPortal namespace with 12 sub-services
Get CustomerSeatsService module
Get CustomerSessionsService module
Get CustomersService module
Get DiscountsService module
Get DisputesService module
Get EventTypesService module
Get EventsService module
Get FilesService module
Get LicenseKeysService module
Get MemberSessionsService module
Get MembersService module
Get MetersService module
Get MetricsService module
Get Oauth2Service module
Get OrdersService module
Get OrganizationAccessTokensService module
Get OrganizationsService module
Get PaymentsService module
Get ProductsService module
Get RefundsService module
Get SubscriptionsService module
Returns the library version.
Get WebhooksService module
Functions
Get BenefitGrantsService module
Get BenefitsService module
Get CheckoutLinksService module
Get CheckoutsService module
@spec client() :: PolarExpress.Client.t()
Create a new PolarExpress client from application config.
Reads :api_key and other options from config :polar_express.
Raises if :api_key is not configured.
Example
# config/runtime.exs
config :polar_express, api_key: System.fetch_env!("POLAR_ACCESS_TOKEN")
# Then in your code:
client = PolarExpress.client()
@spec client(String.t() | keyword()) :: PolarExpress.Client.t()
Create a new PolarExpress client with overrides.
When given a string, treated as an explicit API key. When given a keyword list, merges with application config.
Examples
# Explicit API key
client = PolarExpress.client("pk_test_...")
# Config defaults + overrides
client = PolarExpress.client(server: :sandbox, max_retries: 5)
@spec client( String.t(), keyword() ) :: PolarExpress.Client.t()
Create a new PolarExpress client with an explicit API key.
Application config provides defaults for all other options.
Examples
client = PolarExpress.client("pk_test_...")
client = PolarExpress.client("pk_test_...", server: :sandbox, max_retries: 5)
Get CustomFieldsService module
Get CustomerMetersService module
Get CustomerPortal namespace with 12 sub-services
Get CustomerSeatsService module
Get CustomerSessionsService module
Get CustomersService module
Get DiscountsService module
Get DisputesService module
Get EventTypesService module
Get EventsService module
Get FilesService module
Get LicenseKeysService module
Get MemberSessionsService module
Get MembersService module
Get MetersService module
Get MetricsService module
Get Oauth2Service module
Get OrdersService module
Get OrganizationAccessTokensService module
Get OrganizationsService module
Get PaymentsService module
Get ProductsService module
Get RefundsService module
Get SubscriptionsService module
@spec version() :: String.t()
Returns the library version.
Get WebhooksService module