orders[] = $order; } } else { foreach ($order as $o) { if (var_is_object_of_class($o, 'fianet_order_xml')) { $this->orders[] = $o; } } } } //Envoie toutes les commandes une par une function send_orders_singet() { if (!count($this->orders) > 0) { fianet_insert_log("fianet_sender.php - send_orders_singet()
\nNo order to send."); return; } if (!$this->check_order_data()) { fianet_insert_log("fianet_sender.php - send_orders_singet()
\nOrders list is not valid."); return; } foreach ($this->orders as $order) { $xml = '' . "\n"; $xml .= $order->get_xml(); $data['siteid'] = $order->info_commande->siteid; $data['controlcallback'] = clean_xml($xml); $this->send_fsock_singet($data); } } //Envoie les commandes par lot de 25 function send_orders_stacking() { if (!count($this->orders) > 0) { fianet_insert_log("fianet_sender.php - send_orders_stackfast()
\nNo order to send."); return; } if (!$this->check_order_data()) { fianet_insert_log("fianet_sender.php - send_orders_stackfast()
\nOrders list is not valid."); return; } $stack = array(); $count = 0; $results = array(); foreach ($this->orders as $order) { if ($count < 25) { $count++; $stack[] = $order; } elseif ($count == 25) { $results = array_merge($results, $this->process_stack($stack)); $stack = array(); $stack[] = $order; $count = 1; } } $results = array_merge($results, $this->process_stack($stack)); return ($results); } //Recupère une liste d'évaluations function get_evaluation($order_list, $Separ = ',') { $evaluations = array(); if (count($order_list) > 0) { $order_list_by_stack = array_chunk($order_list, 50, true); foreach ($order_list_by_stack as $stack) { $evaluations = array_merge($this->get_evaluation_by_stack($stack, $Separ), $evaluations); } } return ($evaluations); } function get_evaluation_by_stack($order_list, $Separ = ',') { if (count($order_list) > 0) { if ($this->mode == 'production') { $url = URL_SAC_PROD; } else { $url = URL_SAC_TEST; } $siteid = FIANET_SAC_SITE_ID; $pwd = FIANET_SAC_PWD; $mode = 'mini'; $repFT = '0'; $listID = ''; foreach ($order_list as $id_order) { if ($listID != '') { $listID .= $Separ . $id_order; } else { $listID .= $id_order; } } $data['SiteID'] = $siteid; $data['Pwd'] = $pwd; $data['Mode'] = $mode; $data['RepFT'] = $repFT; $data['ListID'] = $listID; $data['Separ'] = $Separ; $s = new fianet_socket($url, URl_SAC_GETVALIDSTACK, 'POST', $data); $result = $s->send(); $evaluations = array(); if ($result === false) { fianet_insert_log("fianet_sender.php - get_evaluation()
\nError when opening file :
\n".$url); } else { $xmldata = $result['data']; $xml_array = xml2array($xmldata); //debug($xml_array); $evaluations = $this->process_result($xml_array); return ($evaluations); } return ($evaluations); } } /* méthodes privées */ function process_result($xml_array) { $evaluations = array(); //debug($xml_array, 'xml_array'); if (isset($xml_array['stack']['result'])) { if (isset($xml_array['stack']['result'][0])) { foreach ($xml_array['stack']['result'] as $res) { if (eregi("error", $res['attr']['retour'])) { fianet_insert_log("fianet_sender.php - process_result()
\nErreur :
\n".$res['attr']['message']); } else { //$index = count($evaluations); //$evaluations[$index] = $this->process_result_array($res); $eval = $this->process_result_array($res); if ($eval['refid'] != null) { $evaluations[$eval['refid']] = $eval; } } } } else { $res = $xml_array['stack']['result']; if (eregi("error", $res['attr']['retour'])) { fianet_insert_log("fianet_sender.php - process_result()
\nErreur :
\n".$res['attr']['message']); } else { //$index = count($evaluations); $eval = $this->process_result_array($res); if ($eval['refid'] != null) { $evaluations[$eval['refid']] = $eval; } } } } elseif (isset($xml_array['result']['transaction'])) { if (isset($xml_array['result']['transaction'][0])) { foreach ($xml_array['result']['transaction'] as $transaction) { $eval = $this->process_transaction_array($transaction); //debug($eval); if ($eval['refid'] != null) { $evaluations[$eval['refid']] = $eval; } } } else { $transaction = $xml_array['result']['transaction']; $eval = $this->process_transaction_array($transaction); if ($eval['refid'] != null) { $evaluations[$eval['refid']] = $eval; } } } return ($evaluations); } function process_result_array($res) { //debug($res, 'Result'); $eval['refid'] = $res['attr']['refid']; if ( $res['attr']['retour'] == 'absente') { $eval['info'] = 'absente'; } else { if (isset($res['transaction'][0])) { $transaction = end($res['transaction']); } else { $transaction = $res['transaction']; } $etat = $this->process_transaction_array($transaction); $eval['eval'] = $etat['eval']; $eval['info'] = $etat['info']; $eval['cid'] = $etat['cid']; } return ($eval); } function process_transaction_array($transaction) { $eval = array(); //debug($transaction); if ($transaction['attr']['avancement'] == 'error') { $eval['eval'] = 'error'; $eval['info'] = $transaction['detail']['value']; $eval['cid'] = ''; $eval['refid'] = $transaction['attr']['refid']; } elseif ($transaction['attr']['avancement'] == 'encours') { $eval['eval'] = 'encours'; $eval['info'] = $transaction['detail']['value']; $eval['cid'] = ''; $eval['refid'] = $transaction['attr']['refid']; } elseif ($transaction['attr']['avancement'] == 'traitee') { $eval['eval'] = $transaction['analyse']['eval']['value']; $eval['info'] = $transaction['analyse']['eval']['attr']['info']; $eval['cid'] = $transaction['attr']['cid']; $eval['refid'] = $transaction['attr']['refid']; } return ($eval); } function process_stack($stack) { $xml = '' . "\n"; $xml .= '' . "\n"; foreach ($stack as $order) { $xml .= $order->get_xml(); if (!isset($siteid)) { $siteid = $order->info_commande->siteid; } } $xml .= ''; $data['siteid'] = $siteid; $data['controlcallback'] = clean_xml($xml); $result = array(); $result = $this->send_fsock_stacking($data); return ($result); } function process_result_stacking($xml_data) { $result = array(); $xml_array = xml2array($xml_data); //debug($xml_array); if (isset($xml_array['validstack']['unluck'])) { fianet_insert_log("fianet_sender.php - process_result_stacking()
\nError :
\n".$xml_array['validstack']['unluck']['value']); return ($result); } elseif (isset($xml_array['validstack']['result'])) { $xml_array = $xml_array['validstack']['result']; //debug($xml_array); if (isset($xml_array[0])) { foreach ($xml_array as $transaction_result) { $index = count($result); $result[$index]['refid'] = $transaction_result['attr']['refid']; $result[$index]['etat'] = $transaction_result['attr']['avancement']; $result[$index]['details'] = $transaction_result['detail']['value']; } } else { $index = count($result); $result[$index]['refid'] = $xml_array['attr']['refid']; $result[$index]['etat'] = $xml_array['attr']['avancement']; $result[$index]['details'] = $xml_array['detail']['value']; } } return ($result); } function check_order_data() { $res = true; foreach ($this->orders as $order) { if (!var_is_object_of_class($order, 'fianet_order_xml')) { $res = false; } } return ($res); } function send_fsock_singet($data) { if ($this->mode == 'production') { $url_action = URL_SAC_PROD; } else { $url_action = URL_SAC_TEST; } $path = URl_SAC_SINGET; $s = new fianet_socket($url_action, $path, 'GET', $data); $res = $s->send(); if ($res === false) { fianet_insert_log("fianet_sender.php - send_fsock_post()
\nError when connecting :
\n".$url_action . $path); return (false); } return (true); } function send_fsock_stacking($data) { if ($this->mode == 'production') { $url_action = URL_SAC_PROD; } else { $url_action = URL_SAC_TEST; } $path = URl_SAC_STACKING; $s = new fianet_socket($url_action, $path, 'POST', $data); $res = $s->send(); if ($res === false) { fianet_insert_log("fianet_sender.php - send_fsock_post()
\nError when connecting :
\n".$url_action . $path); return (false); } else { $result = $this->process_result_stacking($res['data']); return ($result); } } function get_reevaluated_order() { if ($this->mode == 'production') { $url_action = URL_SAC_PROD; } else { $url_action = URL_SAC_TEST; } $path = URl_SAC_GETALERT; $mode = 'new'; $output = 'mini'; $repFT = '0'; $data['SiteID'] = FIANET_SAC_SITE_ID; $data['Pwd'] = FIANET_SAC_PWD; $data['Mode'] = $mode; $data['Output'] = $output; $data['RepFT'] = $repFT; $s = new fianet_socket($url_action, $path, "POST", $data); $res = $s->send(); $evaluations = array(); if ($res === false) { fianet_insert_log("fianet_sender.php - get_reevaluated_order()
\nError when opening file :
\n".$url); } else { $xmldata = $res['data']; //Le code commenté suivant permet de tester la réception d'une réevaluation /*$xmldata = ' Paiement validé 100 Transactions à traiter/Nouvelles/Contrôle visuel Paiement validé 100 Transactions à traiter/Nouvelles/Contrôle visuel ';*/ $xml_array = xml2array($xmldata); if (isset($xml_array['result']['attr']['retour'])) { if ($xml_array['result']['attr']['retour'] == "param_error") { fianet_insert_log("fianet_sender.php - get_reevaluated_order()
\nParam_error :
\n".$xml_array['result']['attr']['message']."\n
$url_action"); } } $evaluations = $this->process_result($xml_array); } return ($evaluations); } }