Chilkat Online Tools

Objective-C / GP-API Collection / DCC_1.0 Rate Lookup

Back to Collection Items

#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoHttpResponse.h>

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

CkoHttp *http = [[CkoHttp alloc] init];
BOOL 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.

// {
//   "account_name": "dcc",
//   "model": "FROM_TRANSACTION_CURRENCY",
//   "transaction_type": "SALE",
//   "channel": "CNP",
//   "amount": "10",
//   "currency": "EUR",
//   "country": "GB",
//   "reference": "TRANS-20180114123459878",
//   "payment_method": {
//     "name": "Jane Doe",
//     "entry_mode": "ECOM",
//     "card": {
//       "number": "4006097467207025",
//       "expiry_month": "12",
//       "expiry_year": "20",
//       "cvv": "233"
//     }
//   }
// }

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"account_name" value: @"dcc"];
[json UpdateString: @"model" value: @"FROM_TRANSACTION_CURRENCY"];
[json UpdateString: @"transaction_type" value: @"SALE"];
[json UpdateString: @"channel" value: @"CNP"];
[json UpdateString: @"amount" value: @"10"];
[json UpdateString: @"currency" value: @"EUR"];
[json UpdateString: @"country" value: @"GB"];
[json UpdateString: @"reference" value: @"TRANS-20180114123459878"];
[json UpdateString: @"payment_method.name" value: @"Jane Doe"];
[json UpdateString: @"payment_method.entry_mode" value: @"ECOM"];
[json UpdateString: @"payment_method.card.number" value: @"4006097467207025"];
[json UpdateString: @"payment_method.card.expiry_month" value: @"12"];
[json UpdateString: @"payment_method.card.expiry_year" value: @"20"];
[json UpdateString: @"payment_method.card.cvv" value: @"233"];

[http SetRequestHeader: @"Content-Type" value: @"application/json"];
[http SetRequestHeader: @"X-GP-Version" value: @"{{version}}"];
// Adds the "Authorization: Bearer {{token}}" header.
http.AuthToken = @"{{token}}";

CkoHttpResponse *resp = [http PostJson3: @"https://{{url}}/ucp/currency-conversions" contentType: @"application/json" json: json];
if (http.LastMethodSuccess == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

NSLog(@"%d",[resp.StatusCode intValue]);
NSLog(@"%@",resp.BodyStr);

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": "10",
    "currency": "EUR",
    "country": "GB",
    "reference": "TRANS-20180114123459878",
    "payment_method": {
        "name": "Jane Doe",
        "entry_mode": "ECOM",
        "card": {
            "number": "4006097467207025",
            "expiry_month": "12",
            "expiry_year": "20",
            "cvv": "233"
        }
    }
}'
https://{{url}}/ucp/currency-conversions

Postman Collection Item JSON

{
  "name": "DCC_1.0 Rate Lookup",
  "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\": \"10\",\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\": \"4006097467207025\",\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": [
  ]
}