'igac_payment', 'title' => t('Datos de facturación y pago.'), 'description' => t('Datos de facturación y pago.'), 'active' => TRUE, 'offsite_autoredirect' => false, 'offsite' => true, ); return $payment_methods; } function igac_payment_redirect_form($payment_method, $pane_values, $checkout_pane, $order) { $form = array(); // processing order. $order_load = $pane_values['build_info']['args'][0]; $order_load = commerce_order_load($order_load->order_number); $order_load->status = 'processing'; $response = igac_paymente_ws_send($pane_values['build_info']['args'][0]); drupal_add_js(drupal_get_path('module', 'igac_payment') . '/js/checkout-script.js'); drupal_add_js(array('igac_payment' => array('url' => $response)), 'setting'); //$order_load->field_factura['und'][0]['value']=$response->numeroFactura; $order = commerce_order_load($order_load->order_number); $cust_billing_profile_id= $order->commerce_customer_billing[LANGUAGE_NONE][0]['profile_id']; $profile=commerce_customer_profile_load($cust_billing_profile_id); $profile->commerce_customer_address['und'][0]['name_line']= strtoupper($order_load->data['igac_payment']['name'].' '.$order_load->data['igac_payment']['last_name']); $profile->commerce_customer_address['und'][0]['first_name']= strtoupper($order_load->data['igac_payment']['name']); $profile->commerce_customer_address['und'][0]['last_name'] = strtoupper($order_load->data['igac_payment']['last_name']); $profile->commerce_customer_address['und'][0]['thoroughfare']= strtoupper($order_load->data['igac_payment']['address']); $profile->commerce_customer_address['und'][0]['premise'] = strtoupper($order_load->data['igac_payment']['address']); $profile->field_identificacion['und'][0]['value'] = strtoupper($order_load->data['igac_payment']['identification']); commerce_customer_profile_save($profile); $order_load->commerce_customer_billing['und'][0]['profile_id'] = $profile->profile_id; commerce_order_save($order_load); /* dpm($profile); dpm($order_load);*/ //dpm($response); //_igac_payment_send_mail(); sleep(5); $form['redirect'] = FALSE; $form['link'] = array( '#type' => 'markup', '#markup' => '
Realizar pago' ); return $form; } /** * Payment method callback: submit form. */ function igac_payment_submit_form($payment_method, $pane_values, $checkout_pane, $order) { module_load_include('inc', 'igac_payment', 'igac_payment.form'); return igac_payment_card_form(); } /** * Payment method callback: submit form validation. */ function igac_payment_submit_form_validate($payment_method, $pane_form, $pane_values, $order, $form_parents = array()) { } /** * Payment method callback: submit form submission. */ function igac_payment_submit_form_submit($payment_method, $pane_form, $pane_values, $order, $charge) { // Just as an example, we might store information in the order object from the // payment parameters, though we would never save a full credit card number, // even in examples! drupal_add_js(array('igac_payment' => array('url' => 'google.com',)), 'setting'); $order->data['igac_payment'] = $pane_values; $order->data['igac_payment']['pane_form'] = $pane_form; // Every attempted transaction should result in a new transaction entity being // created for the order to log either the success or the failure. igac_payment_transaction($payment_method, $order, $charge); } /** * Creates an example payment transaction for the specified charge amount. * * @param $payment_method * The payment method instance object used to charge this payment. * @param $order * The order object the payment applies to. * @param $charge * An array indicating the amount and currency code to charge. */ function igac_payment_transaction($payment_method, $order, $charge) { $card_details = $order->data['igac_payment']; $transaction = commerce_payment_transaction_new('igac_payment', $order->order_id); $transaction->instance_id = $payment_method['instance_id']; $transaction->amount = $charge['amount']; $transaction->currency_code = $charge['currency_code']; $transaction->status = COMMERCE_PAYMENT_STATUS_PENDING; $transaction->message = 'identification type: @number
name: @name @last_name'; $transaction->message_variables = array( '@number' => $card_details['identification'], '@last_name' => $card_details['last_name'], '@name' => $card_details['name'], ); commerce_payment_transaction_save($transaction); return $transaction; } function igac_payment_clear_city($cadena) { $no_accept= array ("á","é","í","ó","ú","Á","É","Í","Ó","Ú","ñ","À","Ã","Ì","Ò","Ù","Ù","à ","è","ì","ò","ù","ç","Ç","â","ê","î","ô","û","Â","Ê","ÃŽ","Ô","Û","ü","ö","Ö","ï","ä","«","Ò","Ã","Ä","Ë"); $accept= array ("a","e","i","o","u","A","E","I","O","U","n","N","A","E","I","O","U","a","e","i","o","u","c","C","a","e","i","o","u","A","E","I","O","U","u","o","O","i","a","e","U","I","A","E"); $text = str_replace($no_accept, $accept ,$cadena); return $text; } function igac_paymente_ws_send($order) { $options = array(); $values = $order->data['igac_payment']; $order = commerce_order_load($order->order_number); $cust_billing_profile_id= $order->commerce_customer_shipping[LANGUAGE_NONE][0]['profile_id']; $customer_billing_profiles = entity_load('commerce_customer_profile', array($cust_billing_profile_id)); $city = igac_payment_clear_city($customer_billing_profiles[$cust_billing_profile_id]->commerce_customer_address['und'][0]['locality']); $dir = igac_payment_clear_city($customer_billing_profiles[$cust_billing_profile_id]->commerce_customer_address['und'][0]['thoroughfare']); $pais = igac_payment_clear_city($customer_billing_profiles[$cust_billing_profile_id]->commerce_customer_address['und'][0]['country']); $depto = igac_payment_clear_city($customer_billing_profiles[$cust_billing_profile_id]->commerce_customer_address['und'][0]['administrative_area']); $depto1 = igac_payments_departamento($depto); $city1 = igac_payments_municipio($depto,$city); $headers = array( 'Content-Type: application/json' ); $articles = array(); $fields = array( 'cliente' => array( 'identificacion' => $values['identification'], 'tipoIdentificacion' => $values['identification_type'], 'primerNombre' => strtoupper($values['name']), 'segundoNombre' => '', 'primerApellido' => strtoupper($values['last_name']), 'segundoApellido' => '', 'direccion'=> strtoupper($dir), 'telefono' => $values['phone'], 'contacto' => '', 'ciudad' => strtoupper($city), 'correoElectronico'=> strtoupper($values['mail']), 'pais' => '169', 'departamento' => $depto1, 'municipio' => $city1, ), 'articulos' => igac_payments_process_product_send($order), 'pago' => array( 'ipOrigen' => $order->hostname, 'numeroSolicitud' => $order->order_number, 'prefijoAplicacion' =>'TVR', 'descripcionPago' => 'Compra desde Tienda Virtual', 'successUrl' => 'https://tiendavirtual.igac.gov.co/', 'failureUrl' => 'https://tiendavirtual.igac.gov.co/', 'pendingUrl' => 'https://tiendavirtual.igac.gov.co/', 'reviewUrl' => 'https://tiendavirtual.igac.gov.co/', ) ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, PAYMENT_URL . '/iniciarPago'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($ch); //watchdog('igac_payment', $city, array(), WATCHDOG_ERROR); //watchdog('igac_payment', $city1, array(), WATCHDOG_ERROR); watchdog('igac_payment', json_encode($fields), array(), WATCHDOG_ERROR); //watchdog('igac_payment', $result, array(), WATCHDOG_ERROR); //watchdog('igac_payment',$ch, array(), WATCHDOG_ERROR); return $result; } function igac_payments_process_product_send($order) { if (isset($order->commerce_line_items[LANGUAGE_NONE])) { foreach ($order->commerce_line_items[LANGUAGE_NONE] as $product) { $line_load = commerce_line_item_load($product['line_item_id']); if ($line_load->type == 'product') { $item[] = array( //'descripcionPago' => igac_payments_load_product_name($line_load->commerce_product[LANGUAGE_NONE][0]['product_id']), 'codigo' => igac_payments_load_product_sku($line_load->commerce_product[LANGUAGE_NONE][0]['product_id']), 'cantidad' => round($line_load->quantity), ); $products = commerce_product_load($line_load->commerce_product[LANGUAGE_NONE][0]['product_id']); $products->commerce_stock[LANGUAGE_NONE][0]['value'] = $products->commerce_stock[LANGUAGE_NONE][0]['value']-round($line_load->quantity); commerce_product_save($products); } if ($line_load->type == 'shipping' && $line_load->data['service_details']['enable'] == 'Si') { $item[] = array( //'codigo' => 1768, 'codigo' => $line_load->commerce_unit_price[LANGUAGE_NONE][0]['data']['code'], 'cantidad' => 1 //'cantidad' => $order->commerce_order_total['und'][0]['data']['components'][1]['price']['amount'], ); } } } //dpm($line_load); return $item; } function igac_payments_load_product_sku($product) { $product_load = commerce_product_load($product); return $product_load->sku; } function igac_payments_load_product_name($product) { $product_load = commerce_product_load($product); return $product_load->title; } /** * Request the order and update in cart. */ /* function igac_paymente_get_payments() { $db = db_query("SELECT commerce_order.order_number AS commerce_order_order_number FROM commerce_order WHERE (( (commerce_order.status IN ('processing')) ))"); $result = $db->fetchAll(); foreach ($result as $record) { $order = $record->commerce_order_order_number; $order_load = commerce_order_load($order); $url = PAYMENT_URL . '/consultarPago?prefijoAplicacion=TVR&solicitud=' . $order; $response = drupal_http_request($url); //$codes = $response->code; //$datas = json_decode($response,true); if ($response->code == 56) { $data = json_decode($response->data); if ($data->existeFactura == true) { $order_load->field_factura['und'][0]['value'] = $data->pagos[0]->numeroFactura; if ($data->pagos[0]->estadoPago == 'PAGADO') { $order_load->status = 'completed'; }else if ($data->pagos[0]->estadoPago == 'RECHAZADO') { $order_load->status = 'canceled'; }else if ($data->pagos[0]->estadoPago == 'ABANDONADO') { $order_load->status = 'canceled'; } commerce_order_save($order_load); } } //watchdog('codes', $codes, WATCHDOG_ERROR); //watchdog('datas', $datas, WATCHDOG_ERROR); } } */ function igac_paymente_get_payments() { $db = db_query("SELECT commerce_order.order_number AS commerce_order_order_number FROM commerce_order WHERE (( (commerce_order.status IN ('processing')) )) order by commerce_order.created desc limit 0,40 "); $result = $db->fetchAll(); foreach ($result as $record) { $order = $record->commerce_order_order_number; $order_load = commerce_order_load($order); $url = PAYMENT_URL . '/consultarPago?prefijoAplicacion=TVR&solicitud=' . $order; $cURL = curl_init(); curl_setopt($cURL, CURLOPT_URL, $url); curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true); curl_setopt($cURL, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Accept: application/json' )); $result = curl_exec($cURL); $http_code = curl_getinfo($cURL, CURLINFO_HTTP_CODE); //watchdog('http_code', "http_code ".$http_code, array(), WATCHDOG_ERROR); if ($http_code == intval(200)) { $json = json_decode($result, true); //watchdog('result', "result: ". $result, array(), WATCHDOG_ERROR); if($json["existeFactura"] == 1){ //watchdog('existeFactura', "existeFactura: ". $json["existeFactura"], array(), WATCHDOG_ERROR); $numero_fact = 0; $estado_pago = ""; foreach ($json["pagos"] as $pagos) { $numero_fact = $pagos["numeroFactura"]; $estado_pago = $pagos["estadoPago"]; } //watchdog('orden-numeroFactura-estado', "orden-numeroFactura-estado: ".$order."-". $numero_fact."-".$estado_pago, array(), WATCHDOG_ERROR); $order_load->field_factura['und'][0]['value'] = $numero_fact; $order_load->status = 'completed'; commerce_order_save($order_load); } } else { watchdog('Resource NOTOK', "Resource NOTOK". $http_code, array(), WATCHDOG_ERROR); } } } /** * Implements hook_cron(). */ function igac_payment_cron() { // Update the orders. igac_paymente_get_payments(); } /** * Implements hook_form_FORM_ID_alter(). for user_login */ function igac_payment_form_commerce_checkout_form_login_alter(&$form, &$form_state) { // ldap_servers_module_load_include('inc', 'ldap_authentication', 'ldap_authentication'); // _ldap_authentication_login_form_alter($form, $form_state, 'user_login'); // $form = array(); // $form['login_pane']['links']["#markup"] = // '