Chilkat Online Tools

unicodeC / GP-API Collection / DCC_1.3 ECOM Refund standalone

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",
    //   "type": "REFUND",
    //   "channel": "CNP",
    //   "amount": "10",
    //   "currency": "EUR",
    //   "country": "GB",
    //   "capture_mode": "AUTO",
    //   "reference": "TRANS-20180114123459948",
    //   "payment_method": {
    //     "first_name": "James",
    //     "last_name": "Mason",
    //     "entry_mode": "ECOM",
    //     "card": {
    //       "number": "4006097467207025",
    //       "expiry_month": "12",
    //       "expiry_year": "30",
    //       "cvv": "996"
    //     }
    //   },
    //   "currency_conversion": {
    //     "id": "{{ccs_id}}"
    //   }
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"account_name",L"dcc");
    CkJsonObjectW_UpdateString(json,L"type",L"REFUND");
    CkJsonObjectW_UpdateString(json,L"channel",L"CNP");
    CkJsonObjectW_UpdateString(json,L"amount",L"10");
    CkJsonObjectW_UpdateString(json,L"currency",L"EUR");
    CkJsonObjectW_UpdateString(json,L"country",L"GB");
    CkJsonObjectW_UpdateString(json,L"capture_mode",L"AUTO");
    CkJsonObjectW_UpdateString(json,L"reference",L"TRANS-20180114123459948");
    CkJsonObjectW_UpdateString(json,L"payment_method.first_name",L"James");
    CkJsonObjectW_UpdateString(json,L"payment_method.last_name",L"Mason");
    CkJsonObjectW_UpdateString(json,L"payment_method.entry_mode",L"ECOM");
    CkJsonObjectW_UpdateString(json,L"payment_method.card.number",L"4006097467207025");
    CkJsonObjectW_UpdateString(json,L"payment_method.card.expiry_month",L"12");
    CkJsonObjectW_UpdateString(json,L"payment_method.card.expiry_year",L"30");
    CkJsonObjectW_UpdateString(json,L"payment_method.card.cvv",L"996");
    CkJsonObjectW_UpdateString(json,L"currency_conversion.id",L"{{ccs_id}}");

    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/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 "X-GP-Version: {{version}}"
	-H "Authorization: Bearer {{token}}"
	-d '{
    "account_name": "dcc",
    "type": "REFUND",
    "channel": "CNP",
    "amount": "10",
    "currency": "EUR",
    "country": "GB",
    "capture_mode": "AUTO",
    "reference": "TRANS-20180114123459948",
    "payment_method": {
        "first_name": "James",
        "last_name": "Mason",
        "entry_mode": "ECOM",
        "card": {
            "number": "4006097467207025",
            "expiry_month": "12",
            "expiry_year": "30",
            "cvv": "996"
        }
    },
    "currency_conversion": {
        "id": "{{ccs_id}}"
    }
}'
https://{{url}}/ucp/transactions

Postman Collection Item JSON

{
  "name": "DCC_1.3 ECOM Refund standalone",
  "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": "{\n    \"account_name\": \"dcc\",\n    \"type\": \"REFUND\",\n    \"channel\": \"CNP\",\n    \"amount\": \"10\",\n    \"currency\": \"EUR\",\n    \"country\": \"GB\",\n    \"capture_mode\": \"AUTO\",\n    \"reference\": \"TRANS-20180114123459948\",\n    \"payment_method\": {\n        \"first_name\": \"James\",\n        \"last_name\": \"Mason\",\n        \"entry_mode\": \"ECOM\",\n        \"card\": {\n            \"number\": \"4006097467207025\",\n            \"expiry_month\": \"12\",\n            \"expiry_year\": \"30\",\n            \"cvv\": \"996\"\n        }\n    },\n    \"currency_conversion\": {\n        \"id\": \"{{ccs_id}}\"\n    }\n}"
    },
    "url": {
      "raw": "https://{{url}}/ucp/transactions",
      "protocol": "https",
      "host": [
        "{{url}}"
      ],
      "path": [
        "ucp",
        "transactions"
      ]
    }
  },
  "response": [
  ]
}