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 AuthorizationDemonstrates 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
#include <CkHttpW.h> #include <CkJsonObjectW.h> void ChilkatSample(void) { // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttpW http; bool success; 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"; const wchar_t *responseStr = http.putText(url,json.emit(),L"utf-8",L"application/json",false,false); if (http.get_LastMethodSuccess() == 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",http.get_LastStatus()); CkJsonObjectW jsonResp; jsonResp.Load(responseStr); 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"); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.