hook_paymentapi

Definition

hook_paymentapi(&$txn, $op, $arg3 = '')
contributions/modules/ecommerce/docs/developer/hooks/core.php, line 145

Description

Add a payment method.

The customer can choose one of several payment methods on checkout if more than one method is enabled.

Parameters

&$txn The transaction object for an order. This keeps growing in data from screen to screen.

$op What kind of action is being performed. Possible values:

  • "display name": The name of the method displayed to customers. This is purely for display purposes and my be descriptive.
  • "on checkout": Called after the customer selects their payment method. This can be used for any specific validation the payment method needs to impose. Be sure to call form_set_error() to raise a warning to the system.
  • "form": Called durring the checkout process. This is used to display options to the user for choosing between payment options. Nothing wil be displayed if only one payment option exists.
  • "update/insert": Called after the user has submitted the payment page so any additional payment details can be stored in the database.
  • "payment page": Display the form for accepting credit card information or redirect to a third party payment processor.
  • "delete": Called when the transaction is being deleted.
$arg3
  • Optional parameter to pass along.

Return value

This varies depending on the operation.

  • The "display name" operations return a string.
  • The "on checkout" operation should use form_set_error() if validation fails.
  • The "form" operation should return a valid form array to be merged with the full form on the payment checkout screen.
  • The "update/insert/delete" and "on checkout" operations have no return value.
  • The "payment page" operations should return a URI string or nothing at all.

Related topics

Namesort iconDescription
E-CommerceThe Drupal E-Commerce system.
HooksAllow modules to interact with the Drupal core.

Code

function hook_paymentapi(&$txn, $op, $arg3 = '') {

  switch ($op) {
    case 'display name':
      return t('PayPal');

    case 'on checkout':
      paypal_verify_checkout($txn);
      break;

    case 'form':
      break;

    case 'update':
    case 'insert':
      paypal_save($txn);
      break;

    case 'payment page':
      if ($txn->gross > 0) {
        return paypal_goto($txn);
      }
      break;

    case 'delete':
      paypal_delete($txn);
      break;
    }
}