Chilkat Online Tools

unicodeC / GP-API Collection / DCC_1.1 Rate Lookup Not Available

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": "dcc",
    //   "model": "FROM_TRANSACTION_CURRENCY",
    //   "transaction_type": "SALE",
    //   "channel": "CNP",
    //   "amount": "10000",
    //   "currency": "EUR",
    //   "country": "GB",
    //   "reference": "TRANS-20180114123459878",
    //   "payment_method": {
    //     "name": "Jane Doe",
    //     "entry_mode": "ECOM",
    //     "card": {
    //       "number": "4263970000005262",
    //       "expiry_month": "12",
    //       "expiry_year": "20",
    //       "cvv": "233"
    //     }
    //   }
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"account_name",L"dcc");
    CkJsonObjectW_UpdateString(json,L"model",L"FROM_TRANSACTION_CURRENCY");
    CkJsonObjectW_UpdateString(json,L"transaction_type",L"SALE");
    CkJsonObjectW_UpdateString(json,L"channel",L"CNP");
    CkJsonObjectW_UpdateString(json,L"amount",L"10000");
    CkJsonObjectW_UpdateString(json,L"currency",L"EUR");
    CkJsonObjectW_UpdateString(json,L"country",L"GB");
    CkJsonObjectW_UpdateString(json,L"reference",L"TRANS-20180114123459878");
    CkJsonObjectW_UpdateString(json,L"payment_method.name",L"Jane Doe");
    CkJsonObjectW_UpdateString(json,L"payment_method.entry_mode",L"ECOM");
    CkJsonObjectW_UpdateString(json,L"payment_method.card.number",L"4263970000005262");
    CkJsonObjectW_UpdateString(json,L"payment_method.card.expiry_month",L"12");
    CkJsonObjectW_UpdateString(json,L"payment_method.card.expiry_year",L"20");
    CkJsonObjectW_UpdateString(json,L"payment_method.card.cvv",L"233");

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

    resp = CkHttpW_PostJson3(http,L"https://{{url}}/ucp/currency-conversions",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 "X-GP-Version: {{version}}"
	-H "Authorization: Bearer {{token}}"
	-d '{
    "account_name": "dcc",
    "model": "FROM_TRANSACTION_CURRENCY",
    "transaction_type": "SALE",
    "channel": "CNP",
    "amount": "10000",
    "currency": "EUR",
    "country": "GB",
    "reference": "TRANS-20180114123459878",
    "payment_method": {
        "name": "Jane Doe",
        "entry_mode": "ECOM",
        "card": {
            "number": "4263970000005262",
            "expiry_month": "12",
            "expiry_year": "20",
            "cvv": "233"
        }
    }
}'
https://{{url}}/ucp/currency-conversions

Postman Collection Item JSON

{
  "name": "DCC_1.1 Rate Lookup Not Available",
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    },
    {
      "listen": "test",
      "script": {
        "exec": [
          "var jsonData = JSON.parse(responseBody);\r",
          "\r",
          "postman.setEnvironmentVariable(\"ccs_id\", jsonData.id);"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json",
        "type": "text"
      },
      {
        "key": "X-GP-Version",
        "value": "{{version}}",
        "type": "text"
      },
      {
        "key": "Authorization",
        "value": "Bearer {{token}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n    \"account_name\": \"dcc\",\r\n    \"model\": \"FROM_TRANSACTION_CURRENCY\",\r\n    \"transaction_type\": \"SALE\",\r\n    \"channel\": \"CNP\",\r\n    \"amount\": \"10000\",\r\n    \"currency\": \"EUR\",\r\n    \"country\": \"GB\",\r\n    \"reference\": \"TRANS-20180114123459878\",\r\n    \"payment_method\": {\r\n        \"name\": \"Jane Doe\",\r\n        \"entry_mode\": \"ECOM\",\r\n        \"card\": {\r\n            \"number\": \"4263970000005262\",\r\n            \"expiry_month\": \"12\",\r\n            \"expiry_year\": \"20\",\r\n            \"cvv\": \"233\"\r\n        }\r\n    }\r\n}"
    },
    "url": {
      "raw": "https://{{url}}/ucp/currency-conversions",
      "protocol": "https",
      "host": [
        "{{url}}"
      ],
      "path": [
        "ucp",
        "currency-conversions"
      ]
    }
  },
  "response": [
  ]
}