Unicode C
Unicode C
CardConnect Create Profile
See more CardConnect Examples
Demonstrates how to create a profile.A PUT call to the profile endpoint creates a new profile or adds a new account to an existing profile. ...
See https://developer.cardconnect.com/cardconnect-api?lang=json#create-update-profile-request
Chilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkJsonObjectW json;
const wchar_t *url;
HCkHttpResponseW resp;
HCkJsonObjectW jsonResp;
const wchar_t *country;
const wchar_t *address;
const wchar_t *resptext;
const wchar_t *city;
const wchar_t *acctid;
const wchar_t *respcode;
const wchar_t *defaultacct;
const wchar_t *accttype;
const wchar_t *token;
const wchar_t *license;
const wchar_t *respproc;
const wchar_t *phone;
const wchar_t *profileid;
const wchar_t *name;
const wchar_t *auoptout;
const wchar_t *postal;
const wchar_t *expiry;
const wchar_t *region;
const wchar_t *ssnl4;
const wchar_t *respstat;
success = FALSE;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
CkHttpW_putBasicAuth(http,TRUE);
CkHttpW_putLogin(http,L"API_USERNAME");
CkHttpW_putPassword(http,L"API_PASSWORD");
// Build and send the following JSON:
// {
// "region": "AK",
// "phone": "7778789999",
// "accttype": "VISA",
// "postal": "19090",
// "ssnl4": "3655",
// "expiry": "0214",
// "city": "ANYTOWN",
// "country": "US",
// "address": "123 MAIN STREET",
// "merchid": "496400000840",
// "name": "TOM JONES",
// "account": "4444333322221111",
// "license": "123451254",
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"region",L"AK");
CkJsonObjectW_UpdateString(json,L"phone",L"7778789999");
CkJsonObjectW_UpdateString(json,L"accttype",L"VISA");
CkJsonObjectW_UpdateString(json,L"postal",L"19090");
CkJsonObjectW_UpdateString(json,L"ssnl4",L"3655");
CkJsonObjectW_UpdateString(json,L"expiry",L"0214");
CkJsonObjectW_UpdateString(json,L"city",L"ANYTOWN");
CkJsonObjectW_UpdateString(json,L"country",L"US");
CkJsonObjectW_UpdateString(json,L"address",L"123 MAIN STREET");
CkJsonObjectW_UpdateString(json,L"merchid",L"MERCHANT_ID");
CkJsonObjectW_UpdateString(json,L"name",L"TOM JONES");
CkJsonObjectW_UpdateString(json,L"account",L"4444333322221111");
CkJsonObjectW_UpdateString(json,L"license",L"123451254");
url = L"https://<site>.cardconnect.com:<port>/cardconnect/rest/profile";
resp = CkHttpResponseW_Create();
success = CkHttpW_HttpStr(http,L"PUT",url,CkJsonObjectW_emit(json),L"utf-8",L"application/json",resp);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkHttpResponseW_Dispose(resp);
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",CkHttpResponseW_getStatusCode(resp));
jsonResp = CkJsonObjectW_Create();
CkJsonObjectW_Load(jsonResp,CkHttpResponseW_bodyStr(resp));
CkJsonObjectW_putEmitCompact(jsonResp,FALSE);
wprintf(L"response JSON:\n");
wprintf(L"%s\n",CkJsonObjectW_emit(jsonResp));
// A successful response looks like this:
// {
// "country": "US",
// "address": "123 MAIN STREET",
// "resptext": "Profile Saved",
// "city": "ANYTOWN",
// "acctid": "1",
// "respcode": "09",
// "defaultacct": "Y",
// "accttype": "VISA",
// "token": "9441149619831111",
// "license": "123451254",
// "respproc": "PPS",
// "phone": "7778789999",
// "profileid": "16392957457306633141",
// "name": "TOM JONES",
// "auoptout": "N",
// "postal": "19090",
// "expiry": "0214",
// "region": "AK",
// "ssnl4": "3655",
// "respstat": "A"
// }
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
country = CkJsonObjectW_stringOf(jsonResp,L"country");
address = CkJsonObjectW_stringOf(jsonResp,L"address");
resptext = CkJsonObjectW_stringOf(jsonResp,L"resptext");
city = CkJsonObjectW_stringOf(jsonResp,L"city");
acctid = CkJsonObjectW_stringOf(jsonResp,L"acctid");
respcode = CkJsonObjectW_stringOf(jsonResp,L"respcode");
defaultacct = CkJsonObjectW_stringOf(jsonResp,L"defaultacct");
accttype = CkJsonObjectW_stringOf(jsonResp,L"accttype");
token = CkJsonObjectW_stringOf(jsonResp,L"token");
license = CkJsonObjectW_stringOf(jsonResp,L"license");
respproc = CkJsonObjectW_stringOf(jsonResp,L"respproc");
phone = CkJsonObjectW_stringOf(jsonResp,L"phone");
profileid = CkJsonObjectW_stringOf(jsonResp,L"profileid");
name = CkJsonObjectW_stringOf(jsonResp,L"name");
auoptout = CkJsonObjectW_stringOf(jsonResp,L"auoptout");
postal = CkJsonObjectW_stringOf(jsonResp,L"postal");
expiry = CkJsonObjectW_stringOf(jsonResp,L"expiry");
region = CkJsonObjectW_stringOf(jsonResp,L"region");
ssnl4 = CkJsonObjectW_stringOf(jsonResp,L"ssnl4");
respstat = CkJsonObjectW_stringOf(jsonResp,L"respstat");
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkHttpResponseW_Dispose(resp);
CkJsonObjectW_Dispose(jsonResp);
}