Chilkat Online Tools

C++ / CardPointe API Integration / Signature Capture (Retref + Signature)

Back to Collection Items

#include <CkHttp.h>
#include <CkJsonObject.h>
#include <CkStringBuilder.h>
#include <CkHttpResponse.h>

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

    CkHttp http;
    bool success;

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

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

    // {
    //   "merchid": "{{merchid}}",
    //   "retref": "{{retref}}",
    //   "signature": "{{signature}}"
    // }

    CkJsonObject json;
    json.UpdateString("merchid","{{merchid}}");
    json.UpdateString("retref","{{retref}}");
    json.UpdateString("signature","{{signature}}");

    http.SetRequestHeader("Authorization","{{Authorization}}");
    http.SetRequestHeader("Content-Type","application/json");

    CkStringBuilder sbRequestBody;
    json.EmitSb(sbRequestBody);

    CkHttpResponse *resp = http.PTextSb("PUT","https://domain.com/sigcap",sbRequestBody,"utf-8","application/json",false,false);
    if (http.get_LastMethodSuccess() == false) {
        std::cout << http.lastErrorText() << "\r\n";
        return;
    }

    CkStringBuilder sbResponseBody;
    resp->GetBodySb(sbResponseBody);

    CkJsonObject jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    std::cout << "Response Body:" << "\r\n";
    std::cout << jResp.emit() << "\r\n";

    int respStatusCode = resp->get_StatusCode();
    std::cout << "Response Status Code = " << respStatusCode << "\r\n";
    if (respStatusCode >= 400) {
        std::cout << "Response Header:" << "\r\n";
        std::cout << resp->header() << "\r\n";
        std::cout << "Failed." << "\r\n";
        delete resp;
        return;
    }

    delete resp;

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

    // {
    //   "resptext": "signature stored",
    //   "retref": "010787260965",
    //   "respcode": "02",
    //   "merchid": "496082673999"
    // }

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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    const char *resptext = jResp.stringOf("resptext");
    const char *retref = jResp.stringOf("retref");
    const char *respcode = jResp.stringOf("respcode");
    const char *merchid = jResp.stringOf("merchid");
    }

Curl Command

curl -X PUT
	-H "Authorization: {{Authorization}}"
	-H "Content-Type: application/json"
	-d '{
	"merchid": "{{merchid}}",
	"retref": "{{retref}}",
	"signature": "{{signature}}"
}'
https://domain.com/sigcap

Postman Collection Item JSON

{
  "name": "Signature Capture (Retref + Signature)",
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Authorization",
        "type": "text",
        "value": "{{Authorization}}"
      },
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "type": "text",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n\t\"merchid\": \"{{merchid}}\",\n\t\"retref\": \"{{retref}}\",\n\t\"signature\": \"{{signature}}\"\n}"
    },
    "url": {
      "raw": "{{url}}/sigcap",
      "host": [
        "{{url}}"
      ],
      "path": [
        "sigcap"
      ]
    },
    "description": "[Signature Capture Documentation](https://developer.cardconnect.com/cardconnect-api#signature-capture)"
  },
  "response": [
    {
      "name": "Signature Capture Example",
      "originalRequest": {
        "method": "PUT",
        "header": [
          {
            "key": "Authorization",
            "type": "text",
            "value": "{{Authorization}}"
          },
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "type": "text",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n\t\"merchid\": \"{{merchid}}\",\n\t\"retref\": \"{{retref}}\",\n\t\"signature\": \"{{signature}}\"\n}"
        },
        "url": {
          "raw": "{{url}}/sigcap",
          "host": [
            "{{url}}"
          ],
          "path": [
            "sigcap"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "X-FRAME-OPTIONS",
          "value": "DENY"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "Content-Length",
          "value": "96"
        },
        {
          "key": "Date",
          "value": "Thu, 10 Jan 2019 22:48:14 GMT"
        },
        {
          "key": "Server",
          "value": "CardConnect"
        },
        {
          "key": "Set-Cookie",
          "value": "BIGipServerphu-smb-vip_8080=!LjWLHiB9n9NWwsA7l1uxw4rK+VEmEdwIthKC4TazuLPJh6E1ejLYwbozqYcrk8OdOnAt3b319/yBPZ4=; path=/; Httponly; Secure"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"resptext\": \"signature stored\",\n    \"retref\": \"010787260965\",\n    \"respcode\": \"02\",\n    \"merchid\": \"496082673999\"\n}"
    }
  ]
}