SQL Server
SQL Server
CardConnect Inquire
See more CardConnect Examples
Demonstrates how to get information for an individual transaction, including its settlement status (setlstat) and the response codes from the initial authorization.See https://developer.cardconnect.com/cardconnect-api?lang=json#inquire
Chilkat SQL Server Downloads
-- 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)
DECLARE @success int
SELECT @success = 0
-- 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.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @http, 'BasicAuth', 1
EXEC sp_OASetProperty @http, 'Login', 'API_USERNAME'
EXEC sp_OASetProperty @http, 'Password', 'API_PASSWORD'
DECLARE @url nvarchar(4000)
SELECT @url = 'https://<site>.cardconnect.com:<port>/cardconnect/rest/inquire/<retref>/<merchid>'
DECLARE @responseStr nvarchar(4000)
EXEC sp_OAMethod @http, 'QuickGetStr', @responseStr OUT, @url
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
RETURN
END
-- A response status of 200 indicates potential success. The JSON response body
-- must be examined to determine if it was truly successful or an error.
EXEC sp_OAGetProperty @http, 'LastStatus', @iTmp0 OUT
PRINT 'response status code = ' + @iTmp0
DECLARE @jsonResp int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonResp OUT
EXEC sp_OAMethod @jsonResp, 'Load', @success OUT, @responseStr
EXEC sp_OASetProperty @jsonResp, 'EmitCompact', 0
PRINT 'response JSON:'
EXEC sp_OAMethod @jsonResp, 'Emit', @sTmp0 OUT
PRINT @sTmp0
-- A successful response looks like this:
-- {
-- "amount": "0.00",
-- "resptext": "Approval",
-- "setlstat": "Voided",
-- "capturedate": "20190422180044",
-- "acctid": "1",
-- "respcode": "00",
-- "entrymode": "ECommerce",
-- "merchid": "MERCHANT_ID",
-- "token": "9418594164541111",
-- "authcode": "PPS158",
-- "respproc": "FNOR",
-- "authdate": "20190422",
-- "bintype": "",
-- "profileid": "16618402968441604028",
-- "lastfour": "1111",
-- "name": "TOM JONES",
-- "currency": "USD",
-- "retref": "112989260941",
-- "respstat": "A",
-- "account": "9418594164541111"
-- }
-- Use this online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON
DECLARE @amount nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @amount OUT, 'amount'
DECLARE @resptext nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @resptext OUT, 'resptext'
DECLARE @setlstat nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @setlstat OUT, 'setlstat'
DECLARE @capturedate nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @capturedate OUT, 'capturedate'
DECLARE @acctid nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @acctid OUT, 'acctid'
DECLARE @respcode nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @respcode OUT, 'respcode'
DECLARE @entrymode nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @entrymode OUT, 'entrymode'
DECLARE @merchid nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @merchid OUT, 'merchid'
DECLARE @token nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @token OUT, 'token'
DECLARE @authcode nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @authcode OUT, 'authcode'
DECLARE @respproc nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @respproc OUT, 'respproc'
DECLARE @authdate nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @authdate OUT, 'authdate'
DECLARE @bintype nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @bintype OUT, 'bintype'
DECLARE @profileid nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @profileid OUT, 'profileid'
DECLARE @lastfour nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @lastfour OUT, 'lastfour'
DECLARE @name nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @name OUT, 'name'
DECLARE @currency nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @currency OUT, 'currency'
DECLARE @retref nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @retref OUT, 'retref'
DECLARE @respstat nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @respstat OUT, 'respstat'
DECLARE @account nvarchar(4000)
EXEC sp_OAMethod @jsonResp, 'StringOf', @account OUT, 'account'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @jsonResp
END
GO