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.
// {
// "paymentGatewayId": "{{defaultPaymentGatewayId}}",
// "cardPaymentMethod": {
// "cardHolderName": "{{_userFullName}}",
// "expiryMonth": "11",
// "expiryYear": "2222",
// "cardNumber": "4111111111111111",
// "cvv": "111",
// "cardCategory": "CreditCard",
// "cardType": "VISA",
// "startYear": "2013",
// "startMonth": "7",
// "nickName": "Default Payment Method",
// "accountId": "{{defaultAccountId}}"
// },
// "phone": "4155551212",
// "email": "{{_userEmail}}",
// "additionalData": {
// "key1": "value1",
// "key2": "value2"
// }
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"paymentGatewayId",L"{{defaultPaymentGatewayId}}");
CkJsonObjectW_UpdateString(json,L"cardPaymentMethod.cardHolderName",L"{{_userFullName}}");
CkJsonObjectW_UpdateString(json,L"cardPaymentMethod.expiryMonth",L"11");
CkJsonObjectW_UpdateString(json,L"cardPaymentMethod.expiryYear",L"2222");
CkJsonObjectW_UpdateString(json,L"cardPaymentMethod.cardNumber",L"4111111111111111");
CkJsonObjectW_UpdateString(json,L"cardPaymentMethod.cvv",L"111");
CkJsonObjectW_UpdateString(json,L"cardPaymentMethod.cardCategory",L"CreditCard");
CkJsonObjectW_UpdateString(json,L"cardPaymentMethod.cardType",L"VISA");
CkJsonObjectW_UpdateString(json,L"cardPaymentMethod.startYear",L"2013");
CkJsonObjectW_UpdateString(json,L"cardPaymentMethod.startMonth",L"7");
CkJsonObjectW_UpdateString(json,L"cardPaymentMethod.nickName",L"Default Payment Method");
CkJsonObjectW_UpdateString(json,L"cardPaymentMethod.accountId",L"{{defaultAccountId}}");
CkJsonObjectW_UpdateString(json,L"phone",L"4155551212");
CkJsonObjectW_UpdateString(json,L"email",L"{{_userEmail}}");
CkJsonObjectW_UpdateString(json,L"additionalData.key1",L"value1");
CkJsonObjectW_UpdateString(json,L"additionalData.key2",L"value2");
// Adds the "Authorization: Bearer <access_token>" header.
CkHttpW_putAuthToken(http,L"<access_token>");
resp = CkHttpW_PostJson3(http,L"https://domain.com/services/data/v{{version}}/commerce/payments/payment-methods",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 "Authorization: Bearer <access_token>"
-d '{
"paymentGatewayId" : "{{defaultPaymentGatewayId}}",
"cardPaymentMethod": {
"cardHolderName": "{{_userFullName}}",
"expiryMonth": "11",
"expiryYear": "2222",
"cardNumber": "4111111111111111",
"cvv": "111",
"cardCategory": "CreditCard",
"cardType": "VISA",
"startYear": "2013",
"startMonth": "7",
"nickName": "Default Payment Method",
"accountId": "{{defaultAccountId}}"
},
"phone": "4155551212",
"email": "{{_userEmail}}",
"additionalData":{
"key1":"value1",
"key2":"value2"
}
}'
https://domain.com/services/data/v{{version}}/commerce/payments/payment-methods
Postman Collection Item JSON
{
"name": "Create Payment Method",
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"paymentGatewayId\" : \"{{defaultPaymentGatewayId}}\",\n \"cardPaymentMethod\": {\n \"cardHolderName\": \"{{_userFullName}}\",\n \"expiryMonth\": \"11\",\n \"expiryYear\": \"2222\",\n \"cardNumber\": \"4111111111111111\",\n \"cvv\": \"111\", \n \"cardCategory\": \"CreditCard\",\n \"cardType\": \"VISA\",\n \"startYear\": \"2013\",\n \"startMonth\": \"7\",\n \"nickName\": \"Default Payment Method\",\n \"accountId\": \"{{defaultAccountId}}\"\n },\n \"phone\": \"4155551212\",\n \"email\": \"{{_userEmail}}\",\n \"additionalData\":{\n \"key1\":\"value1\",\n \"key2\":\"value2\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{_endpoint}}/services/data/v{{version}}/commerce/payments/payment-methods",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"data",
"v{{version}}",
"commerce",
"payments",
"payment-methods"
]
}
},
"response": [
]
}