Add-Ons
Unlock more possibilities for your LMS.
Integrations
Connect with tools you already use.
Migration
Switch to Tutor LMS with confidence.
Blog
Learn, grow, and stay ahead in eLearning.
Documentation
Everything you need to build with Tutor LMS.
Videos
Learn visually with tutorials.
Release Notes
See what’s new in every update.
Partners
Explore our trusted Tutor LMS partners.
This guide walks you through the steps to integrate a custom payment gateway into Tutor LMS. It includes understanding the requirements, creating the necessary file structure, and implementing the code. Follow the step-by-step process below to create a custom payment gateway for Tutor LMS.
This guide walks you through the steps to integrate a custom payment gateway into Tutor LMS. It includes understanding the requirements, creating the necessary file structure, and implementing the code.
Before starting, familiarize yourself with the API and documentation of the payment gateway you want to integrate. Key aspects to focus on include:
Note: Throughout this documentation, we will refer to the payment gateway we are implementing as CustomPayment. This is simply a placeholder name. When integrating a specific payment gateway, replace CustomPayment with the name of the gateway you are working with.
To begin, download the demo plugin CustomPayment. This plugin serves as a reference structure that you can update with your own payment gateway’s configuration.
Once you’ve downloaded the plugin, you’ll notice the following file structure:

You’ll modify the files within the custompayment directory to suit the specific gateway you’re integrating.
The CustomPaymentConfig.php file handles the configuration settings for your payment gateway. Here’s a breakdown of the parts of the code and what they do:
Class Declaration and Namespaces
The class is located under the CustomPayment namespace, and it extends from BaseConfig and implements the ConfigContract.
namespace CustomPayment;
use Tutor\Ecommerce\Settings;
use Ollyo\PaymentHub\Core\Payment\BaseConfig;
use Tutor\PaymentGateways\Configs\PaymentUrlsTrait;
use Ollyo\PaymentHub\Contracts\Payment\ConfigContract;Class Properties
The configuration properties such as public_key, secret_key, environment, etc., are defined as private properties in the class. Define the required fields of your payment gateway here.
private $environment;
private $public_key;
private $secret_key;
private $client_id;
protected $name = 'custompayment';These fields are provided by the payment gateway and can be filled in by the user via the WordPress admin panel (through the Payment settings in Tutor LMS).
CustomPaymentConfig.phpStep 1: Update the Class Name and Namespace
Step 2: Update Configuration Fields
Example:
private $merchant_id;
private $currency_type;Then, update the method get_custompayment_config_keys() to reflect the new fields added.
private function get_custompayment_config_keys() {
return array(
'environment' => 'environment',
'secret_key' => 'secret_key',
'public_key' => 'secret_key',
'client_id' => 'secret_key',
'merchant_id' => 'secret_key', // New field
);
}Example for the merchant ID:
private function getMerchantID(): string {
return $this->merchant_id;
}
The is_configured() method is used to check if all required fields are present. If you add new fields, ensure they are included in this check.
Before checking is_configured, you need to ensure that the merchant_id (and any other new fields) are properly initialized in createConfig.
Here’s how you can update the code:
merchant_id in createConfig().public function createConfig(): void {
parent::createConfig();
$config = array( 'merchant_id' => $this->getMerchantID() );
$this->updateConfig( $config );
}is_configured() method to include merchant_id.public function is_configured() {
return $this->secret_key && $this->public_key && $this->merchant_id;
}CustomPaymentConfig.php:merchant_id, currency_type).Overview
The CustomPaymentGateway.php file is responsible for processing payments via the configured gateway. It interacts with the payment processor, handles payment requests, and manages responses.
The CustomPaymentGateway class extends the GatewayBase class, which contains the general functionality for payment gateways. By extending this class, you inherit reusable methods, allowing you to focus only on the specifics of your payment gateway.
The CustomPaymentGateway.php file contains the following properties that help manage the configuration, directory structure, and payment handling for your custom payment gateway.
$dir_name: Specifies the core payment class name for your payment gateway. This will be the folder where all your payment gateway files reside.$config_class: References the configuration class for the custom payment gateway. This is the class that manages the payment gateway settings (such as secret keys, public keys, etc.). In this case, it references CustomPaymentConfig::class.$payment_class: References the payment core class that processes transactions. Here, it points to Custompayment::class, which contains the logic for handling the payment transactions.The class includes several methods to retrieve directory names, configuration settings, and payment processing logic.
get_root_dir_name(): Returns the root directory name where the payment gateway files are stored.
get_payment_class(): Returns the class that handles the actual payment processing.
get_config_class(): Returns the configuration class, which contains the necessary settings (such as API keys and environment settings).
get_autoload_file(): Returns the path to the autoload file for the payment gateway, which is used to load all the dependencies required for your gateway.
CustomPaymentGateway.phpThe $payment_class and $config_class properties are set to reference Custompayment and CustomPaymentConfig classes by default. These properties should be updated to reflect the specific classes that handle the payment transactions and configurations for your gateway.
The $dir_name property is set to 'Custompayment'. This corresponds to the root directory where your payment gateway files are stored. If you choose to rename your folder, make sure to update this property accordingly.
3. Autoload File:
The get_autoload_file() method is used to return the path to the autoload file, typically required if you’re using Composer to manage dependencies. If your gateway requires this autoloader, specify the correct path to it, like so:
public static function get_autoload_file() {
return '/path/to/vendor/autoload.php';
}If no autoload file is required, you can leave the method as is (returning an empty string).
Properties: Update $dir_name, $payment_class, and $config_class to match your gateway’s structure.
Autoload File: Update the path if using Composer for dependency management.
The Init.php file is responsible for initializing the custom payment gateway within the Tutor LMS ecosystem. It registers the necessary hooks to connect the gateway with Tutor LMS, allowing the system to recognize the custom payment method and its configuration.
Payment Gateway Name:
In the code, the payment gateway name is set as 'custompayment'. You should update this to match the name of your payment gateway.
Payment Gateway Classes:
The CustomPaymentGateway::class and CustomPaymentConfig::class in the payment_gateways_with_ref and filter_payment_gateways functions need to be updated to reflect the new gateway class names.
Gateway Label:
The label 'Custom Payment' in the $custom_payment_method array should be updated to the display name of your payment gateway.
Gateway Fields:
The fields array holds the settings and configuration fields for the payment gateway. These are the fields shown to the user in the admin settings. You can add new fields or modify the existing ones as needed for your gateway. For example:
If your payment gateway requires additional fields (e.g. merchant ID), you can add them to the fields array in the same format.
array(
'name' => 'merchant_id',
'type' => 'secret_key',
'label' => 'Merchant ID',
'value' => '',
),Icon:
If you want to add an icon for your payment gateway, specify the URL in the 'icon' field. This could be a link to an image hosted on your server.
Subscription Support:
The 'support_subscription' => false value indicates that the gateway does not support subscriptions. If your payment gateway supports subscriptions, change this value to true.
Adding More Fields:
If your gateway requires additional settings, simply add more fields to the fields array in the $custom_payment_method configuration.
By updating these sections, you can integrate your custom payment gateway into Tutor LMS while customizing it to meet your specific gateway requirements.
The Custompayment.php file contains the core logic for processing payments via the custom payment gateway. This file extends the BasePayment class and overrides certain methods to handle payment operations specific to your gateway.
Ensure the namespace at the top of the file matches your plugin name. Replace Payments\Custom with your preferred namespace to align with your project structure.
check() Method:In the check() method, you will define the configuration keys for your payment gateway. These include values like secret_key, public_key, and mode. Update these keys to match the settings required by your payment gateway. If your gateway requires other configuration values (like API credentials or environment settings), add them to the $configKeys array.
setup() Method:The setup() method is used to configure the necessary settings for making API calls to the payment gateway.
createPayment() Method):createPayment(): Sends the payment data from Tutor LMS to your payment gateway.In the current implementation, createPayment() redirects the user to https://tutorlms.com/. This URL should be replaced with the actual URL where your payment gateway handles transactions.
Retrieve the required values from the settings interface using $this->config->get('property_name'). You can get values like the secret_key, public_key, and mode that were defined in the plugin’s settings page.
verifyAndCreateOrderData() Method):verifyAndCreateOrderData() method receives data from the payment gateway to Tutor LMS.$get_data, $post_data, $server_variables, and $stream are correctly handled based on how your payment gateway sends the webhook data.The order data should be updated to return the correct fields such as payment_status, transaction_id, and fees based on the response from your gateway.
Retrieve the necessary values from the configuration interface (e.g., secret keys) and verify the webhook data accordingly. Use $returnData to return the order information.
setData() and getData()):The payment data sent by Tutor LMS can be accessed via the getData() method, which retrieves the details provided by the LMS when calling setData().
setData($data)This method is used to set the payment data for the current payment object.
object $data: An object containing the payment data to be set.Throwable: If any error occurs while setting the data (i.e. if the parent setData method throws an error).If your gateway requires extra methods for handling payments, such as refunds, cancellations, or payment status checks, add them to this class. Follow the pattern established by the existing methods to ensure consistency and reusability.
This file serves as the main entry point for your custom payment gateway plugin, and it is responsible for registering the plugin, loading necessary files, and initializing the integration with Tutor LMS.
Plugin Metadata:
Update the plugin name, URI, description, author, and version information to reflect the details of your custom payment gateway and your company.
Paths and Directories:
The following constants define the paths and URLs for the plugin. Ensure these paths are correct based on your plugin structure:
// Define plugin meta info.
define( 'CUSTOM_PAYMENT_VERSION', '1.0.0' );
define( 'CUSTOM_PAYMENT_URL', plugin_dir_url( __FILE__ ) );
define( 'CUSTOM_PAYMENT_PATH', plugin_dir_path( __FILE__ ) );
define( 'CUSTOM_PAYMENT_PAYMENTS_DIR', trailingslashit( CUSTOM_PAYMENT_PATH . 'src/Payments' ) );These paths are crucial for locating resources such as payment classes, assets, and other files. If your structure differs, adjust these constants accordingly.
Autoloader:
This line ensures the Composer autoloader is included, allowing any dependencies installed via Composer to be automatically loaded. Make sure the vendor directory exists and contains the required dependencies for your plugin.
Initialization:
The CustomPayment\Init class is instantiated if the necessary conditions are met. This will initialize the gateway integration by registering the necessary hooks and filters.
Make sure the initialization process matches your intended workflow. If there are any additional setup or configurations to be done, you can modify the code here to reflect those changes.
Update Plugin Name and Description
name: This is the package name for your plugin. It should follow the format themeum/package-name.description: Provide a brief description of your plugin and what it does (e.g., integrates a custom payment gateway into Tutor LMS).Update Autoload Section
This defines the mapping between namespaces and the directory structure for your PHP classes.
"autoload": {
"psr-4": {
"Ollyo\\PaymentHub\\": "../tutor/ecommerce/PaymentGateways/Paypal/src", // This namespace 'Ollyo\\PaymentHub\\' is fixed and will remain unchanged
"Payments\\Custom\\": "payments", // You can modify the namespace according to your project needs
"CustomPayment\\": "integration" // You can adjust this namespace as per your directory structure
}
}Join the world’s #1 Tutor LMS community
By submitting your email, you agree to our Terms and Privacy Policy
Product
Solutions
Build, manage, and scale your eLearning business with the most powerful WordPress LMS — all in one place.
Crafted by Humans
© 2026 All Rights Reserved