This feature is available from version 2.3.4
Before the start, we assume that you are already familiar with the modules basics , you created a blank module with all the required headers , and the module is activated and shown in the modules list.
register_payment_gateway('example_gateway', '[module_name]');
register_payment_gateway('example_gateway', '[module_name]');
register_payment_gateway('example_gateway', '[module_name]');
Replace [module_name] with your actual module system name and example_gateway with your module class name (in lowercase).
If you configured everything as it should, navigate to Setup->Settings->Payment Gateways , you will be able to see your Example gateway listed there with the options you specified.
Additionally, depending on the gateway API, you can create a controller to redirect from the process_payment gateway class method.
Because SudoWorkspace uses Codeigniter framework to integrate the payment gateway, you will need to create 1 gateway library (gateway config and process method) and 1 gateway controller (for HTTP requests, show form etc..). You can also take a look at the other gateways’ files in order to get the idea.
In the invoice HTML area, when a customer clicks on the button PAY NOW, we call 1 method from the gateway library, which will process everything additional that is required for this gateway eq redirect to the gateway website and pass parameters or redirect to the controller and show form, etc.
We have simplified a little the process for creating new gateways e.q. the gateway will be auto shown in Setup->Settings->Payment Gateways , encrypting fields, 1 unique function from each gateway library to call etc, but this will still require effort to get started.
Let’s assume for this example, your gateway name is Example
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Example_gateway extends App_gateway
{
public function __construct()
{
/**
* Call App_gateway __construct function
*/
parent::__construct();
/**
* Gateway unique id - REQUIRED
*
The ID must be alphanumeric
The filename (Example_gateway.php) and the class name must contain the id as ID_gateway
In this case our id is "example"
Filename will be Example_gateway.php (first letter is uppercase)
Class name will be Example_gateway (first letter is uppercase)
*/
$this->setId('example');
/**
* REQUIRED
* Gateway name
*/
$this->setName('Example');
/**
* Add gateway settings
* You can add other settings here
* to fit for your gateway requirements
*
* Currently only 3 field types are accepted for gateway
*
* 'type'=>'yes_no'
* 'type'=>'input'
* 'type'=>'textarea'
*
*/
$this->setSettings(array(
array(
'name' => 'api_secret_key',
'encrypted' => true,
'label' => 'API KEY',
'type'=>'input',
),
array(
'name' => 'api_publishable_key',
'label' => 'SECRET KEY',
'type'=>'input'
),
array(
'name' => 'currencies',
'label' => 'settings_paymentmethod_currencies',
'default_value' => 'USD,CAD'
),
));
}
/**
* Each time a customer click PAY NOW button on the invoice HTML area, the script will process the payment via this function.
* You can show forms here, redirect to gateway website, redirect to Codeigniter controller etc..
* @param array $data - Contains the total amount to pay and the invoice information
* @return mixed
*/
public function process_payment($data)
{
var_dump($data);
die;
}
}
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Example_gateway extends App_gateway
{
public function __construct()
{
/**
* Call App_gateway __construct function
*/
parent::__construct();
/**
* Gateway unique id - REQUIRED
*
The ID must be alphanumeric
The filename (Example_gateway.php) and the class name must contain the id as ID_gateway
In this case our id is "example"
Filename will be Example_gateway.php (first letter is uppercase)
Class name will be Example_gateway (first letter is uppercase)
*/
$this->setId('example');
/**
* REQUIRED
* Gateway name
*/
$this->setName('Example');
/**
* Add gateway settings
* You can add other settings here
* to fit for your gateway requirements
*
* Currently only 3 field types are accepted for gateway
*
* 'type'=>'yes_no'
* 'type'=>'input'
* 'type'=>'textarea'
*
*/
$this->setSettings(array(
array(
'name' => 'api_secret_key',
'encrypted' => true,
'label' => 'API KEY',
'type'=>'input',
),
array(
'name' => 'api_publishable_key',
'label' => 'SECRET KEY',
'type'=>'input'
),
array(
'name' => 'currencies',
'label' => 'settings_paymentmethod_currencies',
'default_value' => 'USD,CAD'
),
));
}
/**
* Each time a customer click PAY NOW button on the invoice HTML area, the script will process the payment via this function.
* You can show forms here, redirect to gateway website, redirect to Codeigniter controller etc..
* @param array $data - Contains the total amount to pay and the invoice information
* @return mixed
*/
public function process_payment($data)
{
var_dump($data);
die;
}
}
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Example_gateway extends App_gateway
{
public function __construct()
{
/**
* Call App_gateway __construct function
*/
parent::__construct();
/**
* Gateway unique id - REQUIRED
*
The ID must be alphanumeric
The filename (Example_gateway.php) and the class name must contain the id as ID_gateway
In this case our id is "example"
Filename will be Example_gateway.php (first letter is uppercase)
Class name will be Example_gateway (first letter is uppercase)
*/
$this->setId('example');
/**
* REQUIRED
* Gateway name
*/
$this->setName('Example');
/**
* Add gateway settings
* You can add other settings here
* to fit for your gateway requirements
*
* Currently only 3 field types are accepted for gateway
*
* 'type'=>'yes_no'
* 'type'=>'input'
* 'type'=>'textarea'
*
*/
$this->setSettings(array(
array(
'name' => 'api_secret_key',
'encrypted' => true,
'label' => 'API KEY',
'type'=>'input',
),
array(
'name' => 'api_publishable_key',
'label' => 'SECRET KEY',
'type'=>'input'
),
array(
'name' => 'currencies',
'label' => 'settings_paymentmethod_currencies',
'default_value' => 'USD,CAD'
),
));
}
/**
* Each time a customer click PAY NOW button on the invoice HTML area, the script will process the payment via this function.
* You can show forms here, redirect to gateway website, redirect to Codeigniter controller etc..
* @param array $data - Contains the total amount to pay and the invoice information
* @return mixed
*/
public function process_payment($data)
{
var_dump($data);
die;
}
}
There are comments on the functions and variables; you should spend some time reading them because they are important if you want to help you get started.
Additionally, you can take a look at the other gateway example in application/libraries/gateways or application/controllers/gateways .
If the module payment gateway is using webhooks and makes a POST request to a URL in SudoWorkspace to notify about the payment updates, you will need to exclude this URL from CSRF in order for the request to pass.
You can follow this guide to achieve this.