/**
  * Relay response: order processing
  */
 protected function relayResponseProcessOrder(&$context)
 {
     $response = $context['response'];
     $state =& $context['state'];
     // Exit if no order
     if (empty($response['commerce_order_id'])) {
         return;
     }
     // Reference order in resolved state
     $order =& $state['order'];
     $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
     // Save transaction
     $transaction = $this->controller->saveTransaction($response, $state);
     if ($transaction) {
         $state['transaction'] = $transaction;
     }
     // If this order does not have a billing profile yet ...
     if ($order_wrapper->commerce_customer_billing->value() === NULL) {
         // Create new and set address to resolved billing address from response
         $billing_profile = commerce_customer_profile_new('billing', $order->uid);
         $billing_profile_wrapper = entity_metadata_wrapper('commerce_customer_profile', $billing_profile);
         $billing_profile_wrapper->commerce_customer_address = $state['billing_address'] + addressfield_default_values();
         $billing_profile_wrapper->save();
         $order_wrapper->commerce_customer_billing = $billing_profile_wrapper;
         $order_wrapper->save();
         watchdog('commerce_firstdata_gge4', 'Billing profile created for Order @order_number containing the address data from the offsite Hosted Payment Page.', array('@order_number' => $order->order_number));
     }
     /** @todo need this or checkout pane handle it? paypal does this ... **/
     if (!empty($response['transaction_approved'])) {
         // Send the customer on to the next checkout page.
         commerce_payment_redirect_pane_next_page($order, t('Customer successfully submitted payment at the payment gateway.'));
     } else {
         // Otherwise send the customer back.
         commerce_payment_redirect_pane_previous_page($order, t('Customer payment submission failed at the payment gateway.'));
     }
 }
function take_action($order, $rta2)
{
    $order = commerce_order_load($order);
    $payment_method = commerce_payment_method_instance_load('bank_transfer|commerce_payment_bank_transfer');
    $settings = $payment_method["settings"];
    if ($rta2["StatusCode"] == "-1") {
        $status = $settings["status"]["aprobada"];
        $transaction = commerce_payment_transaction_new('bank_transfer', $order->order_id);
        $transaction->instance_id = $payment_method['instance_id'];
        $transaction->amount = $rta2["Payload"]["Request"]["AMOUNT"] * 100;
        $transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
        $transaction->payload = print_r($rta2["Payload"], 1);
        $transaction->remote_id = $rta2["Payload"]["Answer"]["OPERATIONID"];
        commerce_payment_transaction_save($transaction);
        commerce_order_status_update($order, $status);
        drupal_goto(commerce_checkout_order_uri($order));
    } else {
        if ($rta2["Payload"]["Answer"]["BARCODETYPE"] != "") {
            $transaction = commerce_payment_transaction_new('bank_transfer', $order->order_id);
            $transaction->instance_id = $payment_method['instance_id'];
            $transaction->amount = $rta2["Payload"]["Request"]["AMOUNT"] * 100;
            $transaction->status = COMMERCE_PAYMENT_STATUS_PENDING;
            $transaction->payload = print_r($rta2["Payload"], 1);
            $transaction->remote_id = $rta2["Payload"]["Answer"]["OPERATIONID"];
            commerce_payment_transaction_save($transaction);
            $status = $settings["status"]["offline"];
            ?>
        
            <div id="content" style="width: 75%;">
	     	<div><div class="titulos">Nro de Operaci&oacute;n:</div><em><strong><?php 
            echo $order->order_id;
            ?>
</strong></em><hr></div>
            <div><div class="titulos">Total a pagar</div>$ <?php 
            echo $rta2["Payload"]["Request"]["AMOUNT"] . ".-";
            ?>
<hr></div>
        	<div class="titulos"><h3>DATOS PERSONALES<h3><hr></div>
	        <div><div class="titulos">Nombre</div> <?php 
            echo $user->name;
            ?>
 <hr></div>
<?php 
            if ($rta2["Payload"]["Answer"]["PAYMENTMETHODNAME"] == "PAGOFACIL") {
                $empresa = "PAGO FACIL";
            } else {
                $empresa = "RAPIPAGO";
            }
            $barcode = "12345678";
            if (!empty($rta2["Payload"]["Answer"]["BARCODE"])) {
                $barcode = $rta2["Payload"]["Answer"]["BARCODE"];
            }
            ?>
	       <div><div class="titulos">Podr&aacute;s pagar este cup&oacute;n en los locales de:</div><?php 
            echo $empresa;
            ?>
<hr></div>
<?php 
            echo "<img   src='" . $base_path . drupal_get_path('module', 'commerce_todo_pago') . "/includes/image.php?filetype=PNG&dpi=72&scale=5&rotation=0&font_family=Arial.ttf&font_size=8&text=" . $barcode . "&thickness=30&checksum=&code=BCGi25&' />";
            ?>
            <br /> 
            	<div class="right">
            		<input type="button" name="imprimir" value="Imprimir" onclick="window.print();" class="button">
            		<a href="<?php 
            echo commerce_checkout_order_uri($order);
            ?>
">Click aca para continuar.</a>
            	</div>
            	<br />
            </div>
<?php 
            commerce_order_status_update($order, $status);
        } else {
            _tranUpdate($order->order_id, array("first_step" => null, "second_step" => null));
            if ($rta2["StatusCode"] == 404) {
                drupal_goto('<front>');
                return;
            }
            $status = $settings["status"]["rechazada"];
            commerce_order_status_update($order, $status);
            drupal_set_message(t('Hubo un error en la transaccion, intente nuevamente'), 'error');
            commerce_payment_redirect_pane_previous_page($order);
            drupal_goto(commerce_checkout_order_uri($order));
        }
    }
}