Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3854102
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:34:19+00:00 2026-05-19T17:34:19+00:00

What is the best way, using PHP, to design a modular system that can

  • 0

What is the best way, using PHP, to design a modular system that can be added to as easily as possible? For example, if you had a shopping cart, you might have a payment base class that has all your required methods. Then you can have a Paypal class that extends that class, and a Visa/Mastercard that also extends the base class, but how do you actually put them in use?

If you did a functional version of the cart, you could make a function called doExecute and pass in the required information. Then you name all the files as Payment_Method.php. The file names are then read, creating a list of acceptable payment methods. Once one is picked, that file is the only one included in the script, and then the doExecute method is called guaranteeing that the method in the payment method include file is the one called.

However, for an object oriented approach, that really does work that well. How do you add in the additional methods without having to keep modifying the code to include objects of the new classes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:34:20+00:00Added an answer on May 19, 2026 at 5:34 pm

    The way I’ve implemented payment systems like this is to have the base class, as you mentioned, but have the base class instantiate the required payment vendor, which extends the base class. Then the base class is in control of what file gets loaded, centralizing control, logging, etc.

    public function loadVendor($vendorName) {
         static $validVendors = array('credit_card','paypal');
         if ( !in_array($vendorName, $validVendors ) {
             return false;
         }
         include('/path/to//vendors/'.$vendorName.'.php');
         $processor = new $vendorName();
         //additional default setup
         return $processor
    }
    

    Since all vendors have different data submission structures. Your base class should have a function to “load” the data. This put it in your standard format. Each payment class would then have a “map” function to map your structure to their structure. For example, splitting up dates into separate year, month, day fields.

    You then have a “submit” function to submit the data to the processing vendor. Then a “parse response” function to parse the response and put it in a standardize response data structure you come up with.

    For simplicity, you can have a single method that calls all three of the functions (map->submit->map. But for testing, it easier to have them separate.
    $processor->mapData();
    $processor->submit();
    $response = $processor->parseResponse();

    Of course, this doesn’t really work with Paypal. Paypal is asynchronous, you send the user to their site. Paypal then sends them back to your site when they have done processing. Google checkout is the same way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the best way to print from MySQL using PHP when you know there's
let say I have a post that can be found on page post.php?pid=60 but
Ok... so here's my actual status: Been a PHP Scripter for way too long,
What's the best way to target a particular <div> with a selection from a
I am looking for the best way to set a list item's currentmenu class,
I have a PHP script that I keep updated and need to run on
Alright, so after years of feeling that I've been doing it the wrong way,
I am new to programming, and have developed the main design features of my
I'm looking for advice/experience on using public variables vs private variables with accessor methods
I am writing a site that basically looks for places within a 25 mile

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.