You are here

function commerce_sagepay_void_access in Drupal Commerce SagePay Integration 7

Determines access to the void form for SagePay.

Parameters

commerce_order $order: The order the transaction is on.

commerce_payment_transaction $transaction: The payment transaction object to be aborted.

Return value

bool TRUE or FALSE indicating void access.

1 string reference to 'commerce_sagepay_void_access'
commerce_sagepay_menu in ./commerce_sagepay.module
Implements hook_menu().

File

./commerce_sagepay.module, line 391

Code

function commerce_sagepay_void_access($order, $transaction) {
  global $user;

  // Return FALSE if the transaction isn't for SagePay Server or Direct.
  if ($transaction->payment_method != 'commerce_sagepay_server' && $transaction->payment_method != 'commerce_sagepay_direct') {
    return FALSE;
  }
  if ($transaction->remote_status != 'PAYMENT' && $transaction->remote_status != 'RELEASED' && $transaction->remote_status != 'DEFERRED') {
    return FALSE;
  }

  // Check if transaction status is not already cancelled.
  if ($transaction->status == COMMERCE_PAYMENT_STATUS_FAILURE) {
    return FALSE;
  }

  // check SagePay Payment permission
  if (!user_access('sagepay void payment', $user)) {
    return FALSE;
  }

  // Allow access if the user can update payments on this order.
  return commerce_payment_transaction_access('update', $order, $user);
}