You are here

function Payment::execute in Payment 7

Execute the actual payment.

File

./payment.classes.inc, line 150
The API and related functions for executing and managing payments.

Class

Payment
A single payment. Contains all payment-specific data.

Code

function execute() {

  // Preprocess the payment.
  module_invoke_all('payment_pre_execute', $this);
  if (module_exists('rules')) {
    rules_invoke_event('payment_pre_execute', $this);
  }

  // Execute the payment.
  if ($this->method) {
    try {
      $this->method
        ->validate($this);
      $this
        ->setStatus(new PaymentStatusItem(PAYMENT_STATUS_PENDING));
      $this->method->controller
        ->execute($this);
    } catch (PaymentValidationException $e) {
      $this
        ->setStatus(new PaymentStatusItem(PAYMENT_STATUS_FAILED));
    }
  }
  else {
    $this
      ->setStatus(new PaymentStatusItem(PAYMENT_STATUS_FAILED));
  }

  // This is only called if the payment execution didn't redirect the user
  // offsite. Otherwise it's the payment method return page's responsibility.
  $this
    ->finish();
}