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 thepaymentProcessorto"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 Sandboxand follow the provided steps. - Go to Settings, scroll to
Developersand 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 selectPreviewandDevelopment. - Access
Settings->Webhookson the left menu and click onAdd Endpoint. - Paste your Ngrok static URL (without the
:3000) withhttps://at the beginning and add/api/webhook/polarat the end. For theFormat, selectRaw. - Press
Generateand copy the secret and runbunx vercel env add POLAR_WEBHOOK_SECRET, enter the secret and selectPreviewandDevelopment. - Select the events:
benefit_grant.created,benefit_grant.revoked. - Press
Create. - Run
bun envto 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 sandboxin the right of the top banner. - Repeat the steps 2~9 from the section above. For the
bunx vercel env addcommands, select theProductionenvironment. In the 6th step, use your production URL instead of the Ngrok URL.
Creating Products
- In the Dashboard, access the
Productspage and click onNew Product. Fill as you wish. - On the
Automated Benefitssection, click to add aCustombenefit. 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
Productspage again and on the three dots of the product you just created, pressCopy Price ID. Paste in thesrc/lib/productsAndPlans.tsas thepriceIdfor 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
Benefitspage, select the one you just created and click onCopy ID. Paste it in thesrc/lib/productsAndPlans.tsas thepolarBenefitIdfor 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