Chilkat Online Tools

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

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;

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

    http = CkHttpW_Create();

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

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

    CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
    CkHttpW_SetRequestHeader(http,L"X-GP-Version",L"2020-12-22");
    // Adds the "Authorization: Bearer {{token}}" header.
    CkHttpW_putAuthToken(http,L"{{token}}");
    CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");

    resp = CkHttpW_PostJson3(http,L"https://apis.sandbox.globalpay.com/ucp/transactions",L"application/json",json);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);

    }

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": [
  ]
}