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

C++ Example

#include <CkRest.h>
#include <CkStringBuilder.h>
#include <CkJsonObject.h>

void ChilkatSample(void)
    {
    CkRest rest;
    bool success;

    //  URL: https://api.stripe.com/v1/balance/history?limit=3
    bool bTls = true;
    int port = 443;
    bool bAutoReconnect = true;
    success = rest.Connect("api.stripe.com",port,bTls,bAutoReconnect);
    if (success != true) {
        std::cout << "ConnectFailReason: " << rest.get_ConnectFailReason() << "\r\n";
        std::cout << rest.lastErrorText() << "\r\n";
        return;
    }

    rest.SetAuthBasic("STRIPE_SECRET_KEY","");

    CkStringBuilder sbResponseBody;
    success = rest.FullRequestNoBodySb("GET","/v1/balance/history?limit=3",sbResponseBody);
    if (success != true) {
        std::cout << rest.lastErrorText() << "\r\n";
        return;
    }

    CkJsonObject jsonResponse;
    jsonResponse.LoadSb(sbResponseBody);

    const char *object = 0;
    const char *url = 0;
    bool has_more;
    int i;
    int count_i;
    const char *id = 0;
    int amount;
    int available_on;
    int created;
    const char *currency = 0;
    bool description;
    bool exchange_rate;
    int fee;
    int net;
    const char *source = 0;
    const char *status = 0;
    const char *type = 0;
    int j;
    int count_j;

    object = jsonResponse.stringOf("object");
    url = jsonResponse.stringOf("url");
    has_more = jsonResponse.BoolOf("has_more");
    i = 0;
    count_i = jsonResponse.SizeOfArray("data");
    while (i < count_i) {
        jsonResponse.put_I(i);
        id = jsonResponse.stringOf("data[i].id");
        object = jsonResponse.stringOf("data[i].object");
        amount = jsonResponse.IntOf("data[i].amount");
        available_on = jsonResponse.IntOf("data[i].available_on");
        created = jsonResponse.IntOf("data[i].created");
        currency = jsonResponse.stringOf("data[i].currency");
        description = jsonResponse.IsNullOf("data[i].description");
        exchange_rate = jsonResponse.IsNullOf("data[i].exchange_rate");
        fee = jsonResponse.IntOf("data[i].fee");
        net = jsonResponse.IntOf("data[i].net");
        source = jsonResponse.stringOf("data[i].source");
        status = jsonResponse.stringOf("data[i].status");
        type = jsonResponse.stringOf("data[i].type");
        j = 0;
        count_j = jsonResponse.SizeOfArray("data[i].fee_details");
        while (j < count_j) {
            jsonResponse.put_J(j);
            j = j + 1;
        }

        i = i + 1;
    }
    }

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