You are here

function commerce_sagepay_authorise_access in Drupal Commerce SagePay Integration 7

Determines access to the authorise form for SagePay.

Parameters

commerce_order $order: The order the transaction is on.

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

Return value

bool TRUE or FALSE indicating void access.

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

File

./commerce_sagepay.module, line 471

Code

function commerce_sagepay_authorise_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 != 'AUTHENTICATE' && $transaction->remote_status != 'REGISTERED') {
    return FALSE;
  }

  // Return FALSE if it is more than 90 days past the original authorization.
  if (time() - $transaction->created > 86400 * 90) {
    return FALSE;
  }

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

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