Unicode C 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

Unicode C Example

#include <C_CkRestW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jsonResponse;
    const wchar_t *object;
    const wchar_t *url;
    BOOL has_more;
    int i;
    int count_i;
    const wchar_t *id;
    int amount;
    int available_on;
    int created;
    const wchar_t *currency;
    BOOL description;
    BOOL exchange_rate;
    int fee;
    int net;
    const wchar_t *source;
    const wchar_t *status;
    const wchar_t *type;
    int j;
    int count_j;

    rest = CkRestW_Create();

    //  URL: https://api.stripe.com/v1/balance/history?limit=3
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"api.stripe.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    CkRestW_SetAuthBasic(rest,L"STRIPE_SECRET_KEY",L"");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/v1/balance/history?limit=3",sbResponseBody);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jsonResponse = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jsonResponse,sbResponseBody);

    object = CkJsonObjectW_stringOf(jsonResponse,L"object");
    url = CkJsonObjectW_stringOf(jsonResponse,L"url");
    has_more = CkJsonObjectW_BoolOf(jsonResponse,L"has_more");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"data");
    while (i < count_i) {
        CkJsonObjectW_putI(jsonResponse,i);
        id = CkJsonObjectW_stringOf(jsonResponse,L"data[i].id");
        object = CkJsonObjectW_stringOf(jsonResponse,L"data[i].object");
        amount = CkJsonObjectW_IntOf(jsonResponse,L"data[i].amount");
        available_on = CkJsonObjectW_IntOf(jsonResponse,L"data[i].available_on");
        created = CkJsonObjectW_IntOf(jsonResponse,L"data[i].created");
        currency = CkJsonObjectW_stringOf(jsonResponse,L"data[i].currency");
        description = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].description");
        exchange_rate = CkJsonObjectW_IsNullOf(jsonResponse,L"data[i].exchange_rate");
        fee = CkJsonObjectW_IntOf(jsonResponse,L"data[i].fee");
        net = CkJsonObjectW_IntOf(jsonResponse,L"data[i].net");
        source = CkJsonObjectW_stringOf(jsonResponse,L"data[i].source");
        status = CkJsonObjectW_stringOf(jsonResponse,L"data[i].status");
        type = CkJsonObjectW_stringOf(jsonResponse,L"data[i].type");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jsonResponse,L"data[i].fee_details");
        while (j < count_j) {
            CkJsonObjectW_putJ(jsonResponse,j);
            j = j + 1;
        }

        i = i + 1;
    }



    CkRestW_Dispose(rest);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jsonResponse);

    }

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"
    }
  ]
}