Ixonn Group

Module as Payment Gateway

You are here:
< All Topics
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.

  • In modules/[module_name]/ create folder named libraries
  • In modules/[module_name]/libraries create a class name e.q. Example_gateway.php, the filename must end with _gateway.php
  • See below Sample implementation
  • In your module init file, register the payment gateway with the following code:
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, depends on the gateway API, you can create a controller to redirect from the process_payment gateway class method.

Sample Implementation

Because Ixonn 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 NOWwe call 1 method from the gateway library which will process everything additional that is required for this gateway eq redirect to gateway website and pass parameters or redirect to controller and show form etc…

We have simplified a little the process for creating new gateways e.q. the gateway will be auto showed 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.

Before starting, make sure that you set development mode in order to see any errors and functions/hooks deprecation warnings.

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;

    }

}

There are comments on the functions and variables, you should spend some time to read 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.

Related Articles

Table of Contents
Scroll Up