-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Polar integration #461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Polar integration #461
Conversation
- improve encapsulation and separation of concerns - simplify stats calculation
- add JSDoc comments for PaymentProcessor methods - improve JSDoc comments for exported object
- Enable processor selection by environment variable or specified override for testing scenarios - Refactor env var validation
- Add type-safety to webhook handler - Apply current Wasp env var validation
|
@vincanger Still a WIP, but as I've gotten to the point where I can create orders and subscriptions, I thought I should share the changes I've made that affect other parts of the codebase for discussion. Configurable provider selectionThe current codebase requires the developer implementing the template to modify the codebase to select which payment provider to implement. I understand the reasoning behind this decision, but it also makes it impossible to implement e2e tests for multiple providers without modifying the codebase. To address this, I implemented a new Updated schema validationOpenSaas currently uses a custom validation function to ensure the required env vars are set, but with the introduction of Zod validation, this seems redundant and so I implemented Zod-based validation for this provider, which could also be applied to the existing platforms, if desired. Refactored stats jobThe stats job previously contained functions for both Stripe and LemonSqueezy, which felt like a bit of code smell as it violates the open/closed principle, so I refactored that code to make the revenue calculation a function of the PaymentProcessor interface to be implemented by each integration. |
vincanger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a quick review. I see out moduleResolution is causing import issues for the polar SDK. Hopefully we can get that sorted out quick. Everything looks to be on the right track though! The main thing I'd like to change at the moment is to remove comments that are redundant as many of them just repeat what's discernible from the function name.
- Fix order status checking - Remove redundant subscription status mapping type and custom status values - Remove redundant JSDoc comments
FranjoMindek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Genyus,
went over the PR.
Great work on this.
I'm sorry that we are asking you to remove so much from PR, but we want to focus on getting only Polar working here first.
Also I would appreciate it if you could reduce the amount of unnecessary jsdocs/comments. Didn't want to point it out everywhere since there is a lot. Do take care to use it only when we need it.
For now I've only went through the code, didn't run anything yet.
After you implement changes I would like to actually test everything out with Polar sandbox account. I would recommend you do the same.
- Remove payment processors and types - Restore hard-coded payment processor references - Remove validation schemas
- Remove unnecessary try/catch blocks - Remove excessive JSDoc comments
- Remove env var and rely solely on polar.customerSessions.create call
- Refactor sandbox mode selection logic
Co-authored-by: Mihovil Ilakovac <mihovil@ilakovac.com>
Co-authored-by: Mihovil Ilakovac <mihovil@ilakovac.com>
Co-authored-by: Mihovil Ilakovac <mihovil@ilakovac.com>
infomiho
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments
| @@ -0,0 +1,95 @@ | |||
| --- | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should name the folder payment-integrations, spaces in folder names make it annoying to cd into and it's not really common to have folders with spaces 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the initial name, but since we have autogenerate turned on, it created payment-integrations title for the page. I need to change everything to manual mode, but I also think it's worth it. You are right.
| :::note[Which should I choose?] | ||
| Stripe is the industry standard, is more configurable, and has cheaper fees. | ||
| Lemon Squeezy acts a [Merchant of Record](https://www.lemonsqueezy.com/reporting/merchant-of-record). This means they take care of paying taxes in multiple countries for you, but charge higher fees per transaction. | ||
| Polar is an open-source [Merchant of Record](https://docs.polar.sh/merchant-of-record/introduction#merchant-of-record) designed specifically for developers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| export const paymentProcessor: PaymentProcessor = stripePaymentProcessor; | ||
| // export const paymentProcessor: PaymentProcessor = lemonSqueezyPaymentProcessor; | ||
| // export const paymentProcessor: PaymentProcessor = polarPaymentProcessor; | ||
| export const paymentProcessor: PaymentProcessor = lemonSqueezyPaymentProcessor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two of them are uncommented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| First, go to `/src/payment/paymentProcessor.ts` and choose which payment processor you'd like to use: | ||
|
|
||
| <Tabs syncKey="payment-provider"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd get rid of these tabs, they seem annoying to maintain in the docs for what should be one sentence: "uncomment one of the paymentProcessor variables to pick which payment processor you want to use"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is that Open SaaS docs are really in detail.
And I want to keep that spirit.
But just adding more options make it unreadable.
e.g. I don't want to continue this chain:

The nice thing about these tabs is that they are connected.
e.g. When you select Polar on one of them, all of tabs change to use Polar.
They are a bit verbose to to maintain but still better than just listing everything.
And I don't want to simplify the instructions here.
| - `order.paid` | ||
| - `subscription.updated` | ||
| 6. Click `Save`. | ||
| 7. Copy the generated webhook secret and add it to your `.env.server` file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 7. Copy the generated webhook secret and add it to your `.env.server` file: | |
| 7. Copy the generated webhook secret and set the `POLAR_WEBHOOK_SECRET` env variable value: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as here, this would be fine without the code block. #461 (comment)
| Before testing payments, make sure that you: | ||
| - Created and set your `POLAR_ORGANIZATION_ACCESS_TOKEN` in `.env.server`. | ||
| - Created your products and set their `<NAME>_PLAN_ID` in `.env.server`. | ||
| - Created your webhook and set `POLAR_WEBHOOK_SECRET` in `.env.server`. | ||
| - Your `ngrok` tunnel is running. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Before testing payments, make sure that you: | |
| - Created and set your `POLAR_ORGANIZATION_ACCESS_TOKEN` in `.env.server`. | |
| - Created your products and set their `<NAME>_PLAN_ID` in `.env.server`. | |
| - Created your webhook and set `POLAR_WEBHOOK_SECRET` in `.env.server`. | |
| - Your `ngrok` tunnel is running. | |
| Before testing payments, make sure that you set all the required env variables in `.env.server` (`POLAR_ORGANIZATION_ACCESS_TOKEN`, `<NAME>_PLAN_ID` and `POLAR_WEBHOOK_SECRET` ) and that your `ngrok` tunnel is running. |
Maybe you can simplify it like this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like my example more when rendered, it's easier to keep track of the requirements when it's laid out nicely. Though I can change it if you want me to.
opensaas-sh/blog/src/content/docs/guides/Payment Integrations/polar.mdx
Outdated
Show resolved
Hide resolved
opensaas-sh/blog/src/content/docs/guides/Payment Integrations/polar.mdx
Outdated
Show resolved
Hide resolved
opensaas-sh/blog/src/content/docs/guides/Payment Integrations/stripe.mdx
Outdated
Show resolved
Hide resolved
# Conflicts: # opensaas-sh/app_diff/src/payment/user.ts.diff # template/app/src/payment/plans.ts # template/app/src/payment/user.ts
…polar.mdx Co-authored-by: Mihovil Ilakovac <mihovil@ilakovac.com>
…polar.mdx Co-authored-by: Mihovil Ilakovac <mihovil@ilakovac.com>
Co-authored-by: Mihovil Ilakovac <mihovil@ilakovac.com>
…index.mdx Co-authored-by: Mihovil Ilakovac <mihovil@ilakovac.com>
…index.mdx Co-authored-by: Mihovil Ilakovac <mihovil@ilakovac.com>
…lemon-squeezy.mdx Co-authored-by: Mihovil Ilakovac <mihovil@ilakovac.com>



Description
Adds support for Polar payments platform. Closes #441
Related to wasp-lang/wasp#3034 as we need to remove
Stitchesinternally in order to be able to use the correctmoduleResolutionthat Polar's SDK depends on in our tsconfig.Contributor Checklist