Installation
Setup
Configure environment variables
Add your Polar credentials to
.env:.env
Variables prefixed with
PUBLIC_ are exposed to the client. Keep your access token private.Server Endpoints
Create API endpoints for server-side operations:src/pages/api/checkout.ts
Webhook Endpoint
Handle Polar webhooks with API routes:src/pages/api/webhooks/polar.ts
Client-Side Integration
Use Astro’s client directives for interactive components:src/components/BuyButton.astro
React/Vue/Svelte Components
Use Astro’s framework integrations with Polar:src/components/ProductCard.tsx
src/pages/products.astro
Dynamic Routes
Fetch product data for dynamic routes:src/pages/products/[id].astro
Static Site Generation
Generate static pages at build time:src/pages/products/[id].astro
Middleware
Add authentication or session management:src/middleware.ts
Best Practices
Use server endpoints
Keep sensitive operations in API routes to protect your access token.
Optimize builds
Use SSG for product pages when possible to improve performance.
Type safety
Import TypeScript types from the SDK for better development experience.
Cache wisely
Use Astro’s built-in caching for frequently accessed data.
Next Steps
Checkout
Implement Polar Checkout in your Astro site.
Webhooks
Handle real-time events from Polar.
TypeScript SDK
Explore the full TypeScript SDK documentation.
API Reference
Browse the complete API reference.