You are here

function commerce_sagepay_refund_access in Drupal Commerce SagePay Integration 7

Determines access to the refund form for SagePay.

Parameters

commerce_order $order: The order the transaction is on.

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

Return value

bool TRUE or FALSE indicating refund access.

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

File

./commerce_sagepay.module, line 310

Code

function commerce_sagepay_refund_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;
  }

  // Return FALSE is the remote status is FAIL or INVALID.
  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,
    SAGEPAY_REMOTE_STATUS_REPEAT_DEFERRED,
  ))) {
    return FALSE;
  }
  if ($transaction->status == COMMERCE_PAYMENT_STATUS_FAILURE) {
    return FALSE;
  }

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

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