C
C
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 C Downloads
#include <C_CkHttp.h>
#include <C_CkBinData.h>
#include <C_CkZip.h>
#include <C_CkZipEntry.h>
#include <C_CkCrypt2.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttp http;
HCkBinData bdZip;
int respStatusCode;
HCkZip zip;
int numUnzipped;
HCkZipEntry entry;
HCkBinData bdP7m;
HCkCrypt2 crypt;
success = FALSE;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_Create();
// 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.
CkHttp_putAuthToken(http,"NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE=");
CkHttp_SetRequestHeader(http,"Accept","application/json");
bdZip = CkBinData_Create();
success = CkHttp_QuickGetBd(http,"https://ws.fatturazioneelettronica.aruba.it/services/invoice/in/getZipByFilename?filename=IT01879020517_jtlk1.xml.p7m",bdZip);
if (success == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkBinData_Dispose(bdZip);
return;
}
respStatusCode = CkHttp_getLastStatus(http);
printf("response status code = %d\n",respStatusCode);
if (respStatusCode != 200) {
// If it failed, the response body will not contain the .zip file data.
// It will likely contain an error message.
printf("%s\n",CkBinData_getString(bdZip,"utf-8"));
printf("Failed.\n");
CkHttp_Dispose(http);
CkBinData_Dispose(bdZip);
return;
}
// Open the zip and extract the .p7m
zip = CkZip_Create();
success = CkZip_OpenBd(zip,bdZip);
if (success == FALSE) {
printf("%s\n",CkZip_lastErrorText(zip));
CkHttp_Dispose(http);
CkBinData_Dispose(bdZip);
CkZip_Dispose(zip);
return;
}
// If desired, we can unzip to the filesystem..
numUnzipped = CkZip_Unzip(zip,"c:/mySignedInvoices");
if (numUnzipped < 0) {
printf("%s\n",CkZip_lastErrorText(zip));
CkHttp_Dispose(http);
CkBinData_Dispose(bdZip);
CkZip_Dispose(zip);
return;
}
// Alternatively, we can unzip into memory..
entry = CkZipEntry_Create();
success = CkZip_EntryAt(zip,0,entry);
if (success == FALSE) {
printf("%s\n",CkZip_lastErrorText(zip));
CkHttp_Dispose(http);
CkBinData_Dispose(bdZip);
CkZip_Dispose(zip);
CkZipEntry_Dispose(entry);
return;
}
bdP7m = CkBinData_Create();
success = CkZipEntry_UnzipToBd(entry,bdP7m);
if (success == FALSE) {
printf("%s\n",CkZipEntry_lastErrorText(entry));
CkHttp_Dispose(http);
CkBinData_Dispose(bdZip);
CkZip_Dispose(zip);
CkZipEntry_Dispose(entry);
CkBinData_Dispose(bdP7m);
return;
}
// 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..
crypt = CkCrypt2_Create();
success = CkCrypt2_OpaqueVerifyBd(crypt,bdP7m);
if (success == FALSE) {
printf("%s\n",CkCrypt2_lastErrorText(crypt));
CkHttp_Dispose(http);
CkBinData_Dispose(bdZip);
CkZip_Dispose(zip);
CkZipEntry_Dispose(entry);
CkBinData_Dispose(bdP7m);
CkCrypt2_Dispose(crypt);
return;
}
printf("The signature was verified.\n");
// The bdp7m now contains the XML that was originally signed.
printf("Original XML:\n");
printf("%s\n",CkBinData_getString(bdP7m,"utf-8"));
CkHttp_Dispose(http);
CkBinData_Dispose(bdZip);
CkZip_Dispose(zip);
CkZipEntry_Dispose(entry);
CkBinData_Dispose(bdP7m);
CkCrypt2_Dispose(crypt);
}