Created
October 26, 2012 23:33
-
-
Save tiagomatos/3962192 to your computer and use it in GitHub Desktop.
InvoceXpress Client Create Invoce does not accept item tax.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'uri' | |
require 'net/https' | |
require 'ostruct' | |
require 'rubygems' | |
require 'yaml' | |
invoicexpressyml ||= YAML.load_file("config/invoicexpress.yml") | |
invoicexpresscfg = invoicexpressyml["development"] | |
host = [invoicexpresscfg["screen_name"], invoicexpresscfg["host"]].join(".") | |
api_key = invoicexpresscfg["api_key"] | |
create_invoice_data = <<EOF | |
<?xml version="1.0" encoding="UTF-8"?> | |
<invoice> | |
<date>#{Time.now.strftime("%D")}</date> | |
<due_date>#{Time.now.strftime("%D")}</due_date> | |
<observations>some observations</observations> | |
<items type="array"> | |
<item> | |
<name>some name</name> | |
<description>some description</description> | |
<unit_price>123</unit_price> | |
<quantity>1.0</quantity> | |
<unit>unit</unit> | |
<tax> | |
<name>VAT23</name> | |
</tax> | |
</item> | |
</items> | |
</invoice> | |
EOF | |
http = Net::HTTP.new(host, 443) | |
http.use_ssl = true | |
headers = { | |
'Content-Type' => 'application/xml; charset=utf-8', | |
'Accept' => 'text/plain' | |
} | |
@client_id = 284262 | |
res = http.post("/clients/#{@client_id}/create/invoice.xml?api_key=#{api_key}", create_invoice_data, headers) | |
case res | |
when Net::HTTPSuccess, Net::HTTPRedirection | |
puts res.body | |
else | |
puts res.to_ary[1] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment