Chilkat Online Tools

C / Salesforce Platform APIs / Create Payment Method

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkJsonObject json;
    HCkHttpResponse resp;

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

    http = CkHttp_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 = CkJsonObject_Create();
    CkJsonObject_UpdateString(json,"paymentGatewayId","{{defaultPaymentGatewayId}}");
    CkJsonObject_UpdateString(json,"cardPaymentMethod.cardHolderName","{{_userFullName}}");
    CkJsonObject_UpdateString(json,"cardPaymentMethod.expiryMonth","11");
    CkJsonObject_UpdateString(json,"cardPaymentMethod.expiryYear","2222");
    CkJsonObject_UpdateString(json,"cardPaymentMethod.cardNumber","4111111111111111");
    CkJsonObject_UpdateString(json,"cardPaymentMethod.cvv","111");
    CkJsonObject_UpdateString(json,"cardPaymentMethod.cardCategory","CreditCard");
    CkJsonObject_UpdateString(json,"cardPaymentMethod.cardType","VISA");
    CkJsonObject_UpdateString(json,"cardPaymentMethod.startYear","2013");
    CkJsonObject_UpdateString(json,"cardPaymentMethod.startMonth","7");
    CkJsonObject_UpdateString(json,"cardPaymentMethod.nickName","Default Payment Method");
    CkJsonObject_UpdateString(json,"cardPaymentMethod.accountId","{{defaultAccountId}}");
    CkJsonObject_UpdateString(json,"phone","4155551212");
    CkJsonObject_UpdateString(json,"email","{{_userEmail}}");
    CkJsonObject_UpdateString(json,"additionalData.key1","value1");
    CkJsonObject_UpdateString(json,"additionalData.key2","value2");

    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttp_putAuthToken(http,"<access_token>");

    resp = CkHttp_PostJson3(http,"https://domain.com/services/data/v{{version}}/commerce/payments/payment-methods","application/json",json);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        return;
    }

    printf("%d\n",CkHttpResponse_getStatusCode(resp));
    printf("%s\n",CkHttpResponse_bodyStr(resp));
    CkHttpResponse_Dispose(resp);


    CkHttp_Dispose(http);
    CkJsonObject_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": [
  ]
}