You are here

function sagepay_3d_secure_load_transaction in Drupal Commerce SagePay Integration 7

Check if an order has a partial 3D secure transaction and return it.

Parameters

array $tokens: An array of available tokens.

commerce_order $order: The Commerce Order.

1 call to sagepay_3d_secure_load_transaction()
commerce_sagepay_process_response in includes/commerce_sagepay_common.inc
Helper function to process the response from SagePay of any transaction type.

File

modules/sagepay_3d_secure/sagepay_3d_secure.module, line 327

Code

function sagepay_3d_secure_load_transaction($tokens, $order) {

  // There are only two possible status codes - OK or NOTAUTHED.
  $status_3d_secure = isset($tokens['3DSecureStatus']) ? $tokens['3DSecureStatus'] : '';

  // If there is no 3D Secure status, we don't need to do anything else.
  if ($status_3d_secure == '') {
    return NULL;
  }

  // A successful 3D Secure transaction will also have a CAVV value.
  $cavv_code = isset($tokens['CAVV']) ? $tokens['CAVV'] : '';

  // Search for exisiting transaction.
  $conditions = array(
    'order_id' => $order->order_id,
    'remote_status' => SAGEPAY_REMOTE_STATUS_3D_SECURE,
  );
  $transactions = commerce_payment_transaction_load_multiple(array(), $conditions);
  if (empty($transactions)) {
    return NULL;
  }
  $transaction = array_pop($transactions);
  return $transaction;
}