/** * build xml with customer's and order's data et send it to FIA-NET * * @param int $id_order * @return boolean */ public function sendXML($id_order) { $order = new Order($id_order); $montant = $order->total_paid; $date = $order->date_add; $customer = new Customer($order->id_customer); $lastname = $customer->lastname; $firstname = $customer->firstname; $id_currency = $order->id_currency; $currency = new Currency($id_currency); if (_PS_VERSION_ < '1.5') { $civility = $customer->id_gender; $accepted_civility = array("1", "2", "3"); if (!in_array($civility, $accepted_civility)) { $civility = '1'; } } else { $gender = new Gender($customer->id_gender); $id_lang = Language::getIdByIso($this->context->language->iso_code); $civility = $gender->name[$id_lang] == 'Mr.' ? 1 : 2; } //xml construction if (_PS_VERSION_ < '1.5') { $fianetsceau = new Sceau(); } else { $fianetsceau = new Sceau((int) $order->id_shop); } $utilisateur = new SceauXMLElement('<utilisateur></utilisateur>'); $nom = $utilisateur->childNom($customer->lastname); $nom->addAttribute('titre', $civility); $utilisateur->childPrenom($customer->firstname); $utilisateur->childEmail(strtolower($customer->email)); $infocommande = new SceauXMLElement('<infocommande></infocommande>'); $infocommande->childSiteid($fianetsceau->getSiteid()); $infocommande->childRefid($id_order); $montant = $infocommande->childMontant($order->total_paid); $montant->addAttribute('devise', $currency->iso_code); $ip = new SceauXMLElement('<ip>' . $this->getCustomerIP($id_order) . '</ip>'); $ip->addAttribute('timestamp', $order->date_add); $infocommande->childIp($ip); $paiement = new SceauXMLElement('<paiement></paiement>'); $paiement->childType($this->getPaymentFianetType($id_order)); $lang = Language::getIsoById($order->id_lang); $langue = $infocommande->childLangue($lang); $xml_order = new SceauControl(); $xml_order->childUtilisateur($utilisateur); $xml_order->childInfocommande($infocommande); $xml_order->childPaiement($paiement); $fianetsceau->addCrypt($xml_order); $result = $fianetsceau->sendSendrating($xml_order); if (!($result === false)) { $resxml = new SceauXMLElement($result); if ($resxml->getAttribute('type') != "OK") { //update fianetsceau_state 3:error $this->updateOrder($id_order, array('id_fianetsceau_state' => '3')); SceauLogger::insertLogSceau(__METHOD__ . " : " . __LINE__, 'Order ' . $id_order . ' XML Send error : ' . $resxml->getChildByName('detail')->getValue()); return false; } else { //update fianetsceau_state 2:sent $this->updateOrder($id_order, array('id_fianetsceau_state' => '2')); } return true; } else { //update fianetsceau_state 3:error $this->updateOrder($id_order, array('id_fianetsceau_state' => '3')); SceauLogger::insertLogSceau(__METHOD__ . " : " . __LINE__, 'Order ' . $id_order . ' XML Send error : ' . $resxml->getChildByName('detail')->getValue()); return false; } }