Forecasting Cash Flow from Paystack Data
Cash flow forecasting from Paystack: 1) Export monthly revenue totals from GET /transaction (group by month, sum amounts). 2) Get MRR from active subscriptions: GET /subscription?status=active, sum amounts. 3) Get settlement schedule: GET /settlement for historical payout timing (T+1 or T+2). 4) Feed aggregated data to LLM — not raw transactions. 5) Prompt for projection with stated assumptions. Key: the LLM should return a range (low/mid/high), not a single number, and must state what assumptions drive the projection. Never use an AI cash flow projection for financial commitments without human review.
Preparing Paystack Data for Forecasting
// Prepare aggregated data for LLM — never raw transactions
async function buildForecastInput() {
var headers = { Authorization: 'Bearer ' + process.env.PAYSTACK_SECRET_KEY };
// 1. Monthly revenue for past 6 months
var monthlyRevenue = [];
for (var i = 5; i >= 0; i--) {
var d = new Date();
d.setMonth(d.getMonth() - i);
var from = new Date(d.getFullYear(), d.getMonth(), 1).toISOString().slice(0, 10);
var to = new Date(d.getFullYear(), d.getMonth() + 1, 0).toISOString().slice(0, 10);
var res = await fetch('https://api.paystack.co/transaction?status=success&from=' + from + '&to=' + to + '&perPage=100', { headers });
var txns = (await res.json()).data || [];
monthlyRevenue.push({
month: from.slice(0, 7),
total_ngn: txns.reduce((s, t) => s + t.amount, 0) / 100,
count: txns.length,
});
}
// 2. Current MRR from active subscriptions
var subsRes = await fetch('https://api.paystack.co/subscription?status=active&perPage=100', { headers });
var subs = (await subsRes.json()).data || [];
var mrr = subs.reduce((s, sub) => s + sub.amount, 0) / 100;
// 3. Settlement lag (from recent settlements)
var settleRes = await fetch('https://api.paystack.co/settlement?perPage=10', { headers });
var settlements = (await settleRes.json()).data || [];
var avgLagDays = settlements.length
? settlements.reduce((s, st) => {
var txDate = new Date(st.effective_date);
var settleDate = new Date(st.settlement_date);
return s + (settleDate - txDate) / 86400000;
}, 0) / settlements.length
: 1; // default T+1
return { monthlyRevenue, mrr_ngn: mrr, active_subscriptions: subs.length, avg_settlement_lag_days: avgLagDays };
}
// Feed to LLM for forecast
async function generateCashFlowForecast() {
var data = await buildForecastInput();
var prompt = `Here is our Paystack revenue data for the past 6 months:
Monthly revenue: ${JSON.stringify(data.monthlyRevenue)}
Current MRR from active subscriptions: NGN ${data.mrr_ngn}
Active subscriptions: ${data.active_subscriptions}
Average settlement lag: ${data.avg_settlement_lag_days.toFixed(1)} days
Based on this data, forecast next month's revenue (low/mid/high range).
State the assumptions driving each scenario.
Highlight any trends you see in the monthly data.
Note: Paystack settles net of fees (~1.5% + NGN 100 per transaction).`;
var response = await anthropic.messages.create({
model: 'claude-opus-4-6',
max_tokens: 1024,
messages: [{ role: 'user', content: prompt }],
});
return response.content[0].text;
}
Learn More
See building a natural language revenue dashboard for the interactive query pattern over the same data.
Key Takeaways
- ✓Feed the LLM aggregated monthly totals, not raw transaction arrays — lower token cost, better analysis.
- ✓MRR from active subscriptions is the most reliable forward-looking signal in Paystack data.
- ✓Settlement timing (T+1/T+2) matters for cash flow — Paystack settles net of fees, not gross revenue.
- ✓Ask for a range (low/mid/high) with stated assumptions — a single number is false precision.
- ✓AI projections are starting points for planning, not commitments — all forecasts need human review.
Frequently Asked Questions
- How accurate is AI cash flow forecasting from payment data?
- It depends heavily on your business pattern. Subscription businesses with stable MRR get useful projections — the LLM can spot renewal timing and churn patterns. One-time payment businesses with volatile revenue get less reliable forecasts. Think of AI forecasting as surfacing trends and making the data easier to interpret, not as replacing a finance professional's judgment. Use it for planning conversations, not financial commitments.
- Does Paystack's settlement data include all revenue or only settled amounts?
- Settlement data shows what Paystack paid out to your bank — net of fees and after settlement lag. Transaction data shows gross revenue as it is charged. For cash flow forecasting, use transaction data for revenue projection and settlement data for bank account cash timing. These two numbers will differ by fees (roughly 1.5% + NGN 100 per transaction) and timing (T+1 or T+2 settlement).
- How do I factor in currency for multi-currency businesses?
- Forecast by currency separately. NGN, KES, and GHS have different settlement dynamics and exchange rate exposure. Give the LLM each currency's monthly data independently and ask for per-currency projections. If you need a combined projection in one currency, apply exchange rates yourself and note the assumption — do not let the LLM choose exchange rates.
Ready to build real-world apps?
Join the McTaba Labs full-stack marathon (4 months full-time · 6 months part-time). Learn M-Pesa, USSD, and WhatsApp engineering while shipping 8 production apps.
Apply to the McTaba Marathon