Realex Payments Spark

Realex Payments is an online payments provider which provides a solution which does not require the merchant to have their own secure server. The Realex Payments Spark provides an easy to use library to get up an running with Realex very quickly.

Note: Realex Payments is fully PCI compliant to the highest level of PCI, allowing redirect integration which significantly reduces the merchants PCI compliance requirements. Remote integration merchants will need to be fully compliant with PCI.

Core Features

  • Provides the RealAuth solution from Realex Payments
  • Returns the form to connect to Realex
  • Provides the Payment Response end point which Realex calls after a payment has been processed
  • Provides basic success and failure views which are returned to Realex to display on the Payment page

Setup Your Config Preferences

In sparks/realex-payments/config/realex_payments.php you will find the preferences for connecting to your Realex account. The config file is well commented.

Setup Your Languages

In sparks/realex-payments/language/english/realex_payments.php you will find the English language messages used in the form and response view files.

Basic Usage From Your Controller

function __construct(){
    // load the Realex Payments spark
    $this->load->spark( 'realex-payments/[version #]');

function index(){
    // setup the details of the form
    $this->realex_payments->set_field('form_name', 'realex_form')
                            ->set_field('form_id', 'realex_id')
                            ->set_field('currency', 'EUR')
                            ->set_button_delimiters('<div>', '</div>');
    // set specific order details
    $this->realex_payments->set_field('customer_num', 'cust123')
                            ->set_field('product_id', 'PRO-1234')
                            ->set_field('comment1', 'This is a comment about the order')
                            ->set_field('comment2', 'This is another comment');
    // display the form - passing in the order_id and amount
    echo $this->realex_payments->return_form('ORD-1231', '1200');

function payment_response()
    // get the Post details and return in a usable format
    $response_array = $this->realex_payments->return_response_status();

    // Check if the payment was successful
    if( !empty($response_array['success']) ) {
        // perform any database updates
        // display the success view
        $this->load->view('success', $response_array);
    else {

        switch ($response_array['error'])
            case 'PAYMENT_FAILURE':
                $response_array['failure_message'] = $this->_payment_failure($response_array);
            case 'HASH_MISMATCH':
                $response_array['failure_message'] = $this->CI->lang->line( 'realex_payments_response_hash_mismatch' );

                $response_array['failure_message'] = $this->CI->lang->line( 'realex_payments_response_no_data' );

        // perform any database updates

        // display the failure view
        $this->load->view('failure', $response_array);

function _payment_failure($response_array)
    $failure_message = '';
    switch ($response_array->cause)
        case 'DECLINED':
            $failure_message = $this->CI->lang->line( 'realex_response_declined' );
        case 'LOST_STOLEN':
            $failure_message = $this->CI->lang->line( 'realex_response_lost_stolen' );
        case 'BANK_ERROR':
            $failure_message = $this->CI->lang->line( 'realex_response_bank_error' );
        case 'PAYMENT_SYSTEM_ERROR':
            $failure_message = $this->CI->lang->line( 'realex_response_payment_system_error' );

            $failure_message =  $this->CI->lang->line( 'realex_response_other_error' );

    return $failure_message;

Overriding the Realex Payments Views

You can edit the success and failure view files. It is advisable that all returned data is Not displayed to the user.