C Stripe: Retrieve Balance

Back to Index

Retrieves the current account balance, based on the authentication that was used to make the request.

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

CURL Command

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

C Example

#include <C_CkRest.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jsonResponse;
    const char *object;
    BOOL livemode;
    int i;
    int count_i;
    const char *currency;
    int amount;
    int source_typesCard;

    rest = CkRest_Create();

    //  URL: https://api.stripe.com/v1/balance
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRest_Connect(rest,"api.stripe.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        return;
    }

    CkRest_SetAuthBasic(rest,"STRIPE_SECRET_KEY","");

    sbResponseBody = CkStringBuilder_Create();
    success = CkRest_FullRequestNoBodySb(rest,"GET","/v1/balance",sbResponseBody);
    if (success != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    jsonResponse = CkJsonObject_Create();
    CkJsonObject_LoadSb(jsonResponse,sbResponseBody);

    object = CkJsonObject_stringOf(jsonResponse,"object");
    livemode = CkJsonObject_BoolOf(jsonResponse,"livemode");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(jsonResponse,"available");
    while (i < count_i) {
        CkJsonObject_putI(jsonResponse,i);
        currency = CkJsonObject_stringOf(jsonResponse,"available[i].currency");
        amount = CkJsonObject_IntOf(jsonResponse,"available[i].amount");
        source_typesCard = CkJsonObject_IntOf(jsonResponse,"available[i].source_types.card");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jsonResponse,"pending");
    while (i < count_i) {
        CkJsonObject_putI(jsonResponse,i);
        currency = CkJsonObject_stringOf(jsonResponse,"pending[i].currency");
        amount = CkJsonObject_IntOf(jsonResponse,"pending[i].amount");
        source_typesCard = CkJsonObject_IntOf(jsonResponse,"pending[i].source_types.card");
        i = i + 1;
    }



    CkRest_Dispose(rest);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jsonResponse);

    }

Sample JSON Response Body

{
  "object": "balance",
  "available": [
    {
      "currency": "usd",
      "amount": 0,
      "source_types": {
        "card": 0
      }
    }
  ],
  "livemode": false,
  "pending": [
    {
      "currency": "usd",
      "amount": 0,
      "source_types": {
        "card": 0
      }
    }
  ]
}