You are here

function commerce_payleap_transaction_process in Commerce Payleap 7

Proceed to the payment and record a transaction.

2 calls to commerce_payleap_transaction_process()
commerce_payleap_cof_submit_form_submit in ./commerce_payleap.module
Payment method callback: checkout form submission - Card on file.
commerce_payleap_direct_submit_form_submit in ./commerce_payleap.module
Payment method callback: checkout form submission - Direct.

File

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

Code

function commerce_payleap_transaction_process($payment_method, $info, $order, $charge) {

  // Submit the request to PayLeap.
  $response = commerce_payleap_request($payment_method, $info);

  // Prepare a transaction object to log the API response.
  $transaction = commerce_payment_transaction_new($payment_method['settings']['txn_payleap_type'], $order->order_id);
  $transaction->instance_id = $payment_method['instance_id'];
  $transaction->remote_id = isset($response['xml']->PNRef) ? (string) $response['xml']->PNRef : '';
  $transaction->amount = $charge['amount'];
  $transaction->currency_code = $charge['currency_code'];
  $transaction->payload[REQUEST_TIME] = isset($response['xml']) ? $response['xml']
    ->asXML() : '';

  // Store the Message of transaction in the remote status.
  $transaction->remote_status = $response['status'];
  $transaction->message = implode('<br />', commerce_payleap_get_log_message($response, $payment_method['settings']['txn_payleap_type']));

  // Set the transaction status based on the type of transaction this was.
  if ($payment_method['settings']['txn_payleap_type'] == PAYLEAP_TXN_TYPE_DIRECT_CAPTURE && $payment_method['settings']['txn_type'] == COMMERCE_CREDIT_AUTH_ONLY) {
    $transaction->status = COMMERCE_PAYMENT_STATUS_PENDING;
  }
  else {
    if ($response['status']) {
      $transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
    }
    else {
      $transaction->status = COMMERCE_PAYMENT_STATUS_FAILURE;
    }
  }

  // If we didn't get an approval response code.
  // Create a failed transaction with the error message.
  // Save auth code.
  $transaction->data['auth_code'][] = isset($response['xml']) && isset($response['xml']->AuthCode) ? (string) $response['xml']->AuthCode : '';

  // Save the transaction information.
  commerce_payment_transaction_save($transaction);

  // If the payment failed, display an error and rebuild the form.
  if (!$response['status']) {
    drupal_set_message(t('We received the following error processing your card. Please enter you information again or try a different card.'), 'error');
    if (!empty($response['msg'])) {
      drupal_set_message(check_plain($response['msg']), 'error');
    }
    return FALSE;
  }
  return TRUE;
}