Overview

The Payment Statistics API provides aggregated metrics about your payment transactions across different statuses. This helps you monitor payment flows and track success/failure rates.

GET /payments/stats

Authentication

All requests must include your API key in the Authorization header:

Authorization: Bearer YOUR_API_KEY

Response Fields

data
object

Payment statistics container object.

Examples

Basic Statistics Request

curl -X GET "https://api.spendjuice.com/payments/stats" \
-H "Authorization: Bearer YOUR_API_KEY"

Success Response

{
  "data": {
    "captured": 2,
    "failed": 5,
    "pending": 2,
    "settled": 8,
    "total": 20
  }
}

Data Aggregation

The statistics endpoint aggregates payment data with the following characteristics:

  • Updates in near real-time as payment statuses change
  • Includes payments from the last 30 days by default
  • Counts each payment exactly once based on its current status
  • Excludes test mode payments from production statistics

Usage Examples

Monitor Payment Success Rate

const stats = await getPaymentStats();
const successRate = (stats.data.settled / stats.data.total) * 100;
console.log(`Payment Success Rate: ${successRate}%`);

Track Failed Payments

const stats = await getPaymentStats();
if (stats.data.failed > 0) {
  notifyTeam(`${stats.data.failed} failed payments require attention`);
}

Best Practices

  1. Caching

    • Cache statistics for up to 5 minutes to reduce API load
    • Implement stale-while-revalidate caching strategy
    • Clear cache when receiving payment webhooks
  2. Error Handling

    • Implement exponential backoff for retries
    • Handle network timeouts gracefully
    • Log unusual statistical patterns
  3. Monitoring

    • Track success rate trends over time
    • Set up alerts for unusual failure rates
    • Monitor pending payment resolution times

Need Help?

For questions about payment statistics: