Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lat4732's avatar
Level 12

Need help for rebuilding my code

Hello everyone! I need some help about my project. So after register users must set up their account before continue to the website. I successfully build the logic that prevent users to access the website without finishing their set up but I need to rebuild it now. So the steps of set up are the following (3 steps):

Step 1 - Collecting billing information for the user. After successfully stored the billing information in the database table he gets a column added_billing_details value 1 in the users_set_ups table so based on that value (0 or 1) the middleware is redirecting him to:

Step 2 - Choosing the plan and payment method. After choosing their plan and payment method based on that what payment method they choose there is different information appending on step 3 (if it is a credit card payment method - displays credit card form which is not currently integrated - and if it is a bank transfer payment method - displays proforma invoice etc...). So when the user continues to the last step (3) the system is updating the users_set_ups table with a values of {PLAN_ID}, {PAYMENT_METHOD}, {CURRENT_DATE} to the particular columns - selected_plan, selected_payment_method, selected_payment_date where selected_plan and selected_payment_method are in relationship with other tables which contains information about the plans and payment methods.

Step 3 - Actually this step is unnecessary for explaining as it's not participating in the problem I have.

So after explaining to you how my setup process works I'll start talking about that how I want to rebuild it:

I want the database to be updated with all this information only if the user have chosen payment method that is not offline. The main goal is not to store unnecessary data in my database as I'm not sure that the user will finalize his set up (finalizing the set up requires payment as you already know). So my idea is to store all this information in sessions till the user has successfully paid for his plan (there is no free plan) and after successfully paying the specific amount - store the data that he inputted. And here is the problem - how can I rebuild these steps when they are database based and the middleware is checking everything so it can decide where to redirect the user.

Rebuilded steps:

Step 1 - I want to collect that billing details in sessions. So after continuing to step 2 the database is not updating anything yet.

Step 2 - After selecting plan and payment method - based on what payment method the user chose (online or offline) to continue storing. If it is an online payment method (credit/debit card) - store the data in the database. If it is an offline payment method - continue storing the data in sessions till the user pays on step 3 - then store it in the database.

At the end I need to add - If the user stops for example at step 2 and his payment is offline type in the next login he need to start from the beginning.

Any idea how can I rebuild it?

0 likes
2 replies
Jmac's avatar

It's a comprehensive question, and I think no one can give a detailed answer here on designing it.

In my humble experience (if I understand your question), save you some headaches and keep the unfinished transactions in your database. Have a timestamp and use Laravel's prune function to clean out old unfished transactions. This way is against my OCD, but it's much easier to develop and maintain.

I find sessions a bit fiddly if writing them a lot going back and forth between pages, especially if you depend on middleware (since session functions in Laravel are a middleware itself). I am sure it's doable but debugging is much easier if you keep and follow the "state" in the database.

Anyway, good luck!

lat4732's avatar
Level 12

@Jmac Thanks for your advice. I'll keep trying till I achieve my goal.

1 like

Please or to participate in this conversation.