Sample code for 30+ languages & platforms
Java 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 Java Downloads

Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.HttpCurl;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.StringBuilder;

public class ChilkatExample {

    public static void main(String[] args) {
        boolean success = false;

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

        HttpCurl curl = new HttpCurl();
        StringBuilder cmd = new StringBuilder();
        JsonObject json = new JsonObject();

        // curl -X GET "https://api.stripe.com/v1/balance" \
        //   -u "$STRIPE_API_KEY:" \
        //   -H "Stripe-Version: 2026-10-28.endive"
        cmd.setString("curl -X GET \"https://api.stripe.com/v1/balance\"");
        cmd.append(" -u \"@KEY@:\"");
        cmd.append(" -H \"Stripe-Version: 2026-10-28.endive\"");
        int replaced = cmd.replace("@KEY@", apiKey);
        try {
            curl.doYourThing(cmd.getAsString());
        } catch (ChilkatException e) {
            System.out.println("No HTTP response. Chilkat failure code: " + curl.getFailReason());
            return;
        }

        try {
            curl.getResponseJson(json);
            success = true;
        } catch (ChilkatException e) {
            success = false;
        }
        if ((curl.getStatusCode() != 200) || (!success)) {
            System.out.println("Stripe HTTP " + curl.getStatusCode() + "  Request-Id: " + curl.getResponseHeaderField("Request-Id"));
            if (success) {
                System.out.println(json.stringOf("error.message"));
            }

            return;
        }

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

        int availableIndex = 0;
        while (availableIndex < json.sizeOfArray("available")) {
            json.setI(availableIndex);
            System.out.println("available: " + json.stringOf("available[i].amount") + " " + json.stringOf("available[i].currency"));
            availableIndex = availableIndex + 1;
        }

        int pendingIndex = 0;
        while (pendingIndex < json.sizeOfArray("pending")) {
            json.setI(pendingIndex);
            System.out.println("pending: " + json.stringOf("pending[i].amount") + " " + json.stringOf("pending[i].currency"));
            pendingIndex = pendingIndex + 1;
        }
    }
}