Chilkat Online Tools

Swift3 / CardPointe API Integration / Profile (New account/token/card)

Back to Collection Items

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

    let http = CkoHttp()!
    var success: Bool

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "name": "Carson Wentz",
    //   "address": "100 S. Broad Street",
    //   "city": "Philadelphia",
    //   "region": "PA",
    //   "country": "US",
    //   "postal": "19103",
    //   "merchid": "{{merchid}}",
    //   "account": "{{account}}",
    //   "expiry": "{{expiry}}",
    //   "currency": "{{currency}}",
    //   "profile": "{{profileid}}",
    //   "profileupdate": "Y",
    //   "defaultacct": "N"
    // }

    let json = CkoJsonObject()!
    json.update("name", value: "Carson Wentz")
    json.update("address", value: "100 S. Broad Street")
    json.update("city", value: "Philadelphia")
    json.update("region", value: "PA")
    json.update("country", value: "US")
    json.update("postal", value: "19103")
    json.update("merchid", value: "{{merchid}}")
    json.update("account", value: "{{account}}")
    json.update("expiry", value: "{{expiry}}")
    json.update("currency", value: "{{currency}}")
    json.update("profile", value: "{{profileid}}")
    json.update("profileupdate", value: "Y")
    json.update("defaultacct", value: "N")

    http.setRequestHeader("Authorization", value: "{{Authorization}}")
    http.setRequestHeader("Content-Type", value: "application/json")

    let sbRequestBody = CkoStringBuilder()!
    json.emitSb(sbRequestBody)

    var resp: CkoHttpResponse? = http.pTextSb("PUT", url: "https://domain.com/profile", textData: sbRequestBody, charset: "utf-8", contentType: "application/json", md5: false, gzip: false)
    if http.lastMethodSuccess == false {
        print("\(http.lastErrorText!)")
        return
    }

    print("\(resp!.statusCode.intValue)")
    print("\(resp!.bodyStr!)")
    resp = nil

}

Curl Command

curl -X PUT
	-H "Authorization: {{Authorization}}"
	-H "Content-Type: application/json"
	-d '{
    "name": "Carson Wentz",
    "address": "100 S. Broad Street",
    "city": "Philadelphia",
    "region": "PA",
    "country": "US",
    "postal": "19103",
    "merchid": "{{merchid}}",
    "account": "{{account}}",
    "expiry": "{{expiry}}",
    "currency": "{{currency}}",
    "profile": "{{profileid}}",
    "profileupdate": "Y",
    "defaultacct": "N"
}'
https://domain.com/profile

Postman Collection Item JSON

{
  "name": "Profile (New account/token/card)",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "var jsonData = JSON.parse(responseBody);",
          "postman.setEnvironmentVariable(\"profileid\", jsonData.profileid);",
          "var jsonData = JSON.parse(responseBody);",
          "postman.setEnvironmentVariable(\"acctid\", jsonData.acctid);"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Authorization",
        "value": "{{Authorization}}"
      },
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"name\": \"Carson Wentz\",\n    \"address\": \"100 S. Broad Street\",\n    \"city\": \"Philadelphia\",\n    \"region\": \"PA\",\n    \"country\": \"US\",\n    \"postal\": \"19103\",\n    \"merchid\": \"{{merchid}}\",\n    \"account\": \"{{account}}\",\n    \"expiry\": \"{{expiry}}\",\n    \"currency\": \"{{currency}}\",\n    \"profile\": \"{{profileid}}\",\n    \"profileupdate\": \"Y\",\n    \"defaultacct\": \"N\"\n}"
    },
    "url": {
      "raw": "{{url}}/profile",
      "host": [
        "{{url}}"
      ],
      "path": [
        "profile"
      ]
    },
    "description": "[Profile Documentation](https://developer.cardconnect.com/cardconnect-api#profile)\n\n**Notes:** \n* To create subaccounts on an existing profile\n* acctid = n + 1"
  },
  "response": [
  ]
}