flykup_model_development 3.1.2 → 3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/models/orderPayment.model.js +26 -33
- package/package.json +1 -1
|
@@ -58,9 +58,6 @@
|
|
|
58
58
|
|
|
59
59
|
// const OrderPayment = mongoose.model('orderPayment', paymentSchema);
|
|
60
60
|
// export default OrderPayment;
|
|
61
|
-
|
|
62
|
-
// models/OrderPayment.js
|
|
63
|
-
// models/OrderPayment.js
|
|
64
61
|
import mongoose from 'mongoose';
|
|
65
62
|
|
|
66
63
|
const paymentSchema = new mongoose.Schema({
|
|
@@ -79,17 +76,35 @@ const paymentSchema = new mongoose.Schema({
|
|
|
79
76
|
enum: ['RAZORPAY', 'CASHFREE'],
|
|
80
77
|
required: true
|
|
81
78
|
},
|
|
82
|
-
|
|
79
|
+
|
|
83
80
|
// Razorpay-specific fields
|
|
84
|
-
razorpayOrderId:
|
|
81
|
+
razorpayOrderId: {
|
|
82
|
+
type: String,
|
|
83
|
+
// ✅ This field is now required only if the gateway is RAZORPAY
|
|
84
|
+
required: function() {
|
|
85
|
+
return this.paymentGateway === 'RAZORPAY';
|
|
86
|
+
}
|
|
87
|
+
},
|
|
85
88
|
razorpayPaymentId: {
|
|
86
89
|
type: String,
|
|
87
90
|
default: null
|
|
88
91
|
},
|
|
89
|
-
|
|
92
|
+
|
|
90
93
|
// Cashfree-specific fields
|
|
91
|
-
cfPaymentSessionId:
|
|
92
|
-
|
|
94
|
+
cfPaymentSessionId: {
|
|
95
|
+
type: String,
|
|
96
|
+
// ✅ This field is now required only if the gateway is CASHFREE
|
|
97
|
+
required: function() {
|
|
98
|
+
return this.paymentGateway === 'CASHFREE';
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
cfOrderId: {
|
|
102
|
+
type: String,
|
|
103
|
+
// ✅ This field is now required only if the gateway is CASHFREE
|
|
104
|
+
required: function() {
|
|
105
|
+
return this.paymentGateway === 'CASHFREE';
|
|
106
|
+
}
|
|
107
|
+
},
|
|
93
108
|
|
|
94
109
|
amount: {
|
|
95
110
|
type: Number,
|
|
@@ -119,7 +134,7 @@ const paymentSchema = new mongoose.Schema({
|
|
|
119
134
|
default: 'PENDING'
|
|
120
135
|
}
|
|
121
136
|
}]
|
|
122
|
-
}, {
|
|
137
|
+
}, {
|
|
123
138
|
timestamps: true
|
|
124
139
|
});
|
|
125
140
|
|
|
@@ -128,31 +143,9 @@ paymentSchema.index({ razorpayOrderId: 1 });
|
|
|
128
143
|
paymentSchema.index({ cfOrderId: 1 });
|
|
129
144
|
paymentSchema.index({ orderId: 1 });
|
|
130
145
|
|
|
131
|
-
//
|
|
132
|
-
paymentSchema.pre('save', function(next) {
|
|
133
|
-
// If using Razorpay, validate Razorpay fields
|
|
134
|
-
if (this.paymentGateway === 'RAZORPAY') {
|
|
135
|
-
if (!this.razorpayOrderId) {
|
|
136
|
-
return next(new Error('razorpayOrderId is required for RAZORPAY payments'));
|
|
137
|
-
}
|
|
138
|
-
// Remove Cashfree fields
|
|
139
|
-
this.cfPaymentSessionId = undefined;
|
|
140
|
-
this.cfOrderId = undefined;
|
|
141
|
-
}
|
|
142
|
-
// If using Cashfree, validate Cashfree fields
|
|
143
|
-
else if (this.paymentGateway === 'CASHFREE') {
|
|
144
|
-
if (!this.cfPaymentSessionId || !this.cfOrderId) {
|
|
145
|
-
return next(new Error('cfPaymentSessionId and cfOrderId are required for CASHFREE payments'));
|
|
146
|
-
}
|
|
147
|
-
// Remove Razorpay fields
|
|
148
|
-
this.razorpayOrderId = undefined;
|
|
149
|
-
this.razorpayPaymentId = undefined;
|
|
150
|
-
}
|
|
151
|
-
next();
|
|
152
|
-
});
|
|
153
|
-
|
|
146
|
+
// ❌ The pre-save middleware is no longer needed and should be removed.
|
|
154
147
|
|
|
155
148
|
const OrderPayment =
|
|
156
149
|
mongoose.models.OrderPayment || mongoose.model('orderPayment', paymentSchema);
|
|
157
150
|
|
|
158
|
-
export default OrderPayment;
|
|
151
|
+
export default OrderPayment;
|