@talosjs/payment wraps the Polar merchant-of-record API behind six focused, injectable classes — PolarCheckout, PolarProduct, PolarCustomer, PolarCustomerPortal, PolarDiscount, and PolarAnalytics — plus a full set of typed models (IProduct, IPlan, ICredit, ISubscription, IDiscount, checkout and customer payload types, and enums like EPriceType, EDiscountType, ESubscriptionPeriod, EBenefitType) for pricing, subscriptions, and billing metadata. Each class talks to Polar through the official @polar-sh/sdk client and normalizes its responses into these plain Talos types, so call sites never touch the SDK directly.
Installation
@talosjs/payment depends on Polar’s SDK.
Configuration
Every class reads its Polar access token and environment fromAppEnv, resolved through the container.
PaymentException (TOKEN_REQUIRED).
Environment variables
Usage
Checkouts
PolarCheckout creates and retrieves checkout sessions.
get(id) fetches an existing checkout by id; both methods return a CheckoutType with status, clientSecret, url, amount, currency, and the resolved customer.
Products
PolarProduct creates, updates, and archives products, mapping Talos’s IProduct (prices, images, benefits, custom fields) to Polar’s payload.
Customers
PolarCustomer covers the full customer lifecycle, including lookups by your own externalId so you never have to store Polar’s id separately.
Customer portal
PolarCustomerPortal creates authenticated customer sessions and resolves the hosted portal URL for an organization.
Discounts
PolarDiscount creates percentage or fixed discounts, once, repeating, or forever, and manages their lifecycle.
Analytics
PolarAnalytics reads revenue and subscription metrics over a date range and interval, plus the query limits Polar enforces per interval.
API
Exceptions
Every class throwsPaymentException (extending Exception, mapped to InternalServerError) with a machine-readable key.
Types
Beyond the six service classes,@talosjs/payment exports the domain model backing them: IProduct, IPlan, IFeature, ICredit, ISubscription, IDiscount, PriceType, CustomFieldType, BenefitType (and its variants — CreditsBenefitType, LicenseKeysBenefitType, FileDownloadsBenefitType, GitHubRepositoryAccessBenefitType, DiscordAccessBenefitType, CustomBenefitType), the checkout and customer payload types, and the EPriceType, EDiscountType, EDiscountDuration, ESubscriptionPeriod, EBenefitType, EGitHubPermission, EAnalyticsInterval, and EBillingType enums. Currency amounts are typed against CurrencyCodeType from @talosjs/currencies.