Chilkat Online Tools

SQL Server / GP-API Collection / DCC_1.2 ECOM Sale

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    -- 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": "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}}"
    --   }
    -- }

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'account_name', 'dcc'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'type', 'SALE'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'channel', 'CNP'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'amount', '10'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'currency', 'EUR'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'country', 'GB'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'capture_mode', 'AUTO'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'reference', 'TRANS-20180114123459948'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.first_name', 'James'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.last_name', 'Mason'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.entry_mode', 'ECOM'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.card.number', '4006097467207025'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.card.expiry_month', '12'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.card.expiry_year', '30'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.card.cvv', '996'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'currency-conversion.id', '{{ccs_id}}'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'X-GP-Version', '{{version}}'
    -- Adds the "Authorization: Bearer {{token}}" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '{{token}}'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://{{url}}/ucp/transactions', 'application/json', @json
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json


END
GO

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": "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.2 ECOM Sale",
  "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\": \"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": [
  ]
}