SQL Server / GP-API Collection / TRA_9.0 Transaction returns Batch ID
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",
-- "type": "SALE",
-- "capture_mode": "AUTO",
-- "amount": "15",
-- "currency": "USD",
-- "reference": "25482851",
-- "country": "US",
-- "payment_method": {
-- "entry_mode": "MANUAL",
-- "card": {
-- "number": "4012001037141112",
-- "expiry_month": "12",
-- "expiry_year": "25",
-- "cvv": "456"
-- }
-- }
-- }
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, 'type', 'SALE'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'capture_mode', 'AUTO'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'amount', '15'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'currency', 'USD'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'reference', '25482851'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'country', 'US'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.entry_mode', 'MANUAL'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.card.number', '4012001037141112'
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', '25'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'payment_method.card.cvv', '456'
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": "CP",
"type": "SALE",
"capture_mode": "AUTO",
"amount": "15",
"currency": "USD",
"reference": "25482851",
"country":"US",
"payment_method": {
"entry_mode" : "MANUAL",
"card": {
"number": "4012001037141112",
"expiry_month": "12",
"expiry_year": "25",
"cvv": "456"
}
}
}'
https://apis.sandbox.globalpay.com/ucp/transactions
Postman Collection Item JSON
{
"name": "TRA_9.0 Transaction returns Batch ID",
"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{\n \"account_name\": \"{{acc_name}}\",\n \"channel\": \"CP\",\n \"type\": \"SALE\",\n \"capture_mode\": \"AUTO\",\n \"amount\": \"15\",\n \"currency\": \"USD\",\n \"reference\": \"25482851\",\n \"country\":\"US\",\n \"payment_method\": {\n \n \"entry_mode\" : \"MANUAL\",\n \"card\": {\n \"number\": \"4012001037141112\",\n \"expiry_month\": \"12\",\n \"expiry_year\": \"25\",\n \"cvv\": \"456\"\n }\n }\n}\n"
},
"url": {
"raw": "https://apis.sandbox.globalpay.com/ucp/transactions",
"protocol": "https",
"host": [
"apis",
"sandbox",
"globalpay",
"com"
],
"path": [
"ucp",
"transactions"
]
},
"description": "This request creates a transaction that returns a batch id."
},
"response": [
]
}