Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.0.0+

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oJson
LOCAL cUrl
LOCAL oResp
LOCAL oJsonResp
LOCAL cCountry
LOCAL cAddress
LOCAL cResptext
LOCAL cCity
LOCAL cAcctid
LOCAL cRespcode
LOCAL cDefaultacct
LOCAL cAccttype
LOCAL cToken
LOCAL cLicense
LOCAL cRespproc
LOCAL cPhone
LOCAL cProfileid
LOCAL cName
LOCAL cAuoptout
LOCAL cPostal
LOCAL cExpiry
LOCAL cRegion
LOCAL cSsnl4
LOCAL cRespstat

nSuccess := 0

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

oHttp := CreateObject("Chilkat.Http")

oHttp:BasicAuth := 1
oHttp:Login := "API_USERNAME"
oHttp:Password := "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",
//  }

oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("region", "AK")
oJson:UpdateString("phone", "7778789999")
oJson:UpdateString("accttype", "VISA")
oJson:UpdateString("postal", "19090")
oJson:UpdateString("ssnl4", "3655")
oJson:UpdateString("expiry", "0214")
oJson:UpdateString("city", "ANYTOWN")
oJson:UpdateString("country", "US")
oJson:UpdateString("address", "123 MAIN STREET")
oJson:UpdateString("merchid", "MERCHANT_ID")
oJson:UpdateString("name", "TOM JONES")
oJson:UpdateString("account", "4444333322221111")
oJson:UpdateString("license", "123451254")

cUrl := "https://<site>.cardconnect.com:<port>/cardconnect/rest/profile"

oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpStr("PUT", cUrl, oJson:Emit(), "utf-8", "application/json", oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oJson:destroy()
    oResp:destroy()
    RETURN
ENDIF

//  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.
? "response status code = " + Str(oResp:StatusCode)

oJsonResp := CreateObject("Chilkat.JsonObject")
oJsonResp:Load(oResp:BodyStr)
oJsonResp:EmitCompact := 0

? "response JSON:"
? oJsonResp:Emit()

//  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

cCountry := oJsonResp:StringOf("country")
cAddress := oJsonResp:StringOf("address")
cResptext := oJsonResp:StringOf("resptext")
cCity := oJsonResp:StringOf("city")
cAcctid := oJsonResp:StringOf("acctid")
cRespcode := oJsonResp:StringOf("respcode")
cDefaultacct := oJsonResp:StringOf("defaultacct")
cAccttype := oJsonResp:StringOf("accttype")
cToken := oJsonResp:StringOf("token")
cLicense := oJsonResp:StringOf("license")
cRespproc := oJsonResp:StringOf("respproc")
cPhone := oJsonResp:StringOf("phone")
cProfileid := oJsonResp:StringOf("profileid")
cName := oJsonResp:StringOf("name")
cAuoptout := oJsonResp:StringOf("auoptout")
cPostal := oJsonResp:StringOf("postal")
cExpiry := oJsonResp:StringOf("expiry")
cRegion := oJsonResp:StringOf("region")
cSsnl4 := oJsonResp:StringOf("ssnl4")
cRespstat := oJsonResp:StringOf("respstat")

oHttp:destroy()
oJson:destroy()
oResp:destroy()
oJsonResp:destroy()