/**
  * Handle the order actions callback for creating a manual payment
  *
  * @param WC_Order $order
  *
  * @return boolean
  */
 public function manual_payment($order)
 {
     // Payment Manager
     $payment_manager = new WC_XR_Payment_Manager();
     // Send Payment
     $payment_manager->send_payment($order->id);
     return true;
 }
 /**
  * Send invoice to XERO API
  *
  * @param int $order_id
  *
  * @return bool
  */
 public function send_invoice($order_id)
 {
     // Get the order
     $order = wc_get_order($order_id);
     // Get the invoice
     $invoice = $this->get_invoice_by_order($order);
     // Settings object
     $settings = new WC_XR_Settings();
     // Write exception message to log
     $logger = new WC_XR_Logger();
     // Check if the order total is 0 and if we need to send 0 total invoices to Xero
     if (0 == $invoice->get_total() && 'on' !== $settings->get_option('export_zero_amount')) {
         $logger->write('INVOICE HAS TOTAL OF 0, NOT SENDING ORDER WITH ID ' . $order->id);
         $order->add_order_note(__("XERO: Didn't create invoice because total is 0 and send order with zero total is set to off.", 'wc-xero'));
         return false;
     }
     // Invoice Request
     $invoice_request = new WC_XR_Request_Invoice($this->get_invoice_by_order($order));
     // Logging
     $logger->write('START XERO NEW INVOICE. order_id=' . $order->id);
     // Try to do the request
     try {
         // Do the request
         $invoice_request->do_request();
         // Parse XML Response
         $xml_response = $invoice_request->get_response_body_xml();
         // Check response status
         if ('OK' == $xml_response->Status) {
             // Add order meta data
             add_post_meta($order->id, '_xero_invoice_id', (string) $xml_response->Invoices->Invoice[0]->InvoiceID);
             add_post_meta($order->id, '_xero_currencyrate', (string) $xml_response->Invoices->Invoice[0]->CurrencyRate);
             // Log response
             $logger->write('XERO RESPONSE:' . "\n" . $invoice_request->get_response_body());
             // Add Order Note
             $order->add_order_note(__('Xero Invoice created.  ', 'wc-xero') . ' Invoice ID: ' . (string) $xml_response->Invoices->Invoice[0]->InvoiceID);
             // Settings object
             $settings = new WC_XR_Settings();
             // Check if sending payment is on
             if ('on' === $settings->get_option('send_payments') && $invoice->get_total() > 0) {
                 // Payment Manager
                 $payment_manager = new WC_XR_Payment_Manager();
                 // Send payment
                 $payment_manager->send_payment($order->id);
             }
         } else {
             // XML reponse is not OK
             // Log reponse
             $logger->write('XERO ERROR RESPONSE:' . "\n" . $invoice_request->get_response_body());
             // Format error message
             $error_message = $xml_response->Elements->DataContractBase->ValidationErrors->ValidationError->Message ? $xml_response->Elements->DataContractBase->ValidationErrors->ValidationError->Message : __('None', 'wc-xero');
             // Add order note
             $order->add_order_note(__('ERROR creating Xero invoice: ', 'wc-xero') . __(' ErrorNumber: ', 'wc-xero') . $xml_response->ErrorNumber . __(' ErrorType: ', 'wc-xero') . $xml_response->Type . __(' Message: ', 'wc-xero') . $xml_response->Message . __(' Detail: ', 'wc-xero') . $error_message);
         }
     } catch (Exception $e) {
         // Add Exception as order note
         $order->add_order_note($e->getMessage());
         $logger->write($e->getMessage());
         return false;
     }
     $logger->write('END XERO NEW INVOICE');
     return true;
 }