-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
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
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
opensaas-sh/blog/src/content/docs/guides/payment-integrations/index.mdx
Outdated
Show resolved
Hide resolved
opensaas-sh/blog/src/content/docs/guides/payment-integrations/index.mdx
Outdated
Show resolved
Hide resolved
opensaas-sh/blog/src/content/docs/guides/payment-integrations/index.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/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>
|
|
||
| ## Deploying your App | ||
|
|
||
| ### Deploying to Fly.io |
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.
We are missing the Deploying to Railway section or we could rework this to be a Deploying with wasp deploy or similar so it cover some agnostic advice and then link to both providers in the Wasp docs for details.
We don't have to do it in this PR, but I'd create an issue and tackle it sooner than later.
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 have a task to take care of this this sprint.
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.
Polar Docs look great. Just made a few small suggestions. Nice work :)
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
| ### Sandbox and Production Mode | ||
|
|
||
| Polar features two separate environemnts: [sandbox](https://sandbox.polar.sh/dashboard) and [production](https://polar.sh/dashboard). | ||
| They are fully isolated from each other, which means that you need to create seperate organizations for each of them. They also feature indepdendant products, sales, access tokens, etc. |
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.
you need to create seperate organizations for each of them
really? I know Stripe allows you to work in sandbox mode and then copy all those settings to production. That's not possible with Polar?
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.
Nope. Sadly.
opensaas-sh/blog/src/content/docs/guides/payment-integrations/polar.mdx
Outdated
Show resolved
Hide resolved
|
|
||
| ### Create and Use the Polar Webhook in Local Development | ||
|
|
||
| Polar notifies your Wasp app about events through a webhook (for example, when a payment succeeds). During development, you need to expose your locally running Wasp server (started with `wasp start`) to the internet. Wasp server runs on port 3001 by default, so you can, for example, run `ngrok` on port 3001 to expose your server to the internet. `ngrok` will generate a public URL that you can give to Polar. |
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.
| Polar notifies your Wasp app about events through a webhook (for example, when a payment succeeds). During development, you need to expose your locally running Wasp server (started with `wasp start`) to the internet. Wasp server runs on port 3001 by default, so you can, for example, run `ngrok` on port 3001 to expose your server to the internet. `ngrok` will generate a public URL that you can give to Polar. | |
| Polar notifies your Wasp app about customer and payment events through a webhook. During development, your locally running Wasp server (started with `wasp start`) where the webhook endpoint is located is not yet available to Polar via the internet (it's running on port 3001 by default). We can make it available to Polar by installing and running `ngrok` on port 3001, which will generate a public URL for it. |
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.
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/polar.mdx
Outdated
Show resolved
Hide resolved
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.
I'm good 👍 good job

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