Sample code for 30+ languages & platforms
Xbase++ 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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oBdZip
LOCAL nRespStatusCode
LOCAL oZip
LOCAL nNumUnzipped
LOCAL oEntry
LOCAL oBdP7m
LOCAL oCrypt

nSuccess := 0

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

oHttp := CreateObject("Chilkat.Http")

//  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.
oHttp:AuthToken := "NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE="
oHttp:SetRequestHeader("Accept", "application/json")

oBdZip := CreateObject("Chilkat.BinData")
nSuccess := oHttp:QuickGetBd("https://ws.fatturazioneelettronica.aruba.it/services/invoice/in/getZipByFilename?filename=IT01879020517_jtlk1.xml.p7m", oBdZip)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oBdZip:destroy()
    RETURN
ENDIF

nRespStatusCode := oHttp:LastStatus
? "response status code = " + Str(nRespStatusCode)

IF (nRespStatusCode != 200)
    //  If it failed, the response body will not contain the .zip file data.
    //  It will likely contain an error message.
    ? oBdZip:GetString("utf-8")
    ? "Failed."
    oHttp:destroy()
    oBdZip:destroy()
    RETURN
ENDIF

//  Open the zip and extract the .p7m
oZip := CreateObject("Chilkat.Zip")

nSuccess := oZip:OpenBd(oBdZip)
IF (nSuccess == 0)
    ? oZip:LastErrorText
    oHttp:destroy()
    oBdZip:destroy()
    oZip:destroy()
    RETURN
ENDIF

//  If desired, we can unzip to the filesystem..
nNumUnzipped := oZip:Unzip("c:/mySignedInvoices")
IF (nNumUnzipped < 0)
    ? oZip:LastErrorText
    oHttp:destroy()
    oBdZip:destroy()
    oZip:destroy()
    RETURN
ENDIF

//  Alternatively, we can unzip into memory..
oEntry := CreateObject("Chilkat.ZipEntry")
nSuccess := oZip:EntryAt(0, oEntry)
IF (nSuccess == 0)
    ? oZip:LastErrorText
    oHttp:destroy()
    oBdZip:destroy()
    oZip:destroy()
    oEntry:destroy()
    RETURN
ENDIF

oBdP7m := CreateObject("Chilkat.BinData")
nSuccess := oEntry:UnzipToBd(oBdP7m)
IF (nSuccess == 0)
    ? oEntry:LastErrorText
    oHttp:destroy()
    oBdZip:destroy()
    oZip:destroy()
    oEntry:destroy()
    oBdP7m:destroy()
    RETURN
ENDIF

//  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..
oCrypt := CreateObject("Chilkat.Crypt2")
nSuccess := oCrypt:OpaqueVerifyBd(oBdP7m)
IF (nSuccess == 0)
    ? oCrypt:LastErrorText
    oHttp:destroy()
    oBdZip:destroy()
    oZip:destroy()
    oEntry:destroy()
    oBdP7m:destroy()
    oCrypt:destroy()
    RETURN
ENDIF

? "The signature was verified."

//  The bdp7m now contains the XML that was originally signed.
? "Original XML:"
? oBdP7m:GetString("utf-8")

oHttp:destroy()
oBdZip:destroy()
oZip:destroy()
oEntry:destroy()
oBdP7m:destroy()
oCrypt:destroy()