Sample code for 30+ languages & platforms
PureBasic

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 PureBasic Downloads

PureBasic
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    success.i = 0

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkHttp::setCkBasicAuth(http, 1)
    CkHttp::setCkLogin(http, "API_USERNAME")
    CkHttp::setCkPassword(http, "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.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"region","AK")
    CkJsonObject::ckUpdateString(json,"phone","7778789999")
    CkJsonObject::ckUpdateString(json,"accttype","VISA")
    CkJsonObject::ckUpdateString(json,"postal","19090")
    CkJsonObject::ckUpdateString(json,"ssnl4","3655")
    CkJsonObject::ckUpdateString(json,"expiry","0214")
    CkJsonObject::ckUpdateString(json,"city","ANYTOWN")
    CkJsonObject::ckUpdateString(json,"country","US")
    CkJsonObject::ckUpdateString(json,"address","123 MAIN STREET")
    CkJsonObject::ckUpdateString(json,"merchid","MERCHANT_ID")
    CkJsonObject::ckUpdateString(json,"name","TOM JONES")
    CkJsonObject::ckUpdateString(json,"account","4444333322221111")
    CkJsonObject::ckUpdateString(json,"license","123451254")

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

    resp.i = CkHttpResponse::ckCreate()
    If resp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckHttpStr(http,"PUT",url,CkJsonObject::ckEmit(json),"utf-8","application/json",resp)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        CkHttpResponse::ckDispose(resp)
        ProcedureReturn
    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.
    Debug "response status code = " + Str(CkHttpResponse::ckStatusCode(resp))

    jsonResp.i = CkJsonObject::ckCreate()
    If jsonResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoad(jsonResp,CkHttpResponse::ckBodyStr(resp))
    CkJsonObject::setCkEmitCompact(jsonResp, 0)

    Debug "response JSON:"
    Debug CkJsonObject::ckEmit(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.s = CkJsonObject::ckStringOf(jsonResp,"country")
    address.s = CkJsonObject::ckStringOf(jsonResp,"address")
    resptext.s = CkJsonObject::ckStringOf(jsonResp,"resptext")
    city.s = CkJsonObject::ckStringOf(jsonResp,"city")
    acctid.s = CkJsonObject::ckStringOf(jsonResp,"acctid")
    respcode.s = CkJsonObject::ckStringOf(jsonResp,"respcode")
    defaultacct.s = CkJsonObject::ckStringOf(jsonResp,"defaultacct")
    accttype.s = CkJsonObject::ckStringOf(jsonResp,"accttype")
    token.s = CkJsonObject::ckStringOf(jsonResp,"token")
    license.s = CkJsonObject::ckStringOf(jsonResp,"license")
    respproc.s = CkJsonObject::ckStringOf(jsonResp,"respproc")
    phone.s = CkJsonObject::ckStringOf(jsonResp,"phone")
    profileid.s = CkJsonObject::ckStringOf(jsonResp,"profileid")
    name.s = CkJsonObject::ckStringOf(jsonResp,"name")
    auoptout.s = CkJsonObject::ckStringOf(jsonResp,"auoptout")
    postal.s = CkJsonObject::ckStringOf(jsonResp,"postal")
    expiry.s = CkJsonObject::ckStringOf(jsonResp,"expiry")
    region.s = CkJsonObject::ckStringOf(jsonResp,"region")
    ssnl4.s = CkJsonObject::ckStringOf(jsonResp,"ssnl4")
    respstat.s = CkJsonObject::ckStringOf(jsonResp,"respstat")


    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)
    CkHttpResponse::ckDispose(resp)
    CkJsonObject::ckDispose(jsonResp)


    ProcedureReturn
EndProcedure