Chilkat Online Tools

Swift / GP-API Collection / TKA_2.8 Single to Multi Use Token

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.

    // {
    //   "account_name": "{{acc_name}}",
    //   "channel": "CNP",
    //   "capture_mode": "AUTO",
    //   "type": "SALE",
    //   "amount": "100",
    //   "currency": "USD",
    //   "reference": "45467761",
    //   "country": "US",
    //   "payment_method": {
    //     "name": "Jane",
    //     "entry_mode": "ECOM",
    //     "id": "PMT_96959619-5ef6-41b1-bfeb-fc13c4b2b359",
    //     "storage_model": "ALWAYS"
    //   }
    // }

    let json = CkoJsonObject()
    json.UpdateString("account_name", value: "{{acc_name}}")
    json.UpdateString("channel", value: "CNP")
    json.UpdateString("capture_mode", value: "AUTO")
    json.UpdateString("type", value: "SALE")
    json.UpdateString("amount", value: "100")
    json.UpdateString("currency", value: "USD")
    json.UpdateString("reference", value: "45467761")
    json.UpdateString("country", value: "US")
    json.UpdateString("payment_method.name", value: "Jane")
    json.UpdateString("payment_method.entry_mode", value: "ECOM")
    json.UpdateString("payment_method.id", value: "PMT_96959619-5ef6-41b1-bfeb-fc13c4b2b359")
    json.UpdateString("payment_method.storage_model", value: "ALWAYS")

    http.SetRequestHeader("Content-Type", value: "application/json")
    http.SetRequestHeader("X-GP-Version", value: "2020-12-22")
    // Adds the "Authorization: Bearer {{token}}" header.
    http.AuthToken = "{{token}}"
    http.SetRequestHeader("Accept", value: "application/json")

    var resp: CkoHttpResponse? = http.PostJson3("https://apis.sandbox.globalpay.com/ucp/transactions", contentType: "application/json", json: json)
    if http.LastMethodSuccess == false {
        print("\(http.LastErrorText)")
        return
    }

    print("\(resp!.StatusCode.intValue)")
    print("\(resp!.BodyStr)")
    resp = nil

}

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-H "Authorization: Bearer {{token}}"
	-H "Accept: application/json"
	-H "X-GP-Version: 2020-12-22"
	-d '{
    "account_name": "{{acc_name}}",
    "channel": "CNP",
    "capture_mode":"AUTO",
    "type": "SALE",
    "amount": "100",
    "currency": "USD",
    "reference": "45467761",
    "country": "US",
    "payment_method": {
        "name": "Jane",
        "entry_mode": "ECOM",
        "id": "PMT_96959619-5ef6-41b1-bfeb-fc13c4b2b359",
        "storage_model": "ALWAYS"
    }
}'
https://apis.sandbox.globalpay.com/ucp/transactions

Postman Collection Item JSON

{
  "name": "TKA_2.8 Single to Multi Use Token",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Authorization",
        "value": "Bearer {{token}}"
      },
      {
        "key": "Accept",
        "value": "application/json"
      },
      {
        "key": "X-GP-Version",
        "value": "2020-12-22"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"account_name\": \"{{acc_name}}\",\n    \"channel\": \"CNP\",\n    \"capture_mode\":\"AUTO\",\n    \"type\": \"SALE\",\n    \"amount\": \"100\",\n    \"currency\": \"USD\",\n    \"reference\": \"45467761\",\n    \"country\": \"US\",\n    \"payment_method\": {\n        \"name\": \"Jane\",\n        \"entry_mode\": \"ECOM\",\n        \"id\": \"PMT_96959619-5ef6-41b1-bfeb-fc13c4b2b359\",\n        \"storage_model\": \"ALWAYS\"\n    }\n}"
    },
    "url": {
      "raw": "https://apis.sandbox.globalpay.com/ucp/transactions",
      "protocol": "https",
      "host": [
        "apis",
        "sandbox",
        "globalpay",
        "com"
      ],
      "path": [
        "ucp",
        "transactions"
      ]
    }
  },
  "response": [
  ]
}