SQL Server / GP-API Collection / TKA_2.8 Single to Multi Use Token
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": "CNP",
-- "capture_mode": "AUTO",
-- "type": "SALE",
-- "amount": "100",
-- "currency": "USD",
-- "reference": "45467761",
-- "country": "US",
-- "payment_method": {
-- "name": "Jane",
-- "entry_mode": "ECOM",
-- "id": "PMT_96959619-5ef6-41b1-bfeb-fc13c4b2b359",
-- "storage_model": "ALWAYS"
-- }
-- }
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', 'CNP'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'capture_mode', 'AUTO'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'type', 'SALE'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'amount', '100'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'currency', 'USD'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'reference', '45467761'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'country', 'US'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.name', 'Jane'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.entry_mode', 'ECOM'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.id', 'PMT_96959619-5ef6-41b1-bfeb-fc13c4b2b359'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.storage_model', 'ALWAYS'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'X-GP-Version', '2020-12-22'
-- Adds the "Authorization: Bearer {{token}}" header.
EXEC sp_OASetProperty @http, 'AuthToken', '{{token}}'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://apis.sandbox.globalpay.com/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: 2020-12-22"
-d '{
"account_name": "{{acc_name}}",
"channel": "CNP",
"capture_mode":"AUTO",
"type": "SALE",
"amount": "100",
"currency": "USD",
"reference": "45467761",
"country": "US",
"payment_method": {
"name": "Jane",
"entry_mode": "ECOM",
"id": "PMT_96959619-5ef6-41b1-bfeb-fc13c4b2b359",
"storage_model": "ALWAYS"
}
}'
https://apis.sandbox.globalpay.com/ucp/transactions
Postman Collection Item JSON
{
"name": "TKA_2.8 Single to Multi Use Token",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{token}}"
},
{
"key": "Accept",
"value": "application/json"
},
{
"key": "X-GP-Version",
"value": "2020-12-22"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"account_name\": \"{{acc_name}}\",\n \"channel\": \"CNP\",\n \"capture_mode\":\"AUTO\",\n \"type\": \"SALE\",\n \"amount\": \"100\",\n \"currency\": \"USD\",\n \"reference\": \"45467761\",\n \"country\": \"US\",\n \"payment_method\": {\n \"name\": \"Jane\",\n \"entry_mode\": \"ECOM\",\n \"id\": \"PMT_96959619-5ef6-41b1-bfeb-fc13c4b2b359\",\n \"storage_model\": \"ALWAYS\"\n }\n}"
},
"url": {
"raw": "https://apis.sandbox.globalpay.com/ucp/transactions",
"protocol": "https",
"host": [
"apis",
"sandbox",
"globalpay",
"com"
],
"path": [
"ucp",
"transactions"
]
}
},
"response": [
]
}