Skip to main content

Payment Analytics

Payment Analytics provides comprehensive insights into payment processing operations, fee collection, and payment account metrics for financial operations and business intelligence.

API Endpoints Overview

MethodEndpointDescription
GET/v1/admin/analytics/payments/payment-accountsPayment account analytics
GET/v1/admin/analytics/payments/active-payment-accountsActive payment account metrics
GET/v1/admin/analytics/payments/payment-processedProcessed payment analytics
GET/v1/admin/analytics/payments/collected-feesCollected fees analytics

Service Methods & Business Logic

Payment Accounts Analytics

paymentAccounts(startDate, endDate) - Payment account tracking

  • Retrieves payment account analytics with date range filtering
  • Tracks accounts with payment processing capability
  • Calculates payment account growth rate comparing periods
  • Returns payment account data with growth metrics
  • MongoDB Collections: _accounts, _store.subscriptions
  • Key Filters: Payment-enabled accounts within date range

Active Payment Accounts Analytics

activePaymentAccounts(startDate, endDate) - Active payment tracking

  • Tracks active payment accounts with processing activity
  • Filters accounts with active payment processing within period
  • Calculates active payment account growth rate
  • Returns active payment account metrics with trend analysis
  • MongoDB Collections: _accounts, _store.subscriptions
  • Key Filters: Accounts with active payment processing

Payment Processed Analytics

paymentProcessed(startDate, endDate) - Payment processing tracking

  • Tracks total payment processing volume and frequency
  • Analyzes payment processing trends over time
  • Calculates payment processing growth rate
  • Returns processed payment analytics with volume metrics
  • MongoDB Collections: Payment processing collections
  • Key Filters: Processed payments within date range

Collected Fees Analytics

collectedFees(startDate, endDate) - Fee collection tracking

  • Tracks fee collection from payment processing
  • Analyzes fee collection trends and growth
  • Calculates fee collection growth rate comparing periods
  • Returns collected fees analytics with revenue impact
  • MongoDB Collections: Fee collection records
  • Key Filters: Fee collections within date range

Technical Implementation Details

Payment Account Aggregation

const paymentAccountsAggregation = [
{
$facet: {
currentPaymentsAccountData: [
{ $match: paymentAccountOptions },
{
$group: {
_id: '$created_at',
count: { $sum: 1 },
},
},
{
$project: {
tmp: {
date: '$_id',
count: '$count',
},
},
},
{
$group: {
_id: null,
total: { $sum: '$tmp.count' },
data: { $addToSet: '$tmp' },
},
},
],
previousPaymentsAccountCount: [
{ $match: previousPaymentAccountOptions },
{ $count: 'total' },
],
},
},
{
$set: {
growthRate: growthRateCalculation,
},
},
];

Fee Collection Analysis

const collectedFeesTracking = [
{
$match: {
created_at: { $gte: startDate, $lte: endDate },
},
},
{
$group: {
_id: '$created_at',
count: { $sum: '$fee_amount' },
},
},
{
$project: {
tmp: {
date: '$_id',
count: '$count',
},
},
},
{
$group: {
_id: null,
total: { $sum: '$tmp.count' },
data: { $addToSet: '$tmp' },
},
},
];

Growth Rate Calculation

const paymentGrowthRate = {
$ifNull: [
{
$trunc: [
{
$multiply: [
{
$cond: [
{ $eq: [previousValue, 0] },
0,
{
$divide: [{ $subtract: [currentValue, previousValue] }, previousValue],
},
],
},
100,
],
},
2,
],
},
0,
],
};

API Response Formats

Payment Accounts Response

{
"success": true,
"message": "SUCCESS",
"data": {
"currentData": {
"total": 325,
"data": [
{
"date": "2024-10-01T00:00:00.000Z",
"count": 12
},
{
"date": "2024-10-02T00:00:00.000Z",
"count": 15
}
]
},
"growthRate": 8.5
}
}

Processed Payments Response

{
"success": true,
"message": "SUCCESS",
"data": {
"currentData": {
"total": 1250000,
"data": [
{
"date": "2024-10-01T00:00:00.000Z",
"count": 45000
},
{
"date": "2024-10-02T00:00:00.000Z",
"count": 52000
}
]
},
"growthRate": 12.0
}
}

Collected Fees Response

{
"success": true,
"message": "SUCCESS",
"data": {
"currentData": {
"total": 37500,
"data": [
{
"date": "2024-10-01T00:00:00.000Z",
"count": 1350
},
{
"date": "2024-10-02T00:00:00.000Z",
"count": 1560
}
]
},
"growthRate": 15.5
}
}

Active Payment Accounts Response

{
"success": true,
"message": "SUCCESS",
"data": {
"currentData": {
"total": 280,
"data": [
{
"date": "2024-10-01T00:00:00.000Z",
"count": 10
},
{
"date": "2024-10-02T00:00:00.000Z",
"count": 13
}
]
},
"growthRate": 6.8
}
}

Business Logic Workflows

Payment Processing Analytics Flow

graph TD
A[Payment Analytics Request] --> B[Date Range Processing]
B --> C[Payment Data Aggregation]
C --> D[Volume Calculation]
D --> E[Growth Rate Analysis]
E --> F[Response Formatting]

subgraph "Payment Metrics"
G[Processing Volume]
H[Account Count]
I[Fee Collection]
J[Growth Rates]
end

D --> G --> F
D --> H --> F
D --> I --> F
E --> J --> F

Fee Collection Analysis Flow

graph TD
A[Fee Analytics Request] --> B[Fee Collection Query]
B --> C[Time Series Aggregation]
C --> D[Fee Total Calculation]
D --> E[Period Comparison]
E --> F[Growth Rate Calculation]
F --> G[Fee Analytics Response]

subgraph "Fee Data"
H[Daily Fee Collections]
I[Total Fee Revenue]
J[Fee Growth Rate]
end

C --> H --> G
D --> I --> G
F --> J --> G

Query Parameters

Standard Parameters

  • start_date (ISO string, optional) - Analytics period start date
  • end_date (ISO string, optional) - Analytics period end date

Default Behavior

  • Date range defaults to last 30 days if not specified
  • All monetary values returned in cents (Stripe format)
  • Growth rates calculated as percentages with 2 decimal precision

Payment Metrics Definitions

Key Payment Metrics

  • Payment Accounts: Total accounts with payment processing capability
  • Active Payment Accounts: Accounts with active payment processing activity
  • Payment Processed: Total volume of processed payments
  • Collected Fees: Total fees collected from payment processing

Fee Structure

Payment processing fees are calculated based on:

  • Transaction percentage fees
  • Fixed per-transaction fees
  • Volume-based fee tiers
  • Premium service fees

Authorization & Access Control

Administrative Access

  • DashClicks staff authentication required
  • adminAppCheck('analytics') middleware protection
  • Rate limiting with validateLimit middleware
  • Comprehensive audit logging for financial data access

Financial Data Security

  • Restricted access to payment processing data
  • Secure handling of fee collection information
  • Input validation and sanitization
  • Error response sanitization for security

Performance Optimization

Database Optimization

  • Indexes on payment processing date fields
  • Composite indexes for account and payment data joins
  • Optimized aggregation pipelines for large transaction volumes

Query Efficiency

  • Efficient date range filtering
  • Optimized fee calculation aggregations
  • Memory-efficient processing for high-volume data

Usage Examples

Get Payment Accounts Analytics

GET /v1/admin/analytics/payments/payment-accounts?start_date=2024-09-01&end_date=2024-09-30
Authorization: Bearer {admin_token}

Get Processed Payments Volume

GET /v1/admin/analytics/payments/payment-processed
Authorization: Bearer {admin_token}

Get Fee Collection Analytics

GET /v1/admin/analytics/payments/collected-fees?start_date=2024-10-01&end_date=2024-10-31
Authorization: Bearer {admin_token}

Get Active Payment Accounts

GET /v1/admin/analytics/payments/active-payment-accounts
Authorization: Bearer {admin_token}
💬

Documentation Assistant

Ask me anything about the docs

Hi! I'm your documentation assistant. Ask me anything about the docs!

I can help you with:
- Code examples
- Configuration details
- Troubleshooting
- Best practices

Try asking: How do I configure the API?
09:31 AM