function _parse_ticket($ticket_xml)
 {
     // This XML parser gives us almost what we need, just tidy it up a bit
     $p = new XMLParser($ticket_xml);
     $result = $p->getOutput();
     if (@$result['ticket'] == '') {
         return $result;
     }
     $result = $result['ticket'];
     $result['id'] = $result['token'];
     //### FIXME: Remove when token renamed in service
     return $result;
 }
 function parseProductDetails($data)
 {
     $productList = new DobaProducts();
     $p = new XMLParser($data);
     $ProdDetails = $p->getOutput();
     if ($ProdDetails['dce']['response']['outcome'] == 'success') {
         if (array_key_exists('product', $ProdDetails['dce']['response']['products'])) {
             //Only 1 product;
             $prod = $ProdDetails['dce']['response']['products']['product'];
             $tempDPDArray = DobaProductAPI::findItems($prod);
             foreach ($tempDPDArray as $currProd) {
                 $currProd->product_id($prod['product_id']);
                 $currProd->title($prod['title']);
                 $currProd->description($prod['description']);
                 DobaProductAPI::findImage($prod, $currProd);
                 $currProd->product_sku($prod['product_sku']);
                 $currProd->ship_weight($prod['ship_weight']);
                 $currProd->ship_cost($prod['ship_cost']);
                 $currProd->upc($prod['upc']);
                 $currProd->brand($prod['brand']);
                 if (isset($prod['OSC_BRAND'])) {
                     $currProd->brand($prod['OSC_BRAND']);
                 }
                 $currProd->category_name('');
                 if (isset($prod['OSC_CATEGORY'])) {
                     $currProd->category_name($prod['OSC_CATEGORY']);
                 }
                 //Set Price
                 if (isset($prod['OSC_WHOLESALE_MARKUP_PERCENT'])) {
                     $currProd->price(DobaInteraction::setPrice('osc_wholesale_markup_percent', $prod['OSC_WHOLESALE_MARKUP_PERCENT'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                 } elseif (isset($prod['OSC_WHOLESALE_MARKUP_DOLLAR'])) {
                     $currProd->price(DobaInteraction::setPrice('osc_wholesale_markup_dollar', $prod['OSC_WHOLESALE_MARKUP_DOLLAR'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                 } elseif (isset($prod['OSC_MARKUP_EXACT'])) {
                     $currProd->price(DobaInteraction::setPrice('osc_markup_exact', $prod['OSC_MARKUP_EXACT'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                 } elseif (isset($prod['OSC_MSRP_MARKUP_PERCENT'])) {
                     $currProd->price(DobaInteraction::setPrice('osc_msrp_markup_percent', $prod['OSC_MSRP_MARKUP_PERCENT'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                 } elseif (isset($prod['OSC_MSRP_MARKUP_DOLLAR'])) {
                     $currProd->price(DobaInteraction::setPrice('osc_msrp_markup_dollar', $prod['OSC_MSRP_MARKUP_DOLLAR'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                 } else {
                     $currProd->price(DobaInteraction::setPrice('none', $currProd->wholesale_price(), $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                 }
                 //Set Quantity
                 if (isset($prod['OSC_QUANTITY_AUTOADJUST'])) {
                     $currProd->quantity(DobaInteraction::setQuantity('osc_quantity_autoadjust', $prod['OSC_QUANTITY_AUTOADJUST'], $currProd->quantity));
                 } elseif (isset($prod['OSC_QUANTITY_EXACT'])) {
                     $currProd->quantity(DobaInteraction::setQuantity('osc_quantity_exact', $prod['OSC_QUANTITY_EXACT'], $currProd->quantity));
                 } else {
                     $currProd->quantity(DobaInteraction::setQuantity('none', $currProd->quantity, $currProd->quantity));
                 }
                 $productList->addProduct($currProd);
             }
         } else {
             foreach ($ProdDetails['dce']['response']['products'] as $prod) {
                 $tempDPDArray = DobaProductAPI::findItems($prod);
                 foreach ($tempDPDArray as $currProd) {
                     $currProd->product_id($prod['product_id']);
                     $currProd->title($prod['title']);
                     $currProd->description($prod['description']);
                     DobaProductAPI::findImage($prod, $currProd);
                     $currProd->product_sku($prod['product_sku']);
                     $currProd->ship_weight($prod['ship_weight']);
                     $currProd->ship_cost($prod['ship_cost']);
                     $currProd->upc($prod['upc']);
                     $currProd->brand($prod['brand']);
                     if (isset($prod['OSC_BRAND'])) {
                         $currProd->brand($prod['OSC_BRAND']);
                     } else {
                         if (isset($prod['osc_brand'])) {
                             $currProd->brand($prod['osc_brand']);
                         }
                     }
                     $currProd->category_name('');
                     if (isset($prod['OSC_CATEGORY'])) {
                         $currProd->category_name($prod['OSC_CATEGORY']);
                     } else {
                         if (isset($prod['osc_category'])) {
                             $currProd->category_name($prod['osc_category']);
                         }
                     }
                     //Set Price
                     if (isset($prod['OSC_WHOLESALE_MARKUP_PERCENT'])) {
                         $currProd->price(DobaInteraction::setPrice('osc_wholesale_markup_percent', $prod['OSC_WHOLESALE_MARKUP_PERCENT'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                     } elseif (isset($prod['OSC_WHOLESALE_MARKUP_DOLLAR'])) {
                         $currProd->price(DobaInteraction::setPrice('osc_wholesale_markup_dollar', $prod['OSC_WHOLESALE_MARKUP_DOLLAR'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                     } elseif (isset($prod['OSC_MARKUP_EXACT'])) {
                         $currProd->price(DobaInteraction::setPrice('osc_markup_exact', $prod['OSC_MARKUP_EXACT'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                     } elseif (isset($prod['OSC_MSRP_MARKUP_PERCENT'])) {
                         $currProd->price(DobaInteraction::setPrice('osc_msrp_markup_percent', $prod['OSC_MSRP_MARKUP_PERCENT'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                     } elseif (isset($prod['OSC_MSRP_MARKUP_DOLLAR'])) {
                         $currProd->price(DobaInteraction::setPrice('osc_msrp_markup_dollar', $prod['OSC_MSRP_MARKUP_DOLLAR'], $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                     } else {
                         $currProd->price(DobaInteraction::setPrice('none', $currProd->wholesale_price(), $currProd->wholesale_price(), $currProd->map(), $currProd->msrp()));
                     }
                     //Set Quantity
                     if (isset($prod['OSC_QUANTITY_AUTOADJUST'])) {
                         $currProd->quantity(DobaInteraction::setQuantity('osc_quantity_autoadjust', $prod['OSC_QUANTITY_AUTOADJUST'], $currProd->quantity));
                     } elseif (isset($prod['OSC_QUANTITY_EXACT'])) {
                         $currProd->quantity(DobaInteraction::setQuantity('osc_quantity_exact', $prod['OSC_QUANTITY_EXACT'], $currProd->quantity));
                     } else {
                         $currProd->quantity(DobaInteraction::setQuantity('none', $currProd->quantity, $currProd->quantity));
                     }
                     $productList->addProduct($currProd);
                 }
             }
         }
         return $productList;
     } else {
         return $ProdDetails['dce']['response']['outcome'];
     }
 }
 /**
  * 
  * @return DobaOrders object
  * @param $data XML string
  */
 function parseGetOrderDetailResponse($data)
 {
     $orderList = new DobaOrders();
     $p = new XMLParser($data);
     $orderDetails = $p->getOutput();
     if ($orderDetails['dce']['response']['outcome'] == 'Success') {
         $tempDobaOrderArray = new DobaOrders();
         if (array_key_exists('order', $orderDetails['dce']['response']['orders'])) {
             //only one order;
             $tempPO = $orderDetails['dce']['response']['orders']['order']['order_id'];
             $tmpName = DobaOrdersAPI::name_to_parts($orderD['dce']['response']['orders']['order']['ship_name']);
             if (array_key_exists('supplier_order', $orderDetails['dce']['response']['orders']['order']['supplier_orders'])) {
                 //Only 1 supplier_order;
                 $ord = $orderDetails['dce']['response']['orders']['order']['supplier_orders']['supplier_order'];
                 $tempDobaOrderArray = DobaOrdersAPI::findItems($ord);
                 foreach ($tempDobaOrderArray as $currOrder) {
                     $currOrder->po_number($ord['order_id']);
                     $currOrder->max_expected_total($ord['order_total']);
                     $currOrder->first_name($tmpName['FirstName']);
                     $currOrder->last_name($tmpName['LastName']);
                     $currOrder->street($ord['ship_street']);
                     $currOrder->city($ord['ship_city']);
                     $currOrder->postal($ord['ship_postal']);
                     $currOrder->country($ord['ship_country']);
                     $orderList->addOrder($currOrder);
                 }
             } else {
                 //What does multiple supplier_order mean???
             }
             return $orderList;
         } else {
             foreach ($orderDetails['dce']['response']['orders'] as $ord) {
                 $tempPO = $orderDetails['dce']['response']['orders']['order']['order_id'];
                 $tmpName = DobaOrdersAPI::name_to_parts($orderD['dce']['response']['orders']['order']['ship_name']);
                 if (array_key_exists('supplier_order', $orderDetails['dce']['response']['orders']['order']['supplier_orders'])) {
                     //Only 1 supplier_order;
                     $ord = $orderDetails['dce']['response']['orders']['order']['supplier_orders']['supplier_order'];
                     $tempDobaOrderArray = DobaOrdersAPI::findItems($ord);
                     foreach ($tempDobaOrderArray as $currOrder) {
                         $currOrder->po_number($ord['order_id']);
                         $currOrder->max_expected_total($ord['order_total']);
                         $currOrder->first_name($tmpName['FirstName']);
                         $currOrder->last_name($tmpName['LastName']);
                         $currOrder->street($ord['ship_street']);
                         $currOrder->city($ord['ship_city']);
                         $currOrder->postal($ord['ship_postal']);
                         $currOrder->country($ord['ship_country']);
                         $orderList->addOrder($currOrder);
                     }
                 } else {
                     //What does multiple supplier_order mean???
                 }
             }
             return $orderList;
         }
     } else {
         return $orderDetails['dce']['response']['outcome'];
     }
 }
 public function sendOrder()
 {
     // connect
     $ch = curl_init();
     // This is the URL that you want PHP to fetch. You can also set this option when initializing a session with the curl_init()  function.
     curl_setopt($ch, CURLOPT_URL, $this->afterbuy_URL);
     // curl_setopt($ch, CURLOPT_CAFILE, 'D:/curl-ca.crt');
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     //bei einer leeren Transmission Error Mail + cURL Problemen die nächste Zeile auskommentieren
     //curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
     // Set this option to a non-zero value if you want PHP to do a regular HTTP POST. This POST is a normal application/x-www-form-urlencoded  kind, most commonly used by HTML forms.
     curl_setopt($ch, CURLOPT_POST, 1);
     // #############  CHECK  #############
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $this->afterbuyString);
     $result = curl_exec($ch);
     // close session
     curl_close($ch);
     if ($this->logging == 1) {
         $current = file_get_contents($this->file);
         $current .= "{$result} \n";
         file_put_contents($this->file, $current);
     }
     if (preg_match("/<success>1<\\/success>/", $result)) {
         // result ok, mark order
         // extract ID from result
         $cdr = explode('<KundenNr>', $result);
         $cdr = explode('</KundenNr>', $cdr[1]);
         $cdr = $cdr[0];
         xtc_db_query("update " . TABLE_ORDERS . " set afterbuy_success='1',afterbuy_id='" . $cdr . "' where orders_id='" . $this->order_id . "'");
         $p = new XMLParser($result);
         $array_complete_parse = $p->getOutput();
         $array_results_parse = $array_complete_parse["result"];
         $ab_aid = $array_results_parse["data"]["AID"];
         $ab_uid = $array_results_parse["data"]["UID"];
         $ab_ui = trim($array_results_parse["data"]["UID"], "{}");
         $ab_kundennr = $array_results_parse["data"]["KundenNr"];
         $ab_ekundennr = $array_results_parse["data"]["EKundenNr"];
         $this->afterbuy_aid = $ab_aid;
         //wenn Kundenkommentar
         if ($oData['comments'] != '') {
             $mail_content .= "Name: " . $oData['billing_firstname'] . " " . $oData['billing_lastname'] . "\nEmailadresse: " . $oData['customers_email_address'] . "\nKundenkommentar: " . $oData['comments'] . "\nBestellnummer: " . $this->order_id . chr(13) . chr(10) . "\n";
             mail(EMAIL_BILLING_ADDRESS, "Kundenkommentar bei Bestellung", $mail_content);
             //mail(EMAIL_BILLING_ADDRESS, "Kundenkommentar bei Bestellung", $mail_content);
         }
         //set new order status
         if ($order_status != '') {
             xtc_db_query("update " . TABLE_ORDERS . " set orders_status='" . $order_status . "' where orders_id='" . $this->order_id . "'");
         }
     } else {
         // mail to shopowner
         $mail_content = 'Fehler bei &Uuml;bertragung der Bestellung: ' . $this->order_id . chr(13) . chr(10) . 'Folgende Fehlermeldung wurde vom afterbuy.de zur&uuml;ckgegeben:' . chr(13) . chr(10) . $result;
         mail(EMAIL_BILLING_ADDRESS, "Afterbuy-Fehl&uuml;bertragung", $mail_content);
         //mail("*****@*****.**", "Afterbuy-Fehl&uuml;bertragung", $mail_content);
     }
 }