Skip to content
FREE & OPEN SOURCE Million Dollar Script is a free WordPress plugin for sponsor walls, campaign grids, fundraiser boards, and premium add-on workflows.

General

How to make custom Payment module?

Started June 25, 2010 by Avram

Hello,I was wondering if there is a tutorial/document on how to make custom Payment module? I have SMS payment provider which offers something like PayPal's IPN and I am sure I have enough PHP knowledge to make custom payment module, I just need some directions.Also, as my provider offers only fixed payments, would it be possible for users to accumulate their payments and purchase large areas of pixels with multiple payments?

5 replies

Hi there,[b]Avram wrote:[/b][quote]Hello,I was wondering if there is a tutorial/document on how to make custom Payment module? I have SMS payment provider which offers something like PayPal's IPN and I am sure I have enough PHP knowledge to make custom payment module, I just need some directions.[/quote]I know I still haven't migrated all of the old support articles over but I doubt there is anything telling how to make a custom payment module. I could be wrong so I will double check and get some more of them old articles moved over. I think the best bet would be to check out the existing payment modules and see how they are set up and go from there. It shouldn't be too hard if you look at the other ones and use your payment providers API.[quote]Also, as my provider offers only fixed payments, would it be possible for users to accumulate their payments and purchase large areas of pixels with multiple payments?[/quote]I can't think of a way you can do this other than modifying some of the code in the ordering process and somehow integrating that with your payment module. It does sound like a good feature to add in though in the future along with the ability to install extra payment modules right from the web interface.

Hey, I should have checked before I posted but what do you know... there is something that you might find useful in there. I will make a new article out of it in the FAQ section but I will paste it here as well for you.This article is aimed at PHP programmers who want to create their own payment modules.The payment system is loosely designed around the Model-View-Controller (MVC) pattern from OO programming.The payment module system is controlled by payment/payment_manager.php (Payment Manager)The Payment Manager is responsible for loading the module files, listing the payment options, and configuration of the payment modules from the Admin.The configuration data is stored in the 'config' table in the databaseEach payment module has it's own payment object in a separate file. Each payment module is responsible for rendering it's own payment button, rendering configuration forms, loading / saving configuration data and handling the payment gateway integration.Anatomy of a payment moduleA payment module has two sections, the top part is the integration with the payment gateway, and the bottom part is an implementation of the payment object.Here is an example based around the Paypal module:$_PAYMENT_OBJECTS['PayPal'] = new PayPal; // Change to whatever is your payment class nameif ($_POST['txn_id']!='') {// insert your gateway handling code here (see paypalIPN.php for further hints)// This code should only execute when called by the gateway, in this case this script is called// by the PayPal IPN system, where a txn_id is posted to the script.// The script will then do all the PayPal IPN stuff in here. (Validate the request & complete the order)}class PayPal { // Change to whatever is your payment object namevar $name="PayPal"; // Change to whatever is your payment methodvar $description="PayPal Secure Credit Card Payment"; // Change to whatever you want displayedvar $className="PayPal"; // // Change to whatever is your payment class name// A payment object has to implement the following functions:function PayPal() {} // Constructor that loads all the configuration from the config tablefunction get_currency() {} // returns the payment module's current currencyfunction install() {} // installs all the payment module to the config tablefunction uninstall {} // removes the payment module form the config tablefunction payment_button() {} // renders the payment button for the advertiserfunction config_form() // config form in the adminfunction save_config() // save_configfunction is_enabled() {}function is_installed() {}function enable() {}function disable() {}}What is the best way to create a new payment module?1. Copy paypalIPN.php and name the new file whatever you like.2. Edit the new file, remove the old gateway handling code, change the class names and $_PAYMENT_OBJECTS variable.3. Determine which variables you will need for the payment button. Implement a basic payment button.4. Implement the Admin side of the module, including the config form, installing / enabling, constructor, etc5. Test your payment module to see that the configuration is saved, payment button is properly displayed.6. Implement the payment gateway section.7. Test the payment gateway

I added an article (complete with syntax highlighting) here:[url=https://milliondollarscript.com/faq/technical-support/payment-modules-creating-your-own-advanced]Payment Modules: Creating your own. (Advanced)[/url]

Thank you very much. I will review this document and my SMS provider integration documentation and see what can I do to create custom payment module.

You are welcome. I am converting everything into Joomla and once thats all done, in the future I will make it so payment modules will be uploadable through little packages inside the script.Also, I didn't mean to insinuate that there is nothing useful in the old FAQs, just that I did not expect such an advanced and detailed document to be found in there that just so happens to be exactly what you want. I just got done migrating the rest of the FAQs from the old support site so if you have any other problems you might want to search in there for help. If you can't find it I will be more than happy to try my best to help out =)Ryan