flykup_model_development 3.1.0 → 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.
@@ -59,7 +59,7 @@
59
59
  // const OrderPayment = mongoose.model('orderPayment', paymentSchema);
60
60
  // export default OrderPayment;
61
61
 
62
-
62
+ // models/OrderPayment.js
63
63
  // models/OrderPayment.js
64
64
  import mongoose from 'mongoose';
65
65
 
@@ -81,30 +81,15 @@ const paymentSchema = new mongoose.Schema({
81
81
  },
82
82
 
83
83
  // Razorpay-specific fields
84
- razorpayOrderId: {
85
- type: String,
86
- required: function() {
87
- return this.paymentGateway === 'RAZORPAY';
88
- }
89
- },
84
+ razorpayOrderId: String,
90
85
  razorpayPaymentId: {
91
86
  type: String,
92
87
  default: null
93
88
  },
94
89
 
95
90
  // Cashfree-specific fields
96
- cfPaymentSessionId: {
97
- type: String,
98
- required: function() {
99
- return this.paymentGateway === 'CASHFREE';
100
- }
101
- },
102
- cfOrderId: {
103
- type: String,
104
- required: function() {
105
- return this.paymentGateway === 'CASHFREE';
106
- }
107
- },
91
+ cfPaymentSessionId: String,
92
+ cfOrderId: String,
108
93
 
109
94
  amount: {
110
95
  type: Number,
@@ -134,14 +119,40 @@ const paymentSchema = new mongoose.Schema({
134
119
  default: 'PENDING'
135
120
  }
136
121
  }]
137
- }, { timestamps: true });
122
+ }, {
123
+ timestamps: true
124
+ });
138
125
 
139
126
  // Create indexes for better performance
140
127
  paymentSchema.index({ razorpayOrderId: 1 });
141
128
  paymentSchema.index({ cfOrderId: 1 });
142
129
  paymentSchema.index({ orderId: 1 });
143
130
 
131
+ // Add a pre-save middleware to handle validation
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
+
154
+
144
155
  const OrderPayment =
145
- mongoose.models.OrderPayment || mongoose.model('OrderPayment', paymentSchema);
156
+ mongoose.models.OrderPayment || mongoose.model('orderPayment', paymentSchema);
146
157
 
147
158
  export default OrderPayment;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flykup_model_development",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "private": false,