-3

I'm in the process of building a web app where users can buy subscriptions for an online magazine.

The back-end is powered by PHP (Laravel) and the front-end is very light, just HTML/CSS and a little bit of vanilla JavaScript.

I'm curious to know what is the best approach to chain a bunch of actions that need to happen in a row.

For example: the user should be able to select the desired subscription period (1 day, 1 week, 1 month), pay for the subscription using an online payment processor and then have an active subscription in the app and receive an email with an access code.

What I have so far is this:

  • User navigates to the subscriptions page and selects the desired period.
  • Then gets redirected to the checkout page where he enters contact and billing details.
  • If the entered data is valid an order is created in the app and the user gets redirected to the payment page where he can enter credit card details.
  • The payment processor makes a request back to the app to inform about the payment status.

So far so good, but here's is where I need some advice. Basically, if the payment is successful I need to update the status of the order, create a new subscription, generate a new access code and send it to the user via email.

Should I create a new Laravel job to handle all this? Should I create separate jobs for each task and then call one job after another? Should I keep it simple and perform all tasks in the controller method that handles the IPN?

Thanks.

Cosmin
  • 864
  • 3
  • 16
  • 34
  • 2
    This question is unfortunately too vague and unfocused. We're glad to help you sort out specific issues you might run into with your existing implementation attempt, which means that you need to do the [appropriate amount of research](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) and make some proper attempts yourself first. – hakre Jul 18 '21 at 15:51

1 Answers1

1

It's ideal situation for Event/Listener pattern.

Just fire Event SubscriptionConfirmed in callback - and write listeners for every your need.

Maksim
  • 2,653
  • 2
  • 13
  • 28