Skip to content
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

feat: subscribe with the customer portal instead of stripe #6049

Draft
wants to merge 48 commits into
base: 4.x
Choose a base branch
from

Conversation

djaiss
Copy link
Member

@djaiss djaiss commented Mar 9, 2022

We have two huge constraints ahead of us:

  • We need to move from Stripe to Paddle for our subscriptions, for tax purposes.
  • Later this year we'll move to a new major version of Monica, and we'll keep the current version active as long as needed.

Because we'll have two versions of Monica, we should not manage two billing systems. I want the same subscription to work with Monica v1 and Monica v2.

The only solution for this is to move all billing logic to a dedicated app, that we call the customer portal. This customer portal will let customers purchase a licence key (with the same plans as we offer today), and we will use this licence key in both Monica v1 and Monica v2.

The best thing about moving all the billing logic from Monica to the customer portal is that we will finally be able

  • to simplify the codebase by getting rid of the billing code,
  • to offer Monica as a true open source product without any mention of billing anywhere.

It's a win win.

So this is how it works:

  • the licence key is generated on the customer portal.
  • the user has to copy the licence key on the Subscription page under the Settings page.
  • to store this licence key, we've added three new columns on the Account object:
    • valid_until_at: the date the licence key should be renewed
    • licence_key: the licence key itself
    • frequency: monthly or annual plan
  • The key itself is encrypted and will be decoded before being stored.
  • When we paste the licence key in Monica, we need to validate it to make sure it's valid.
  • The new ActivateLicenceKey service does this:
    • it sends a request to the customer portal
    • and waits for its response. If the response is 200, that means the key is valid.
  • At this point, the user has a valid account and can freely play with Monica.
  • Then, we've created a new job that will check all the accounts that need to be renewed once the valid_until_at field is reached. This job is called CheckLicenceKeys. It is triggered every six hours. This job checks if the key is still valid once the date is reached.

For existing customers with Stripe:

  • Currently we have many subscribers with Stripe.
  • Stripe has recently opened up their subscription portal that let the customers manage the credit card info and the subscription itself. And also let them see all the previous invoices. We will use this.
  • Those customers have a new flag in the db called is_on_stripe on the Account table.
  • When this flag is set to true, in the Settings/Subscriptions page, they have access to a new view called stripe.blade.php.
  • This displays a view that tells customers to go to the stripe customer portal.
  • This URL is defined in a new env variable called CUSTOMER_PORTAL_STRIPE_URL.

Drawbacks:

  • we have removed all the current subscription logic from the codebase. Everything.
  • we have three new env variables:
    • CUSTOMER_PORTAL_URL
    • LICENCE_KEY_ENCRYPTION_KEY
    • CUSTOMER_PORTAL_SECRET_KEY

Copy link
Member

@asbiin asbiin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, great work 👍🏽
I left some comments ...

@@ -54,6 +55,8 @@ protected function schedule(Schedule $schedule)
$this->scheduleCommand($schedule, 'cloudflare:reload', 'daily');
}
$this->scheduleCommand($schedule, 'model:prune', 'daily');

$schedule->job(new CheckLicenceKeys)->everySixHours();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to use the scheduleCommand command, see above

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if it's a not a command but a job?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On some installation, schedule can't be done exactly at xx:00 hours. Laravel doesn't really support that.

app/Services/Account/Subscription/ActivateLicenceKey.php Outdated Show resolved Hide resolved
app/Services/Account/Subscription/ActivateLicenceKey.php Outdated Show resolved Hide resolved
app/Services/Account/Subscription/ActivateLicenceKey.php Outdated Show resolved Hide resolved
resources/views/settings/subscriptions/blank.blade.php Outdated Show resolved Hide resolved
resources/views/settings/subscriptions/blank.blade.php Outdated Show resolved Hide resolved
resources/views/settings/subscriptions/blank.blade.php Outdated Show resolved Hide resolved
resources/views/settings/subscriptions/blank.blade.php Outdated Show resolved Hide resolved
resources/views/settings/subscriptions/blank.blade.php Outdated Show resolved Hide resolved
djaiss and others added 18 commits May 14, 2022 16:15
Co-authored-by: Alexis Saettler <alexis@saettler.org>
Co-authored-by: Alexis Saettler <alexis@saettler.org>
Co-authored-by: Alexis Saettler <alexis@saettler.org>
Co-authored-by: Alexis Saettler <alexis@saettler.org>
Co-authored-by: Alexis Saettler <alexis@saettler.org>
Co-authored-by: Alexis Saettler <alexis@saettler.org>
Co-authored-by: Alexis Saettler <alexis@saettler.org>
Co-authored-by: Alexis Saettler <alexis@saettler.org>
Co-authored-by: Alexis Saettler <alexis@saettler.org>
@sonarcloud
Copy link

sonarcloud bot commented Oct 2, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug B 1 Bug
Vulnerability A 0 Vulnerabilities
Security Hotspot E 1 Security Hotspot
Code Smell A 10 Code Smells

64.3% 64.3% Coverage
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants