EventBuzz_Backend/src/models/OrganizationPaymentProfile.js

47 lines
1.4 KiB
JavaScript

const mongoose = require('mongoose');
const GATEWAY_PROVIDERS = ['razorpay', 'payu', 'ccavenue', 'cashfree', 'stripe', 'paytm'];
const orgGatewaySchema = new mongoose.Schema(
{
provider: {
type: String,
enum: GATEWAY_PROVIDERS,
required: true,
},
label: { type: String, default: '' },
isActive: { type: Boolean, default: true },
isPrimary: { type: Boolean, default: false },
testMode: { type: Boolean, default: true },
/** AES-GCM encrypted JSON — provider-specific secrets */
credentialsEnc: { type: String, required: true },
},
{ timestamps: true }
);
const organizationPaymentProfileSchema = new mongoose.Schema(
{
organization: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Organization',
required: true,
unique: true,
},
checkoutMode: {
type: String,
enum: ['platform_razorpay', 'custom'],
default: 'platform_razorpay',
},
/** Override platform default when using platform checkout */
platformCommissionBps: { type: Number, default: null },
defaultCurrency: { type: String, default: 'INR' },
taxRate: { type: Number, default: null },
taxType: { type: String, default: '' },
gateways: { type: [orgGatewaySchema], default: [] },
},
{ timestamps: true }
);
module.exports = mongoose.model('OrganizationPaymentProfile', organizationPaymentProfileSchema);
module.exports.GATEWAY_PROVIDERS = GATEWAY_PROVIDERS;