Polar
Polar is an awesome and new way to process payments.
You probably should use it if your country is supported and if your product is within their Acceptable use policy .
Setup
- In the
src/server/serverConsts.ts
, set thepaymentProcessor
to"polar"
. - Create your Polar account by accessing https://polar.sh .
- Setup Ngrok by following our guide.
Development
- In the Dashboard , click on the bottom left button to expand the menu and press
Go to Sandbox
and follow the provided steps. - Go to Settings, scroll to
Developers
and pressNew Token
. Enter any name,No expiration
, and select:checkouts:write
,customers:write
,customer_sessions:write
. - Press
Create
. - Copy the token and run
bunx vercel env add POLAR_ACCESS_TOKEN
, enter the token and selectPreview
andDevelopment
. - Access
Settings
->Webhooks
on the left menu and click onAdd Endpoint
. - Paste your Ngrok static URL (without the
:3000
) withhttps://
at the beginning and add/api/webhook/polar
at the end. For theFormat
, selectRaw
. - Press
Generate
and copy the secret and runbunx vercel env add POLAR_WEBHOOK_SECRET
, enter the secret and selectPreview
andDevelopment
. - Select the events:
benefit_grant.created
,benefit_grant.revoked
. - Press
Create
. - Run
bun env
to update the new local env file.
Production
- In the Dashboard, be sure you are in the Production mode. If you are in the Sandbox mode, click
Exit sandbox
in the right of the top banner. - Repeat the steps 2~9 from the section above. For the
bunx vercel env add
commands, select theProduction
environment. In the 6th step, use your production URL instead of the Ngrok URL.
Creating Products
- In the Dashboard, access the
Products
page and click onNew Product
. Fill as you wish. - On the
Automated Benefits
section, click to add aCustom
benefit. The description can be anything. PressCreate
.- Each benefit should be a Plan level. If you application only has one plan, you will only need this single benefit which can be used for multiple prices/products.
- Press
Create
. - Access the
Products
page again and on the three dots of the product you just created, pressCopy Price ID
. Paste in thesrc/lib/productsAndPlans.ts
as thepriceId
for the corresponding product and price.- The priceId is different for Sandbox and for Production. Use the pattern
isDevelopment ? "price_<testPriceId>" : "price_<livePriceId>"
.
- The priceId is different for Sandbox and for Production. Use the pattern
- Go to the
Benefits
page, select the one you just created and click onCopy ID
. Paste it in thesrc/lib/productsAndPlans.ts
as thepolarBenefitId
for the corresponding product.
Testing Payments
To test a payment in the local environment, you can use the card of number 4242 4242 4242 4242
with any expiration date and any CVC.
Afilliate Program
Affiliates are a great way to have your customers to help spread your product by giving them a percentage.
They get you paying customers and for each user that uses their link or cupom code, they get some percentage of them.
Affonso.io is the official Polar’s affiliate program. You can join it by accessing this link and following their guide.
Links
- Website: https://polar.sh
- Docs: https://docs.polar.sh
- Discord: https://discord.gg/Pnhfz3UThd
- GitHub: https://github.com/polarsource
Last updated on