In practice, the role-based access control system is often combined with a payment system, so that when the user pays for a subscription, their role will be automatically changed from free user
to paid user
, which allows then access to the premium content or services.
Here is how this system would work:
First of all, there should be a pricing page where users can select their desired payment plan, such as monthly subscription, annual subscription, onetime payment with lifetime access, and more.
When the user clicks on the Get This Plan button, they should be taken to the checkout page, where they can put in their credit card or other payment information. This page is usually hosted by a third-party payment platform, as we are going to discuss later.
The payment platform processes the payment, and sends an HTTP request back to your SaaS app. The request will be accepted and processed by an API endpoint, which will update the user information in the database accordingly, such as changing the user role from free user
to paid user
.
In this lesson, we are going to discuss how to create such a system using Stripe, the most popular online payment platform in the world.
Setting up Stripe
Go to stripe.com and create a new account. You will be asked to provide the name for your business and the country of operation. The name will be displayed to the user in the checkout page, as well as the invoice, and the country of operation may have tax implications.
You should be careful here, you can change the name in the future, but not the country of operation.