Visual FoxPro Stripe: List Balance History

Back to Index

Returns a list of transactions that have contributed to the Stripe account balance (e.g., charges, transfers, and so forth). The transactions are returned in sorted order, with the most recent transactions appearing first.

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

CURL Command

curl https://api.stripe.com/v1/balance/history?limit=3 \
   -u STRIPE_SECRET_KEY: \
   -G

Visual FoxPro Example

LOCAL loRest
LOCAL lnSuccess
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loSbResponseBody
LOCAL loJsonResponse
LOCAL lcObject
LOCAL lcUrl
LOCAL lnHas_more
LOCAL i
LOCAL lnCount_i
LOCAL lcId
LOCAL lnAmount
LOCAL lnAvailable_on
LOCAL lnCreated
LOCAL lcCurrency
LOCAL lnDescription
LOCAL lnExchange_rate
LOCAL lnFee
LOCAL lnNet
LOCAL lcSource
LOCAL lcStatus
LOCAL lcType
LOCAL j
LOCAL lnCount_j

loRest = CreateObject('Chilkat_9_5_0.Rest')

*  URL: https://api.stripe.com/v1/balance/history?limit=3
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("api.stripe.com",lnPort,lnBTls,lnBAutoReconnect)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

loRest.SetAuthBasic("STRIPE_SECRET_KEY","")

loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/v1/balance/history?limit=3",loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJsonResponse = CreateObject('Chilkat_9_5_0.JsonObject')
loJsonResponse.LoadSb(loSbResponseBody)

lcObject = loJsonResponse.StringOf("object")
lcUrl = loJsonResponse.StringOf("url")
lnHas_more = loJsonResponse.BoolOf("has_more")
i = 0
lnCount_i = loJsonResponse.SizeOfArray("data")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lcId = loJsonResponse.StringOf("data[i].id")
    lcObject = loJsonResponse.StringOf("data[i].object")
    lnAmount = loJsonResponse.IntOf("data[i].amount")
    lnAvailable_on = loJsonResponse.IntOf("data[i].available_on")
    lnCreated = loJsonResponse.IntOf("data[i].created")
    lcCurrency = loJsonResponse.StringOf("data[i].currency")
    lnDescription = loJsonResponse.IsNullOf("data[i].description")
    lnExchange_rate = loJsonResponse.IsNullOf("data[i].exchange_rate")
    lnFee = loJsonResponse.IntOf("data[i].fee")
    lnNet = loJsonResponse.IntOf("data[i].net")
    lcSource = loJsonResponse.StringOf("data[i].source")
    lcStatus = loJsonResponse.StringOf("data[i].status")
    lcType = loJsonResponse.StringOf("data[i].type")
    j = 0
    lnCount_j = loJsonResponse.SizeOfArray("data[i].fee_details")
    DO WHILE j < lnCount_j
        loJsonResponse.J = j
        j = j + 1
    ENDDO
    i = i + 1
ENDDO

RELEASE loRest
RELEASE loSbResponseBody
RELEASE loJsonResponse

Sample JSON Response Body

{
  "object": "list",
  "url": "/v1/balance/history",
  "has_more": false,
  "data": [
    {
      "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"
    }
  ]
}