### Install TanStack Start Adapter with bun Source: https://docs.polar.sh/llms-full.txt Install the necessary Polar packages for TanStack Start using bun. Ensure zod is also installed. ```bash bun add zod @polar-sh/tanstack-start ``` -------------------------------- ### TypeScript SDK Quickstart Example Source: https://docs.polar.sh/llms-full.txt Quickstart example for the TypeScript SDK, demonstrating how to initialize the client and list user benefits asynchronously. It uses environment variables for the access token and server mode. ```typescript import { Polar } from '@polar-sh/sdk' const polar = new Polar({ accessToken: process.env.POLAR_ACCESS_TOKEN, server: process.env.POLAR_MODE || 'sandbox' // sandbox or production }) async function run() { const result = await polar.users.benefits.list({}) for await (const page of result) { // Handle the page console.log(page) } } run() ``` -------------------------------- ### Install TanStack Start Adapter with npm Source: https://docs.polar.sh/llms-full.txt Install the necessary Polar packages for TanStack Start using npm. Ensure zod is also installed. ```bash npm install zod @polar-sh/tanstack-start ``` -------------------------------- ### Install Go SDK Source: https://docs.polar.sh/llms-full.txt Install the Polar Go SDK using the go get command. Ensure you have Go installed and configured. ```bash go get github.com/polarsource/polar-go ``` -------------------------------- ### Install TanStack Start Adapter with pnpm Source: https://docs.polar.sh/llms-full.txt Install the necessary Polar packages for TanStack Start using pnpm. Ensure zod is also installed. ```bash pnpm add zod @polar-sh/tanstack-start ``` -------------------------------- ### Install TanStack Start Adapter with yarn Source: https://docs.polar.sh/llms-full.txt Install the necessary Polar packages for TanStack Start using yarn. Ensure zod is also installed. ```bash yarn add zod @polar-sh/tanstack-start ``` -------------------------------- ### Install and Run polar-migrate CLI Source: https://docs.polar.sh/llms-full.txt Use this command to install the latest version of the `polar-migrate` CLI tool and run it to begin migrating from Lemon Squeezy to Polar. Ensure you have Node.js and npm installed. ```bash npx polar-migrate@latest ``` -------------------------------- ### Install Polar.sh SvelteKit Adapter with bun Source: https://docs.polar.sh/llms-full.txt Install the necessary Polar packages for SvelteKit using bun. Ensure zod is also installed. ```bash bun add zod @polar-sh/sveltekit ``` -------------------------------- ### Install Polar.sh SvelteKit Adapter with pnpm Source: https://docs.polar.sh/llms-full.txt Install the necessary Polar packages for SvelteKit using pnpm. Ensure zod is also installed. ```bash pnpm add zod @polar-sh/sveltekit ``` -------------------------------- ### Install Polar.sh Hono Adapter (bun) Source: https://docs.polar.sh/llms-full.txt Install the necessary Polar.sh packages for Hono using bun. Ensure zod is also installed. ```bash bun add zod @polar-sh/hono ``` -------------------------------- ### Install Polar SDK with bun Source: https://docs.polar.sh/llms-full.txt Install the necessary Polar packages for Remix using bun. ```bash bun add zod @polar-sh/remix ``` -------------------------------- ### Install Polar SDK for Python Source: https://docs.polar.sh/llms-full.txt Install the Polar SDK for Python using pip or uv. ```bash pip install polar-sdk ``` ```bash uv add polar-sdk ``` -------------------------------- ### Install Polar.sh SvelteKit Adapter with npm Source: https://docs.polar.sh/llms-full.txt Install the necessary Polar packages for SvelteKit using npm. Ensure zod is also installed. ```bash npm install zod @polar-sh/sveltekit ``` -------------------------------- ### Install Javascript SDK Source: https://docs.polar.sh/llms-full.txt Install the necessary package for the Polar.sh ingestion SDK. ```bash pnpm add @polar-sh/ingestion ``` -------------------------------- ### Install Polar TypeScript SDK with npm Source: https://docs.polar.sh/llms-full.txt Install the Polar TypeScript SDK using npm. ```bash npm install @polar-sh/sdk ``` -------------------------------- ### Install Polar.sh Hono Adapter (yarn) Source: https://docs.polar.sh/llms-full.txt Install the necessary Polar.sh packages for Hono using yarn. Ensure zod is also installed. ```bash yarn add zod @polar-sh/hono ``` -------------------------------- ### Install Polar TypeScript SDK with yarn Source: https://docs.polar.sh/llms-full.txt Install the Polar TypeScript SDK using yarn. ```bash yarn add @polar-sh/sdk ``` -------------------------------- ### Install Polar SDK with pnpm Source: https://docs.polar.sh/llms-full.txt Install the necessary Polar packages for Remix using pnpm. ```bash pnpm add zod @polar-sh/remix ``` -------------------------------- ### Install standard-webhooks Package Source: https://docs.polar.sh/llms-full.txt Install the standard-webhooks package using Composer to handle incoming webhook payloads. ```bash composer require standard-webhooks/standard-webhooks:dev-main ``` -------------------------------- ### Install Polar.sh Hono Adapter (npm) Source: https://docs.polar.sh/llms-full.txt Install the necessary Polar.sh packages for Hono using npm. Ensure zod is also installed. ```bash npm install zod @polar-sh/hono ``` -------------------------------- ### Install Polar TypeScript SDK with pnpm Source: https://docs.polar.sh/llms-full.txt Install the Polar TypeScript SDK using pnpm. ```bash pnpm add @polar-sh/sdk ``` -------------------------------- ### Install Polar Packages (bun) Source: https://docs.polar.sh/llms-full.txt Install the necessary Polar packages for Supabase integration using bun. ```bash bun add zod @polar-sh/supabase ``` -------------------------------- ### Install Polar SDK with npm Source: https://docs.polar.sh/llms-full.txt Install the necessary Polar packages for Remix using npm. ```bash npm install zod @polar-sh/remix ``` -------------------------------- ### Install Polar Packages with bun Source: https://docs.polar.sh/llms-full.txt Install the necessary Polar packages for your Next.js project using bun. ```bash bun add zod @polar-sh/nextjs ``` -------------------------------- ### JavaScript: Open and Setup Checkout Source: https://polar.sh/docs/features/checkout/embed This snippet shows how to open the checkout and then set it up using JavaScript. It assumes you have an element with the ID 'open-checkout' to trigger the process. ```javascript document.getElementById("open-checkout").addEventListener("click", async () => { const checkout = await openCheckout(); setupCheckout(checkout); }); ``` -------------------------------- ### Go Quickstart: List Organizations Source: https://docs.polar.sh/llms-full.txt A basic Go program to authenticate with the Polar API using an access token and list organizations. It demonstrates pagination handling. ```go 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 } } } } ``` -------------------------------- ### Example Usage: Getting Checkout Element Source: https://polar.sh/docs/features/checkout/embed Demonstrates how to get a reference to the checkout element using its ID. This is a common first step before attaching event listeners or manipulating the checkout. ```javascript document.getElementById("checkout") ``` -------------------------------- ### Initialize Polar SDK in Sandbox (Go) Source: https://docs.polar.sh/llms-full.txt Configure and create a new Go client for the Polar sandbox environment, setting the server and security using an environment variable. ```go s := polargo.New( polargo.WithServer("sandbox"), polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")), ) ``` -------------------------------- ### Create Checkout Session with Python SDK Source: https://polar.sh/docs/api-reference/checkouts/create-session Example of creating a checkout session using the Polar Python SDK. Ensure you have the SDK installed and your access token configured. ```python import polar_sdk polar_sdk.configure(access_token='') res = polar_sdk.checkouts.create( customer_name='John Doe', customer_billing_address=polar_sdk.AddressInput( country=polar_sdk.AddressInputCountryAlpha2Input.US, ), locale='en', products=[ '', '', '', ], ) # Handle response print(res) ``` -------------------------------- ### Create Checkout Session with TypeScript SDK Source: https://polar.sh/docs/api-reference/checkouts/create-session Create a checkout session using the TypeScript SDK. This example assumes you have the SDK installed and your Polar access token is set as an environment variable. ```typescript import { Polar } from "@polar-sh/sdk"; const polar = new Polar({ accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "", }); async function run() { const result = await polar.checkouts.create({ customerName: "John Doe", customerBillingAddress: { country: "US", }, locale: "en", products: [ "", "", "", ], }); console.log(result); } run(); ``` -------------------------------- ### Create Customer Session with PHP SDK Source: https://polar.sh/docs/api-reference/customer-portal/sessions/create This PHP snippet demonstrates creating a customer session. Remember to replace '' with your token and install the SDK via Composer. ```php declare(strict_types=1); require 'vendor/autoload.php'; use Polar; use Polar\\Models\\Components; $sdk = Polar\\Polar::builder() ->setSecurity( '' ) ->build(); $request = new Components\\CustomerSessionCustomerExternalIDCreate( externalCustomerId: '', ); $response = $sdk->customerSessions->create( request: $request ); if ($response->customerSession !== null) { // handle response } ``` -------------------------------- ### Basic Flask Webhook Endpoint in Python Source: https://polar.sh/docs/integrate/webhooks/delivery This Python Flask example demonstrates a basic setup for receiving webhook requests. It includes necessary imports and a placeholder for handling the incoming request. ```python import os from flask import Flask, request app = Flask(__name__) @app.route("/webhook", methods=["POST"]) def webhook(): # TODO: Implement webhook verification and handling return "Webhook received" if __name__ == "__main__": app.run(port=int(os.environ.get("PORT", 3000))) ``` -------------------------------- ### Setup and Use S3 Ingestion Strategy in Javascript Source: https://docs.polar.sh/llms-full.txt Configure and utilize the S3 Ingestion Strategy to automatically ingest bytes from S3 uploads. This example demonstrates setting up the S3 client, initializing the ingestion strategy, and sending an object to S3. ```typescript import { Ingestion } from "@polar-sh/ingestion"; import { S3Strategy } from "@polar-sh/ingestion/strategies/S3"; import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3"; const s3Client = new S3Client({ region: process.env.AWS_REGION, endpoint: process.env.AWS_ENDPOINT_URL, credentials: { accessKeyId: process.env.AWS_ACCESS_KEY_ID!, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!, }, }); // Setup the S3 Ingestion Strategy const s3Ingestion = Ingestion({accessToken: process.env.POLAR_ACCESS_TOKEN }) .strategy(new S3Strategy(s3Client)) .ingest("s3-uploads"); export async function POST(request: Request) { try { // Get the wrapped S3 Client // Pass Customer Id to properly annotate the ingestion events with a specific customer const s3 = s3Ingestion.client({ customerId: request.headers.get("X-Polar-Customer-Id") ?? "", }); await s3.send( new PutObjectCommand({ Bucket: process.env.AWS_BUCKET_NAME, Key: "a-random-key", Body: JSON.stringify({ name: "John Doe", age: 30, }), ContentType: "application/json", }) ); return Response.json({}); } catch (error) { return Response.json({ error: error.message }); } } ``` -------------------------------- ### PHP Quickstart: List Organizations Source: https://docs.polar.sh/llms-full.txt A PHP script to initialize the Polar SDK with a bearer token and list organizations. It shows how to iterate through paginated responses. ```php declare(strict_types=1); require 'vendor/autoload.php'; use Polar; $sdk = Polar\Polar::builder() ->setSecurity('') ->build(); $responses = $sdk->organizations->list( page: 1, limit: 10 ); foreach ($responses as $response) { if ($response->statusCode === 200) { // handle response } } ``` -------------------------------- ### Get Benefit Source: https://polar.sh/docs/merchant-of-record/account-reviews Get a benefit by ID. ```APIDOC ## GET /v1/benefits/{id} ### Description Get a benefit by ID. ### Method GET ### Endpoint /v1/benefits/{id} ### Scopes `benefits:read` `benefits:write` ``` -------------------------------- ### Initialize Polar SDK with Sandbox Server (Go) Source: https://docs.polar.sh/llms-full.txt Set up the Polar Go SDK to use the sandbox environment. Use the WithServer option to specify 'sandbox' and WithSecurity for the access token. ```go s := polargo.New( polargo.WithServer("sandbox"), polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")), ) ``` -------------------------------- ### Get Discount Source: https://polar.sh/docs/features/benefits/introduction Get a discount by ID. ```APIDOC ## GET /v1/discounts/{id} ### Description Get a discount by ID. ### Method GET ### Endpoint /v1/discounts/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the discount. ``` -------------------------------- ### Get Order Source: https://polar.sh/docs/features/benefits/introduction Get an order by ID. ```APIDOC ## GET /v1/orders/{id} ### Description Get an order by ID. ### Method GET ### Endpoint /v1/orders/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the order. ``` -------------------------------- ### Initialize Next.js Project with Polar Source: https://docs.polar.sh/llms-full.txt Use this command to set up a new Next.js project with Polar integration. ```bash npx polar-init ``` -------------------------------- ### Create Product Source: https://polar.sh/docs/features/benefits/introduction Creates a new product. Requires `products:write` scope. ```APIDOC ## POST /v1/products/ ### Description Create a product. ### Method POST ### Endpoint /v1/products/ ### Scopes `products:write` ``` -------------------------------- ### Get Subscription Source: https://polar.sh/docs/features/benefits/introduction Get a subscription by ID. ```APIDOC ## GET /v1/subscriptions/{id} ### Description Get a subscription by ID. ### Method GET ### Endpoint /v1/subscriptions/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the subscription. ``` -------------------------------- ### List Customers (Go SDK) Source: https://polar.sh/docs/api-reference/customers/list Demonstrates how to list customers using the Polar Go SDK. It includes setting up the client with authentication and making the list request with an organization ID filter. Handles pagination by iterating through results. ```go package main import ( "context" "os" polargo "github.com/polarsource/polar-go" "github.com/polarsource/polar-go/models/operations" "log" ) func main() { ctx := context.Background() s := polargo.New( polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")), ) res, err := s.Customers.List(ctx, operations.CustomersListRequest{ OrganizationID: polargo.Pointer(operations.CreateCustomersListQueryParamOrganizationIDFilterStr( "1dbfc517-0bbf-4301-9ba8-555ca42b9737", )), }) if err != nil { log.Fatal(err) } if res.ListResourceCustomer != nil { for { // handle items res, err = res.Next() if err != nil { // handle error } if res == nil { break } } } } ``` -------------------------------- ### Listen for Webhooks Locally Source: https://polar.sh/docs/integrate/webhooks/locally Start listening for webhooks and forward them to your local development server. You will be prompted to select an organization. ```bash polar listen http://localhost:3000/ ``` -------------------------------- ### Install Polar.sh SvelteKit Adapter with yarn Source: https://docs.polar.sh/llms-full.txt Install the necessary Polar packages for SvelteKit using yarn. Ensure zod is also installed. ```bash yarn add zod @polar-sh/sveltekit ``` -------------------------------- ### Create Customer Session with PHP SDK Source: https://polar.sh/docs/api-reference/customer-portal/sessions/create Use the PHP SDK to create a customer session. This snippet demonstrates setting up the SDK client and making the request. ```php declare(strict_types=1); require 'vendor/autoload.php'; use Polar; use Polar\\Models\\Components; $sdk = Polar\\Polar::builder() ->setSecurity( '' ) ->build(); $request = new Components\\CustomerSessionCustomerExternalIDCreate( externalCustomerId: '', ); $response = $sdk->customerSessions->create( request: $request ); if ($response->customerSession !== null) { // handle ``` -------------------------------- ### Activate License Key Response Source: https://docs.polar.sh/llms-full.txt Example of a successful response (200 OK) when activating a license key. ```json { "id": "b6724bc8-7ad9-4ca0-b143-7c896fcbb6fe", "license_key_id": "508176f7-065a-4b5d-b524-4e9c8a11ed63", "label": "hello", "meta": { "ip": "84.19.145.194" }, "created_at": "2024-09-02T13:48:13.251621Z", "modified_at": null, "license_key": { "id": "508176f7-065a-4b5d-b524-4e9c8a11ed63", "organization_id": "fda84e25-7b55-4d67-916d-60ead04ff61f", "user_id": "d910050c-be66-4ca0-b4cc-34fde514f227", "benefit_id": "32a8eda4-56cf-4a94-8228-792d324a519e", "key": "1C285B2D-6CE6-4BC7-B8BE-ADB6A7E304DA", "display_key": "****-E304DA", "status": "granted", "limit_activations": 3, "usage": 0, "limit_usage": 100, "validations": 0, "last_validated_at": null, "expires_at": "2026-08-30T08:40:34.769148Z" } } ``` -------------------------------- ### Install Polar.sh Hono Adapter (pnpm) Source: https://docs.polar.sh/llms-full.txt Install the necessary Polar.sh packages for Hono using pnpm. Ensure zod is also installed. ```bash pnpm add zod @polar-sh/hono ``` -------------------------------- ### List Customers (TypeScript SDK) Source: https://polar.sh/docs/api-reference/customers/list Provides an example of listing customers with the Polar TypeScript SDK. Uses environment variables for the access token. Demonstrates an asynchronous approach to handle paginated results. ```typescript import { Polar } from "@polar-sh/sdk"; const polar = new Polar({ accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "", }); async function run() { const result = await polar.customers.list({ organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737", }); for await (const page of result) { console.log(page); } } run(); ``` -------------------------------- ### Initialize Polar SDK with Sandbox Server (PHP) Source: https://docs.polar.sh/llms-full.txt Build the Polar SDK instance in PHP for sandbox access. Use the builder pattern to set the server to 'sandbox' and provide the security token. ```php $sdk = Polar\Polar::builder() ->setServer('sandbox') ->setSecurity(getenv('POLAR_ACCESS_TOKEN')) ->build(); ``` -------------------------------- ### Install Polar Fastify Adapter (bun) Source: https://docs.polar.sh/llms-full.txt Install the necessary packages for Fastify integration using bun. This includes zod for validation and the Polar Fastify adapter. ```bash bun add zod @polar-sh/fastify ``` -------------------------------- ### Get User Info Source: https://polar.sh/docs/features/benefits/introduction Get information about the authenticated user. ```APIDOC ## GET /v1/oauth2/userinfo ### Description Get information about the authenticated user. ### Method GET ### Endpoint /v1/oauth2/userinfo ``` -------------------------------- ### Install Polar Ingestion SDK and AI SDK Source: https://docs.polar.sh/llms-full.txt Install the necessary packages for the Javascript LLM strategy using pnpm. ```bash pnpm add @polar-sh/ingestion ai @ai-sdk/openai ``` -------------------------------- ### Get Order Invoice Source: https://polar.sh/docs/features/benefits/introduction Get an order's invoice data. ```APIDOC ## GET /v1/orders/{id}/invoice ### Description Get an order's invoice data. ### Method GET ### Endpoint /v1/orders/{id}/invoice ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the order. ``` -------------------------------- ### SDK Initialization Source: https://docs.polar.sh/llms-full.txt Demonstrates how to initialize the Polar SDK in TypeScript, Python, Go, and PHP, including setting the access token and server environment. ```APIDOC ## SDK Initialization All official SDKs accept a `server` parameter for sandbox usage. ### TypeScript ```ts import { Polar } from "@polar-sh/sdk"; const polar = new Polar({ accessToken: process.env.POLAR_ACCESS_TOKEN!, server: "sandbox", // omit or use 'production' for live }); ``` ### Python ```py from polar import Polar client = Polar( access_token=os.environ["POLAR_ACCESS_TOKEN"], server="sandbox", ) ``` ### Go ```go s := polargo.New( polargo.WithServer("sandbox"), polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")), ) ``` ### PHP ```php $sdk = Polar\Polar::builder() ->setServer('sandbox') ->setSecurity(getenv('POLAR_ACCESS_TOKEN')) ->build(); ``` ``` -------------------------------- ### Install Laravel Polar Package Source: https://docs.polar.sh/llms-full.txt Install the danestves/laravel-polar package using Composer. ```bash composer require danestves/laravel-polar ``` -------------------------------- ### List Customers (Python SDK) Source: https://polar.sh/docs/api-reference/customers/list Shows how to list customers using the Polar Python SDK. Requires an access token for authentication. Demonstrates making a paginated request and iterating through the results. ```python from polar_sdk import Polar with Polar( access_token="", ) as polar: res = polar.customers.list(organization_id="1dbfc517-0bbf-4301-9ba8-555ca42b9737", page=1, limit=10) while res is not None: # Handle items res = res.next() ``` -------------------------------- ### Install Polar Python SDK Source: https://docs.polar.sh/llms-full.txt Install the Polar Python SDK using pip. ```bash pip install polar-sdk ``` -------------------------------- ### Get Benefit Source: https://polar.sh/docs/integrate/customer-state Get a benefit by ID. Scopes: benefits:read, benefits:write ```APIDOC ## GET /v1/benefits/{id} ### Description Get a benefit by ID. ### Method GET ### Endpoint /v1/benefits/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the benefit. ### Scopes `benefits:read` `benefits:write` ``` -------------------------------- ### Create Customer Session with Python SDK Source: https://polar.sh/docs/api-reference/customer-portal/sessions/create Create a customer session using the Python SDK. Replace placeholder values with your actual token and customer ID. ```python from polar_sdk import Polar with Polar( access_token="", ) as polar: res = polar.customer_sessions.create(request={ "return_url": "https://example.com/account", "external_customer_id": "", }) # Handle response print(res) ``` -------------------------------- ### Activate License Key Source: https://docs.polar.sh/llms-full.txt Activate a license key if your setup has a maximum activation instance limit. This step is optional if there is no activation limit. ```bash curl -X POST https://api.polar.sh/v1/customer-portal/license-keys/activate -H "Content-Type: application/json" -d '{ "key": "1C285B2D-6CE6-4BC7-B8BE-ADB6A7E304DA", "organization_id": "fda84e25-7b55-4d67-916d-60ead04ff61f", "label": "hello", "conditions": { "major_version": 1 }, "meta": { "ip": "84.19.145.194" } }' ```