polargo

package module
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 14 Imported by: 2

README

github.com/polarsource/polar-go

Developer-friendly & type-safe Go SDK specifically catered to leverage github.com/polarsource/polar-go API.

Summary

Polar API: Polar HTTP and Webhooks API

Read the docs at https://polar.sh/docs/api-reference

Table of Contents

SDK Installation

To add the SDK as a dependency to your project:

go get github.com/polarsource/polar-go

SDK Example Usage

Example
package main

import (
	"context"
	polargo "github.com/polarsource/polar-go"
	"log"
	"os"
)

func main() {
	ctx := context.Background()

	s := polargo.New(
		polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
	)

	res, err := s.Organizations.List(ctx, nil, polargo.Pointer[int64](1), polargo.Pointer[int64](10), nil)
	if err != nil {
		log.Fatal(err)
	}
	if res.ListResourceOrganization != nil {
		for {
			// handle items

			res, err = res.Next()

			if err != nil {
				// handle error
			}

			if res == nil {
				break
			}
		}
	}
}

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

Name Type Scheme Environment Variable
AccessToken http HTTP Bearer POLAR_ACCESS_TOKEN

You can configure it using the WithSecurity option when initializing the SDK client instance. For example:

package main

import (
	"context"
	polargo "github.com/polarsource/polar-go"
	"log"
	"os"
)

func main() {
	ctx := context.Background()

	s := polargo.New(
		polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
	)

	res, err := s.Organizations.List(ctx, nil, polargo.Pointer[int64](1), polargo.Pointer[int64](10), nil)
	if err != nil {
		log.Fatal(err)
	}
	if res.ListResourceOrganization != nil {
		for {
			// handle items

			res, err = res.Next()

			if err != nil {
				// handle error
			}

			if res == nil {
				break
			}
		}
	}
}

Per-Operation Security Schemes

Some operations in this SDK require the security scheme to be specified at the request level. For example:

package main

import (
	"context"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/models/operations"
	"log"
)

func main() {
	ctx := context.Background()

	s := polargo.New()

	res, err := s.CustomerPortal.BenefitGrants.List(ctx, operations.CustomerPortalBenefitGrantsListRequest{}, operations.CustomerPortalBenefitGrantsListSecurity{})
	if err != nil {
		log.Fatal(err)
	}
	if res.ListResourceCustomerBenefitGrant != nil {
		for {
			// handle items

			res, err = res.Next()

			if err != nil {
				// handle error
			}

			if res == nil {
				break
			}
		}
	}
}

Available Resources and Operations

Available methods
BenefitGrants
  • List - List Benefit Grants
Benefits
  • List - List Checkout Links
  • Create - Create Checkout Link
  • Get - Get Checkout Link
  • Delete - Delete Checkout Link
  • Update - Update Checkout Link
Checkouts
  • List - List Checkout Sessions
  • Create - Create Checkout Session
  • Get - Get Checkout Session
  • Update - Update Checkout Session
  • ClientGet - Get Checkout Session from Client
  • ClientUpdate - Update Checkout Session from Client
  • ClientConfirm - Confirm Checkout Session from Client
CustomFields
  • List - List Custom Fields
  • Create - Create Custom Field
  • Get - Get Custom Field
  • Delete - Delete Custom Field
  • Update - Update Custom Field
CustomerMeters
  • List - List Customer Meters
  • Get - Get Customer Meter
CustomerPortal.BenefitGrants
  • List - List Benefit Grants
  • Get - Get Benefit Grant
  • Update - Update Benefit Grant
CustomerPortal.CustomerMeters
  • List - List Meters
  • Get - Get Customer Meter
CustomerPortal.CustomerSession
CustomerPortal.Customers
CustomerPortal.Downloadables
  • List - List Downloadables
CustomerPortal.LicenseKeys
CustomerPortal.Members
CustomerPortal.Orders
CustomerPortal.Organizations
  • Get - Get Organization
CustomerPortal.Seats
CustomerPortal.Subscriptions
  • List - List Subscriptions
  • Get - Get Subscription
  • Cancel - Cancel Subscription
  • Update - Update Subscription
CustomerPortal.Wallets
  • List - List Wallets
  • Get - Get Wallet
CustomerSeats
CustomerSessions
  • Create - Create Customer Session
Customers
Discounts
Disputes
  • List - List Disputes
  • Get - Get Dispute
EventTypes
  • List - List Event Types
  • Update - Update Event Type
Events
Files
LicenseKeys
Members
Meters
Metrics
Oauth2
Oauth2.Clients
Orders
OrganizationAccessTokens
Organizations
  • List - List Organizations
  • Create - Create Organization
  • Get - Get Organization
  • Update - Update Organization
Payments
  • List - List Payments
  • Get - Get Payment
Products
Refunds
Subscriptions
  • List - List Subscriptions
  • Create - Create Subscription
  • Export - Export Subscriptions
  • Get - Get Subscription
  • Revoke - Revoke Subscription
  • Update - Update Subscription
Webhooks

Pagination

Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the returned response object will have a Next method that can be called to pull down the next group of results. If the return value of Next is nil, then there are no more pages to be fetched.

Here's an example of one such pagination call:

package main

import (
	"context"
	polargo "github.com/polarsource/polar-go"
	"log"
	"os"
)

func main() {
	ctx := context.Background()

	s := polargo.New(
		polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
	)

	res, err := s.Organizations.List(ctx, nil, polargo.Pointer[int64](1), polargo.Pointer[int64](10), nil)
	if err != nil {
		log.Fatal(err)
	}
	if res.ListResourceOrganization != nil {
		for {
			// handle items

			res, err = res.Next()

			if err != nil {
				// handle error
			}

			if res == nil {
				break
			}
		}
	}
}

Retries

Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.

To change the default retry strategy for a single API call, simply provide a retry.Config object to the call by using the WithRetries option:

package main

import (
	"context"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/retry"
	"log"
	"models/operations"
	"os"
)

func main() {
	ctx := context.Background()

	s := polargo.New(
		polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
	)

	res, err := s.Organizations.List(ctx, nil, polargo.Pointer[int64](1), polargo.Pointer[int64](10), nil, operations.WithRetries(
		retry.Config{
			Strategy: "backoff",
			Backoff: &retry.BackoffStrategy{
				InitialInterval: 1,
				MaxInterval:     50,
				Exponent:        1.1,
				MaxElapsedTime:  100,
			},
			RetryConnectionErrors: false,
		}))
	if err != nil {
		log.Fatal(err)
	}
	if res.ListResourceOrganization != nil {
		for {
			// handle items

			res, err = res.Next()

			if err != nil {
				// handle error
			}

			if res == nil {
				break
			}
		}
	}
}

If you'd like to override the default retry strategy for all operations that support retries, you can use the WithRetryConfig option at SDK initialization:

package main

import (
	"context"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/retry"
	"log"
	"os"
)

func main() {
	ctx := context.Background()

	s := polargo.New(
		polargo.WithRetryConfig(
			retry.Config{
				Strategy: "backoff",
				Backoff: &retry.BackoffStrategy{
					InitialInterval: 1,
					MaxInterval:     50,
					Exponent:        1.1,
					MaxElapsedTime:  100,
				},
				RetryConnectionErrors: false,
			}),
		polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
	)

	res, err := s.Organizations.List(ctx, nil, polargo.Pointer[int64](1), polargo.Pointer[int64](10), nil)
	if err != nil {
		log.Fatal(err)
	}
	if res.ListResourceOrganization != nil {
		for {
			// handle items

			res, err = res.Next()

			if err != nil {
				// handle error
			}

			if res == nil {
				break
			}
		}
	}
}

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both.

By Default, an API error will return apierrors.APIError. When custom error responses are specified for an operation, the SDK may also return their associated error. You can refer to respective Errors tables in SDK docs for more details on possible error types for each operation.

For example, the List function may return the following errors:

Error Type Status Code Content Type
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*
Example
package main

import (
	"context"
	"errors"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/models/apierrors"
	"log"
	"os"
)

func main() {
	ctx := context.Background()

	s := polargo.New(
		polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
	)

	res, err := s.Organizations.List(ctx, nil, polargo.Pointer[int64](1), polargo.Pointer[int64](10), nil)
	if err != nil {

		var e *apierrors.HTTPValidationError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *apierrors.APIError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}
	}
}

Server Selection

Select Server by Name

You can override the default server globally using the WithServer(server string) option when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the names associated with the available servers:

Name Server Description
production https://api.polar.sh Production environment
sandbox https://sandbox-api.polar.sh Sandbox environment
Example
package main

import (
	"context"
	polargo "github.com/polarsource/polar-go"
	"log"
	"os"
)

func main() {
	ctx := context.Background()

	s := polargo.New(
		polargo.WithServer("production"),
		polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
	)

	res, err := s.Organizations.List(ctx, nil, polargo.Pointer[int64](1), polargo.Pointer[int64](10), nil)
	if err != nil {
		log.Fatal(err)
	}
	if res.ListResourceOrganization != nil {
		for {
			// handle items

			res, err = res.Next()

			if err != nil {
				// handle error
			}

			if res == nil {
				break
			}
		}
	}
}

Override Server URL Per-Client

The default server can also be overridden globally using the WithServerURL(serverURL string) option when initializing the SDK client instance. For example:

package main

import (
	"context"
	polargo "github.com/polarsource/polar-go"
	"log"
	"os"
)

func main() {
	ctx := context.Background()

	s := polargo.New(
		polargo.WithServerURL("https://api.polar.sh"),
		polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
	)

	res, err := s.Organizations.List(ctx, nil, polargo.Pointer[int64](1), polargo.Pointer[int64](10), nil)
	if err != nil {
		log.Fatal(err)
	}
	if res.ListResourceOrganization != nil {
		for {
			// handle items

			res, err = res.Next()

			if err != nil {
				// handle error
			}

			if res == nil {
				break
			}
		}
	}
}

Custom HTTP Client

The Go SDK makes API calls that wrap an internal HTTP client. The requirements for the HTTP client are very simple. It must match this interface:

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

The built-in net/http client satisfies this interface and a default client based on the built-in is provided by default. To replace this default with a client of your own, you can implement this interface yourself or provide your own client configured as desired. Here's a simple example, which adds a client with a 30 second timeout.

import (
	"net/http"
	"time"

	"github.com/polarsource/polar-go"
)

var (
	httpClient = &http.Client{Timeout: 30 * time.Second}
	sdkClient  = polargo.New(polargo.WithClient(httpClient))
)

This can be a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration.

Special Types

This SDK defines the following custom types to assist with marshalling and unmarshalling data.

Date

types.Date is a wrapper around time.Time that allows for JSON marshaling a date string formatted as "2006-01-02".

Usage
d1 := types.NewDate(time.Now()) // returns *types.Date

d2 := types.DateFromTime(time.Now()) // returns types.Date

d3, err := types.NewDateFromString("2019-01-01") // returns *types.Date, error

d4, err := types.DateFromString("2019-01-01") // returns types.Date, error

d5 := types.MustNewDateFromString("2019-01-01") // returns *types.Date and panics on error

d6 := types.MustDateFromString("2019-01-01") // returns types.Date and panics on error

Development

Maturity

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Contributions

While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.

SDK Created by Speakeasy

Documentation

Index

Constants

View Source
const (
	// Production environment
	ServerProduction string = "production"
	// Sandbox environment
	ServerSandbox string = "sandbox"
)

Variables

View Source
var ServerList = map[string]string{
	ServerProduction: "https://api.polar.sh",
	ServerSandbox:    "https://sandbox-api.polar.sh",
}

ServerList contains the list of servers available to the SDK

Functions

func Bool

func Bool(b bool) *bool

Bool provides a helper function to return a pointer to a bool

func Float32

func Float32(f float32) *float32

Float32 provides a helper function to return a pointer to a float32

func Float64

func Float64(f float64) *float64

Float64 provides a helper function to return a pointer to a float64

func Int

func Int(i int) *int

Int provides a helper function to return a pointer to an int

func Int64

func Int64(i int64) *int64

Int64 provides a helper function to return a pointer to an int64

func Pointer

func Pointer[T any](v T) *T

Pointer provides a helper function to return a pointer to a type

func String

func String(s string) *string

String provides a helper function to return a pointer to a string

Types

type BenefitGrants

type BenefitGrants struct {
	// contains filtered or unexported fields
}

func (*BenefitGrants) List

List Benefit Grants List benefit grants across all benefits for the authenticated organization.

**Scopes**: `benefits:read` `benefits:write`

type Benefits

type Benefits struct {
	// contains filtered or unexported fields
}

func (*Benefits) Create

Create Benefit Create a benefit.

**Scopes**: `benefits:write`

func (*Benefits) Delete

Delete Benefit Delete a benefit.

> [!WARNING] > Every grants associated with the benefit will be revoked. > Users will lose access to the benefit.

**Scopes**: `benefits:write`

func (*Benefits) Get

Get Benefit Get a benefit by ID.

**Scopes**: `benefits:read` `benefits:write`

func (*Benefits) Grants

Grants - List Benefit Grants List the individual grants for a benefit.

It's especially useful to check if a user has been granted a benefit.

**Scopes**: `benefits:read` `benefits:write`

func (*Benefits) List

List Benefits List benefits.

**Scopes**: `benefits:read` `benefits:write`

func (*Benefits) Update

Update Benefit Update a benefit.

**Scopes**: `benefits:write`

type CheckoutLinks struct {
	// contains filtered or unexported fields
}

func (*CheckoutLinks) Create

Create Checkout Link Create a checkout link.

**Scopes**: `checkout_links:write`

func (*CheckoutLinks) Delete

Delete Checkout Link Delete a checkout link.

**Scopes**: `checkout_links:write`

func (*CheckoutLinks) Get

Get Checkout Link Get a checkout link by ID.

**Scopes**: `checkout_links:read` `checkout_links:write`

func (*CheckoutLinks) List

List Checkout Links List checkout links.

**Scopes**: `checkout_links:read` `checkout_links:write`

func (*CheckoutLinks) Update

Update Checkout Link Update a checkout link.

**Scopes**: `checkout_links:write`

type Checkouts

type Checkouts struct {
	// contains filtered or unexported fields
}

func (*Checkouts) ClientConfirm added in v0.2.0

func (s *Checkouts) ClientConfirm(ctx context.Context, clientSecret string, checkoutConfirmStripe components.CheckoutConfirmStripe, opts ...operations.Option) (*operations.CheckoutsClientConfirmResponse, error)

ClientConfirm - Confirm Checkout Session from Client Confirm a checkout session by client secret.

Orders and subscriptions will be processed.

func (*Checkouts) ClientGet added in v0.2.0

func (s *Checkouts) ClientGet(ctx context.Context, clientSecret string, opts ...operations.Option) (*operations.CheckoutsClientGetResponse, error)

ClientGet - Get Checkout Session from Client Get a checkout session by client secret.

func (*Checkouts) ClientUpdate added in v0.2.0

func (s *Checkouts) ClientUpdate(ctx context.Context, clientSecret string, checkoutUpdatePublic components.CheckoutUpdatePublic, opts ...operations.Option) (*operations.CheckoutsClientUpdateResponse, error)

ClientUpdate - Update Checkout Session from Client Update a checkout session by client secret.

func (*Checkouts) Create

Create Checkout Session Create a checkout session.

**Scopes**: `checkouts:write`

func (*Checkouts) Get

Get Checkout Session Get a checkout session by ID.

**Scopes**: `checkouts:read` `checkouts:write`

func (*Checkouts) List added in v0.2.0

List Checkout Sessions List checkout sessions.

**Scopes**: `checkouts:read` `checkouts:write`

func (*Checkouts) Update added in v0.2.0

Update Checkout Session Update a checkout session.

**Scopes**: `checkouts:write`

type Clients

type Clients struct {
	// contains filtered or unexported fields
}

func (*Clients) Create

Create Client Create an OAuth2 client.

func (*Clients) Delete

Delete Client Delete an OAuth2 client.

func (*Clients) Get

Get Client Get an OAuth2 client by Client ID.

func (*Clients) Update

Update Client Update an OAuth2 client.

type CustomFields

type CustomFields struct {
	// contains filtered or unexported fields
}

func (*CustomFields) Create

Create Custom Field Create a custom field.

**Scopes**: `custom_fields:write`

func (*CustomFields) Delete

Delete Custom Field Delete a custom field.

**Scopes**: `custom_fields:write`

func (*CustomFields) Get

Get Custom Field Get a custom field by ID.

**Scopes**: `custom_fields:read` `custom_fields:write`

func (*CustomFields) List

List Custom Fields List custom fields.

**Scopes**: `custom_fields:read` `custom_fields:write`

func (*CustomFields) Update

Update Custom Field Update a custom field.

**Scopes**: `custom_fields:write`

type CustomerMeters added in v0.4.10

type CustomerMeters struct {
	// contains filtered or unexported fields
}

func (*CustomerMeters) Get added in v0.4.10

Get Customer Meter Get a customer meter by ID.

**Scopes**: `customer_meters:read`

func (*CustomerMeters) List added in v0.4.10

List Customer Meters List customer meters.

**Scopes**: `customer_meters:read`

type CustomerPortal

type CustomerPortal struct {
	BenefitGrants   *PolarBenefitGrants
	Customers       *PolarCustomers
	CustomerMeters  *PolarCustomerMeters
	Seats           *Seats
	CustomerSession *CustomerSession
	Downloadables   *Downloadables
	LicenseKeys     *PolarLicenseKeys
	Members         *PolarMembers
	Orders          *PolarOrders
	Organizations   *PolarOrganizations
	Subscriptions   *PolarSubscriptions
	Wallets         *Wallets
	// contains filtered or unexported fields
}

type CustomerSeats added in v0.12.0

type CustomerSeats struct {
	// contains filtered or unexported fields
}

func (*CustomerSeats) AssignSeat added in v0.12.0

AssignSeat - Assign Seat **Scopes**: `customer_seats:write`

func (*CustomerSeats) ClaimSeat added in v0.12.0

ClaimSeat - Claim Seat

func (*CustomerSeats) GetClaimInfo added in v0.12.0

func (s *CustomerSeats) GetClaimInfo(ctx context.Context, invitationToken string, opts ...operations.Option) (*operations.CustomerSeatsGetClaimInfoResponse, error)

GetClaimInfo - Get Claim Info

func (*CustomerSeats) ListSeats added in v0.12.0

func (s *CustomerSeats) ListSeats(ctx context.Context, subscriptionID *string, orderID *string, opts ...operations.Option) (*operations.CustomerSeatsListSeatsResponse, error)

ListSeats - List Seats **Scopes**: `customer_seats:write`

func (*CustomerSeats) ResendInvitation added in v0.12.0

ResendInvitation - Resend Invitation **Scopes**: `customer_seats:write`

func (*CustomerSeats) RevokeSeat added in v0.12.0

RevokeSeat - Revoke Seat **Scopes**: `customer_seats:write`

type CustomerSession added in v0.10.1

type CustomerSession struct {
	// contains filtered or unexported fields
}

func (*CustomerSession) GetAuthenticatedUser added in v0.13.0

GetAuthenticatedUser - Get Authenticated Portal User Get information about the currently authenticated portal user.

**Scopes**: `customer_portal:read` `customer_portal:write`

func (*CustomerSession) Introspect added in v0.10.1

Introspect Customer Session Introspect the current session and return its information.

**Scopes**: `customer_portal:read` `customer_portal:write`

type CustomerSessions

type CustomerSessions struct {
	// contains filtered or unexported fields
}

func (*CustomerSessions) Create

Create Customer Session Create a customer session.

For organizations with `member_model_enabled`, this will automatically create a member session for the owner member of the customer.

**Scopes**: `customer_sessions:write`

type Customers

type Customers struct {
	// contains filtered or unexported fields
}

func (*Customers) Create

Create Customer Create a customer.

**Scopes**: `customers:write`

func (*Customers) Delete

func (s *Customers) Delete(ctx context.Context, id string, anonymize *bool, opts ...operations.Option) (*operations.CustomersDeleteResponse, error)

Delete Customer Delete a customer.

This action cannot be undone and will immediately: - Cancel any active subscriptions for the customer - Revoke all their benefits - Clear any `external_id`

Use it only in the context of deleting a user within your own service. Otherwise, use more granular API endpoints to cancel a specific subscription or revoke certain benefits.

Note: The customers information will nonetheless be retained for historic orders and subscriptions.

Set `anonymize=true` to also anonymize PII for GDPR compliance.

**Scopes**: `customers:write`

func (*Customers) DeleteExternal added in v0.4.1

func (s *Customers) DeleteExternal(ctx context.Context, externalID string, anonymize *bool, opts ...operations.Option) (*operations.CustomersDeleteExternalResponse, error)

DeleteExternal - Delete Customer by External ID Delete a customer by external ID.

Immediately cancels any active subscriptions and revokes any active benefits.

Set `anonymize=true` to also anonymize PII for GDPR compliance.

**Scopes**: `customers:write`

func (*Customers) Export added in v0.9.0

Export Customers Export customers as a CSV file.

**Scopes**: `customers:read` `customers:write`

func (*Customers) Get

Get Customer Get a customer by ID.

**Scopes**: `customers:read` `customers:write`

func (*Customers) GetExternal added in v0.4.1

func (s *Customers) GetExternal(ctx context.Context, externalID string, opts ...operations.Option) (*operations.CustomersGetExternalResponse, error)

GetExternal - Get Customer by External ID Get a customer by external ID.

**Scopes**: `customers:read` `customers:write`

func (*Customers) GetState added in v0.4.3

GetState - Get Customer State Get a customer state by ID.

The customer state includes information about the customer's active subscriptions and benefits.

It's the ideal endpoint to use when you need to get a full overview of a customer's status.

**Scopes**: `customers:read` `customers:write`

func (*Customers) GetStateExternal added in v0.4.3

func (s *Customers) GetStateExternal(ctx context.Context, externalID string, opts ...operations.Option) (*operations.CustomersGetStateExternalResponse, error)

GetStateExternal - Get Customer State by External ID Get a customer state by external ID.

The customer state includes information about the customer's active subscriptions and benefits.

It's the ideal endpoint to use when you need to get a full overview of a customer's status.

**Scopes**: `customers:read` `customers:write`

func (*Customers) List

List Customers List customers.

**Scopes**: `customers:read` `customers:write`

func (*Customers) Update

Update Customer Update a customer.

**Scopes**: `customers:write`

func (*Customers) UpdateExternal added in v0.4.1

func (s *Customers) UpdateExternal(ctx context.Context, externalID string, customerUpdateExternalID components.CustomerUpdateExternalID, opts ...operations.Option) (*operations.CustomersUpdateExternalResponse, error)

UpdateExternal - Update Customer by External ID Update a customer by external ID.

**Scopes**: `customers:write`

type Discounts

type Discounts struct {
	// contains filtered or unexported fields
}

func (*Discounts) Create

Create Discount Create a discount.

**Scopes**: `discounts:write`

func (*Discounts) Delete

Delete Discount Delete a discount.

**Scopes**: `discounts:write`

func (*Discounts) Get

Get Discount Get a discount by ID.

**Scopes**: `discounts:read` `discounts:write`

func (*Discounts) List

List Discounts List discounts.

**Scopes**: `discounts:read` `discounts:write`

func (*Discounts) Update

Update Discount Update a discount.

**Scopes**: `discounts:write`

type Disputes added in v0.13.0

type Disputes struct {
	// contains filtered or unexported fields
}

func (*Disputes) Get added in v0.13.0

Get Dispute Get a dispute by ID.

**Scopes**: `disputes:read`

func (*Disputes) List added in v0.13.0

List Disputes List disputes.

**Scopes**: `disputes:read`

type Downloadables

type Downloadables struct {
	// contains filtered or unexported fields
}

func (*Downloadables) List

List Downloadables **Scopes**: `customer_portal:read` `customer_portal:write`

type EventTypes added in v0.13.0

type EventTypes struct {
	// contains filtered or unexported fields
}

func (*EventTypes) List added in v0.13.0

List Event Types List event types with aggregated statistics.

**Scopes**: `events:read` `events:write`

func (*EventTypes) Update added in v0.13.0

Update Event Type Update an event type's label.

type Events added in v0.1.8

type Events struct {
	// contains filtered or unexported fields
}

func (*Events) Get added in v0.1.8

Get Event Get an event by ID.

**Scopes**: `events:read` `events:write`

func (*Events) Ingest added in v0.1.8

Ingest Events Ingest batch of events.

**Scopes**: `events:write`

func (*Events) List added in v0.1.8

List Events List events.

**Scopes**: `events:read` `events:write`

func (*Events) ListNames added in v0.4.10

ListNames - List Event Names List event names.

**Scopes**: `events:read` `events:write`

type Files

type Files struct {
	// contains filtered or unexported fields
}

func (*Files) Create

Create File Create a file.

**Scopes**: `files:write`

func (*Files) Delete

Delete File Delete a file.

**Scopes**: `files:write`

func (*Files) List

List Files List files.

**Scopes**: `files:read` `files:write`

func (*Files) Update

Update File Update a file.

**Scopes**: `files:write`

func (*Files) Uploaded

func (s *Files) Uploaded(ctx context.Context, id string, fileUploadCompleted components.FileUploadCompleted, opts ...operations.Option) (*operations.FilesUploadedResponse, error)

Uploaded - Complete File Upload Complete a file upload.

**Scopes**: `files:write`

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient provides an interface for supplying the SDK with a custom HTTP client

type LicenseKeys

type LicenseKeys struct {
	// contains filtered or unexported fields
}

func (*LicenseKeys) Activate added in v0.8.2

Activate License Key Activate a license key instance.

**Scopes**: `license_keys:write`

func (*LicenseKeys) Deactivate added in v0.8.2

Deactivate License Key Deactivate a license key instance.

**Scopes**: `license_keys:write`

func (*LicenseKeys) Get

Get License Key Get a license key.

**Scopes**: `license_keys:read` `license_keys:write`

func (*LicenseKeys) GetActivation

func (s *LicenseKeys) GetActivation(ctx context.Context, id string, activationID string, opts ...operations.Option) (*operations.LicenseKeysGetActivationResponse, error)

GetActivation - Get Activation Get a license key activation.

**Scopes**: `license_keys:read` `license_keys:write`

func (*LicenseKeys) List

List License Keys Get license keys connected to the given organization & filters.

**Scopes**: `license_keys:read` `license_keys:write`

func (*LicenseKeys) Update

Update License Key Update a license key.

**Scopes**: `license_keys:write`

func (*LicenseKeys) Validate added in v0.8.2

Validate License Key Validate a license key.

**Scopes**: `license_keys:write`

type Members added in v0.13.0

type Members struct {
	// contains filtered or unexported fields
}

func (*Members) CreateMember added in v0.13.0

CreateMember - Create Member Create a new member for a customer.

Only B2B customers with the member management feature enabled can add members. The authenticated user or organization must have access to the customer's organization.

**Scopes**: `members:write`

func (*Members) DeleteMember added in v0.13.0

DeleteMember - Delete Member Delete a member.

The authenticated user or organization must have access to the member's organization.

**Scopes**: `members:write`

func (*Members) GetMember added in v0.13.0

GetMember - Get Member Get a member by ID.

The authenticated user or organization must have access to the member's organization.

**Scopes**: `members:read` `members:write`

func (*Members) ListMembers added in v0.13.0

ListMembers - List Members List members with optional customer ID filter.

**Scopes**: `members:read` `members:write`

func (*Members) UpdateMember added in v0.13.0

UpdateMember - Update Member Update a member.

Only name and role can be updated. The authenticated user or organization must have access to the member's organization.

**Scopes**: `members:write`

type Meters added in v0.1.8

type Meters struct {
	// contains filtered or unexported fields
}

func (*Meters) Create added in v0.1.8

Create Meter Create a meter.

**Scopes**: `meters:write`

func (*Meters) Get added in v0.1.8

Get Meter Get a meter by ID.

**Scopes**: `meters:read` `meters:write`

func (*Meters) List added in v0.1.8

List Meters List meters.

**Scopes**: `meters:read` `meters:write`

func (*Meters) Quantities added in v0.1.8

Quantities - Get Meter Quantities Get quantities of a meter over a time period.

**Scopes**: `meters:read` `meters:write`

func (*Meters) Update added in v0.1.8

Update Meter Update a meter.

**Scopes**: `meters:write`

type Metrics

type Metrics struct {
	// contains filtered or unexported fields
}

func (*Metrics) CreateDashboard added in v0.16.0

CreateDashboard - Create Metric Dashboard Create a user-defined metric dashboard.

**Scopes**: `metrics:write`

func (*Metrics) DeleteDashboard added in v0.16.0

DeleteDashboard - Delete Metric Dashboard Delete a user-defined metric dashboard.

**Scopes**: `metrics:write`

func (*Metrics) Get

Get Metrics Get metrics about your orders and subscriptions.

Currency values are output in cents.

**Scopes**: `metrics:read`

func (*Metrics) GetDashboard added in v0.16.0

GetDashboard - Get Metric Dashboard Get a user-defined metric dashboard by ID.

**Scopes**: `metrics:read`

func (*Metrics) Limits

Limits - Get Metrics Limits Get the interval limits for the metrics endpoint.

**Scopes**: `metrics:read`

func (*Metrics) ListDashboards added in v0.16.0

ListDashboards - List Metric Dashboards List user-defined metric dashboards.

**Scopes**: `metrics:read`

func (*Metrics) UpdateDashboard added in v0.16.0

func (s *Metrics) UpdateDashboard(ctx context.Context, id string, metricDashboardUpdate components.MetricDashboardUpdate, opts ...operations.Option) (*operations.MetricsUpdateDashboardResponse, error)

UpdateDashboard - Update Metric Dashboard Update a user-defined metric dashboard.

**Scopes**: `metrics:write`

type Oauth2

type Oauth2 struct {
	Clients *Clients
	// contains filtered or unexported fields
}

func (*Oauth2) Authorize

Authorize

func (*Oauth2) Introspect

Introspect Token Get information about an access token.

func (*Oauth2) Revoke

Revoke Token Revoke an access token or a refresh token.

func (*Oauth2) Token

Request Token Request an access token using a valid grant.

func (*Oauth2) Userinfo

Userinfo - Get User Info Get information about the authenticated user.

type Orders

type Orders struct {
	// contains filtered or unexported fields
}

func (*Orders) Export added in v0.12.0

Export Orders Export orders as a CSV file.

**Scopes**: `orders:read`

func (*Orders) GenerateInvoice added in v0.5.0

func (s *Orders) GenerateInvoice(ctx context.Context, id string, opts ...operations.Option) (*operations.OrdersGenerateInvoiceResponse, error)

GenerateInvoice - Generate Order Invoice Trigger generation of an order's invoice.

**Scopes**: `orders:read`

func (*Orders) Get

Get Order Get an order by ID.

**Scopes**: `orders:read`

func (*Orders) Invoice

Invoice - Get Order Invoice Get an order's invoice data.

**Scopes**: `orders:read`

func (*Orders) List

List Orders List orders.

**Scopes**: `orders:read`

func (*Orders) Update added in v0.5.0

Update Order Update an order.

**Scopes**: `orders:write`

type OrganizationAccessTokens added in v0.13.0

type OrganizationAccessTokens struct {
	// contains filtered or unexported fields
}

func (*OrganizationAccessTokens) Create added in v0.13.0

Create **Scopes**: `organization_access_tokens:write`

func (*OrganizationAccessTokens) Delete added in v0.13.0

Delete **Scopes**: `organization_access_tokens:write`

func (*OrganizationAccessTokens) List added in v0.13.0

List List organization access tokens.

**Scopes**: `organization_access_tokens:read` `organization_access_tokens:write`

func (*OrganizationAccessTokens) Update added in v0.13.0

Update **Scopes**: `organization_access_tokens:write`

type Organizations

type Organizations struct {
	// contains filtered or unexported fields
}

func (*Organizations) Create

Create Organization Create an organization.

**Scopes**: `organizations:write`

func (*Organizations) Get

Get Organization Get an organization by ID.

**Scopes**: `organizations:read` `organizations:write`

func (*Organizations) List

List Organizations List organizations.

**Scopes**: `organizations:read` `organizations:write`

func (*Organizations) Update

Update Organization Update an organization.

**Scopes**: `organizations:write`

type Payments added in v0.4.17

type Payments struct {
	// contains filtered or unexported fields
}

func (*Payments) Get added in v0.4.17

Get Payment Get a payment by ID.

**Scopes**: `payments:read`

func (*Payments) List added in v0.4.17

List Payments List payments.

**Scopes**: `payments:read`

type Polar

type Polar struct {
	SDKVersion               string
	Organizations            *Organizations
	Subscriptions            *Subscriptions
	Oauth2                   *Oauth2
	Benefits                 *Benefits
	BenefitGrants            *BenefitGrants
	Webhooks                 *Webhooks
	Products                 *Products
	Orders                   *Orders
	Refunds                  *Refunds
	Disputes                 *Disputes
	Checkouts                *Checkouts
	Files                    *Files
	Metrics                  *Metrics
	LicenseKeys              *LicenseKeys
	CheckoutLinks            *CheckoutLinks
	CustomFields             *CustomFields
	Discounts                *Discounts
	Customers                *Customers
	Members                  *Members
	CustomerPortal           *CustomerPortal
	CustomerSeats            *CustomerSeats
	CustomerSessions         *CustomerSessions
	Events                   *Events
	EventTypes               *EventTypes
	Meters                   *Meters
	OrganizationAccessTokens *OrganizationAccessTokens
	CustomerMeters           *CustomerMeters
	Payments                 *Payments
	// contains filtered or unexported fields
}

Polar API: Polar HTTP and Webhooks API Read the docs at https://polar.sh/docs/api-reference

func New

func New(opts ...SDKOption) *Polar

New creates a new instance of the SDK with the provided options

type PolarBenefitGrants added in v0.9.0

type PolarBenefitGrants struct {
	// contains filtered or unexported fields
}

func (*PolarBenefitGrants) Get added in v0.9.0

Get Benefit Grant Get a benefit grant by ID for the authenticated customer.

**Scopes**: `customer_portal:read` `customer_portal:write`

func (*PolarBenefitGrants) List added in v0.9.0

List Benefit Grants List benefits grants of the authenticated customer.

**Scopes**: `customer_portal:read` `customer_portal:write`

func (*PolarBenefitGrants) Update added in v0.9.0

Update Benefit Grant Update a benefit grant for the authenticated customer.

**Scopes**: `customer_portal:write`

type PolarCustomerMeters added in v0.4.10

type PolarCustomerMeters struct {
	// contains filtered or unexported fields
}

func (*PolarCustomerMeters) Get added in v0.4.10

Get Customer Meter Get a meter by ID for the authenticated customer.

**Scopes**: `customer_portal:read` `customer_portal:write`

func (*PolarCustomerMeters) List added in v0.4.10

List Meters List meters of the authenticated customer.

**Scopes**: `customer_portal:read` `customer_portal:write`

type PolarCustomers

type PolarCustomers struct {
	// contains filtered or unexported fields
}

func (*PolarCustomers) AddPaymentMethod added in v0.4.0

AddPaymentMethod - Add Customer Payment Method Add a payment method to the authenticated customer.

func (*PolarCustomers) ConfirmPaymentMethod added in v0.9.2

ConfirmPaymentMethod - Confirm Customer Payment Method Confirm a payment method for the authenticated customer.

func (*PolarCustomers) DeletePaymentMethod added in v0.4.0

DeletePaymentMethod - Delete Customer Payment Method Delete a payment method from the authenticated customer.

func (*PolarCustomers) Get

Get Customer Get authenticated customer.

**Scopes**: `customer_portal:read` `customer_portal:write`

func (*PolarCustomers) ListPaymentMethods added in v0.7.2

ListPaymentMethods - List Customer Payment Methods Get saved payment methods of the authenticated customer.

func (*PolarCustomers) Update added in v0.4.0

Update Customer Update authenticated customer.

type PolarLicenseKeys

type PolarLicenseKeys struct {
	// contains filtered or unexported fields
}

func (*PolarLicenseKeys) Activate

Activate License Key Activate a license key instance.

> This endpoint doesn't require authentication and can be safely used on a public > client, like a desktop application or a mobile app. > If you plan to validate a license key on a server, use the `/v1/license-keys/activate` > endpoint instead.

func (*PolarLicenseKeys) Deactivate

Deactivate License Key Deactivate a license key instance.

> This endpoint doesn't require authentication and can be safely used on a public > client, like a desktop application or a mobile app. > If you plan to validate a license key on a server, use the `/v1/license-keys/deactivate` > endpoint instead.

func (*PolarLicenseKeys) Get

Get License Key Get a license key.

**Scopes**: `customer_portal:read` `customer_portal:write`

func (*PolarLicenseKeys) List

List License Keys **Scopes**: `customer_portal:read` `customer_portal:write`

func (*PolarLicenseKeys) Validate

Validate License Key Validate a license key.

> This endpoint doesn't require authentication and can be safely used on a public > client, like a desktop application or a mobile app. > If you plan to validate a license key on a server, use the `/v1/license-keys/validate` > endpoint instead.

type PolarMembers added in v0.13.0

type PolarMembers struct {
	// contains filtered or unexported fields
}

func (*PolarMembers) AddMember added in v0.13.0

AddMember - Add Member Add a new member to the customer's team.

Only available to owners and billing managers of team customers.

Rules: - Cannot add a member with the owner role (there must be exactly one owner) - If a member with this email already exists, the existing member is returned

func (*PolarMembers) ListMembers added in v0.13.0

ListMembers - List Members List all members of the customer's team.

Only available to owners and billing managers of team customers.

func (*PolarMembers) RemoveMember added in v0.13.0

RemoveMember - Remove Member Remove a member from the team.

Only available to owners and billing managers of team customers.

Rules: - Cannot remove yourself - Cannot remove the only owner

func (*PolarMembers) UpdateMember added in v0.13.0

UpdateMember - Update Member Update a member's role.

Only available to owners and billing managers of team customers.

Rules: - Cannot modify your own role (to prevent self-demotion) - Customer must have exactly one owner at all times

type PolarOrders

type PolarOrders struct {
	// contains filtered or unexported fields
}

func (*PolarOrders) ConfirmRetryPayment added in v0.8.2

ConfirmRetryPayment - Confirm Retry Payment Confirm a retry payment using a Stripe confirmation token.

func (*PolarOrders) GenerateInvoice added in v0.5.0

GenerateInvoice - Generate Order Invoice Trigger generation of an order's invoice.

func (*PolarOrders) Get

Get Order Get an order by ID for the authenticated customer.

func (*PolarOrders) GetPaymentStatus added in v0.8.2

GetPaymentStatus - Get Order Payment Status Get the current payment status for an order.

func (*PolarOrders) Invoice

Invoice - Get Order Invoice Get an order's invoice data.

func (*PolarOrders) List

List Orders List orders of the authenticated customer.

func (*PolarOrders) Update added in v0.5.0

Update Order Update an order for the authenticated customer.

type PolarOrganizations

type PolarOrganizations struct {
	// contains filtered or unexported fields
}

func (*PolarOrganizations) Get

Get Organization Get a customer portal's organization by slug.

type PolarSubscriptions

type PolarSubscriptions struct {
	// contains filtered or unexported fields
}

func (*PolarSubscriptions) Cancel

Cancel Subscription Cancel a subscription of the authenticated customer.

func (*PolarSubscriptions) Get

Get Subscription Get a subscription for the authenticated customer.

**Scopes**: `customer_portal:read` `customer_portal:write`

func (*PolarSubscriptions) List

List Subscriptions List subscriptions of the authenticated customer.

**Scopes**: `customer_portal:read` `customer_portal:write`

func (*PolarSubscriptions) Update

Update Subscription Update a subscription of the authenticated customer.

type Products

type Products struct {
	// contains filtered or unexported fields
}

func (*Products) Create

Create Product Create a product.

**Scopes**: `products:write`

func (*Products) Get

Get Product Get a product by ID.

**Scopes**: `products:read` `products:write`

func (*Products) List

List Products List products.

**Scopes**: `products:read` `products:write`

func (*Products) Update

Update Product Update a product.

**Scopes**: `products:write`

func (*Products) UpdateBenefits

func (s *Products) UpdateBenefits(ctx context.Context, id string, productBenefitsUpdate components.ProductBenefitsUpdate, opts ...operations.Option) (*operations.ProductsUpdateBenefitsResponse, error)

UpdateBenefits - Update Product Benefits Update benefits granted by a product.

**Scopes**: `products:write`

type Refunds added in v0.1.5

type Refunds struct {
	// contains filtered or unexported fields
}

func (*Refunds) Create added in v0.1.5

Create Refund Create a refund.

**Scopes**: `refunds:write`

func (*Refunds) List added in v0.1.5

List Refunds List refunds.

**Scopes**: `refunds:read` `refunds:write`

type SDKOption

type SDKOption func(*Polar)

func WithClient

func WithClient(client HTTPClient) SDKOption

WithClient allows the overriding of the default HTTP client used by the SDK

func WithRetryConfig

func WithRetryConfig(retryConfig retry.Config) SDKOption

func WithSecurity

func WithSecurity(accessToken string) SDKOption

WithSecurity configures the SDK to use the provided security details

func WithSecuritySource

func WithSecuritySource(security func(context.Context) (components.Security, error)) SDKOption

WithSecuritySource configures the SDK to invoke the Security Source function on each method call to determine authentication

func WithServer

func WithServer(server string) SDKOption

WithServer allows the overriding of the default server by name

func WithServerURL

func WithServerURL(serverURL string) SDKOption

WithServerURL allows providing an alternative server URL

func WithTemplatedServerURL

func WithTemplatedServerURL(serverURL string, params map[string]string) SDKOption

WithTemplatedServerURL allows the overriding of the default server URL with a templated URL populated with the provided parameters

func WithTimeout

func WithTimeout(timeout time.Duration) SDKOption

WithTimeout Optional request timeout applied to each operation

type Seats added in v0.10.1

type Seats struct {
	// contains filtered or unexported fields
}

func (*Seats) AssignSeat added in v0.10.1

AssignSeat - Assign Seat

func (*Seats) ListClaimedSubscriptions added in v0.10.1

ListClaimedSubscriptions - List Claimed Subscriptions List all subscriptions where the authenticated customer has claimed a seat.

**Scopes**: `customer_portal:read` `customer_portal:write`

func (*Seats) ListSeats added in v0.10.1

ListSeats - List Seats **Scopes**: `customer_portal:read` `customer_portal:write`

func (*Seats) ResendInvitation added in v0.10.1

ResendInvitation - Resend Invitation

func (*Seats) RevokeSeat added in v0.10.1

RevokeSeat - Revoke Seat

type Subscriptions

type Subscriptions struct {
	// contains filtered or unexported fields
}

func (*Subscriptions) Create added in v0.12.0

Create Subscription Create a subscription programmatically.

This endpoint only allows to create subscription on free products. For paid products, use the checkout flow.

No initial order will be created and no confirmation email will be sent.

**Scopes**: `subscriptions:write`

func (*Subscriptions) Export

Export Subscriptions Export subscriptions as a CSV file.

**Scopes**: `subscriptions:read` `subscriptions:write`

func (*Subscriptions) Get added in v0.1.7

Get Subscription Get a subscription by ID.

**Scopes**: `subscriptions:read` `subscriptions:write`

func (*Subscriptions) List

List Subscriptions List subscriptions.

**Scopes**: `subscriptions:read` `subscriptions:write`

func (*Subscriptions) Revoke added in v0.1.1

Revoke Subscription Revoke a subscription, i.e cancel immediately.

**Scopes**: `subscriptions:write`

func (*Subscriptions) Update added in v0.1.1

Update Subscription Update a subscription.

**Scopes**: `subscriptions:write`

type Wallets added in v0.12.0

type Wallets struct {
	// contains filtered or unexported fields
}

func (*Wallets) Get added in v0.12.0

Get Wallet Get a wallet by ID for the authenticated customer.

func (*Wallets) List added in v0.12.0

List Wallets List wallets of the authenticated customer.

type Webhooks added in v0.6.1

type Webhooks struct {
	// contains filtered or unexported fields
}

func (*Webhooks) CreateWebhookEndpoint added in v0.6.1

CreateWebhookEndpoint - Create Webhook Endpoint Create a webhook endpoint.

**Scopes**: `webhooks:write`

func (*Webhooks) DeleteWebhookEndpoint added in v0.6.1

func (s *Webhooks) DeleteWebhookEndpoint(ctx context.Context, id string, opts ...operations.Option) (*operations.WebhooksDeleteWebhookEndpointResponse, error)

DeleteWebhookEndpoint - Delete Webhook Endpoint Delete a webhook endpoint.

**Scopes**: `webhooks:write`

func (*Webhooks) GetWebhookEndpoint added in v0.6.1

GetWebhookEndpoint - Get Webhook Endpoint Get a webhook endpoint by ID.

**Scopes**: `webhooks:read` `webhooks:write`

func (*Webhooks) ListWebhookDeliveries added in v0.6.1

ListWebhookDeliveries - List Webhook Deliveries List webhook deliveries.

Deliveries are all the attempts to deliver a webhook event to an endpoint.

**Scopes**: `webhooks:read` `webhooks:write`

func (*Webhooks) ListWebhookEndpoints added in v0.6.1

func (s *Webhooks) ListWebhookEndpoints(ctx context.Context, organizationID *operations.QueryParamOrganizationID, page *int64, limit *int64, opts ...operations.Option) (*operations.WebhooksListWebhookEndpointsResponse, error)

ListWebhookEndpoints - List Webhook Endpoints List webhook endpoints.

**Scopes**: `webhooks:read` `webhooks:write`

func (*Webhooks) RedeliverWebhookEvent added in v0.6.1

func (s *Webhooks) RedeliverWebhookEvent(ctx context.Context, id string, opts ...operations.Option) (*operations.WebhooksRedeliverWebhookEventResponse, error)

RedeliverWebhookEvent - Redeliver Webhook Event Schedule the re-delivery of a webhook event.

**Scopes**: `webhooks:write`

func (*Webhooks) ResetWebhookEndpointSecret added in v0.7.3

func (s *Webhooks) ResetWebhookEndpointSecret(ctx context.Context, id string, opts ...operations.Option) (*operations.WebhooksResetWebhookEndpointSecretResponse, error)

ResetWebhookEndpointSecret - Reset Webhook Endpoint Secret Regenerate a webhook endpoint secret.

**Scopes**: `webhooks:write`

func (*Webhooks) UpdateWebhookEndpoint added in v0.6.1

func (s *Webhooks) UpdateWebhookEndpoint(ctx context.Context, id string, webhookEndpointUpdate components.WebhookEndpointUpdate, opts ...operations.Option) (*operations.WebhooksUpdateWebhookEndpointResponse, error)

UpdateWebhookEndpoint - Update Webhook Endpoint Update a webhook endpoint.

**Scopes**: `webhooks:write`

Directories

Path Synopsis
internal
models

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL