This tutorial is mostly targeted at developers as a bit programming knowledge is required to add a new gateway. It works with all gateways that use a form (mostly appears as button) submit to get the information and process the payment with the guest from there on.
It only works with easyReservations 3.3 and above.

Basic setup

To start we create a new wordpress plugin by going in the folder /wp-content/plugins/ and creating a new folder with any name.
Then create a new file named like the folder with the extension .php. In this tutorial it will be example and example.php.
Open it with your editor and copy the standard plugin header from the wordpress codex.
You can change the values, but they only matter to find and activate it in the plugins list later on.

Register the gateway

To start we register our new gateway. Only a few informations are required for it.

Select Code
1
2
3
4
5
6
7
8
9
function register_my_custom_gateway($gateways){
    $gateways['my_gateway'] = array(
        'name' => 'Custom Gateway',
        'form_name' => 'gateway_form',
        'amount_name' => 'amount'
    );
    return $gateways;
}
add_filter('reservations_register_gateway', 'register_my_custom_gateway', 10, 1);

The key of the array, in the example my_gateway, is only a identifier and wont be used later on. The name is only used if you activate multiple gateways to choose from. In form_name and amount_name enter the html names of the payment form and the name of the amount (price) field in it. You’ll see them later in the tutorial.

If you want to add options to the settings you have to enter the options name to the array with the key “options”.

Generate payment form

Next is to generate the payment form. You’ll need some informations like the name and format of the fields and the URL to post the form to from the documentation of the gateway and an image for the payment button.

Select Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function generate_my_gateway_payment_form($res,$id,$title,$price,$nonce){
    //Open form with link to gateway; the name of this should be the value of form_name at gateway registration
    $form = '<form name="gateway_form" action="http://link-to-custom-gateway.com" method="post" id="easy_paypal_form">';

    //Add a image as button to click on
    $form.= '<input type="image" src="http://link-to-image.png" border="0" name="submit" alt="Pay with custom gateway!">';

    //Create array with the fields required by gateway
    $array = array(
        //The id required for the ipn function is the variable $id
        'invoice' => $id,

        //Description is the variable $title
        'item_name' => $title,

        //Field for price; It's key should be the value of amount_name at gateway registration
        'amount' => $price,

        //Link to your ipn script if you create one
        'notify_url' => WP_PLUGIN_URL.'/example/example_ipn.php',

        //If the gateway supports a custom field use it for the nonce and check it in the ipn
        'custom' => $nonce,

        //Some examples that are required in most gateways in some form
        'business' => 'my_shop_identifier',
        'cancel_return' => 'http://my-site.com/cancel/',
        'currency_code' => 'USD',
        'return' => 'http://my-site.com/thanks/'
    );

    //Generate hidden fields from the array
    $form .= easyreservations_generate_hidden_fields($array);
    //Close form
    $form .= '</form>';

    return $form;
}
add_filter('reservations_generate_gateway_button', 'generate_my_gateway_payment_form', 10, 5);

After replacing the URLs and correctly naming and adding the required fields your done with the basic implementation.
On this point it is fully usable. Your guest can pay and you get the money, but the reservation wont get updated in easyreservations.
No matter if you want to proceed or that’s enough, this is a good point to test everything and get the last errors out.

IPN (Instant Payment Notification)

To get the reservations updating their price and payment status, as well as use the automatically approval function, you’ll need to write an IPN script. It verifies that the payment has been made before calling the payment callback function. As the way of verification is very different an example is senseless, but in the folder /lib/modules/paypal/ you can find all IPN scripts of the existing gateways. In them you can find four different ways so it should cover the most. The documentation of the gateway should also have an example of it.
Create a new file in the same folder, insert the payment verification and let it call the following function if it’s correct:

Select Code
1
easyreservations_ipn_callback($_POST['invoice'], $_POST['amount']);

Where invoice is the same as sent to the gateway and amount is the amount paid.
Don’t forget to enter the URL to your IPN script to the payment forms generation.

Settings

If you want to add a options panel to the settings there’a an action to insert it on the right spot:

Select Code
1
2
3
4
function my_gateways_settings(){
    //Generate and output your options here
}
add_action('reservations_gateway_settings', 'my_gateways_settings');

The option to activate it should be saved as “modus”. Use the wordpress options to save them and don’t forget to add it’s name to the gateway registration array with the key “options”.

Get your Gateway integrated into easyReservations

If you’re done and want to share your results with other users of easyReservations feel free to send me the script to support@easyreservations.org and I’ll see if I get it integrated.
While I can’t give any financial reward it has the benefit that I’ll keep it up to date and compatible with all future updates of easyReservations and probably improve it with the time.