{"_id":"@alexdelia/polar-betterauth","_rev":"10-8bbdee1869e3d52e67681460162e6928","name":"@alexdelia/polar-betterauth","dist-tags":{"latest":"1.1.8"},"versions":{"1.1.2":{"name":"@alexdelia/polar-betterauth","version":"1.1.2","keywords":["polar","better-auth","payments","subscriptions"],"license":"Apache-2.0","_id":"@alexdelia/polar-betterauth@1.1.2","maintainers":[{"name":"alexdelia","email":"alex-delia@outlook.com"}],"homepage":"https://github.com/alex-delia/polar-adapters#readme","bugs":{"url":"https://github.com/alex-delia/polar-adapters/issues"},"dist":{"shasum":"0ada06b71d6ca00707efb62598ac6b304cf89a17","tarball":"https://registry.npmjs.org/@alexdelia/polar-betterauth/-/polar-betterauth-1.1.2.tgz","fileCount":9,"integrity":"sha512-QHQA8rgxVGRUM7UpJvAvoX/FwxsKw7fxIfB0MdP4xHOyGBrAP2ym+pbKaZnzNLNxpep2//1Muq6GzyXeNAsbMg==","signatures":[{"sig":"MEQCIGqZtCg2t6KxN6WxCfWz3DUsqsVzr1o7AtXFLwNhEE0jAiBUgYcgMulLF0js7pI6JdAghWbiHfBxjc5wSlAeOCgMSQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":303223},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=16"},"exports":{"import":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","require":"./dist/index.cjs"}},"gitHead":"f683bdfacd663ea1b571da68c73d2ea75ddf75b8","scripts":{"dev":"npm run build -- --watch","test":"vitest","build":"tsup ./src/index.ts --format esm,cjs --dts --clean --sourcemap","check":"biome check --write ./src","test:watch":"vitest","test:coverage":"vitest run --coverage"},"_npmUser":{"name":"alexdelia","email":"alex-delia@outlook.com"},"repository":{"url":"git+https://github.com/alex-delia/polar-adapters.git","type":"git","directory":"packages/polar-betterauth"},"_npmVersion":"11.1.0","description":"Custom Polar integration for better-auth","directories":{},"_nodeVersion":"22.13.1","dependencies":{"zod":"^3.24.2"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.5","vitest":"^2.1.8","@types/node":"^20.0.0","better-auth":"^1.2.7","@polar-sh/sdk":"^0.34.8","@biomejs/biome":"1.9.4","@sindresorhus/tsconfig":"^7.0.0","@polar-sh/adapter-utils":"workspace:*"},"peerDependencies":{"better-auth":"^1.2.7","@polar-sh/sdk":"^0.34.8"},"_npmOperationalInternal":{"tmp":"tmp/polar-betterauth_1.1.2_1757384535409_0.09920505794685086","host":"s3://npm-registry-packages-npm-production"}},"1.1.3":{"name":"@alexdelia/polar-betterauth","version":"1.1.3","keywords":["polar","better-auth","payments","subscriptions"],"license":"Apache-2.0","_id":"@alexdelia/polar-betterauth@1.1.3","maintainers":[{"name":"alexdelia","email":"alex-delia@outlook.com"}],"homepage":"https://github.com/alex-delia/polar-adapters#readme","bugs":{"url":"https://github.com/alex-delia/polar-adapters/issues"},"dist":{"shasum":"f1e673e30c5b0741e17bcb2ec45118ff1a2f76b2","tarball":"https://registry.npmjs.org/@alexdelia/polar-betterauth/-/polar-betterauth-1.1.3.tgz","fileCount":9,"integrity":"sha512-vtfIxqe3yaT1w0z3wgcIeKhe4hBmRlPER+8zH4SmzKokVyLK4suKd49DjGuN3TcrUGPpnlS+aBzvckfd+FrUoQ==","signatures":[{"sig":"MEYCIQDT0CG6tW+79ANMfCMQ8iugwo1FrZ7k8oZa3O1nhxpW9AIhAM77vXM1gnKVCXRA5zCYn/Y0xS7hztTmtaFjsuVP0+kH","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":303223},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=16"},"exports":{"import":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","require":"./dist/index.cjs"}},"gitHead":"d2998a19a805236c8f344c00e6e9d7226386bbc3","scripts":{"dev":"npm run build -- --watch","test":"vitest","build":"tsup ./src/index.ts --format esm,cjs --dts --clean --sourcemap","check":"biome check --write ./src","test:watch":"vitest","test:coverage":"vitest run --coverage"},"_npmUser":{"name":"alexdelia","email":"alex-delia@outlook.com"},"repository":{"url":"git+https://github.com/alex-delia/polar-adapters.git","type":"git","directory":"packages/polar-betterauth"},"_npmVersion":"11.1.0","description":"Custom Polar integration for better-auth","directories":{},"_nodeVersion":"22.13.1","dependencies":{"zod":"^3.24.2"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.5","vitest":"^2.1.8","@types/node":"^20.0.0","better-auth":"^1.2.7","@polar-sh/sdk":"^0.34.8","@biomejs/biome":"1.9.4","@sindresorhus/tsconfig":"^7.0.0","@polar-sh/adapter-utils":"workspace:*"},"peerDependencies":{"better-auth":"^1.2.7","@polar-sh/sdk":"^0.34.8"},"_npmOperationalInternal":{"tmp":"tmp/polar-betterauth_1.1.3_1757386670494_0.33066098440100467","host":"s3://npm-registry-packages-npm-production"}},"1.1.4":{"name":"@alexdelia/polar-betterauth","version":"1.1.4","keywords":["polar","better-auth","payments","subscriptions"],"license":"Apache-2.0","_id":"@alexdelia/polar-betterauth@1.1.4","maintainers":[{"name":"alexdelia","email":"alex-delia@outlook.com"}],"homepage":"https://github.com/alex-delia/polar-adapters#readme","bugs":{"url":"https://github.com/alex-delia/polar-adapters/issues"},"dist":{"shasum":"cd6882b2bbfdf44dbedd73a953ff91ae3bba5203","tarball":"https://registry.npmjs.org/@alexdelia/polar-betterauth/-/polar-betterauth-1.1.4.tgz","fileCount":9,"integrity":"sha512-kfZdiqXDJ4uzCneeBxZ8z5VpgbvV/BO5APCnjs3EZOTOD6yxny+ACBGGUimImb13YHvQnQuolGdVO6F5Z+csHw==","signatures":[{"sig":"MEQCICQDaIulHfrARpyeslp3MmWBHMm97DL74VD/+y7Wf1m5AiAsaojE5h86M6FP0nWZR5/NrioaR2lm/uys/5lf8vnIVg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":305211},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=16"},"exports":{"import":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","require":"./dist/index.cjs"}},"gitHead":"d2998a19a805236c8f344c00e6e9d7226386bbc3","scripts":{"dev":"npm run build -- --watch","test":"vitest","build":"tsup ./src/index.ts --format esm,cjs --dts --clean --sourcemap","check":"biome check --write ./src","test:watch":"vitest","test:coverage":"vitest run --coverage"},"_npmUser":{"name":"alexdelia","email":"alex-delia@outlook.com"},"repository":{"url":"git+https://github.com/alex-delia/polar-adapters.git","type":"git","directory":"packages/polar-betterauth"},"_npmVersion":"11.1.0","description":"Custom Polar integration for better-auth","directories":{},"_nodeVersion":"22.13.1","dependencies":{"zod":"^3.24.2"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.5","vitest":"^2.1.8","@types/node":"^20.0.0","better-auth":"^1.2.7","@polar-sh/sdk":"^0.34.8","@biomejs/biome":"1.9.4","@sindresorhus/tsconfig":"^7.0.0","@polar-sh/adapter-utils":"workspace:*"},"peerDependencies":{"better-auth":"^1.2.7","@polar-sh/sdk":"^0.34.8"},"_npmOperationalInternal":{"tmp":"tmp/polar-betterauth_1.1.4_1757388411659_0.5039776248288366","host":"s3://npm-registry-packages-npm-production"}},"1.1.5":{"name":"@alexdelia/polar-betterauth","version":"1.1.5","keywords":["polar","better-auth","payments","subscriptions"],"license":"Apache-2.0","_id":"@alexdelia/polar-betterauth@1.1.5","maintainers":[{"name":"alexdelia","email":"alex-delia@outlook.com"}],"homepage":"https://github.com/alex-delia/polar-adapters#readme","bugs":{"url":"https://github.com/alex-delia/polar-adapters/issues"},"dist":{"shasum":"d230d4390779a7e6899d3790700f937a3e5adbda","tarball":"https://registry.npmjs.org/@alexdelia/polar-betterauth/-/polar-betterauth-1.1.5.tgz","fileCount":9,"integrity":"sha512-P+H89qGETa4ozJY9BQ+qT6oKpeoHa1B0nOvvR4VDkbJSAWeAazsNHzRsFE+97G4zmylwkrvSC9xItEJQpSqmlQ==","signatures":[{"sig":"MEYCIQCxeWMWgrn3imMq+JwUNec7jdlF5ZuD2b0eexptkumFJgIhALKdxgpWohkdMQM1cOjckAroWLrepusSwIK9/UOw+WAP","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":305071},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=16"},"exports":{"import":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","require":"./dist/index.cjs"}},"gitHead":"96e5cc938b10a67b80a8b3a7c35c3a9ec44a0c81","scripts":{"dev":"npm run build -- --watch","test":"vitest","build":"tsup ./src/index.ts --format esm,cjs --dts --clean --sourcemap","check":"biome check --write ./src","test:watch":"vitest","test:coverage":"vitest run --coverage"},"_npmUser":{"name":"alexdelia","email":"alex-delia@outlook.com"},"repository":{"url":"git+https://github.com/alex-delia/polar-adapters.git","type":"git","directory":"packages/polar-betterauth"},"_npmVersion":"11.1.0","description":"Custom Polar integration for better-auth","directories":{},"_nodeVersion":"22.13.1","dependencies":{"zod":"^3.24.2"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.5","vitest":"^2.1.8","@types/node":"^20.0.0","better-auth":"^1.2.7","@polar-sh/sdk":"^0.34.8","@biomejs/biome":"1.9.4","@sindresorhus/tsconfig":"^7.0.0","@polar-sh/adapter-utils":"workspace:*"},"peerDependencies":{"better-auth":"^1.2.7","@polar-sh/sdk":"^0.34.8"},"_npmOperationalInternal":{"tmp":"tmp/polar-betterauth_1.1.5_1757390674334_0.15719438123329676","host":"s3://npm-registry-packages-npm-production"}},"1.1.6":{"name":"@alexdelia/polar-betterauth","version":"1.1.6","keywords":["polar","better-auth","payments","subscriptions"],"license":"Apache-2.0","_id":"@alexdelia/polar-betterauth@1.1.6","maintainers":[{"name":"alexdelia","email":"alex-delia@outlook.com"}],"homepage":"https://github.com/alex-delia/polar-adapters#readme","bugs":{"url":"https://github.com/alex-delia/polar-adapters/issues"},"dist":{"shasum":"944ddc313e4a26a0a0bc584e08da69087b33df0a","tarball":"https://registry.npmjs.org/@alexdelia/polar-betterauth/-/polar-betterauth-1.1.6.tgz","fileCount":9,"integrity":"sha512-8cnsT0SDKMhn7efRWWoSXN4lEAFCvEFZfezqwdsWaFPb2I0QiJRwnnhJiWW6W+tvSMYFhv2zo6fd+8V9O63L/A==","signatures":[{"sig":"MEYCIQDYtsyxaYcPx/bAORZB9+8iSMZ1Sjm+DYakPYl0xc292wIhANS42o9LdFusAx/H6dI8PNZ+0wczi0lTkFYMtG9pwsO8","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":305311},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=16"},"exports":{"import":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","require":"./dist/index.cjs"}},"gitHead":"d257c321f9436306f0f0fbfee5244ce04685802b","scripts":{"dev":"npm run build -- --watch","test":"vitest","build":"tsup ./src/index.ts --format esm,cjs --dts --clean --sourcemap","check":"biome check --write ./src","test:watch":"vitest","test:coverage":"vitest run --coverage"},"_npmUser":{"name":"alexdelia","email":"alex-delia@outlook.com"},"repository":{"url":"git+https://github.com/alex-delia/polar-adapters.git","type":"git","directory":"packages/polar-betterauth"},"_npmVersion":"11.1.0","description":"Custom Polar integration for better-auth","directories":{},"_nodeVersion":"22.13.1","dependencies":{"zod":"^3.24.2"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.5","vitest":"^2.1.8","@types/node":"^20.0.0","better-auth":"^1.2.7","@polar-sh/sdk":"^0.34.8","@biomejs/biome":"1.9.4","@sindresorhus/tsconfig":"^7.0.0","@polar-sh/adapter-utils":"workspace:*"},"peerDependencies":{"better-auth":"^1.2.7","@polar-sh/sdk":"^0.34.8"},"_npmOperationalInternal":{"tmp":"tmp/polar-betterauth_1.1.6_1757397511053_0.42279898874181887","host":"s3://npm-registry-packages-npm-production"}},"1.1.7":{"name":"@alexdelia/polar-betterauth","version":"1.1.7","keywords":["polar","better-auth","payments","subscriptions"],"license":"Apache-2.0","_id":"@alexdelia/polar-betterauth@1.1.7","maintainers":[{"name":"alexdelia","email":"alex-delia@outlook.com"}],"homepage":"https://github.com/alex-delia/polar-adapters#readme","bugs":{"url":"https://github.com/alex-delia/polar-adapters/issues"},"dist":{"shasum":"da4841bbdd334cc43db128ebdb95f3cc8634986a","tarball":"https://registry.npmjs.org/@alexdelia/polar-betterauth/-/polar-betterauth-1.1.7.tgz","fileCount":9,"integrity":"sha512-V3jWcQs+EQadSQaSCQw1RF42KZWC7L7jJ6A5HIbPkbV8RCrbow7gkklZ0wYTYYguAXjoL8A35iomfjBn3JMezw==","signatures":[{"sig":"MEYCIQCR5bYJ6zw1bS0UWR2vlrUwtf8Kv6pyHAa3qWbjqyiCngIhAPl9Eewtw6Ydyj8H80Kgj4c92I62CMK5bk46QSYISBQk","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":305313},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=16"},"exports":{"import":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","require":"./dist/index.cjs"}},"gitHead":"70c8d2269ef887af246af939b9aa74398748ec79","scripts":{"dev":"npm run build -- --watch","test":"vitest","build":"tsup ./src/index.ts --format esm,cjs --dts --clean --sourcemap","check":"biome check --write ./src","test:watch":"vitest","test:coverage":"vitest run --coverage"},"_npmUser":{"name":"alexdelia","email":"alex-delia@outlook.com"},"repository":{"url":"git+https://github.com/alex-delia/polar-adapters.git","type":"git","directory":"packages/polar-betterauth"},"_npmVersion":"11.1.0","description":"Custom Polar integration for better-auth","directories":{},"_nodeVersion":"22.13.1","dependencies":{"zod":"^3.24.2"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.5","vitest":"^2.1.8","@types/node":"^20.0.0","better-auth":"^1.3.9","@polar-sh/sdk":"^0.34.17","@biomejs/biome":"1.9.4","@sindresorhus/tsconfig":"^7.0.0","@polar-sh/adapter-utils":"workspace:*"},"peerDependencies":{"better-auth":"^1.3.9","@polar-sh/sdk":"^0.34.16"},"_npmOperationalInternal":{"tmp":"tmp/polar-betterauth_1.1.7_1758307851465_0.33866462105053796","host":"s3://npm-registry-packages-npm-production"}},"1.1.8":{"name":"@alexdelia/polar-betterauth","version":"1.1.8","description":"Custom Polar integration for better-auth","repository":{"type":"git","url":"git+https://github.com/alex-delia/polar-adapters.git","directory":"packages/polar-betterauth"},"main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{"import":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","require":"./dist/index.cjs"}},"type":"module","engines":{"node":">=16"},"scripts":{"test":"vitest","test:watch":"vitest","test:coverage":"vitest run --coverage","build":"tsup ./src/index.ts --format esm,cjs --dts --clean --sourcemap","dev":"npm run build -- --watch","check":"biome check --write ./src"},"license":"Apache-2.0","publishConfig":{"access":"public"},"keywords":["polar","better-auth","payments","subscriptions"],"devDependencies":{"@biomejs/biome":"1.9.4","@polar-sh/adapter-utils":"workspace:*","@polar-sh/sdk":"^0.34.17","@sindresorhus/tsconfig":"^7.0.0","@types/node":"^20.0.0","better-auth":"^1.3.9","tsup":"^8.3.5","vitest":"^2.1.8"},"dependencies":{"zod":"^3.24.2"},"peerDependencies":{"@polar-sh/sdk":"^0.34.16","better-auth":"^1.3.18"},"_id":"@alexdelia/polar-betterauth@1.1.8","gitHead":"6923b0a6fdf6f544f209fc49bc34f427cdb1e91c","bugs":{"url":"https://github.com/alex-delia/polar-adapters/issues"},"homepage":"https://github.com/alex-delia/polar-adapters#readme","_nodeVersion":"22.13.1","_npmVersion":"11.1.0","dist":{"integrity":"sha512-MUaPiy6T7P4U/clfmpldfup+PpJ2S4Tkh9qSRiqO+v2WhH9nmpGFjm/B8VhPs/Q8WwAMNEdS4bPPBbHM9acNVA==","shasum":"bd464248548d9c64b8f11ea0acd8f8ccf0053db3","tarball":"https://registry.npmjs.org/@alexdelia/polar-betterauth/-/polar-betterauth-1.1.8.tgz","fileCount":9,"unpackedSize":305314,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIE+ESgchQgga2ZlbQOxQbrE1Blm9+uCgv4Tu2FPY2CgNAiEArJW9dL6Aet1Wlz9HakxADU1w/GNivwrDaOQrQl5RY+w="}]},"_npmUser":{"name":"alexdelia","email":"alex-delia@outlook.com"},"directories":{},"maintainers":[{"name":"alexdelia","email":"alex-delia@outlook.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/polar-betterauth_1.1.8_1761250820784_0.5929491299258853"},"_hasShrinkwrap":false}},"time":{"created":"2025-09-09T02:22:15.320Z","modified":"2025-10-23T20:20:21.194Z","1.1.1":"2025-09-09T02:17:05.026Z","1.1.2":"2025-09-09T02:22:15.668Z","1.1.3":"2025-09-09T02:57:50.726Z","1.1.4":"2025-09-09T03:26:51.866Z","1.1.5":"2025-09-09T04:04:34.537Z","1.1.6":"2025-09-09T05:58:31.257Z","1.1.7":"2025-09-19T18:50:51.967Z","1.1.8":"2025-10-23T20:20:21.003Z"},"bugs":{"url":"https://github.com/alex-delia/polar-adapters/issues"},"license":"Apache-2.0","homepage":"https://github.com/alex-delia/polar-adapters#readme","keywords":["polar","better-auth","payments","subscriptions"],"repository":{"type":"git","url":"git+https://github.com/alex-delia/polar-adapters.git","directory":"packages/polar-betterauth"},"description":"Custom Polar integration for better-auth","maintainers":[{"name":"alexdelia","email":"alex-delia@outlook.com"}],"readme":"# @alexdelia/polar-betterauth\r\n\r\nA [Better Auth](https://github.com/better-auth/better-auth) plugin for integrating [Polar](https://polar.sh) payments and subscriptions into your authentication flow.\r\n\r\n*Fork of [@polar-sh/better-auth](https://github.com/polarsource/polar-adapters) with custom modifications*\r\n## Features\r\n\r\n- Checkout Integration\r\n- Customer Portal\r\n- Automatic Customer creation on signup\r\n- Event Ingestion & Customer Meters for flexible Usage Based Billing\r\n- Handle Polar Webhooks securely with signature verification\r\n- Reference System to associate purchases with organizations\r\n\r\n## Installation\r\n\r\n```bash\r\npnpm add better-auth @alexdelia/polar-betterauth @polar-sh/sdk\r\n```\r\n\r\n## Preparation\r\n\r\nGo to your Polar Organization Settings, and create an Organization Access Token. Add it to your environment.\r\n\r\n```bash\r\n# .env\r\nPOLAR_ACCESS_TOKEN=...\r\n```\r\n\r\n### Configuring BetterAuth Server\r\n\r\nThe Polar plugin comes with a handful additional plugins which adds functionality to your stack.\r\n\r\n- Checkout - Enables a seamless checkout integration\r\n- Portal - Makes it possible for your customers to manage their orders, subscriptions & granted benefits\r\n- Usage - Simple extension for listing customer meters & ingesting events for Usage Based Billing\r\n- Webhooks - Listen for relevant Polar webhooks\r\n\r\n```typescript\r\nimport { betterAuth } from \"better-auth\";\r\nimport { polar, checkout, portal, usage, webhooks } from \"@alexdelia/polar-betterauth\";\r\nimport { Polar } from \"@polar-sh/sdk\";\r\n\r\nconst polarClient = new Polar({\r\n    accessToken: process.env.POLAR_ACCESS_TOKEN,\r\n    // Use 'sandbox' if you're using the Polar Sandbox environment\r\n    // Remember that access tokens, products, etc. are completely separated between environments.\r\n    // Access tokens obtained in Production are for instance not usable in the Sandbox environment.\r\n    server: 'sandbox'\r\n});\r\n\r\nconst auth = betterAuth({\r\n    // ... Better Auth config\r\n    plugins: [\r\n        polar({\r\n            client: polarClient,\r\n            createCustomerOnSignUp: true,\r\n            use: [\r\n                checkout({\r\n                    products: [\r\n                        {\r\n                            productId: \"123-456-789\", // ID of Product from Polar Dashboard\r\n                            slug: \"pro\" // Custom slug for easy reference in Checkout URL, e.g. /checkout/pro\r\n                        }\r\n                    ],\r\n                    successUrl: \"/success?checkout_id={CHECKOUT_ID}\",\r\n                    authenticatedUsersOnly: true\r\n                }),\r\n                portal(),\r\n                usage(),\r\n                webhooks({\r\n                    secret: process.env.POLAR_WEBHOOK_SECRET,\r\n                    onCustomerStateChanged: (payload) => // Triggered when anything regarding a customer changes\r\n                    onOrderPaid: (payload) => // Triggered when an order was paid (purchase, subscription renewal, etc.)\r\n                    ...  // Over 25 granular webhook handlers\r\n                    onPayload: (payload) => // Catch-all for all events\r\n                })\r\n            ],\r\n        })\r\n    ]\r\n});\r\n```\r\n\r\n### Configuring BetterAuth Client\r\n\r\nYou will be using the BetterAuth Client to interact with the Polar functionalities.\r\n\r\n```typescript\r\nimport { createAuthClient } from \"better-auth/react\";\r\nimport { polarClient } from \"@alexdelia/polar-betterauth\";\r\nimport { organizationClient } from \"better-auth/client/plugins\";\r\n\r\n// This is all that is needed\r\n// All Polar plugins, etc. should be attached to the server-side BetterAuth config\r\nexport const authClient = createAuthClient({\r\n  plugins: [polarClient()],\r\n});\r\n```\r\n\r\n## Configuration Options\r\n\r\n```typescript\r\nimport { betterAuth } from \"better-auth\";\r\nimport {\r\n  polar,\r\n  checkout,\r\n  portal,\r\n  usage,\r\n  webhooks,\r\n} from \"@alexdelia/polar-betterauth\";\r\nimport { Polar } from \"@polar-sh/sdk\";\r\n\r\nconst polarClient = new Polar({\r\n  accessToken: process.env.POLAR_ACCESS_TOKEN,\r\n  // Use 'sandbox' if you're using the Polar Sandbox environment\r\n  // Remember that access tokens, products, etc. are completely separated between environments.\r\n  // Access tokens obtained in Production are for instance not usable in the Sandbox environment.\r\n  server: \"sandbox\",\r\n});\r\n\r\nconst auth = betterAuth({\r\n  // ... Better Auth config\r\n  plugins: [\r\n    polar({\r\n      client: polarClient,\r\n      createCustomerOnSignUp: true,\r\n      getCustomerCreateParams: ({ user }, request) => ({\r\n        metadata: {\r\n          myCustomProperty: 123,\r\n        },\r\n      }),\r\n      use: [\r\n        // This is where you add Polar plugins\r\n      ],\r\n    }),\r\n  ],\r\n});\r\n```\r\n\r\n### Required Options\r\n\r\n- `client`: Polar SDK client instance\r\n\r\n### Optional Options\r\n\r\n- `createCustomerOnSignUp`: Automatically create a Polar customer when a user signs up\r\n- `getCustomerCreateParams`: Custom function to provide additional customer creation metadata\r\n\r\n### Customers\r\n\r\nWhen `createCustomerOnSignUp` is enabled, a new Polar Customer is automatically created when a new User is added in the Better-Auth Database.\r\n\r\nAll new customers are created with an associated `externalId`, which is the ID of your User in the Database. This allows us to skip any Polar <-> User mapping in your Database.\r\n\r\n## Checkout Plugin\r\n\r\nTo support checkouts in your app, simply pass the Checkout plugin to the use-property.\r\n\r\n```typescript\r\nimport { polar, checkout } from \"@alexdelia/polar-betterauth\";\r\n\r\nconst auth = betterAuth({\r\n    // ... Better Auth config\r\n    plugins: [\r\n        polar({\r\n            ...\r\n            use: [\r\n                checkout({\r\n                    // Optional field - will make it possible to pass a slug to checkout instead of Product ID\r\n                    products: [ { productId: \"123-456-789\", slug: \"pro\" } ],\r\n                    // Relative URL to return to when checkout is successfully completed\r\n                    successUrl: \"/success?checkout_id={CHECKOUT_ID}\",\r\n                    // Wheather you want to allow unauthenticated checkout sessions or not\r\n                    authenticatedUsersOnly: true,\r\n                    // Enforces the theme - System-preferred theme will be set if left omitted\r\n                    theme: \"dark\"\r\n                })\r\n            ],\r\n        })\r\n    ]\r\n});\r\n```\r\n\r\nWhen checkouts are enabled, you're able to initialize Checkout Sessions using the checkout-method on the BetterAuth Client. This will redirect the user to the Product Checkout.\r\n\r\n```typescript\r\nawait authClient.checkout({\r\n  // Any Polar Product ID can be passed here\r\n  products: [\"e651f46d-ac20-4f26-b769-ad088b123df2\"],\r\n  // Or, if you setup \"products\" in the Checkout Config, you can pass the slug\r\n  slug: \"pro\",\r\n});\r\n```\r\n\r\nCheckouts will automatically carry the authenticated User as the customer to the checkout. Email-address will be \"locked-in\".\r\n\r\nIf `authenticatedUsersOnly` is `false` - then it will be possible to trigger checkout sessions without any associated customer.\r\n\r\n### Organization Support\r\n\r\nThis plugin supports the Organization plugin. If you pass the organization ID to the Checkout referenceId, you will be able to keep track of purchases made from organization members.\r\n\r\n```typescript\r\nconst organizationId = (await authClient.organization.list())?.data?.[0]?.id,\r\n\r\nawait authClient.checkout({\r\n    // Any Polar Product ID can be passed here\r\n    products: [\"e651f46d-ac20-4f26-b769-ad088b123df2\"],\r\n    // Or, if you setup \"products\" in the Checkout Config, you can pass the slug\r\n    slug: 'pro',\r\n    // Reference ID will be saved as `referenceId` in the metadata of the checkout, order & subscription object\r\n    referenceId: organizationId\r\n});\r\n```\r\n\r\n## Portal Plugin\r\n\r\nA plugin which enables customer management of their purchases, orders and subscriptions.\r\n\r\n```typescript\r\nimport { polar, checkout, portal } from \"@alexdelia/polar-betterauth\";\r\n\r\nconst auth = betterAuth({\r\n    // ... Better Auth config\r\n    plugins: [\r\n        polar({\r\n            ...\r\n            use: [\r\n                checkout(...),\r\n                portal()\r\n            ],\r\n        })\r\n    ]\r\n});\r\n```\r\n\r\nThe portal-plugin gives the BetterAuth Client a set of customer management methods, scoped under `authClient.customer`.\r\n\r\n### Customer Portal Management\r\n\r\nThe following method will redirect the user to the Polar Customer Portal, where they can see orders, purchases, subscriptions, benefits, etc.\r\n\r\n```typescript\r\nawait authClient.customer.portal();\r\n```\r\n\r\n### Customer State\r\n\r\nThe portal plugin also adds a convenient state-method for retrieving the general Customer State.\r\n\r\n```typescript\r\nconst { data: customerState } = await authClient.customer.state();\r\n```\r\n\r\nThe customer state object contains:\r\n\r\n- All the data about the customer.\r\n- The list of their active subscriptions\r\n  - Note: This does not include subscriptions done by a parent organization. See the subscription list-method below for more information.\r\n- The list of their granted benefits.\r\n- The list of their active meters, with their current balance.\r\n\r\nThus, with that single object, you have all the required information to check if you should provision access to your service or not.\r\n\r\n[You can learn more about the Polar Customer State in the Polar Docs](https://docs.polar.sh/integrate/customer-state).\r\n\r\n### Benefits, Orders & Subscriptions\r\n\r\nThe portal plugin adds 3 convenient methods for listing benefits, orders & subscriptions relevant to the authenticated user/customer.\r\n\r\n[All of these methods use the Polar CustomerPortal APIs](https://docs.polar.sh/api-reference/customer-portal)\r\n\r\n#### Benefits\r\n\r\nThis method only lists granted benefits for the authenticated user/customer.\r\n\r\n```typescript\r\nconst { data: benefits } = await authClient.customer.benefits.list({\r\n  query: {\r\n    page: 1,\r\n    limit: 10,\r\n  },\r\n});\r\n```\r\n\r\n#### Orders\r\n\r\nThis method lists orders like purchases and subscription renewals for the authenticated user/customer.\r\n\r\n```typescript\r\nconst { data: orders } = await authClient.customer.orders.list({\r\n  query: {\r\n    page: 1,\r\n    limit: 10,\r\n    productBillingType: \"one_time\", // or 'recurring'\r\n  },\r\n});\r\n```\r\n\r\n#### Subscriptions\r\n\r\nThis method lists the subscriptions associated with authenticated user/customer.\r\n\r\n```typescript\r\nconst { data: subscriptions } = await authClient.customer.subscriptions.list({\r\n  query: {\r\n    page: 1,\r\n    limit: 10,\r\n    active: true,\r\n  },\r\n});\r\n```\r\n\r\n**Important** - Organization Support\r\n\r\nThis will **not** return subscriptions made by a parent organization to the authenticated user.\r\n\r\nHowever, you can pass a `referenceId` to this method. This will return all subscriptions associated with that referenceId instead of subscriptions associated with the user.\r\n\r\nSo in order to figure out if a user should have access, pass the user's organization ID to see if there is an active subscription for that organization.\r\n\r\n```typescript\r\nconst organizationId = (await authClient.organization.list())?.data?.[0]?.id,\r\n\r\nconst { data: subscriptions } = await authClient.customer.subscriptions.list({\r\n    query: {\r\n\t    page: 1,\r\n\t\tlimit: 10,\r\n\t\tactive: true,\r\n        referenceId: organizationId\r\n    },\r\n});\r\n\r\nconst userShouldHaveAccess = subscriptions.some(\r\n    sub => // Your logic to check subscription product or whatever.\r\n)\r\n```\r\n\r\n## Usage Plugin\r\n\r\nA simple plugin for Usage Based Billing.\r\n\r\n```typescript\r\nimport { polar, checkout, portal, usage } from \"@alexdelia/polar-betterauth\";\r\n\r\nconst auth = betterAuth({\r\n    // ... Better Auth config\r\n    plugins: [\r\n        polar({\r\n            ...\r\n            use: [\r\n                checkout(...),\r\n                portal(),\r\n                usage()\r\n            ],\r\n        })\r\n    ]\r\n});\r\n```\r\n\r\n### Event Ingestion\r\n\r\nPolar's Usage Based Billing builds entirely on event ingestion. Ingest events from your application, create Meters to represent that usage, and add metered prices to Products to charge for it.\r\n\r\n[Learn more about Usage Based Billing in the Polar Docs.](https://docs.polar.sh/features/usage-based-billing/introduction)\r\n\r\n```typescript\r\nconst { data: ingested } = await authClient.usage.ingest({\r\n  event: \"file-uploads\",\r\n  metadata: {\r\n    uploadedFiles: 12,\r\n  },\r\n});\r\n```\r\n\r\nThe authenticated user is automatically associated with the ingested event.\r\n\r\n### Customer Meters\r\n\r\nA simple method for listing the authenticated user's Usage Meters, or as we call them, Customer Meters.\r\n\r\nCustomer Meter's contains all information about their consumtion on your defined meters.\r\n\r\n- Customer Information\r\n- Meter Information\r\n- Customer Meter Information\r\n  - Consumed Units\r\n  - Credited Units\r\n  - Balance\r\n\r\n```typescript\r\nconst { data: customerMeters } = await authClient.usage.meters.list({\r\n  query: {\r\n    page: 1,\r\n    limit: 10,\r\n  },\r\n});\r\n```\r\n\r\n## Webhooks Plugin\r\n\r\nThe Webhooks plugin can be used to capture incoming events from your Polar organization.\r\n\r\n```typescript\r\nimport { polar, webhooks } from \"@alexdelia/polar-betterauth\";\r\n\r\nconst auth = betterAuth({\r\n    // ... Better Auth config\r\n    plugins: [\r\n        polar({\r\n            ...\r\n            use: [\r\n                webhooks({\r\n                    secret: process.env.POLAR_WEBHOOK_SECRET,\r\n                    onCustomerStateChanged: (payload) => // Triggered when anything regarding a customer changes\r\n                    onOrderPaid: (payload) => // Triggered when an order was paid (purchase, subscription renewal, etc.)\r\n                    ...  // Over 25 granular webhook handlers\r\n                    onPayload: (payload) => // Catch-all for all events\r\n                })\r\n            ],\r\n        })\r\n    ]\r\n});\r\n```\r\n\r\nConfigure a Webhook endpoint in your Polar Organization Settings page. Webhook endpoint is configured at /polar/webhooks.\r\n\r\nAdd the secret to your environment.\r\n\r\n```bash\r\n# .env\r\nPOLAR_WEBHOOK_SECRET=...\r\n```\r\n\r\nThe plugin supports handlers for all Polar webhook events:\r\n\r\n- `onPayload` - Catch-all handler for any incoming Webhook event\r\n- `onCheckoutCreated` - Triggered when a checkout is created\r\n- `onCheckoutUpdated` - Triggered when a checkout is updated\r\n- `onOrderCreated` - Triggered when an order is created\r\n- `onOrderPaid` - Triggered when an order is paid\r\n- `onOrderRefunded` - Triggered when an order is refunded\r\n- `onRefundCreated` - Triggered when a refund is created\r\n- `onRefundUpdated` - Triggered when a refund is updated\r\n- `onSubscriptionCreated` - Triggered when a subscription is created\r\n- `onSubscriptionUpdated` - Triggered when a subscription is updated\r\n- `onSubscriptionActive` - Triggered when a subscription becomes active\r\n- `onSubscriptionCanceled` - Triggered when a subscription is canceled\r\n- `onSubscriptionRevoked` - Triggered when a subscription is revoked\r\n- `onSubscriptionUncanceled` - Triggered when a subscription cancellation is reversed\r\n- `onProductCreated` - Triggered when a product is created\r\n- `onProductUpdated` - Triggered when a product is updated\r\n- `onOrganizationUpdated` - Triggered when an organization is updated\r\n- `onBenefitCreated` - Triggered when a benefit is created\r\n- `onBenefitUpdated` - Triggered when a benefit is updated\r\n- `onBenefitGrantCreated` - Triggered when a benefit grant is created\r\n- `onBenefitGrantUpdated` - Triggered when a benefit grant is updated\r\n- `onBenefitGrantRevoked` - Triggered when a benefit grant is revoked\r\n- `onCustomerCreated` - Triggered when a customer is created\r\n- `onCustomerUpdated` - Triggered when a customer is updated\r\n- `onCustomerDeleted` - Triggered when a customer is deleted\r\n- `onCustomerStateChanged` - Triggered when a customer is created\r\n","readmeFilename":"README.md"}