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();
CkHttpW_putBasicAuth(http,TRUE);
CkHttpW_putLogin(http,L"100100248");
CkHttpW_putPassword(http,L"117f3fe5a01a0e400f3e4782baf8ffa43a9d21e9217a15f50d545bc72480d081ecaecc1d6a42ac7a785b7437232bd4cf62dbee679b78a75a3892547059018f9b");
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "amount": {
// "amount": "37.00",
// "currency": "USD"
// },
// "consumer": {
// "phoneNumber": "2120000000",
// "givenNames": "Joe",
// "surname": "Consumer",
// "email": "test@afterpay.com"
// },
// "billing": {
// "name": "Joe Consumer",
// "line1": "1004 Point Lobos Ave",
// "area1": "San Francisco",
// "region": "CA",
// "postcode": "94121",
// "countryCode": "US",
// "phoneNumber": "2120000000"
// },
// "shipping": {
// "name": "Joe Consumer",
// "line1": "1004 Point Lobos Ave",
// "area1": "San Francisco",
// "region": "CA",
// "postcode": "94121",
// "countryCode": "US",
// "phoneNumber": "2120000000"
// },
// "items": [
// {
// "name": "Blue Carabiner",
// "sku": "12341234",
// "quantity": 1,
// "pageUrl": "https://www.afterpay-merchant.com/carabiner-354193.html",
// "imageUrl": "https://img.afterpay-merchant.com/carabiner-7378-391453-1.jpg",
// "price": {
// "amount": "40.00",
// "currency": "USD"
// },
// "categories": [
// [
// "Sporting Goods",
// "Climbing Equipment",
// "Climbing",
// "Climbing Carabiners"
// ],
// [
// "Discounts",
// "Climbing"
// ]
// ]
// },
// {
// "name": "Jeans",
// "sku": "12341235",
// "quantity": 1,
// "pageUrl": "https://www.afterpay-merchant.com/jeans-354193.html",
// "imageUrl": "https://img.afterpay-merchant.com/jeans-7378-391453-1.jpg",
// "price": {
// "amount": "20.00",
// "currency": "USD"
// }
// }
// ],
// "discounts": [
// {
// "displayName": "10% Off Subtotal",
// "amount": {
// "amount": "3.00",
// "currency": "USD"
// }
// }
// ],
// "merchant": {
// "redirectConfirmUrl": "https://www.afterpay-merchant.com/confirm",
// "redirectCancelUrl": "https://www.afterpay-merchant.com/cancel"
// },
// "merchantReference": "merchant-order-number",
// "taxAmount": {
// "amount": "0.00",
// "currency": "USD"
// },
// "shippingAmount": {
// "amount": "10.00",
// "currency": "USD"
// }
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"amount.amount",L"37.00");
CkJsonObjectW_UpdateString(json,L"amount.currency",L"USD");
CkJsonObjectW_UpdateString(json,L"consumer.phoneNumber",L"2120000000");
CkJsonObjectW_UpdateString(json,L"consumer.givenNames",L"Joe");
CkJsonObjectW_UpdateString(json,L"consumer.surname",L"Consumer");
CkJsonObjectW_UpdateString(json,L"consumer.email",L"test@afterpay.com");
CkJsonObjectW_UpdateString(json,L"billing.name",L"Joe Consumer");
CkJsonObjectW_UpdateString(json,L"billing.line1",L"1004 Point Lobos Ave");
CkJsonObjectW_UpdateString(json,L"billing.area1",L"San Francisco");
CkJsonObjectW_UpdateString(json,L"billing.region",L"CA");
CkJsonObjectW_UpdateString(json,L"billing.postcode",L"94121");
CkJsonObjectW_UpdateString(json,L"billing.countryCode",L"US");
CkJsonObjectW_UpdateString(json,L"billing.phoneNumber",L"2120000000");
CkJsonObjectW_UpdateString(json,L"shipping.name",L"Joe Consumer");
CkJsonObjectW_UpdateString(json,L"shipping.line1",L"1004 Point Lobos Ave");
CkJsonObjectW_UpdateString(json,L"shipping.area1",L"San Francisco");
CkJsonObjectW_UpdateString(json,L"shipping.region",L"CA");
CkJsonObjectW_UpdateString(json,L"shipping.postcode",L"94121");
CkJsonObjectW_UpdateString(json,L"shipping.countryCode",L"US");
CkJsonObjectW_UpdateString(json,L"shipping.phoneNumber",L"2120000000");
CkJsonObjectW_UpdateString(json,L"items[0].name",L"Blue Carabiner");
CkJsonObjectW_UpdateString(json,L"items[0].sku",L"12341234");
CkJsonObjectW_UpdateInt(json,L"items[0].quantity",1);
CkJsonObjectW_UpdateString(json,L"items[0].pageUrl",L"https://www.afterpay-merchant.com/carabiner-354193.html");
CkJsonObjectW_UpdateString(json,L"items[0].imageUrl",L"https://img.afterpay-merchant.com/carabiner-7378-391453-1.jpg");
CkJsonObjectW_UpdateString(json,L"items[0].price.amount",L"40.00");
CkJsonObjectW_UpdateString(json,L"items[0].price.currency",L"USD");
CkJsonObjectW_UpdateString(json,L"items[0].categories[0][0]",L"Sporting Goods");
CkJsonObjectW_UpdateString(json,L"items[0].categories[0][1]",L"Climbing Equipment");
CkJsonObjectW_UpdateString(json,L"items[0].categories[0][2]",L"Climbing");
CkJsonObjectW_UpdateString(json,L"items[0].categories[0][3]",L"Climbing Carabiners");
CkJsonObjectW_UpdateString(json,L"items[0].categories[1][0]",L"Discounts");
CkJsonObjectW_UpdateString(json,L"items[0].categories[1][1]",L"Climbing");
CkJsonObjectW_UpdateString(json,L"items[1].name",L"Jeans");
CkJsonObjectW_UpdateString(json,L"items[1].sku",L"12341235");
CkJsonObjectW_UpdateInt(json,L"items[1].quantity",1);
CkJsonObjectW_UpdateString(json,L"items[1].pageUrl",L"https://www.afterpay-merchant.com/jeans-354193.html");
CkJsonObjectW_UpdateString(json,L"items[1].imageUrl",L"https://img.afterpay-merchant.com/jeans-7378-391453-1.jpg");
CkJsonObjectW_UpdateString(json,L"items[1].price.amount",L"20.00");
CkJsonObjectW_UpdateString(json,L"items[1].price.currency",L"USD");
CkJsonObjectW_UpdateString(json,L"discounts[0].displayName",L"10% Off Subtotal");
CkJsonObjectW_UpdateString(json,L"discounts[0].amount.amount",L"3.00");
CkJsonObjectW_UpdateString(json,L"discounts[0].amount.currency",L"USD");
CkJsonObjectW_UpdateString(json,L"merchant.redirectConfirmUrl",L"https://www.afterpay-merchant.com/confirm");
CkJsonObjectW_UpdateString(json,L"merchant.redirectCancelUrl",L"https://www.afterpay-merchant.com/cancel");
CkJsonObjectW_UpdateString(json,L"merchantReference",L"merchant-order-number");
CkJsonObjectW_UpdateString(json,L"taxAmount.amount",L"0.00");
CkJsonObjectW_UpdateString(json,L"taxAmount.currency",L"USD");
CkJsonObjectW_UpdateString(json,L"shippingAmount.amount",L"10.00");
CkJsonObjectW_UpdateString(json,L"shippingAmount.currency",L"USD");
CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");
resp = CkHttpW_PostJson3(http,L"https://api.us-sandbox.afterpay.com/v2/checkouts",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
-u '100100248:117f3fe5a01a0e400f3e4782baf8ffa43a9d21e9217a15f50d545bc72480d081ecaecc1d6a42ac7a785b7437232bd4cf62dbee679b78a75a3892547059018f9b'
-H "Accept: application/json"
-H "Content-Type: application/json"
-d '{
"amount": {
"amount": "37.00",
"currency": "USD"
},
"consumer": {
"phoneNumber": "2120000000",
"givenNames": "Joe",
"surname": "Consumer",
"email": "test@afterpay.com"
},
"billing": {
"name": "Joe Consumer",
"line1": "1004 Point Lobos Ave",
"area1": "San Francisco",
"region": "CA",
"postcode": "94121",
"countryCode": "US",
"phoneNumber": "2120000000"
},
"shipping": {
"name": "Joe Consumer",
"line1": "1004 Point Lobos Ave",
"area1": "San Francisco",
"region": "CA",
"postcode": "94121",
"countryCode": "US",
"phoneNumber": "2120000000"
},
"items":[
{
"name": "Blue Carabiner",
"sku": "12341234",
"quantity": 1,
"pageUrl": "https://www.afterpay-merchant.com/carabiner-354193.html",
"imageUrl": "https://img.afterpay-merchant.com/carabiner-7378-391453-1.jpg",
"price": {
"amount": "40.00",
"currency": "USD"
},
"categories": [
["Sporting Goods", "Climbing Equipment", "Climbing", "Climbing Carabiners"],
["Discounts", "Climbing"]
]
},
{
"name": "Jeans",
"sku": "12341235",
"quantity": 1,
"pageUrl": "https://www.afterpay-merchant.com/jeans-354193.html",
"imageUrl": "https://img.afterpay-merchant.com/jeans-7378-391453-1.jpg",
"price": {
"amount": "20.00",
"currency": "USD"
}
}
],
"discounts": [
{
"displayName": "10% Off Subtotal",
"amount": {
"amount": "3.00",
"currency": "USD"
}
}
],
"merchant": {
"redirectConfirmUrl": "https://www.afterpay-merchant.com/confirm",
"redirectCancelUrl": "https://www.afterpay-merchant.com/cancel"
},
"merchantReference": "merchant-order-number",
"taxAmount": {
"amount": "0.00",
"currency": "USD"
},
"shippingAmount": {
"amount": "10.00",
"currency": "USD"
}
}'
https://api.us-sandbox.afterpay.com/v2/checkouts
Postman Collection Item JSON
{
"name": "Create Checkout",
"event": [
{
"listen": "test",
"script": {
"id": "6e77d6b5-ef19-40b1-a665-41bbc1cff1c8",
"exec": [
"var jsonData = JSON.parse(responseBody);",
"postman.setEnvironmentVariable(\"token\", jsonData.token);"
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"id": "28dad3a2-886b-4a2a-8605-6257dee08b82",
"exec": [
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Accept",
"value": "application/json"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"amount\": {\n \"amount\": \"37.00\",\n \"currency\": \"USD\"\n },\n \"consumer\": {\n \"phoneNumber\": \"2120000000\",\n \"givenNames\": \"Joe\",\n \"surname\": \"Consumer\",\n \"email\": \"test@afterpay.com\"\n },\n \"billing\": {\n \"name\": \"Joe Consumer\",\n \"line1\": \"1004 Point Lobos Ave\",\n \"area1\": \"San Francisco\",\n \"region\": \"CA\",\n \"postcode\": \"94121\",\n \"countryCode\": \"US\",\n \"phoneNumber\": \"2120000000\"\n },\n \"shipping\": {\n \"name\": \"Joe Consumer\",\n \"line1\": \"1004 Point Lobos Ave\",\n \"area1\": \"San Francisco\",\n \"region\": \"CA\",\n \"postcode\": \"94121\",\n \"countryCode\": \"US\",\n \"phoneNumber\": \"2120000000\"\n },\n \"items\":[\n {\n \"name\": \"Blue Carabiner\",\n \"sku\": \"12341234\",\n \"quantity\": 1,\n \"pageUrl\": \"https://www.afterpay-merchant.com/carabiner-354193.html\",\n \"imageUrl\": \"https://img.afterpay-merchant.com/carabiner-7378-391453-1.jpg\",\n \"price\": {\n \"amount\": \"40.00\",\n \"currency\": \"USD\"\n },\n \"categories\": [\n [\"Sporting Goods\", \"Climbing Equipment\", \"Climbing\", \"Climbing Carabiners\"],\n [\"Discounts\", \"Climbing\"]\n ]\n },\n {\n \"name\": \"Jeans\",\n \"sku\": \"12341235\",\n \"quantity\": 1,\n \"pageUrl\": \"https://www.afterpay-merchant.com/jeans-354193.html\",\n \"imageUrl\": \"https://img.afterpay-merchant.com/jeans-7378-391453-1.jpg\",\n \"price\": {\n \"amount\": \"20.00\",\n \"currency\": \"USD\"\n }\n }\n ],\n \"discounts\": [\n {\n \"displayName\": \"10% Off Subtotal\",\n \"amount\": {\n \"amount\": \"3.00\",\n \"currency\": \"USD\"\n }\n }\n ],\n \"merchant\": {\n \"redirectConfirmUrl\": \"https://www.afterpay-merchant.com/confirm\",\n \"redirectCancelUrl\": \"https://www.afterpay-merchant.com/cancel\"\n },\n \"merchantReference\": \"merchant-order-number\",\n \"taxAmount\": {\n \"amount\": \"0.00\",\n \"currency\": \"USD\"\n },\n \"shippingAmount\": {\n \"amount\": \"10.00\",\n \"currency\": \"USD\"\n }\n }"
},
"url": {
"raw": "https://api.us-sandbox.afterpay.com/v2/checkouts",
"protocol": "https",
"host": [
"api",
"us-sandbox",
"afterpay",
"com"
],
"path": [
"v2",
"checkouts"
]
},
"description": "This endpoint creates a checkout that is used to initiate the afterpay payment process. Afterpay uses the information in the checkout request to assist with the consumer’s pre-approval process."
},
"response": [
]
}