Learn how to check your Stripe account balance using the Dashboard, API, and code examples in Node.js, Python, PHP, Ruby, Java, and .NET. Secure, step-by-step guide.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
How to Check Your Stripe Account Balance: A Comprehensive Guide
In this tutorial, I'll show you several methods to check your Stripe account balance, including using the Stripe Dashboard, API, and various programming languages.
Step 1: Checking Balance via Stripe Dashboard
The simplest way to check your Stripe balance is through the web dashboard:
Step 2: Using the Stripe API Directly
You can retrieve your balance using Stripe's REST API:
curl https://api.stripe.com/v1/balance \\
-H "Authorization: Bearer sk_test_YOUR_SECRET_KEY"
Replace sk_test_YOUR_SECRET_KEY
with your actual Stripe secret key. Remember never to expose your secret key in client-side code.
Step 3: Checking Balance with Node.js
To check your Stripe balance using Node.js:
First, install the Stripe package:
npm install stripe
Then use the following code:
const stripe = require('stripe')('sk_test_YOUR_SECRET_KEY');
async function checkBalance() {
try {
const balance = await stripe.balance.retrieve();
console.log('Available balance:', balance.available);
console.log('Pending balance:', balance.pending);
// For a detailed breakdown by currency
balance.available.forEach(balanceItem => {
console.log(`Available in ${balanceItem.currency}: ${balanceItem.amount / 100} ${balanceItem.currency.toUpperCase()}`);
});
return balance;
} catch (error) {
console.error('Error retrieving balance:', error);
}
}
checkBalance();
Step 4: Checking Balance with Python
For Python, install the Stripe library first:
pip install stripe
Then use this code:
import stripe
# Set your API key
stripe.api_key = "sk_test_YOUR_SECRET\_KEY"
def check\_balance():
try:
balance = stripe.Balance.retrieve()
print("Available balance:")
for balance\_item in balance.available:
print(f"{balance_item.amount / 100} {balance_item.currency.upper()}")
print("\nPending balance:")
for balance\_item in balance.pending:
print(f"{balance_item.amount / 100} {balance_item.currency.upper()}")
return balance
except Exception as e:
print(f"Error retrieving balance: {str(e)}")
if **name** == "**main**":
check\_balance()
Step 5: Checking Balance with PHP
For PHP, first install the Stripe library:
composer require stripe/stripe-php
Then use this code:
available as $balanceItem) {
$amount = $balanceItem->amount / 100;
$currency = strtoupper($balanceItem->currency);
echo "$amount $currency\n";
}
echo "\nPending balance:\n";
foreach ($balance->pending as $balanceItem) {
$amount = $balanceItem->amount / 100;
$currency = strtoupper($balanceItem->currency);
echo "$amount $currency\n";
}
} catch (\Stripe\Exception\ApiErrorException $e) {
echo "Error retrieving balance: " . $e->getMessage();
}
Step 6: Checking Balance with Ruby
For Ruby, install the Stripe gem:
gem install stripe
Then use this code:
require 'stripe'
Stripe.api_key = 'sk_test_YOUR_SECRET\_KEY'
begin
balance = Stripe::Balance.retrieve
puts "Available balance:"
balance.available.each do |balance\_item|
puts "#{balance_item.amount / 100.0} #{balance_item.currency.upcase}"
end
puts "\nPending balance:"
balance.pending.each do |balance\_item|
puts "#{balance_item.amount / 100.0} #{balance_item.currency.upcase}"
end
rescue Stripe::StripeError => e
puts "Error retrieving balance: #{e.message}"
end
Step 7: Checking Balance with Java
For Java, add the Stripe dependency to your project:
For Maven:
com.stripe
stripe-java
22.9.0
For Gradle:
implementation 'com.stripe:stripe-java:22.9.0'
Then use this code:
import com.stripe.Stripe;
import com.stripe.exception.StripeException;
import com.stripe.model.Balance;
public class CheckStripeBalance {
public static void main(String[] args) {
Stripe.apiKey = "sk_test_YOUR_SECRET_KEY";
try {
Balance balance = Balance.retrieve();
System.out.println("Available balance:");
balance.getAvailable().forEach(balanceItem -> {
double amount = balanceItem.getAmount() / 100.0;
String currency = balanceItem.getCurrency().toUpperCase();
System.out.printf("%.2f %s%n", amount, currency);
});
System.out.println("\nPending balance:");
balance.getPending().forEach(balanceItem -> {
double amount = balanceItem.getAmount() / 100.0;
String currency = balanceItem.getCurrency().toUpperCase();
System.out.printf("%.2f %s%n", amount, currency);
});
} catch (StripeException e) {
System.out.println("Error retrieving balance: " + e.getMessage());
}
}
}
Step 8: Checking Balance with .NET/C#
For .NET, install the Stripe.net NuGet package:
Install-Package Stripe.net
Then use this code:
using Stripe;
using System;
class Program
{
static void Main()
{
StripeConfiguration.ApiKey = "sk_test_YOUR_SECRET_KEY";
try
{
var balanceService = new BalanceService();
var balance = balanceService.Get();
Console.WriteLine("Available balance:");
foreach (var balanceItem in balance.Available)
{
decimal amount = balanceItem.Amount / 100m;
string currency = balanceItem.Currency.ToUpper();
Console.WriteLine($"{amount} {currency}");
}
Console.WriteLine("\nPending balance:");
foreach (var balanceItem in balance.Pending)
{
decimal amount = balanceItem.Amount / 100m;
string currency = balanceItem.Currency.ToUpper();
Console.WriteLine($"{amount} {currency}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error retrieving balance: {ex.Message}");
}
}
}
Step 9: Understanding the Balance Response
Regardless of which method you use, the balance response will contain these key components:
Each of these contains an array of objects with:
Step 10: Implementing Automated Balance Checks
For ongoing monitoring, you might want to automate balance checks. Here's a simple Node.js implementation that checks your balance daily and sends an email notification:
const stripe = require('stripe')('sk_test_YOUR_SECRET_KEY');
const nodemailer = require('nodemailer');
// First, install nodemailer: npm install nodemailer
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'your-app-password'
}
});
async function checkAndNotifyBalance() {
try {
const balance = await stripe.balance.retrieve();
// Format the balance for email
let emailContent = 'Stripe Balance Report:\n\n';
emailContent += 'Available Balance:\n';
balance.available.forEach(item => {
emailContent += `${(item.amount / 100).toFixed(2)} ${item.currency.toUpperCase()}\n`;
});
emailContent += '\nPending Balance:\n';
balance.pending.forEach(item => {
emailContent += `${(item.amount / 100).toFixed(2)} ${item.currency.toUpperCase()}\n`;
});
// Send email
await transporter.sendMail({
from: '[email protected]',
to: '[email protected]',
subject: 'Daily Stripe Balance Report',
text: emailContent
});
console.log('Balance check completed and email sent');
} catch (error) {
console.error('Error in balance check:', error);
}
}
// Run daily at 9:00 AM
const scheduleBalanceCheck = () => {
const now = new Date();
const scheduledTime = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate(),
9, 0, 0 // 9:00:00 AM
);
// If it's already past 9 AM, schedule for tomorrow
if (now > scheduledTime) {
scheduledTime.setDate(scheduledTime.getDate() + 1);
}
const timeUntilRun = scheduledTime.getTime() - now.getTime();
// Schedule the first run
setTimeout(() => {
checkAndNotifyBalance();
// Then schedule it to run daily
setInterval(checkAndNotifyBalance, 24 _ 60 _ 60 \* 1000);
}, timeUntilRun);
}
scheduleBalanceCheck();
Conclusion
Checking your Stripe balance is essential for financial management. Whether you prefer the visual dashboard or API-based solutions, Stripe provides multiple ways to monitor your funds. Remember to keep your secret API keys secure and never expose them in client-side code.
For production environments, consider implementing proper error handling, logging, and security measures when accessing your Stripe account programmatically.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.