Sample code for 30+ languages & platforms
Lua Requires Chilkat v11.0.0+

Aruba Fatturazione Elettronica Get Zip by Filename

See more Aruba Fatturazione Examples

Returns an invoice with all of its notifications in Zip format (e.g. IT01879020517_abcde.xml.p7m).

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local http = chilkat.Http.new()

-- Implements the following CURL command:

-- curl -X GET https://ws.fatturazioneelettronica.aruba.it/services/invoice/in/getZipByFilename?filename=IT01879020517_jtlk1.xml.p7m \
--   -H "Accept: application/json" \
--   -H "Authorization: Bearer NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE="

-- Use the following online tool to generate HTTP code from a CURL command
-- Convert a cURL Command to HTTP Source Code

-- Adds the "Authorization: Bearer NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE=" header.
http.auth_token = "NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE="
http:set_request_header("Accept", "application/json")

local bdZip = chilkat.BinData.new()
local success = http:quick_get_bd("https://ws.fatturazioneelettronica.aruba.it/services/invoice/in/getZipByFilename?filename=IT01879020517_jtlk1.xml.p7m", bdZip)
if not success then
    print(http.last_error_text)
    return
end

local respStatusCode = http.last_status
print("response status code = " .. respStatusCode)

if respStatusCode ~= 200 then
    -- If it failed, the response body will not contain the .zip file data.
    -- It will likely contain an error message.
    print(bdZip:get_string("utf-8"))
    print("Failed.")
    return
end

-- Open the zip and extract the .p7m
local zip = chilkat.Zip.new()

success = zip:open_bd(bdZip)
if not success then
    print(zip.last_error_text)
    return
end

-- If desired, we can unzip to the filesystem..
local numUnzipped = zip:unzip("c:/mySignedInvoices")
if numUnzipped < 0 then
    print(zip.last_error_text)
    return
end

-- Alternatively, we can unzip into memory..
local entry = chilkat.ZipEntry.new()
success = zip:entry_at(0, entry)
if not success then
    print(zip.last_error_text)
    return
end

local bdP7m = chilkat.BinData.new()
success = entry:unzip_to_bd(bdP7m)
if not success then
    print(entry.last_error_text)
    return
end

-- Verify the signature and extract the XML from the p7m
-- If the signature verification is successful, the contents of bdP7m are unwrapped and what
-- remains is the original signed document..
local crypt = chilkat.Crypt2.new()
success = crypt:opaque_verify_bd(bdP7m)
if not success then
    print(crypt.last_error_text)
    return
end

print("The signature was verified.")

-- The bdp7m now contains the XML that was originally signed.
print("Original XML:")
print(bdP7m:get_string("utf-8"))