Objective-C / GP-API Collection / DCC_1.2 ECOM Sale with no DCC
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",
// "type": "SALE",
// "channel": "CNP",
// "amount": "10000",
// "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": {
// "exchange_rate": "1",
// "payer_amount": "10000",
// "payer_currency": "EUR"
// }
// }
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"account_name" value: @"dcc"];
[json UpdateString: @"type" value: @"SALE"];
[json UpdateString: @"channel" value: @"CNP"];
[json UpdateString: @"amount" value: @"10000"];
[json UpdateString: @"currency" value: @"EUR"];
[json UpdateString: @"country" value: @"GB"];
[json UpdateString: @"capture_mode" value: @"AUTO"];
[json UpdateString: @"reference" value: @"TRANS-20180114123459948"];
[json UpdateString: @"payment_method.first_name" value: @"James"];
[json UpdateString: @"payment_method.last_name" value: @"Mason"];
[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: @"30"];
[json UpdateString: @"payment_method.card.cvv" value: @"996"];
[json UpdateString: @"currency_conversion.exchange_rate" value: @"1"];
[json UpdateString: @"currency_conversion.payer_amount" value: @"10000"];
[json UpdateString: @"currency_conversion.payer_currency" value: @"EUR"];
[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/transactions" 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",
"type": "SALE",
"channel": "CNP",
"amount": "10000",
"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": {
"exchange_rate": "1",
"payer_amount": "10000",
"payer_currency": "EUR"
}
}'
https://{{url}}/ucp/transactions
Postman Collection Item JSON
{
"name": "DCC_1.2 ECOM Sale with no DCC",
"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\": \"SALE\",\n \"channel\": \"CNP\",\n \"amount\": \"10000\",\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 \"exchange_rate\": \"1\",\n \"payer_amount\": \"10000\",\n \"payer_currency\": \"EUR\"\n }\n}"
},
"url": {
"raw": "https://{{url}}/ucp/transactions",
"protocol": "https",
"host": [
"{{url}}"
],
"path": [
"ucp",
"transactions"
]
},
"description": "For this request, if you want to do a sale with no DCC chosen, currency_conversion.exchange_rate field must be set to 1, currency_conversion.payer_amount must match 'amount' and currency_conversion.payer_currency must match 'currency'."
},
"response": [
]
}