Skip to main content
The Purchase Management interface allows administrators to track all transaction activity on the platform, including completed purchases, pending payments, and failed transactions.

Overview

Administrators can monitor the full transaction lifecycle, filter by payment status, and view detailed purchase information for financial reporting and customer support.
All revenue calculations include only completed purchases, excluding pending, failed, or refunded transactions

Purchase Status Types

The platform tracks five distinct transaction states:

Completed

Successful payments that resulted in course enrollment

Created

Payment initiated but not yet processed

Pending

Payment processing in progress

Failed

Payment attempt unsuccessful

Refunded

Completed payment that was reversed

Filter System

Status Filtering

Administrators can filter the purchase list by status using the tab interface:
Displays all purchases regardless of status

Dynamic Filtering

Filters are applied server-side for optimal performance:
const filter = status && status !== 'all' ? { status } : {}
const purchases = await Purchase.find(filter)
  .populate('courseId', 'courseTitle')
  .sort({ createdAt: -1 })

Purchase Information Display

Each transaction entry shows detailed information:

Table Columns

ColumnDescriptionVisibility
CourseTitle of the purchased courseAlways visible
User IDUnique identifier of the purchaserHidden on mobile
AmountTransaction amount in Indian RupeesAlways visible
StatusCurrent payment state with color codingAlways visible
DateTransaction creation timestampHidden on tablet

Data Fields

1

Course Title

Populated from the Course collection via courseId reference
2

User ID

Displayed as a monospace string for easy copying
3

Amount

Formatted with Indian locale: ₹2,499
4

Status Badge

Color-coded pill with appropriate styling per status
5

Date

Formatted as “15 Jan 2024” using Indian date format

Revenue Calculation

The page header displays aggregate revenue statistics:
const totalRevenue = purchases
  .filter((p) => p.status === 'completed')
  .reduce((sum, p) => sum + p.amount, 0)
Revenue totals are calculated client-side from the filtered purchase list and update dynamically based on the selected status filter

Revenue Display Logic

Revenue is shown when:
  • Filter is set to “All” (shows completed purchase revenue)
  • Filter is set to “Completed” (shows total from filtered list)
Revenue is hidden for:
  • Created, Pending, Failed, or Refunded filters (as these don’t contribute to revenue)

API Integration

GET /api/admin/purchases

Fetches purchases with optional status filtering: Request:
GET /api/admin/purchases?status=completed
Authorization: Bearer <admin_token>
Response:
{
  "success": true,
  "purchases": [
    {
      "_id": "purchase123",
      "userId": "user_2abc123def456",
      "courseId": {
        "courseTitle": "Introduction to React"
      },
      "amount": 2499,
      "currency": "INR",
      "status": "completed",
      "createdAt": "2024-03-15T14:30:00Z"
    }
  ]
}
Requires admin authentication via Bearer token in the Authorization header

Status Color Coding

Each status has distinct visual styling:

Color Scheme

const STATUS_STYLES = {
  completed: 'bg-teal-50 text-teal-700 border-teal-200',
  created: 'bg-blue-50 text-blue-700 border-blue-200',
  pending: 'bg-amber-50 text-amber-700 border-amber-200',
  failed: 'bg-red-50 text-red-700 border-red-200',
  refunded: 'bg-purple-50 text-purple-700 border-purple-200'
}

Dark Mode Variants

All status badges include dark mode support:
'dark:bg-teal-900/20 dark:text-teal-400 dark:border-teal-800'

Transaction Sorting

Purchases are sorted by creation date in descending order:
.sort({ createdAt: -1 })
This ensures the most recent transactions appear first, which is critical for:
  • Customer support inquiries
  • Real-time revenue monitoring
  • Failed payment follow-up

Empty States

When no purchases match the filter criteria, a centered message appears: “No purchases found”

Use Cases

Monitor completed purchases to track platform revenue in real-time. Filter by date range to analyze trends.
Filter by “Failed” status to identify payment issues and proactively reach out to users experiencing problems.
Track all refunded transactions to maintain accurate financial records and identify refund patterns.
Search by User ID to quickly locate a specific customer’s purchase history during support inquiries.
Export completed purchase data for accounting and tax reporting purposes.

Responsive Design

Mobile

Displays course, amount, and status only for compact viewing

Tablet

Adds User ID column while hiding date for medium screens

Desktop

Shows all columns with complete transaction details

Performance Optimization

Server-side Filtering

Status filters are applied at the database level:
const filter = status !== 'all' ? { status } : {}
const purchases = await Purchase.find(filter)
This ensures only relevant records are transferred over the network.

Field Selection

Only necessary fields are queried:
.select('userId courseId amount currency status createdAt')

Populated References

Course titles are efficiently populated:
.populate('courseId', 'courseTitle')

Data Model

The Purchase model includes:
FieldTypeDescription
userIdStringClerk user identifier
courseIdObjectIdReference to Course document
amountNumberPayment amount in paisa/cents
currencyStringCurrency code (e.g., “INR”)
statusStringOne of: completed, created, pending, failed, refunded
createdAtDateTransaction creation timestamp
Regularly monitor the “Failed” and “Pending” status filters to identify and resolve payment gateway issues before they affect multiple users.