DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
Variant vBdZip
Handle hoBdZip
Integer iRespStatusCode
Handle hoZip
Integer iNumUnzipped
Variant vEntry
Handle hoEntry
Variant vBdP7m
Handle hoBdP7m
Handle hoCrypt
String sTemp1
Move False To iSuccess
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// 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.
Set ComAuthToken Of hoHttp To "NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE="
Send ComSetRequestHeader To hoHttp "Accept" "application/json"
Get Create (RefClass(cComChilkatBinData)) To hoBdZip
If (Not(IsComObjectCreated(hoBdZip))) Begin
Send CreateComObject of hoBdZip
End
Get pvComObject of hoBdZip to vBdZip
Get ComQuickGetBd Of hoHttp "https://ws.fatturazioneelettronica.aruba.it/services/invoice/in/getZipByFilename?filename=IT01879020517_jtlk1.xml.p7m" vBdZip To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComLastStatus Of hoHttp To iRespStatusCode
Showln "response status code = " iRespStatusCode
If (iRespStatusCode <> 200) Begin
// If it failed, the response body will not contain the .zip file data.
// It will likely contain an error message.
Get ComGetString Of hoBdZip "utf-8" To sTemp1
Showln sTemp1
Showln "Failed."
Procedure_Return
End
// Open the zip and extract the .p7m
Get Create (RefClass(cComChilkatZip)) To hoZip
If (Not(IsComObjectCreated(hoZip))) Begin
Send CreateComObject of hoZip
End
Get pvComObject of hoBdZip to vBdZip
Get ComOpenBd Of hoZip vBdZip To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoZip To sTemp1
Showln sTemp1
Procedure_Return
End
// If desired, we can unzip to the filesystem..
Get ComUnzip Of hoZip "c:/mySignedInvoices" To iNumUnzipped
If (iNumUnzipped < 0) Begin
Get ComLastErrorText Of hoZip To sTemp1
Showln sTemp1
Procedure_Return
End
// Alternatively, we can unzip into memory..
Get Create (RefClass(cComChilkatZipEntry)) To hoEntry
If (Not(IsComObjectCreated(hoEntry))) Begin
Send CreateComObject of hoEntry
End
Get pvComObject of hoEntry to vEntry
Get ComEntryAt Of hoZip 0 vEntry To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoZip To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatBinData)) To hoBdP7m
If (Not(IsComObjectCreated(hoBdP7m))) Begin
Send CreateComObject of hoBdP7m
End
Get pvComObject of hoBdP7m to vBdP7m
Get ComUnzipToBd Of hoEntry vBdP7m To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoEntry To sTemp1
Showln sTemp1
Procedure_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..
Get Create (RefClass(cComChilkatCrypt2)) To hoCrypt
If (Not(IsComObjectCreated(hoCrypt))) Begin
Send CreateComObject of hoCrypt
End
Get pvComObject of hoBdP7m to vBdP7m
Get ComOpaqueVerifyBd Of hoCrypt vBdP7m To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoCrypt To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "The signature was verified."
// The bdp7m now contains the XML that was originally signed.
Showln "Original XML:"
Get ComGetString Of hoBdP7m "utf-8" To sTemp1
Showln sTemp1
End_Procedure