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:
- Start by creating a folder for your new plugin in
/wp-content/plguins/
- You’ll need a base plugin file:
/my-plugin/my-plugin.php
. This is where your plugin information and includes will be written. - 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.