function test_connection_callback() { include_once "class-fortnox3-api.php"; $temp = new WCF_API(); $temp->create_license_validation_request(); die; // this is required to return a proper result }
/** * Fetches customer from DB or creates it at Fortnox * * @access public * @param $order * @return int */ private function get_or_create_customer($order) { include_once "class-fortnox3-contact-xml.php"; $databaseInterface = new WCF_Database_Interface(); $customer = $databaseInterface->get_customer_by_email($order->billing_email); //Init API $apiInterface = new WCF_API(); if ($apiInterface->has_error) { return $this->ERROR_LOGIN; } //create Contact XML $contactDoc = new WCF_Contact_XML_Document(); $contactXml = $contactDoc->create($order); if (empty($customer) || $customer[0]->customer_number == 0) { logthis("CREATING CUSTOMER"); $customerId = $databaseInterface->create_customer($order->billing_email); //send Contact XML $contactResponse = $apiInterface->create_customer_request($contactXml); if (array_key_exists('Error', $contactResponse)) { return $this->handle_error($contactResponse); } $customerNumber = $contactResponse['CustomerNumber']; $databaseInterface->update_customer($customerId, $customerNumber); } else { logthis("UPDATING CUSTOMER"); $customerNumber = $customer[0]->customer_number; $contactResponse = $apiInterface->update_customer_request($contactXml, $customerNumber); if (array_key_exists('Error', $contactResponse)) { return $this->handle_error($contactResponse, $link = 'fel-i-kunddatabastabellen'); } } return $customerNumber; }
function check_diff_callback() { global $wpdb; // this is how you get access to the database include_once "class-fortnox3-api.php"; check_ajax_referer('fortnox_woocommerce', 'security'); $pf = new WC_Product_Factory(); $child = $pf->get_product($_POST['product_id']); $sku = $child->get_sku(); $apiInterface = new WCF_API(); $article = $apiInterface->get_article($sku); if ($sku === NULL) { echo json_encode(array('success' => false, 'product_id' => $_POST['product_id'], 'sku' => 'Inget artikelnummer', 'title' => $child->get_title())); } else { if (array_key_exists('Error', $article)) { echo json_encode(array('success' => false, 'product_id' => $_POST['product_id'], 'sku' => $sku, 'title' => $child->get_title())); } else { echo json_encode(array('success' => true, 'product_id' => $_POST['product_id'], 'sku' => $sku, 'title' => $child->get_title())); } } die; // this is required to return a proper result }