Skip to Content

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

  1. In the src/server/serverConsts.ts, set the paymentProcessor to "polar".
  2. Create your Polar account by accessing https://polar.sh.
  3. Setup Ngrok by following our guide.

Development

  1. In the Dashboard, click on the bottom left button to expand the menu and press Go to Sandbox and follow the provided steps.
  2. Go to Settings, scroll to Developers and press New Token. Enter any name, No expiration, and select: checkouts:write, customers:write, customer_sessions:write.
  3. Press Create.
  4. Copy the token and run bunx vercel env add POLAR_ACCESS_TOKEN, enter the token and select Preview and Development.
  5. Access Settings -> Webhooks on the left menu and click on Add Endpoint.
  6. Paste your Ngrok static URL (without the :3000) with https:// at the beginning and add /api/webhook/polar at the end. For the Format, select Raw.
  7. Press Generate and copy the secret and run bunx vercel env add POLAR_WEBHOOK_SECRET, enter the secret and select Preview and Development.
  8. Select the events: benefit_grant.created, benefit_grant.revoked.
  9. Press Create.
  10. Run bun env to update the new local env file.

Production

  1. 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.
  2. Repeat the steps 2~9 from the section above. For the bunx vercel env add commands, select the Production environment. In the 6th step, use your production URL instead of the Ngrok URL.

Creating Products

  1. In the Dashboard, access the Products page and click on New Product. Fill as you wish.
  2. On the Automated Benefits section, click to add a Custom benefit. The description can be anything. Press Create.
    • 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.
  3. Press Create.
  4. Access the Products page again and on the three dots of the product you just created, press Copy Price ID. Paste in the src/lib/productsAndPlans.ts as the priceId for the corresponding product and price.
    • The priceId is different for Sandbox and for Production. Use the pattern isDevelopment ? "price_<testPriceId>" : "price_<livePriceId>".
  5. Go to the Benefits page, select the one you just created and click on Copy ID. Paste it in the src/lib/productsAndPlans.ts as the polarBenefitId 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.

Last updated on