Sample code for 30+ languages & platforms
Swift

Aruba Fatturazione Elettronica Upload Invoice Signed

See more Aruba Fatturazione Examples

This method must be used by the EO to send an invoice in XML format that has already been digitally signed in accordance with one of these AGID standards:
  • with the extension .p7m and in CAdES-BES format (CMS Advanced Electronic Signatures);
  • with.xml extension and in XAdES-BES format (XML Advanced Electronic Signatures).

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

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

    let http = CkoHttp()!

    // Implements the following CURL command:

    // curl -X POST https://ws.fatturazioneelettronica.aruba.it/services/invoice/uploadSigned \
    //   -H "Accept: application/json" \
    //   -H "Authorization: Bearer NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE=" \
    //   -H "Content-Type: application/json;charset=UTF-8" \
    //   -d '{
    //   "dataFile" : "dGVzdA=="
    // }'

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

    // Use this online tool to generate code from sample JSON:
    // Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "dataFile": "dGVzdA=="
    // }

    // Load the file to be uploaded.
    let bdSignedInvoice = CkoBinData()!
    success = bdSignedInvoice.loadFile(path: "qa_data/aruba/signedInvoice.xml.p7m")

    let json = CkoJsonObject()!
    json.updateString(jsonPath: "dataFile", value: bdSignedInvoice.getEncoded(encoding: "base64"))

    http.setRequestHeader(name: "Accept", value: "application/json")
    // Adds the "Authorization: Bearer NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE=" header.
    http.authToken = "NLOGDVXLVaF3tzmnVPkTwpkuh7dG0i09uSCcog3u+rE="
    http.setRequestHeader(name: "Content-Type", value: "application/json;charset=UTF-8")

    let resp = CkoHttpResponse()!
    success = http.httpJson(verb: "POST", url: "https://ws.fatturazioneelettronica.aruba.it/services/invoice/uploadSigned", json: json, contentType: "application/json", response: resp)
    if success == false {
        print("\(http.lastErrorText!)")
        return
    }

    let sbResponseBody = CkoStringBuilder()!
    resp.getBodySb(sb: sbResponseBody)
    let jResp = CkoJsonObject()!
    jResp.loadSb(sb: sbResponseBody)
    jResp.emitCompact = false

    print("Response Body:")
    print("\(jResp.emit()!)")

    var respStatusCode: Int = resp.statusCode.intValue
    print("Response Status Code = \(respStatusCode)")
    if respStatusCode >= 400 {
        print("Response Header:")
        print("\(resp.header!)")
        print("Failed.")
        return
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "errorCode": "",
    //   "errorDescription": "Operazione effettuata - 521e052902be7b879d41e0fd586f0e21",
    //   "uploadFileName": "IT01879020517_azdxg.xml.p7m"
    // }

    // Sample code for parsing the JSON response...
    // Use the following online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    var errorCode: String? = jResp.string(of: "errorCode")
    var errorDescription: String? = jResp.string(of: "errorDescription")
    var uploadFileName: String? = jResp.string(of: "uploadFileName")

}