This topic is locked
[SOLVED]

SaaS, Create Stripe Webhook to create Database Structure and Dynamic Security

11/8/2024 5:23:45 PM
PHPRunner General questions
lefty author

I am implementing , a subscription based service for companys and users of that company. I am using Stripe API for after purchase to create a new database with just the structure and one what i will call Sub-Admin and myself ADMIN.
Before I go about coding , I have the original databasse and just want to clone it. My question is if I clone Dynamic Security Tables , will I run into an issue?

Do I need to take a different approach or can this be done as I need the same Groups that dynamic security uses that are virtually the same for each company and
need this to be dynamic , so users can be changed in thier respective database from group to group when neccessary.

I have read the older blog , but I see nothing about Dynamic Security built into a multi-tenanat 1 Project only / Database (each company) information?

I already know about the coding part as it is pretty extensive in regards, to Stripes webhook.

I have asked this question in the past , but I did not really get a positive response?

lefty author 11/8/2024

So I guess I forgot the other Main question, since we setup a database connection in our main project. How do I overcome this problem with the second, third and so on database connection since it's new and the project obiously has the first connection. particulary dynamically.

Sergey Kornilov admin 11/9/2024

You simply need to use Dynamic Permissions based on tables located in the client's database. When you clone the database, permissions tables and permissions themselves will be cloned and your new client will be ready to go.

lefty author 11/13/2024

So that is simple enough. But to ensure on each call in the project , I will need to initialize this before each query.
I remeber in other versions we had a common.php file . I want to put this in version 11 . where would I put this code in the new version so I don't have to use it on every page and/or event.
Or can I put this code in After Application Initialized for global use? So I don't have to call everytime.

function initializeCompanyDatabase() {
if (!isset($_SESSION['comid'])) {
redirect('login.php'); // Redirect to login if no company ID set
}

$dbname = 'database' . $_SESSION['comid']; // Construct the database name
DB::SetConnection($dbname); // Set the PHPrunner connection to the specific company database

}

// Call this function at the start of each page/request
initializeCompanyDatabase();

Sergey Kornilov admin 11/14/2024

You need to read SaaS application design article one more time:
https://xlinesoft.com/blog/2019/10/03/saas-application-design/

lefty author 11/14/2024

Okay , Thanks for the reply

Had to edit this. I still don't get what the blog image ( see image 1 at top it has 5 databases listed ) What is in those databases, or are they just connections. The image is confusing me.
Then below you have written :

"You can see that we have a common saasdb database here and multiple identical client databases. We only need to add to the project one of those client databases, database1 one in our example."

What are the other ones ( like are they empty clones - confusing ) ? Meaning do I have to add all the databases I plan to use in the future to the project as they will be created on the fly with a webhook after purchase?
or that image was just an example and I only need two database connection , 1 for users table and security and the other for the rest of the project and if so how is dynamic security going to work as they are different databases 1 for users table and one for the rest of the project as your example explains? When I go into admin area online , it will then just show the users table and the security table. How is it possible , it
wil show the all the tables from the other database?

What am I missing here?

lefty author 11/14/2024

I finally wrapped my head around it I believe. I clone the security settings for the Project database which you mentioned earlier.
I will have to test this method, as I still don't see how advanced security will work with the users table in another database , unless
in the project I can select the users table from the other database. I am good for now.

Thanks again for the replies.

Edited: Yes you can , This is solved .