def save_invoice(invoice)
      request_xml = invoice.to_xml

      response_xml = nil
      create_or_save = nil
      if invoice.invoice_id.nil?
        # Create new invoice record.
        response_xml = http_put(@client, "#{@xero_url}/Invoices", request_xml, {})
        create_or_save = :create
      else
        # Update existing invoice record.
        response_xml = http_post(@client, "#{@xero_url}/Invoices", request_xml, {})
        create_or_save = :save
      end

      response = parse_response(response_xml, {:request_xml => request_xml}, {:request_signature => "#{create_or_save == :create ? 'PUT' : 'POST'}/invoice"})

      # Xero returns invoices inside an <Invoices> tag, even though there's only ever
      # one for this request
      response.response_item = response.invoices.first

      if response.success? && response.invoice && response.invoice.invoice_id
        invoice.invoice_id = response.invoice.invoice_id
      end

      response
    end
def save_invoice(invoice)
      request_xml = invoice.to_xml

      response_xml = nil
      create_or_save = nil
      if invoice.invoice_id.nil?
        # Create new invoice record.
        response_xml = http_put(@client, "#{@xero_url}/Invoices", request_xml, {})
        create_or_save = :create
      else
        # Update existing invoice record.
        response_xml = http_post(@client, "#{@xero_url}/Invoices", request_xml, {})
        create_or_save = :save
      end

      response = parse_response(response_xml, {:request_xml => request_xml}, {:request_signature => "#{create_or_save == :create ? 'PUT' : 'POST'}/invoice"})

      # Xero returns invoices inside an <Invoices> tag, even though there's only ever
      # one for this request
      response.response_item = response.invoices.first

      if response.success? && response.invoice && response.invoice.invoice_id
        invoice.invoice_id = response.invoice.invoice_id
      end

      response
    end
Create or update an invoice record based on if it has an invoice_id.