Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) CardConnect Create ProfileDemonstrates 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
#include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkJsonObjectW json; const wchar_t *url; const wchar_t *responseStr; 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; // 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"; responseStr = CkHttpW_putText(http,url,CkJsonObjectW_emit(json),L"utf-8",L"application/json",FALSE,FALSE); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); 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",CkHttpW_getLastStatus(http)); jsonResp = CkJsonObjectW_Create(); CkJsonObjectW_Load(jsonResp,responseStr); 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); CkJsonObjectW_Dispose(jsonResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.