Sample code for 30+ languages & platforms
Unicode C++

CardConnect Authorization

See more CardConnect Examples

Demonstrates how to send an Authorization request.
Authorization is the initial step in accepting payment from a cardholder. This action "authorizes" or requests permission from the bank to transfer money from the cardholder to the merchant.

See https://developer.cardconnect.com/cardconnect-api#authorization

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>

void ChilkatSample(void)
    {
    bool success = false;

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

    CkHttpW http;

    http.put_BasicAuth(true);
    http.put_Login(L"API_USERNAME");
    http.put_Password(L"API_PASSWORD");

    // Build and send the following JSON:

    // Note: The CardConnect online documentation might use an expiry that is in the past, such as "1218".
    // This causes the request to fail.  Use a month/year that is in the future..
    // (Likewise, this example will have an invalid month/year after Dec 2021)

    // {
    //   "merchid": "MERCHANT_ID",
    //   "accttype": "VISA",
    //   "orderid": "AB-11-9876",
    //   "account": "4111111111111111",
    //   "expiry": "1221",
    //   "amount": "0",
    //   "currency": "USD",
    //   "name": "TOM JONES",
    //   "address": "123 MAIN STREET",
    //   "city": "anytown",
    //   "region": "NY",
    //   "country": "US",
    //   "postal": "55555",
    //   "profile": "Y",
    //   "ecomind": "E",
    //   "cvv2": "123",
    //   "track": null,
    //   "capture": "Y"
    // }

    // Use this online tool to generate the code from sample JSON: 
    // Generate Code to Create JSON
    CkJsonObjectW json;
    json.UpdateString(L"merchid",L"MERCHANT_ID");
    json.UpdateString(L"accttype",L"VISA");
    json.UpdateString(L"orderid",L"AB-11-9876");
    json.UpdateString(L"account",L"4111111111111111");
    json.UpdateString(L"expiry",L"1221");
    json.UpdateString(L"amount",L"20");
    json.UpdateString(L"currency",L"USD");
    json.UpdateString(L"name",L"TOM JONES");
    json.UpdateString(L"address",L"123 MAIN STREET");
    json.UpdateString(L"city",L"anytown");
    json.UpdateString(L"region",L"NY");
    json.UpdateString(L"country",L"US");
    json.UpdateString(L"postal",L"55555");
    json.UpdateString(L"profile",L"Y");
    json.UpdateString(L"ecomind",L"E");
    json.UpdateString(L"cvv2",L"123");
    json.UpdateNull(L"track");
    json.UpdateString(L"capture",L"Y");

    const wchar_t *url = L"https://<site>.cardconnect.com:<port>/cardconnect/rest/auth";

    CkHttpResponseW resp;
    success = http.HttpStr(L"PUT",url,json.emit(),L"utf-8",L"application/json",resp);
    if (success == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    // A response status of 200 indicates potential success.  The JSON response body
    // must be examined to determine if it was truly successful or an error.
    wprintf(L"response status code = %d\n",resp.get_StatusCode());

    CkJsonObjectW jsonResp;
    jsonResp.Load(resp.bodyStr());
    jsonResp.put_EmitCompact(false);

    wprintf(L"response JSON:\n");
    wprintf(L"%s\n",jsonResp.emit());

    // Sample error:

    // {
    //   "respproc": "PPS",
    //   "amount": "0.00",
    //   "resptext": "Invalid amount",
    //   "cardproc": "FNOR",
    //   "acctid": "1",
    //   "retref": "112804260418",
    //   "respstat": "C",
    //   "respcode": "43",
    //   "account": "41XXXXXXXXXX1111",
    //   "defaultacct": "Y",
    //   "merchid": "MERCHANT_ID",
    //   "token": "9418594164541111"
    // }

    // A successful response looks like this:

    // {
    //   "amount": "0.20",
    //   "resptext": "Approval",
    //   "acctid": "1",
    //   "commcard": " C ",
    //   "cvvresp": "M",
    //   "respcode": "00",
    //   "batchid": "1900942291",
    //   "avsresp": "Z",
    //   "entrymode": "ECommerce",
    //   "defaultacct": "Y",
    //   "merchid": "MERCHANT_ID",
    //   "token": "9418594164541111",
    //   "authcode": "PPS158",
    //   "respproc": "FNOR",
    //   "bintype": "",
    //   "profileid": "16618402968441604028",
    //   "retref": "112989260941",
    //   "respstat": "A",
    //   "account": "41XXXXXXXXXX1111"
    // }

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

    const wchar_t *amount = jsonResp.stringOf(L"amount");
    const wchar_t *resptext = jsonResp.stringOf(L"resptext");
    const wchar_t *acctid = jsonResp.stringOf(L"acctid");
    const wchar_t *commcard = jsonResp.stringOf(L"commcard");
    const wchar_t *cvvresp = jsonResp.stringOf(L"cvvresp");
    const wchar_t *respcode = jsonResp.stringOf(L"respcode");
    const wchar_t *batchid = jsonResp.stringOf(L"batchid");
    const wchar_t *avsresp = jsonResp.stringOf(L"avsresp");
    const wchar_t *entrymode = jsonResp.stringOf(L"entrymode");
    const wchar_t *defaultacct = jsonResp.stringOf(L"defaultacct");
    const wchar_t *merchid = jsonResp.stringOf(L"merchid");
    const wchar_t *token = jsonResp.stringOf(L"token");
    const wchar_t *authcode = jsonResp.stringOf(L"authcode");
    const wchar_t *respproc = jsonResp.stringOf(L"respproc");
    const wchar_t *bintype = jsonResp.stringOf(L"bintype");
    const wchar_t *profileid = jsonResp.stringOf(L"profileid");
    const wchar_t *retref = jsonResp.stringOf(L"retref");
    const wchar_t *respstat = jsonResp.stringOf(L"respstat");
    const wchar_t *account = jsonResp.stringOf(L"account");
    }