Chilkat Online Tools

Node.js / GP-API Collection / DCC_1.3 ECOM Refund standalone

Back to Collection Items

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node21-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node21-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node21-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node21-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node21-linux64');
    }
} else if (os.platform() == 'darwin') {
    if (os.arch() == 'arm64') {
        var chilkat = require('@chilkat/ck-node21-mac-m1');
    } else {
        var chilkat = require('@chilkat/ck-node21-macosx');
    }
}


function chilkatExample() {

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

    var http = new chilkat.Http();
    var success;

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

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

    // {
    //   "merchant_id": "{{mer_id}}",
    //   "account_id": "{{tra_id}}",
    //   "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}}"
    //   }
    // }

    var json = new chilkat.JsonObject();
    json.UpdateString("merchant_id","{{mer_id}}");
    json.UpdateString("account_id","{{tra_id}}");
    json.UpdateString("type","REFUND");
    json.UpdateString("channel","CNP");
    json.UpdateString("amount","10");
    json.UpdateString("currency","EUR");
    json.UpdateString("country","GB");
    json.UpdateString("capture_mode","AUTO");
    json.UpdateString("reference","TRANS-20180114123459948");
    json.UpdateString("payment_method.first_name","James");
    json.UpdateString("payment_method.last_name","Mason");
    json.UpdateString("payment_method.entry_mode","ECOM");
    json.UpdateString("payment_method.card.number","4006097467207025");
    json.UpdateString("payment_method.card.expiry_month","12");
    json.UpdateString("payment_method.card.expiry_year","30");
    json.UpdateString("payment_method.card.cvv","996");
    json.UpdateString("currency_conversion.id","{{ccs_id}}");

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

    // resp: HttpResponse
    var resp = http.PostJson3("https://{{url}}/ucp/transactions","application/json",json);
    if (http.LastMethodSuccess == false) {
        console.log(http.LastErrorText);
        return;
    }

    console.log(resp.StatusCode);
    console.log(resp.BodyStr);


}

chilkatExample();

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-H "X-GP-Version: {{version}}"
	-H "Authorization: Bearer {{token}}"
	-d '{
    "merchant_id": "{{mer_id}}",
    "account_id": "{{tra_id}}",
    "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    \"merchant_id\": \"{{mer_id}}\",\n    \"account_id\": \"{{tra_id}}\",\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": [
  ]
}