mcpField
P
polar-integration

polar-integration

github.com/bbssppllvvDevelopment159 installsUpdated 20w ago
Repository

About polar-integration

polar-integration is a development skill that guides teams through integrating Polar payments into applications. It covers SDKs and framework adapters, checkout options, webhooks, customer portals, and related billing workflows.

Key features

  1. 01Guide setup across SDKs and frameworks
  2. 02Configure authentication and sandbox use
  3. 03Set up links, API, or embedded checkout
  4. 04Handle payment events with webhooks
  5. 05Integrate customer portals and billing

Use cases

  1. 01Add Polar checkout to an application
  2. 02Process subscription and order webhooks
  3. 03Offer customers a subscription portal
  4. 04Test payment flows in sandbox

MCP support

The skill's reference index includes a Polar MCP server for AI agents such as Cursor, Claude, and ChatGPT.

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/bbssppllvv/essential-skills --skill polar-integration

After installing, type/polar-integrationin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

README.md
references/
api-reference.md
authentication.md
benefits.md
checkout-api.md
checkout-embedded.md
checkout-links.md
custom-fields.md
customer-portal.md
customer-state.md
discounts.md
events-metering.md
license-keys.md
mcp.md
metrics.md
nextjs.md
oauth2.md
orders-subscriptions.md
products.md
python-sdk.md
refunds.md
sandbox.md
seat-based-pricing.md
supabase.md
sveltekit.md
trials.md
typescript-sdk.md
webhook-events.md
webhooks-delivery.md
webhooks-local.md

Details

From the project README

Polar Integration

Polar is a payment platform for digital products: subscriptions, one-time purchases, licenses, checkout, and webhooks. This skill provides complete integration guidance.

Integration Workflow

1. Determine the Stack

Identify the project's framework. Polar has first-class support for:

2. Install Dependencies
npm install @polar-sh/sdk
# For Next.js projects:
npm install zod @polar-sh/nextjs
# For SvelteKit projects:
npm install zod @polar-sh/sveltekit
# For Supabase projects:
npm install zod @polar-sh/supabase
# For embedded checkout:
npm install @polar-sh/checkout
# For Python projects:
pip install polar-sdk

Note: The Polar SDK is in active development. Pin versions to avoid breaking changes: npm install @polar-sh/sdk@^0.46 / pip install polar-sdk~=0.28

3. Configure Authentication

Set up environment variables:

POLAR_ACCESS_TOKEN=polar_at_xxx     # Organization Access Token from Polar dashboard
POLAR_WEBHOOK_SECRET=xxx            # Webhook signing secret

Create Organization Access Tokens from organization settings in Polar dashboard. See references/authentication.md for details.

For sandbox/testing, use server: "sandbox" in SDK config. For production, use server: "production" or omit. See references/sandbox.md for sandbox details (test cards, API URLs, limitations).

4. Set Up Checkout

Choose approach based on needs:

ApproachWhen to Use
Checkout LinksNo-code, shareable URLs
Checkout APIProgrammatic control, dynamic pricing
Embedded CheckoutInline on your site, no redirect

Quick start (Next.js):

// app/checkout/route.ts
import { Checkout } from "@polar-sh/nextjs";

export const GET = Checkout({
  accessToken: process.env.POLAR_ACCESS_TOKEN,
  successUrl: process.env.SUCCESS_URL,
  server: "sandbox",
});
// Use: GET /checkout?products=PRODUCT_ID

Quick start (SDK):

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env.POLAR_ACCESS_TOKEN,
  server: "sandbox",
});

const checkout = await polar.checkouts.create({
  products: ["PRODUCT_ID"],
});
// Redirect user to checkout.url
5. Set Up Webhooks

Webhooks notify your app about payment events (order created, subscription canceled, etc.).

Quick start (Next.js):

// app/api/webhook/polar/route.ts
import { Webhooks } from "@polar-sh/nextjs";

export const POST = Webhooks({
  webhookSecret: process.env.POLAR_WEBHOOK_SECRET!,
  onPayload: async (payload) => {
    // Handle any event
  },
  onOrderCreated: async (payload) => {
    // Handle new order
  },
  onSubscriptionCreated: async (payload) => {
    // Handle new subscription
  },
});

Quick start (Express):

import express from "express";
import { validateEvent, WebhookVerificationError } from "@polar-sh/sdk/webhooks";

app.post("/webhook", express.raw({ type: "application/json" }), (req, res) => {
  try {
    const event = validateEvent(req.body, req.headers, process.env.POLAR_WEBHOOK_SECRET ?? "");
    // Process event
    res.status(202).send("");
  } catch (error) {
    if (error instanceof WebhookVerificationError) res.status(403).send("");
    throw error;
  }
});

For webhook setup in Polar dashboard: references/webhooks-setup.md For local development with polar listen: references/webhooks-local.md For delivery handling, retries, troubleshooting: references/webhooks-delivery.md

6. Set Up Customer Portal (Optional)

Give customers access to their orders and subscriptions.

Next.js:

// app/portal/route.ts
import { CustomerPortal } from "@polar-sh/nextjs";

export const GET = CustomerPortal({
  accessToken: process.env.POLAR_ACCESS_TOKEN,
  getCustomerId: async (req) => "CUSTOMER_ID", // resolve from your auth
  server: "sandbox",
});

SDK:

const session = await polar.customerSessions.create({ customerId: "CUSTOMER_ID" });
// Redirect to session.customerPortalUrl

See references/customer-portal.md.

Reference Index

Load these files when you need detailed information on a specific topic:

SDK & Frameworks
Authentication
Products & Pricing
Checkout
Webhooks
Benefits & License Keys
  • references/benefits.md — Benefit types (Credits, License Keys, File Downloads, GitHub, Discord, Custom), grant lifecycle, webhooks
  • references/license-keys.md — License key validation, activation/deactivation, limits, brandable prefixes
Events & Metering
Orders & Customers
Webhook Events
Metrics & Analytics
Customer State & Sandbox
API Reference
AI Integration
  • references/mcp.md — Polar MCP server for AI agents (Cursor, Claude, ChatGPT, etc.)

Comments

Markdown supported