Sample code for 30+ languages & platforms
C Requires Chilkat v11.7.0+

Stripe: Show available and pending balances by currency

See more Stripe Examples

Read the available and pending account balances for every currency returned by Stripe.

Stripe documentation and cURL example

Chilkat C Downloads

C
#include <C_CkHttpCurl.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    BOOL success;
    const char *apiKey;
    HCkHttpCurl curl;
    HCkStringBuilder cmd;
    HCkJsonObject json;
    int replaced;
    int availableIndex;
    int pendingIndex;

    success = FALSE;

    //  Requires an unlocked Chilkat bundle. See Global Unlock Sample.
    //  Supply a restricted sandbox key from merchant-controlled configuration.
    apiKey = "YOUR_STRIPE_TEST_KEY";

    curl = CkHttpCurl_Create();
    cmd = CkStringBuilder_Create();
    json = CkJsonObject_Create();

    //  curl -X GET "https://api.stripe.com/v1/balance" \
    //    -u "$STRIPE_API_KEY:" \
    //    -H "Stripe-Version: 2026-10-28.endive"
    CkStringBuilder_SetString(cmd,"curl -X GET \"https://api.stripe.com/v1/balance\"");
    CkStringBuilder_Append(cmd," -u \"@KEY@:\"");
    CkStringBuilder_Append(cmd," -H \"Stripe-Version: 2026-10-28.endive\"");
    replaced = CkStringBuilder_Replace(cmd,"@KEY@",apiKey);
    success = CkHttpCurl_DoYourThing(curl,CkStringBuilder_getAsString(cmd));
    if (success != TRUE) {
        printf("No HTTP response. Chilkat failure code: %d\n",CkHttpCurl_getFailReason(curl));
        CkHttpCurl_Dispose(curl);
        CkStringBuilder_Dispose(cmd);
        CkJsonObject_Dispose(json);
        return;
    }

    success = CkHttpCurl_GetResponseJson(curl,json);
    if ((CkHttpCurl_getStatusCode(curl) != 200) || (success != TRUE)) {
        printf("Stripe HTTP %d  Request-Id: %s\n",CkHttpCurl_getStatusCode(curl),CkHttpCurl_getResponseHeaderField(curl,"Request-Id"));
        if (success == TRUE) {
            printf("%s\n",CkJsonObject_stringOf(json,"error.message"));
        }

        CkHttpCurl_Dispose(curl);
        CkStringBuilder_Dispose(cmd);
        CkJsonObject_Dispose(json);
        return;
    }

    //  Amounts are integer minor units. Read them as text to preserve large balances.

    availableIndex = 0;
    while ((availableIndex < CkJsonObject_SizeOfArray(json,"available"))) {
        CkJsonObject_putI(json,availableIndex);
        printf("available: %s %s\n",CkJsonObject_stringOf(json,"available[i].amount"),CkJsonObject_stringOf(json,"available[i].currency"));
        availableIndex = availableIndex + 1;
    }

    pendingIndex = 0;
    while ((pendingIndex < CkJsonObject_SizeOfArray(json,"pending"))) {
        CkJsonObject_putI(json,pendingIndex);
        printf("pending: %s %s\n",CkJsonObject_stringOf(json,"pending[i].amount"),CkJsonObject_stringOf(json,"pending[i].currency"));
        pendingIndex = pendingIndex + 1;
    }



    CkHttpCurl_Dispose(curl);
    CkStringBuilder_Dispose(cmd);
    CkJsonObject_Dispose(json);

    }