You are here

function commerce_payleap_transaction_request in Commerce Payleap 7

Process a Void or Force transaction.

Parameters

$transaction: The Transaction entity.

$payment_method: The payment method instance array associated with this API request.

$amount: Current transaction amount.

$action: Transaction type, 'Void' or 'Force' supported.

Return value

bool Return TRUE on success.

See also

TransactServices.svc/ProcessCreditCard (Transaction API Guide)

3 calls to commerce_payleap_transaction_request()
commerce_payleap_capture_form_submit in includes/commerce_payleap.admin.inc
Submit handler: process a prior authorization capture via AIM.
commerce_payleap_rules_cancel_capture in ./commerce_payleap.rules.inc
Action: Cancel a pending transaction.
commerce_payleap_rules_capture_pending in ./commerce_payleap.rules.inc
Action: Capture a pending transaction.

File

./commerce_payleap.module, line 758
Implements PayLeap payment services for use in Drupal Commerce.

Code

function commerce_payleap_transaction_request($transaction, $payment_method, $amount, $action) {

  // Action can be Void, Capture.
  // Build the base profile request data.
  $api_request_data = array(
    'TransType' => $action,
    // The PNRef number of the original sale transaction.
    'PNRef' => $transaction->remote_id,
    'Amount' => $amount,
    'ExtData' => '<AuthCode>' . $transaction->data['auth_code']['0'] . '</AuthCode>',
    'CardNum' => '',
    'NameOnCard' => '',
    'ExpDate' => '',
    'Street' => '',
    'Zip' => '',
    'MagData' => '',
    'InvNum' => '',
    'CVNum' => '',
  );
  $payment_method['settings']['txn_payleap_type'] = $action == 'Void' ? PAYLEAP_TXN_TYPE_VOID : PAYLEAP_TXN_TYPE_FORCE;
  $response = commerce_payleap_request($payment_method, $api_request_data);
  $result = TRUE;
  $transaction->payload[REQUEST_TIME] = isset($response['xml']) ? $response['xml']
    ->asXML() : '';

  // If we didn't get an approval response code...
  if (!$response['status']) {

    // Display an error message but leave the transaction pending.
    drupal_set_message(t('PayLeap request failed'), 'error');
    drupal_set_message(check_plain($response['msg']), 'error');
    $result = FALSE;
  }
  else {
    drupal_set_message(t('@action request successfully.', array(
      '@action' => $action,
    )));

    // Update to new remote ID.
    $transaction->remote_id = isset($response['xml']->PNRef) ? (string) $response['xml']->PNRef : '';

    // Update the transaction amount to the actual capture amount.
    $transaction->data['auth_code'][] = isset($response['xml']) && isset($response['xml']->AuthCode) ? (string) $response['xml']->AuthCode : '';
    if ($response['status']) {

      // Set the remote and local status accordingly.
      switch ($action) {
        case 'Void':
          $transaction->status = PAYLEAP_PAYMENT_STATUS_CANCELED;
          break;
        case 'Force':
          $transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
          break;
      }
      $transaction->amount = commerce_currency_decimal_to_amount($amount, $transaction->currency_code);
    }
    $transaction->remote_status = $response['status'];
    $transaction->payload[REQUEST_TIME] = isset($response['xml']) ? $response['xml']
      ->asXML() : '';

    // Append a capture indication to the result message.
    $transaction->message .= implode('<br />', commerce_payleap_get_log_message($response, $payment_method['settings']['txn_payleap_type']));
  }
  commerce_payment_transaction_save($transaction);
  return $result;
}