Chilkat Online Tools

PureBasic / GP-API Collection / DCC_1.3 ECOM Refund standalone

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ; 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": "REFUND",
    ;   "channel": "CNP",
    ;   "amount": "10",
    ;   "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": {
    ;     "id": "{{ccs_id}}"
    ;   }
    ; }

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"account_name","dcc")
    CkJsonObject::ckUpdateString(json,"type","REFUND")
    CkJsonObject::ckUpdateString(json,"channel","CNP")
    CkJsonObject::ckUpdateString(json,"amount","10")
    CkJsonObject::ckUpdateString(json,"currency","EUR")
    CkJsonObject::ckUpdateString(json,"country","GB")
    CkJsonObject::ckUpdateString(json,"capture_mode","AUTO")
    CkJsonObject::ckUpdateString(json,"reference","TRANS-20180114123459948")
    CkJsonObject::ckUpdateString(json,"payment_method.first_name","James")
    CkJsonObject::ckUpdateString(json,"payment_method.last_name","Mason")
    CkJsonObject::ckUpdateString(json,"payment_method.entry_mode","ECOM")
    CkJsonObject::ckUpdateString(json,"payment_method.card.number","4006097467207025")
    CkJsonObject::ckUpdateString(json,"payment_method.card.expiry_month","12")
    CkJsonObject::ckUpdateString(json,"payment_method.card.expiry_year","30")
    CkJsonObject::ckUpdateString(json,"payment_method.card.cvv","996")
    CkJsonObject::ckUpdateString(json,"currency_conversion.id","{{ccs_id}}")

    CkHttp::ckSetRequestHeader(http,"Content-Type","application/json")
    CkHttp::ckSetRequestHeader(http,"X-GP-Version","{{version}}")
    ; Adds the "Authorization: Bearer {{token}}" header.
    CkHttp::setCkAuthToken(http, "{{token}}")

    resp.i = CkHttp::ckPostJson3(http,"https://{{url}}/ucp/transactions","application/json",json)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure

Curl Command

curl -X POST
	-H "Content-Type: application/json"
	-H "X-GP-Version: {{version}}"
	-H "Authorization: Bearer {{token}}"
	-d '{
    "account_name": "dcc",
    "type": "REFUND",
    "channel": "CNP",
    "amount": "10",
    "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": {
        "id": "{{ccs_id}}"
    }
}'
https://{{url}}/ucp/transactions

Postman Collection Item JSON

{
  "name": "DCC_1.3 ECOM Refund standalone",
  "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\": \"REFUND\",\n    \"channel\": \"CNP\",\n    \"amount\": \"10\",\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        \"id\": \"{{ccs_id}}\"\n    }\n}"
    },
    "url": {
      "raw": "https://{{url}}/ucp/transactions",
      "protocol": "https",
      "host": [
        "{{url}}"
      ],
      "path": [
        "ucp",
        "transactions"
      ]
    }
  },
  "response": [
  ]
}