ghostguild-org/server/models/payment.js
Jennie Robinson Faber bf5a333117 feat(payments): add Payment model for Phase 1 receipt data capture
Introduces the payments collection with fields Phase 2 will need to
generate official donation receipts: amount, paymentDate, paymentType
(monthly|annual), helcimTransactionId (unique), and receiptIssued /
receiptId placeholders Phase 2 will populate. Schema-only; no routes
or UI in this commit.
2026-04-20 13:12:17 +01:00

28 lines
1.1 KiB
JavaScript

import mongoose from 'mongoose'
const paymentSchema = new mongoose.Schema(
{
memberId: { type: mongoose.Schema.Types.ObjectId, ref: 'Member', required: true, index: true },
helcimTransactionId: { type: String, required: true, unique: true },
helcimCustomerId: { type: String, index: true },
helcimSubscriptionId: { type: String, index: true, default: null },
amount: { type: Number, required: true, min: 0 },
currency: { type: String, default: 'CAD' },
paymentDate: { type: Date, required: true },
paymentType: { type: String, enum: ['monthly', 'annual'], required: true },
status: { type: String, enum: ['success', 'failed', 'refunded'], required: true, default: 'success' },
failureReason: { type: String, default: null },
receiptIssued: { type: Boolean, default: false },
receiptId: { type: String, default: null },
rawHelcim: { type: mongoose.Schema.Types.Mixed, default: null },
},
{ timestamps: true, collection: 'payments' }
)
paymentSchema.index({ memberId: 1, paymentDate: -1 })
export default mongoose.models.Payment || mongoose.model('Payment', paymentSchema)