You are here

function commerce_sagepay_repeat_deferred_access in Drupal Commerce SagePay Integration 7

Determines access to the repeat form for SagePay.

Parameters

commerce_order $order: The order the transaction is on.

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

Return value

bool TRUE or FALSE indicating void access.

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

File

./commerce_sagepay.module, line 556

Code

function commerce_sagepay_repeat_deferred_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 (in_array($transaction->remote_status, array(
    SAGEPAY_REMOTE_STATUS_FAIL,
    SAGEPAY_REMOTE_STATUS_INVALID,
    SAGEPAY_REMOTE_STATUS_STARTED,
    SAGEPAY_REMOTE_STATUS_UNKNOWN,
    SAGEPAY_REMOTE_STATUS_REFUNDED,
    SAGEPAY_REMOTE_STATUS_REGISTERED,
  ))) {
    return FALSE;
  }

  // Check if this is a successful transaction.
  if ($transaction->status != COMMERCE_PAYMENT_STATUS_SUCCESS) {
    return FALSE;
  }

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

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