Chilkat Online Tools

SQL Server / GP-API Collection / TRA_10.3 Interac Refund

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
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.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": "{{acc_name}}",
    --   "channel": "CP",
    --   "amount": "1000",
    --   "currency": "CAD",
    --   "reference": "11223344",
    --   "country": "CA",
    --   "type": "REFUND",
    --   "payment_method": {
    --     "entry_mode": "CHIP",
    --     "card": {
    --       "track": ";4506445006931933=22122200162907400000?",
    --       "tag": "82021C008407A0000002771010950580000080009A031907319B0268009C01005F280201245F2A0201245F3401019F02060000000010009F03060000000000009F0607A00000027710109F080200019F090200019F100706010A03A4A8009F1A0201249F21031558109F2608395F21408D87BAB09F2701809F3303E0F8C89F34030100029F3501229F360200609F37048C8C7AC59F3901059F410400000025",
    --       "funding": "DEBIT"
    --     },
    --     "authentication": {
    --       "mac": "A01B82D800000000"
    --     }
    --   },
    --   "device": {
    --     "time": "2019-10-14T05:58:40",
    --     "sequence_number": "000010010500"
    --   }
    -- }

    DECLARE @json int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'account_name', '{{acc_name}}'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'channel', 'CP'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'amount', '1000'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'currency', 'CAD'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'reference', '11223344'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'country', 'CA'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'type', 'REFUND'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.entry_mode', 'CHIP'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.card.track', ';4506445006931933=22122200162907400000?'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.card.tag', '82021C008407A0000002771010950580000080009A031907319B0268009C01005F280201245F2A0201245F3401019F02060000000010009F03060000000000009F0607A00000027710109F080200019F090200019F100706010A03A4A8009F1A0201249F21031558109F2608395F21408D87BAB09F2701809F3303E0F8C89F34030100029F3501229F360200609F37048C8C7AC59F3901059F410400000025'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.card.funding', 'DEBIT'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.authentication.mac', 'A01B82D800000000'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'device.time', '2019-10-14T05:58:40'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'device.sequence_number', '000010010500'

    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}}'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'idempotency-key', '12345'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'

    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 "Authorization: Bearer {{token}}"
	-H "Accept: application/json"
	-H "X-GP-Version: {{version}}"
	-H "idempotency-key: 12345"
	-d '{
    "account_name": "{{acc_name}}",
    "channel": "CP",
    "amount": "1000",
    "currency": "CAD",
    "reference": "11223344",
    "country": "CA",
    "type": "REFUND",
    "payment_method": {
        "entry_mode": "CHIP",
        "card": {
            "track": ";4506445006931933=22122200162907400000?",
            "tag": "82021C008407A0000002771010950580000080009A031907319B0268009C01005F280201245F2A0201245F3401019F02060000000010009F03060000000000009F0607A00000027710109F080200019F090200019F100706010A03A4A8009F1A0201249F21031558109F2608395F21408D87BAB09F2701809F3303E0F8C89F34030100029F3501229F360200609F37048C8C7AC59F3901059F410400000025",
            "funding": "DEBIT"
        },
        "authentication": {
            "mac": "A01B82D800000000"
        }
    },
    "device": {
        "time": "2019-10-14T05:58:40",
        "sequence_number": "000010010500"
    }
}'
https://{{url}}/ucp/transactions

Postman Collection Item JSON

{
  "name": "TRA_10.3 Interac Refund",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "pm.environment.unset(\"trn_id\");\r",
          "\r",
          "var jsonData = JSON.parse(responseBody);\r",
          "postman.setEnvironmentVariable(\"trn_id\", jsonData.id);\r",
          "postman.setEnvironmentVariable(\"reference\", jsonData.reference);\r",
          "postman.setEnvironmentVariable(\"refund_trn_id\", jsonData.id);\r",
          "tests[\"Transaction ID \" + pm.environment.get(\"trn_id\")] = true;\r",
          "\r",
          "tests[\"Response time is acceptable\"] = _.inRange(responseTime, 100, 1500); \r",
          "\r",
          "\r",
          "pm.test(\"Successful POST request\", function () {\r",
          "    pm.expect(pm.response.code).to.be.oneOf([200,201,202]);\r",
          "});\r",
          "\r",
          "pm.test(\"Status code name has string\", function () {\r",
          "    pm.response.to.have.status(\"OK\");\r",
          "});"
        ],
        "type": "text/javascript"
      }
    },
    {
      "listen": "prerequest",
      "script": {
        "exec": [
          "var str = String(\"00000000\"+ Math.floor(Math.random()*100000000) + 1).slice(-8);",
          "",
          "pm.environment.set(\"reference\",str);"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Authorization",
        "value": "Bearer {{token}}"
      },
      {
        "key": "Accept",
        "value": "application/json"
      },
      {
        "key": "X-GP-Version",
        "type": "text",
        "value": "{{version}}"
      },
      {
        "key": "idempotency-key",
        "type": "text",
        "value": "12345",
        "disabled": true
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n    \"account_name\": \"{{acc_name}}\",\r\n    \"channel\": \"CP\",\r\n    \"amount\": \"1000\",\r\n    \"currency\": \"CAD\",\r\n    \"reference\": \"11223344\",\r\n    \"country\": \"CA\",\r\n    \"type\": \"REFUND\",\r\n    \"payment_method\": {\r\n        \"entry_mode\": \"CHIP\",\r\n        \"card\": {\r\n            \"track\": \";4506445006931933=22122200162907400000?\",\r\n            \"tag\": \"82021C008407A0000002771010950580000080009A031907319B0268009C01005F280201245F2A0201245F3401019F02060000000010009F03060000000000009F0607A00000027710109F080200019F090200019F100706010A03A4A8009F1A0201249F21031558109F2608395F21408D87BAB09F2701809F3303E0F8C89F34030100029F3501229F360200609F37048C8C7AC59F3901059F410400000025\",\r\n            \"funding\": \"DEBIT\"\r\n        },\r\n        \"authentication\": {\r\n            \"mac\": \"A01B82D800000000\"\r\n        }\r\n    },\r\n    \"device\": {\r\n        \"time\": \"2019-10-14T05:58:40\",\r\n        \"sequence_number\": \"000010010500\"\r\n    }\r\n}"
    },
    "url": {
      "raw": "https://{{url}}/ucp/transactions",
      "protocol": "https",
      "host": [
        "{{url}}"
      ],
      "path": [
        "ucp",
        "transactions"
      ]
    }
  },
  "response": [
  ]
}