You are here

class pay_activity in Pay 7

Same name and namespace in other branches
  1. 6 includes/handlers/pay_activity.inc \pay_activity

@file A base class for payment activities.

Hierarchy

Expanded class hierarchy of pay_activity

5 string references to 'pay_activity'
pay_activity_load in ./pay.module
API Function: Load a payment activity object.
pay_load_object in ./pay.module
API Function: Load a payment class.
pay_transaction::activity in includes/handlers/pay_transaction.inc
pay_update_6004 in ./pay.install
Add a "state" column to the pay_transaction table.
pay_update_6005 in ./pay.install
Rename 'activity' to 'action' in pay_activity table.

File

includes/handlers/pay_activity.inc, line 8
A base class for payment activities.

View source
class pay_activity extends pay {
  var $paid;
  var $pxid;
  var $pmid;
  var $uid;
  var $result;
  var $action;
  var $payment_type;
  var $total;
  var $transaction_total;
  var $timestamp;
  var $hostname;
  var $data = array();
  var $identifier;
  var $table = 'pay_activity';
  var $key = 'paid';
  function set_pay_method($pay_method) {
    $this->pay_method = $pay_method;
    $this->pmid = $pay_method->pmid;
    $this->payment_type = $this
      ->pay_method()->payment_type;
  }
  function set_transaction($transaction) {
    $this->pay_transaction = $transaction;
    $this->pxid = $transaction->pxid;
  }
  function set_action($action) {
    $this->action = check_plain($action);
  }
  function set_transaction_total($val = 0) {
    $this->transaction_total = (double) $val;
  }

  /**
   * Set the $data value, which is stored as a serialized value in the database.
   */
  function set_data($value = NULL) {
    if (!empty($value) && is_scalar($value)) {
      $this->data = unserialize($value);
    }
    else {
      $this->data = $value;
    }
  }
  function currency() {
    return $this
      ->pay_transaction()
      ->currency();
  }

  /**
   * Effect a payment action using the currently-selected payment method.
   *
   * The action must be defined in valid_actions() and the that action's
   * callback must exist for this payment method. Empty actions use a pseudo-
   * action of 'pending'.
   */
  function do_activity($action = NULL, $values = array()) {

    // No action defined: Ensure that this transaction gets logged as 'pending'
    if (!$action || $action == 'pending') {
      $action = 'pending';
      $func = 'pending_action';
    }
    else {
      $info = $this
        ->pay_transaction()
        ->valid_actions($action);
      $func = $info['callback'];
    }
    $this
      ->set_action($action);

    // If the payment method has a function to handle this action, call it!
    if (method_exists($this
      ->pay_method(), $func)) {
      $this
        ->pay_method()->activity = $this;
      $state = $this
        ->pay_method()
        ->{$func}($values);
    }

    // Save any new/changed data for this activity.
    $this
      ->save();

    // Update this activity's transaction.
    $this
      ->pay_transaction()
      ->update_status($state, $this->timestamp);

    // Return boolean result.
    return $this->result;
  }

  /**
   * The transaction balance as of this payment's completion.
   */
  function balance() {
    return (double) db_query("SELECT t.total - SUM(a.transaction_total)\n      FROM {pay_activity} a\n      INNER JOIN {pay_transaction} t USING (pxid)\n      WHERE t.pxid = :t.pxid AND a.paid <= :a.paid", array(
      ':t.pxid' => $this->pxid,
      ':a.paid' => $this->paid,
    ))
      ->fetchField();
  }

  /**
   * Return the payment method related to this activity.
   */
  function pay_method() {
    if (!isset($this->pay_method)) {
      $this->pay_method = pay_method_load($this->pmid);
    }
    return $this->pay_method;
  }

  /**
   * Return the transaction related to this activity.
   */
  function pay_transaction() {
    if (!isset($this->pay_transaction)) {
      $this->pay_transaction = pay_transaction_load($this->pxid);
    }
    return $this->pay_transaction;
  }

  /**
   * Return a history of all payment activities related to this activity.
   * This is any activity for the current transaction that's using the same
   * payment method.
   */
  function history() {
    if (!isset($this->history)) {
      $history = $this
        ->pay_transaction()
        ->pay_method_activities($this->pmid);
      $this->history = is_array($history) ? $history : array();
    }
    return $this->history;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
pay::$permissions property
pay::access function
pay::disable function 1
pay::drupal_invoke function Execute an named Drupal hook function, passing $this as the first parameter.
pay::enable function
pay::form function 3
pay::form_setup function
pay::form_submit function 2
pay::form_validate function 1
pay::form_values function
pay::handler function
pay::handler_title function
pay::menu_path function 1
pay::notes function
pay::pay_activity function @todo Please document this function.
pay::pay_form function @todo Please document this function.
pay::permissions_settings function
pay::save function
pay::settings_form function 2
pay::settings_form_submit function
pay::settings_form_validate function
pay::set_completed function
pay::set_created function
pay::set_handler function
pay::set_hostname function
pay::set_identifer function
pay::set_key function Do not allow this value to be automatically set.
pay::set_mail function
pay::set_notes function
pay::set_status function
pay::set_table function Do not allow this value to be automatically set.
pay::set_timestamp function
pay::set_total function
pay::set_total_paid function
pay::set_uid function
pay::timestamp_value function
pay::title function 2
pay::total function 1
pay::uid function
pay::user function
pay::__construct function
pay_activity::$action property
pay_activity::$data property
pay_activity::$hostname property
pay_activity::$identifier property
pay_activity::$key property Overrides pay::$key
pay_activity::$paid property
pay_activity::$payment_type property
pay_activity::$pmid property
pay_activity::$pxid property
pay_activity::$result property
pay_activity::$table property Overrides pay::$table
pay_activity::$timestamp property
pay_activity::$total property
pay_activity::$transaction_total property
pay_activity::$uid property
pay_activity::balance function The transaction balance as of this payment's completion.
pay_activity::currency function
pay_activity::do_activity function Effect a payment action using the currently-selected payment method.
pay_activity::history function Return a history of all payment activities related to this activity. This is any activity for the current transaction that's using the same payment method.
pay_activity::pay_method function Return the payment method related to this activity.
pay_activity::pay_transaction function Return the transaction related to this activity. Overrides pay::pay_transaction
pay_activity::set_action function
pay_activity::set_data function Set the $data value, which is stored as a serialized value in the database.
pay_activity::set_pay_method function
pay_activity::set_transaction function
pay_activity::set_transaction_total function