flykup_model_development 3.1.1 → 3.1.2
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 +17 -26
- package/package.json +1 -1
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
// const OrderPayment = mongoose.model('orderPayment', paymentSchema);
|
|
60
60
|
// export default OrderPayment;
|
|
61
61
|
|
|
62
|
+
// models/OrderPayment.js
|
|
62
63
|
// models/OrderPayment.js
|
|
63
64
|
import mongoose from 'mongoose';
|
|
64
65
|
|
|
@@ -80,30 +81,15 @@ const paymentSchema = new mongoose.Schema({
|
|
|
80
81
|
},
|
|
81
82
|
|
|
82
83
|
// Razorpay-specific fields
|
|
83
|
-
razorpayOrderId:
|
|
84
|
-
type: String,
|
|
85
|
-
required: function() {
|
|
86
|
-
return this.paymentGateway === 'RAZORPAY';
|
|
87
|
-
}
|
|
88
|
-
},
|
|
84
|
+
razorpayOrderId: String,
|
|
89
85
|
razorpayPaymentId: {
|
|
90
86
|
type: String,
|
|
91
87
|
default: null
|
|
92
88
|
},
|
|
93
89
|
|
|
94
90
|
// Cashfree-specific fields
|
|
95
|
-
cfPaymentSessionId:
|
|
96
|
-
|
|
97
|
-
required: function() {
|
|
98
|
-
return this.paymentGateway === 'CASHFREE';
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
cfOrderId: {
|
|
102
|
-
type: String,
|
|
103
|
-
required: function() {
|
|
104
|
-
return this.paymentGateway === 'CASHFREE';
|
|
105
|
-
}
|
|
106
|
-
},
|
|
91
|
+
cfPaymentSessionId: String,
|
|
92
|
+
cfOrderId: String,
|
|
107
93
|
|
|
108
94
|
amount: {
|
|
109
95
|
type: Number,
|
|
@@ -134,9 +120,7 @@ const paymentSchema = new mongoose.Schema({
|
|
|
134
120
|
}
|
|
135
121
|
}]
|
|
136
122
|
}, {
|
|
137
|
-
timestamps: true
|
|
138
|
-
// Add this to ensure conditional validation works properly
|
|
139
|
-
validateBeforeSave: true
|
|
123
|
+
timestamps: true
|
|
140
124
|
});
|
|
141
125
|
|
|
142
126
|
// Create indexes for better performance
|
|
@@ -144,15 +128,23 @@ paymentSchema.index({ razorpayOrderId: 1 });
|
|
|
144
128
|
paymentSchema.index({ cfOrderId: 1 });
|
|
145
129
|
paymentSchema.index({ orderId: 1 });
|
|
146
130
|
|
|
147
|
-
// Add a pre-save middleware to handle
|
|
131
|
+
// Add a pre-save middleware to handle validation
|
|
148
132
|
paymentSchema.pre('save', function(next) {
|
|
149
|
-
// If using Razorpay,
|
|
133
|
+
// If using Razorpay, validate Razorpay fields
|
|
150
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
|
|
151
139
|
this.cfPaymentSessionId = undefined;
|
|
152
140
|
this.cfOrderId = undefined;
|
|
153
141
|
}
|
|
154
|
-
// If using Cashfree,
|
|
142
|
+
// If using Cashfree, validate Cashfree fields
|
|
155
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
|
|
156
148
|
this.razorpayOrderId = undefined;
|
|
157
149
|
this.razorpayPaymentId = undefined;
|
|
158
150
|
}
|
|
@@ -160,8 +152,7 @@ paymentSchema.pre('save', function(next) {
|
|
|
160
152
|
});
|
|
161
153
|
|
|
162
154
|
|
|
163
|
-
|
|
164
155
|
const OrderPayment =
|
|
165
|
-
mongoose.models.OrderPayment || mongoose.model('
|
|
156
|
+
mongoose.models.OrderPayment || mongoose.model('orderPayment', paymentSchema);
|
|
166
157
|
|
|
167
158
|
export default OrderPayment;
|