SQL Server Stripe: Retrieve a Balance Transaction

Back to Index

Retrieves the balance transaction with the given ID.

Documentation: https://stripe.com/docs/api/curl#balance_transaction_retrieve

CURL Command

curl https://api.stripe.com/v1/balance/history/txn_1BnETJGswQrCoh0XxO2tGYr7 \
   -u STRIPE_SECRET_KEY:

SQL Server Example

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @rest int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Rest', @rest OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    --  URL: https://api.stripe.com/v1/balance/history/txn_1BnETJGswQrCoh0XxO2tGYr7
    DECLARE @bTls int
    SELECT @bTls = 1
    DECLARE @port int
    SELECT @port = 443
    DECLARE @bAutoReconnect int
    SELECT @bAutoReconnect = 1
    EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'api.stripe.com', STR(@port), STR(@bTls), STR(@bAutoReconnect)
    IF STR(@success) <> 1
      BEGIN

        EXEC sp_OAGetProperty @rest, 'ConnectFailReason', @iTmp0 OUT
        PRINT 'ConnectFailReason: ' + @iTmp0
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        RETURN
      END

    EXEC sp_OAMethod @rest, 'SetAuthBasic', @success OUT, 'STRIPE_SECRET_KEY', ''

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @rest, 'FullRequestNoBodySb', @success OUT, 'GET', '/v1/balance/history/txn_1BnETJGswQrCoh0XxO2tGYr7', STR(@sbResponseBody)
    IF STR(@success) <> 1
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

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

    EXEC sp_OAMethod @jsonResponse, 'LoadSb', @success OUT, STR(@sbResponseBody)

    DECLARE @id nvarchar(4000)

    DECLARE @object nvarchar(4000)

    DECLARE @amount int

    DECLARE @available_on int

    DECLARE @created int

    DECLARE @currency nvarchar(4000)

    DECLARE @description int

    DECLARE @exchange_rate int

    DECLARE @fee int

    DECLARE @net int

    DECLARE @source nvarchar(4000)

    DECLARE @status nvarchar(4000)

    DECLARE @type nvarchar(4000)

    DECLARE @i int

    DECLARE @count_i int

    EXEC sp_OAMethod @jsonResponse, 'StringOf', @id OUT, 'id'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @object OUT, 'object'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @amount OUT, 'amount'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @available_on OUT, 'available_on'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @created OUT, 'created'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @currency OUT, 'currency'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @description OUT, 'description'
    EXEC sp_OAMethod @jsonResponse, 'IsNullOf', @exchange_rate OUT, 'exchange_rate'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @fee OUT, 'fee'
    EXEC sp_OAMethod @jsonResponse, 'IntOf', @net OUT, 'net'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @source OUT, 'source'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @status OUT, 'status'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @type OUT, 'type'
    SELECT @i = 0
    EXEC sp_OAMethod @jsonResponse, 'SizeOfArray', @count_i OUT, 'fee_details'
    WHILE STR(@i) < STR(@count_i)
      BEGIN
        EXEC sp_OASetProperty @jsonResponse, 'I', STR(@i)
        SELECT @i = STR(@i) + 1
      END

    EXEC @hr = sp_OADestroy @rest
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jsonResponse


END
GO

Sample JSON Response Body

{
  "id": "txn_1BnETJGswQrCoh0XxO2tGYr7",
  "object": "balance_transaction",
  "amount": 100,
  "available_on": 1516662781,
  "created": 1516662781,
  "currency": "usd",
  "description": null,
  "exchange_rate": null,
  "fee": 0,
  "fee_details": [
  ],
  "net": 100,
  "source": "ch_1BnETJGswQrCoh0XTs0EERBj",
  "status": "pending",
  "type": "charge"
}