Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close

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(){
    parent::__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);
                break;
            case 'HASH_MISMATCH':
                $response_array['failure_message'] = $this->CI->lang->line( 'realex_payments_response_hash_mismatch' );
                break;

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

        // 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' );
            break;
        case 'LOST_STOLEN':
            $failure_message = $this->CI->lang->line( 'realex_response_lost_stolen' );
            break;
        case 'BANK_ERROR':
            $failure_message = $this->CI->lang->line( 'realex_response_bank_error' );
            break;
        case 'PAYMENT_SYSTEM_ERROR':
            $failure_message = $this->CI->lang->line( 'realex_response_payment_system_error' );
            break;

        default:
            $failure_message =  $this->CI->lang->line( 'realex_response_other_error' );
            break;
    }

    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.

Recent activity

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.