Skip to main content

Get Invoices

GET /api/invoice
Retrieves all completed billing invoices for the authenticated user.

Headers

Authorization
string
required
Bearer token for authentication

Response

data
array
Array of completed order invoices
{
  "data": [
    {
      "_id": "65f1a3b2c4d5e6f7g8h9i0j1",
      "userid": "507f1f77bcf86cd799439011",
      "orderid": "order_NXvZ9J8Kq3mL4pR7",
      "months": 12,
      "amount": 299,
      "plan": "pro",
      "status": "completed",
      "projectid": "507f1f77bcf86cd799439012",
      "createdAt": "2024-03-01T10:30:00.000Z",
      "updatedAt": "2024-03-01T10:30:00.000Z"
    },
    {
      "_id": "65f1a3b2c4d5e6f7g8h9i0j2",
      "userid": "507f1f77bcf86cd799439011",
      "orderid": "order_MWuY8I7Jp2kK3oQ6",
      "months": 1,
      "amount": 29,
      "plan": "pro",
      "status": "completed",
      "projectid": "507f1f77bcf86cd799439013",
      "createdAt": "2024-02-01T14:15:00.000Z",
      "updatedAt": "2024-02-01T14:15:00.000Z"
    },
    {
      "_id": "65f1a3b2c4d5e6f7g8h9i0j3",
      "userid": "507f1f77bcf86cd799439011",
      "orderid": "order_LVtX7H6Io1jJ2nP5",
      "months": 6,
      "amount": 599,
      "plan": "business",
      "status": "completed",
      "projectid": "507f1f77bcf86cd799439014",
      "createdAt": "2024-01-15T09:45:00.000Z",
      "updatedAt": "2024-01-15T09:45:00.000Z"
    }
  ]
}

Implementation Details

Data Source

Invoices are retrieved from the CompletedOrder collection, which stores all completed payment transactions.

CompletedOrder Schema

The CompletedOrder model includes the following fields:
{
  userid: ObjectId,        // Reference to User
  orderid: String,         // Payment provider order ID
  months: Number,          // Subscription duration
  amount: Number,          // Payment amount
  plan: String,           // Plan name
  status: String,         // Payment status
  projectid: ObjectId,    // Reference to Project (optional)
  createdAt: Date,        // Auto-generated timestamp
  updatedAt: Date         // Auto-generated timestamp
}

Query Logic

  • Filters invoices by the authenticated user’s ID
  • Returns all completed orders associated with the user
  • Includes both project-specific subscriptions and account-level purchases
  • Orders are returned in database order (typically creation order)

Use Cases

  • Display billing history to users
  • Generate receipts for completed payments
  • Track subscription renewals
  • Audit payment transactions
  • Support billing inquiries
  • User: Referenced by userid field
  • Project: Referenced by projectid field (when invoice is project-specific)

Error Response

{
  "error": "Internal Server Error"
}