Skip to main content
GET
/
api
/
payments
/
admin
/
all
curl -X GET "https://api.vaniykempire.com/api/payments/admin/all?page=1&limit=20" \
  -H "Authorization: Bearer ADMIN_JWT_TOKEN"
{
  "purchases": [
    {
      "_id": "65f1a2b3c4d5e6f7g8h9i0j1",
      "user": {
        "_id": "507f1f77bcf86cd799439011",
        "name": "John Doe",
        "email": "john.doe@example.com"
      },
      "content": {
        "_id": "507f191e810c19729de860ea",
        "title": "Advanced React Patterns",
        "type": "course"
      },
      "amount": 29.99,
      "stripePaymentIntentId": "pi_3MtwBwLkdIwHu7ix28a3tqPa",
      "status": "completed",
      "purchasedAt": "2024-03-15T10:30:00.000Z"
    },
    {
      "_id": "65f1a2b3c4d5e6f7g8h9i0j2",
      "user": {
        "_id": "507f1f77bcf86cd799439012",
        "name": "Jane Smith",
        "email": "jane.smith@example.com"
      },
      "content": {
        "_id": "507f191e810c19729de860eb",
        "title": "Node.js Masterclass",
        "type": "course"
      },
      "amount": 39.99,
      "stripePaymentIntentId": "pi_3MtwCxLkdIwHu7ix29b4urQb",
      "status": "completed",
      "purchasedAt": "2024-03-15T09:15:00.000Z"
    }
  ],
  "totalPages": 5,
  "currentPage": 1,
  "totalPurchases": 87
}
Administrator endpoint for viewing all payment transactions across the platform. Supports pagination and filtering by payment status.

Authentication

Requires authentication with administrator privileges. Include JWT token in Authorization header.
This endpoint requires admin role. Regular users will receive a 403 Forbidden response.

Query Parameters

page
number
default:"1"
Page number for pagination (1-based)
limit
number
default:"20"
Number of purchases per page (max: 100)
status
string
Filter by payment status. Options:
  • pending - Payment intent created but not completed
  • completed - Successfully processed payment
  • failed - Payment failed
  • refunded - Payment refunded by admin
Omit to show all statuses.

Response

purchases
array
Array of purchase objects with populated user and content details
totalPages
number
Total number of pages available
currentPage
number
Current page number
totalPurchases
number
Total count of purchases matching the filter

Sorting

Results are automatically sorted by purchasedAt in descending order (newest first).
curl -X GET "https://api.vaniykempire.com/api/payments/admin/all?page=1&limit=20" \
  -H "Authorization: Bearer ADMIN_JWT_TOKEN"
{
  "purchases": [
    {
      "_id": "65f1a2b3c4d5e6f7g8h9i0j1",
      "user": {
        "_id": "507f1f77bcf86cd799439011",
        "name": "John Doe",
        "email": "john.doe@example.com"
      },
      "content": {
        "_id": "507f191e810c19729de860ea",
        "title": "Advanced React Patterns",
        "type": "course"
      },
      "amount": 29.99,
      "stripePaymentIntentId": "pi_3MtwBwLkdIwHu7ix28a3tqPa",
      "status": "completed",
      "purchasedAt": "2024-03-15T10:30:00.000Z"
    },
    {
      "_id": "65f1a2b3c4d5e6f7g8h9i0j2",
      "user": {
        "_id": "507f1f77bcf86cd799439012",
        "name": "Jane Smith",
        "email": "jane.smith@example.com"
      },
      "content": {
        "_id": "507f191e810c19729de860eb",
        "title": "Node.js Masterclass",
        "type": "course"
      },
      "amount": 39.99,
      "stripePaymentIntentId": "pi_3MtwCxLkdIwHu7ix29b4urQb",
      "status": "completed",
      "purchasedAt": "2024-03-15T09:15:00.000Z"
    }
  ],
  "totalPages": 5,
  "currentPage": 1,
  "totalPurchases": 87
}

Status Filter Examples

QueryDescription
?status=completedOnly successful payments
?status=pendingPayments awaiting completion
?status=failedFailed payment attempts
?status=refundedRefunded transactions
No status parameterAll payments regardless of status

Pagination Example

To iterate through all pages:
let page = 1;
let hasMore = true;

while (hasMore) {
  const response = await fetch(
    `/api/payments/admin/all?page=${page}&limit=20`,
    { headers: { 'Authorization': `Bearer ${token}` } }
  );
  
  const data = await response.json();
  
  // Process purchases
  data.purchases.forEach(purchase => {
    console.log(purchase);
  });
  
  // Check if there are more pages
  hasMore = page < data.totalPages;
  page++;
}

Use Cases

  • Generate financial reports
  • Monitor payment success rates
  • Identify failed payments requiring follow-up
  • Track refunded transactions
  • Export payment data for accounting
  • Customer support investigation

Performance Considerations

  • Default limit of 20 items balances performance and usability
  • Consider implementing cursor-based pagination for very large datasets
  • Populating user and content adds database queries; consider caching for frequent access
  • Add indexes on status and purchasedAt fields for faster filtering and sorting

Implementation Notes

  • Requires authenticate and requireAdmin middleware
  • User is populated with name and email fields only
  • Content is populated with title and type fields only
  • Results are sorted by purchasedAt descending (newest first)
  • Query parameters are coerced to numbers where needed
  • Source: src/controllers/paymentController.js:154-179

Build docs developers (and LLMs) love