Last updated February 17, 2012. Created by stenjo on February 17, 2012.
Edited by Daglees. Log in to edit this page.

The payment API Pay module provides a common API for forms and payment modules to be connected. This page describes the process of writing a payment module to fit the Pay API and enable it to be used as one among many payment options available.

This instruction set is created while implementing the Tripletex payment method and code examples are picked from there.

To implement the interface to Pay, the payment method module must implement the hook hook_pay_method_handler_info() and may look something like this:

* This hook is used to inform Pay of available payment method handlers.
* Administrators will be able to create new instances of payment methods,
* based on the capabilities and options for your handler(s).
function tripletex_pay_method_handler_info() {
  return array(
'pay_method_custom' => array(
'title' => t('Electronic invoice'),
'description' => t('Create an electroinc invoice and have that shipped to the customers e-mail address'),
'parent' => 'pay_method_custom',
'module' => 'tripletex',
'path' => drupal_get_path('module', 'tripletex') .'/includes',

The hook tells the Pay API that the payment method is called "Electronic invoice", that it extends the class pay_method_custom {} and that everything is found in the "tripletex" module. In addition it also defines the path to where the class extention is expected to be found: In the "/includes" subdirectory of the module "tripletex" root.


The implementation is expected to be named class pay_method_custom_tripletex {} and is expected to be found in a file named includes/ as the path property of the info is pointing to that location.

The pay_method_custom class extends the pay_method class which in turn extends the Pay class.

class pay_method_custom_tripletex extends pay_method_custom {
$tripltetex_account = ''// Local property keeping the login account information
function available_currencies() {
settings_form(&$form, &$form_state) {
parent::settings_form($form, $form_state);
$form[$group]['tt']['tripletex_account'] = array(
'#type' => 'textfield',
'#title' => t('Tripletex Account e-mail address'),
'#default_value' => $this->tripltex_account,
'#required' => TRUE,
'#parents' => array($group, 'tripltex_account'),

The class inherits and may overvrite a few important methods. These are:
available_currencies(): Must be implemented and returns an array of currency codes available for this payment method.
settings_form(): With the appropriate call to the parent this function might add payment method specific parameters to the settings form presented when an admin adds this payment method.

Looking for support? Visit the forums, or join #drupal-support in IRC.