iono Documentation - Overview
Code
All of the code in iono is written according to our detailed coding standards. If you are writing code for iono for release, you must abide either by our standards or by standards that you have yourself. Conforming to standards ensures that the code remains easy to read and maintain.
All classes and functions in iono are commented using the PHPDoc documentation format. This means you can download PHPDoc and parse the source code to use dynamically generated source documentation. This provides information about all the functions including a description, parameters and various other useful snippets of information. In addition to parsing the code yourself.
Classes
iono is very much class based. The majority of functions are class functions and iono makes use of inheritance and overloading.
iono is based around nine core classes which perform the eight main functions within iono. All classes can be located in the includes/libraries/ directory with the iono classes being within the includes/libraries/iono/ directory.
The classes are as follows:
- iono - the core application class
- iono_downloads - handles all the downloading functions including encoding, archiving and CVS checkout
- iono_events - handles all events for the hooks system
- iono_extras - contains functions related to product extras
- iono_gateways - class containing all gateway related functions; extends iono
- iono_invoices - contains all functionality for invoices
- iono_licenses - contains all functions for license handling; extends iono
- iono_mailer - handles all mail sending functions
- iono_users - contains functions for handling all users; extends iono
Globals & Submitted Data
For security, iono automatically unsets all normal variables named the same as a key in the $_POST, $_GET and $_REQUEST arrays; usually created if register_globals is on. The data is then cleaned and placed into class variables.
All data submitted via any of these three arrays should be accessed by using the iono class variables:
- Data in $_POST stored in $iono->vars_post array
- Data in $_GET stored in $iono->vars_get array
- Data in $_REQUEST stored in $iono->vars_request array
Whilst you can still access the data in the original arrays, the data stored in the iono class has been cleaned and is accessible throughout the entire application. Session data is also stored in the session variable
$_SESSION['iono_session']
as an array of various data.
Although the data is cleaned, you should do checks to ensure that the data in the array is what you expected. iono provides a function for you to do this called $iono->validate_types(). You provide this function with an array of the data you expect including what data type it should be, and the function will make sure the data is that type. And for strings, it will perform a number of additional cleaning functions.
For example:
$iono->validate_types($iono->vars_post, array('name' => 'STR', 'text' => 'STR_HTML',
'site_wide' => 'INT'));
This code will check the vars_post array for the data you are expecting - name (string), text (string using HTML) and site_wide (integer).
A singular function is also available called $iono->validate_type(). This accepts 2 parameters:
$iono->validate_type($invoice_id, 'INT');
where $invoice_id is the variable to type check to an INT.
The options for the data types are:
- Integer (INT)
- Float (FLOAT)
- String (STR)
- String with HTML (STR_HTML)
Payment Gateway Modules
All the payment gateway modules are written in a standard format. All the source files are unencoded and available in the sources/gateways/ directory. Each file has a standard name and has the following definition. This format should be used when creating your own gateway module.
<?php
/**
* Payment Gateway Module - Gateway Name
* http://www.example.com
*
* @version 2.0.0
*/
class gatewayname extends iono_gateways
{
var $gateway;
/**
* Gets data from parent class and sets up gateway ready to be used.
*
* @param array $gateway Gateway data
* @return bool Returns true
*/
function gatewayname($gateway)
{
$this->gateway = $gateway;
return true;
}
/**
* Handles the remote callback from the gateway
*
* @global object iono
* @return bool Returns true
*/
function callback($gateway)
{
global $iono;
return true;
}
/**
* Generates HTML form to complete payment
*
* @param int $invoice_id
* @global object iono
* @return string HTML
*/
function make_payment_html($invoice_id)
{
global $iono;
return $html;
}
/**
* Handles submission of card details through iono to a remote server
*
* @return false
*/
function process()
{
return false;
}
}
?>
Constructor: gatewayname($gateway)
This receives data from the parent iono_gateways class and makes the gateway settings available in the class property $this->gateway. The available values are:
- gateway_id - The ID of the gateway
- status - The current status of the gateway
- name - The name of the gateway
- description - Description of the gateway
- filename - The filename in sources/gateways/
- email - The e-mail address for the admin's gateway account (if applicable)
- seller_id - The seller/vendor/account ID for the admin's gateway account (if applicable)
- test - Set to 1 if the gateway is in test mode
Function: callback($gateway)
This function will be called when the gateway triggers the callback. This is accessed from the URL is shown under the Callback heading on the Gateways page which you can copy directly. If you look at the other gateways you will see how they are coded. You will notice that at certain points the parent function set_debug() is called with a short message. This is very useful during development because the message will be stored and can be sent to the admin e-mail address as one debug log by calling $this->send_error('Message here'). When a callback is initiated by the gateway there is no output to the user so this allows details of what is happening to be sent to you via e-mail.
When a transaction has taken place, the parent log_transaction function should be called.
log_transaction($invoice_id, $result, $currency, $amount, $fees, $ref, $notes = '')
This will store the details in the database which can be viewed when editing an invoice.
A separate function must be called to mark the invoice as paid. Often you will want to log a transaction but not mark the invoice as paid, e.g. if there is an error. The parent mark_paid() function is used to do this. It will work out whether the invoice must be approved first and then notify the admin/customer appropriately.
mark_paid($invoice_id)
Function: make_payment_html($invoice_id)
This is called when the customer needs to pay and should output an HTML form to submit the necessary data to the payment gateway.
You can get the invoice data by calling the parent function:
get_invoice($invoice_id)
This will return the following data as an array:
- invoice_id - The ID of the invoice
- user_id - The ID of the customer user
- initial_total - The total initial payment value (formatted 0.00)
- recurring_total - The total recurring payment value (formatted 0.00)
- recurring_period - The recurring period for the invoice
You can also get the customer data using the parent function:
get_customer($user_id)
This will return the following data as an array:
- user_id
- username
- first_name
- last_name
- company
- address1
- address2
- city
- county
- postalcode
- country
- phone
Function: process()
Some gateways, such as Authorize.Net, require the data to be submitted through an API call. In these cases you should use the process() function to handle these. The form generated by make_payment_html should submit to
remote.php?remote=gateways&cmd=process&gateway=gatewayname
Where gatewayname is the name of the gateway in the same format as the filename. This will call the process() function which you can use the prepare an API call, submit it and then receive the data back directly. There is usually no need to use the callback() function in these cases.
Gateway Settings
Before a gateway is available to use you must add it through the admin panel. The Gateways section of the manual explains the page in the ACP to use. Click the Add New Gateway button at the bottom of the page and fill out the fields:
- Name - The name of the gateway as it will appear to customers
- Description - The description of the gateway as it will appear to customers
- Status - Whether the gateway is active or disabled
- File - The name of the .php file in the sources/gateways/ directory
- Test Mode - Whether to enable test mode or not
- Account Details - Either the e-mail address or Seller ID for the admin's gateway account.