Creating a Payment Gateway

It’s easy to start creating a payment gateway plugin. In a couple easy steps, you can be on your way to providing your own custom payment method for your customers.

First let’s start with the files:

  1. Start by creating a folder for your new plugin in /wp-content/plguins/
  2. You’ll need a base plugin file: /my-plugin/my-plugin.php. This is where your plugin information and includes will be written.
  3. And a file to hold your gateway: /my-plugin/my-plugin-gateway.php. This is where your actual gateway class will be stored.

You will now need to go into my-plugin.php and give the plugin some good description information. You can follow WordPress’s tutorial on How to Create a Plugin. Your plugin description will look like this:

/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/

This information allows WordPress to detect the plugin and will make an item on the Plugins page so that you can enable your plugin.

From here, we need to set up the Gateway to include the right files at the right times. Every plugin has a Gateway class that extends APP_Gateway. APP_Gateway is an abstract class provided as a part of AppThemes Products. It already has helper functions defined to make it easy for you to get started writing your gateway class.

In my-plugin-gateway.php you should have something like this:

class My_Gateway extends APP_Gateway{
 
// ... stuff goes here ...
 
}
appthemes_register_gateway( 'My_Gateway' );

Now that you have a file set up with a Gateway, you need to include it in your my-plugin.php file. Because the APP_Gateway class is not defined until the theme is loaded, your plugin should not include the file until the ‘init’ action.

The easiest way to do this is to wrap your includes in a function:

add_action( 'init', 'my_plugin_setup' );
function my_plugin_setup(){
    include 'my-plugin-gateway.php';
}

Now, you are almost ready to go. When you create a gateway, there are two methods that you must define. These are methods that the Gateway API will call so that your plugin can be configured, as well as process orders.

Next Step: Creating Form Options

You’ve created the barebones. Now its time to give your plugin some customization. In the next step, you’ll see how to create a form for your plugin.

Creating Settings for Your Payment Gateway

Like this tutorial? Subscribe and get the latest tutorials delivered straight to your inbox or feed reader.

Your rating: none
Rating: 3.5 - 6 votes

Popular Add-ons

Profiler for Vantage

Adds a one page author website to your Vantage theme.


(6)
$39

Authorize.Net

Easily start accepting online payments via credit card and e-check.


(6)
$39

StarStruck

A fast, lightweight, and elegant star rating system for comments, pages,…


(33)
$19