You are here

function commerce_sermepa_process_transaction in Commerce sermepa 7

Save the payment transaction for the order.

Parameters

commerce_order $order: The loaded order that is being processed.

array $payment_method: The payment method settings.

array $feedback_parameters: An associative array of feedback merchant parameters values:

  • Ds_Date: Transaction date (dd/mm/yyyy).
  • Ds_Hour: Transaction time (HH:mm).
  • Ds_Amount: Same of the transaction.
  • Ds_Currency: Same of the transaction.
  • Ds_Order: Same of the transaction.
  • Ds_MerchantCode: Same of the transaction.
  • Ds_Terminal: Assigned by Sermepa.
  • Ds_Response: Response values, see $this->handleResponse.
  • Ds_MerchantData: Optional sended from commerce form.
  • Ds_SecurePayment: 0 for no secure payment, 1 for secure.
  • Ds_TrasactionType: Trasaction type sended from commerce form.
  • Ds_Card_Country: (Optional) Country of issuance of the card that has tried to make the payment..
  • Ds_AuthorisationCode: (Optional) Assigned authorisation code.
  • Ds_ConsumerLanguage: (Optional) 0 indicates that has not been determined the customer's language..
  • Ds_Card_Type: (Optional) C for credit, D for debit.

boolean $redirect: Specifies whether to call redirect functions or not.

3 calls to commerce_sermepa_process_transaction()
commerce_sermepa_callback in ./commerce_sermepa.module
Get POST response from sermepa.
commerce_sermepa_process_callback in ./commerce_sermepa.module
Process callback information from Sermepa.
commerce_sermepa_submit_form_submit in ./commerce_sermepa.module
Payment method callback: submit form submission.

File

./commerce_sermepa.module, line 555
Provides a payment method for Drupal Commerce using Sermepa/Redsys gateway.

Code

function commerce_sermepa_process_transaction($order, $payment_method, $feedback_parameters, $redirect = TRUE) {
  $authorisation_code = $feedback_parameters['Ds_AuthorisationCode'];
  $transaction_id = commerce_sermepa_get_payment_transaction($authorisation_code);
  if (!$transaction_id) {
    $transaction = commerce_payment_transaction_new('commerce_sermepa', $order->order_id);
  }
  else {
    $transaction = commerce_payment_transaction_load($transaction_id);
  }

  // Handle the response of the bank.
  if (!class_exists('Sermepa')) {
    libraries_load('sermepa');
  }
  $response_code = $feedback_parameters['Ds_Response'];
  $transaction_status = array(
    'code' => $response_code <= 99 ? COMMERCE_PAYMENT_STATUS_SUCCESS : COMMERCE_PAYMENT_STATUS_FAILURE,
    'message' => Sermepa::handleResponse($response_code),
  );
  $transaction->instance_id = $payment_method['instance_id'];
  $transaction->amount = $order->commerce_order_total[LANGUAGE_NONE][0]['amount'];
  $transaction->currency_code = $order->commerce_order_total[LANGUAGE_NONE][0]['currency_code'];
  $transaction->remote_id = $authorisation_code;
  $transaction->remote_status = $feedback_parameters['Ds_Response'];
  $transaction->status = $transaction_status['code'];
  if ($transaction_status['code'] == COMMERCE_PAYMENT_STATUS_SUCCESS) {
    $transaction->message = 'Transaction accepted with id @transaction_id';
  }
  elseif ($transaction_status['code'] == COMMERCE_PAYMENT_STATUS_FAILURE) {
    $transaction->message = 'Error for the transaction with id @transaction_id: ' . $transaction_status['message'];
  }
  $transaction->message_variables = array(
    '@transaction_id' => $authorisation_code,
  );
  commerce_payment_transaction_save($transaction);
  if ($redirect) {
    if ($transaction_status['code'] == COMMERCE_PAYMENT_STATUS_FAILURE) {
      commerce_payment_redirect_pane_previous_page($order);
    }
    else {
      commerce_payment_redirect_pane_next_page($order);
    }
  }
}