database-connector 2.1.4 → 2.2.1
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/Payment.js +10 -58
- package/models/Subscription.js +11 -0
- package/models/SubscriptionOffer.js +10 -0
- package/models/Transaction.js +105 -0
- package/models/index.js +2 -0
- package/package.json +1 -1
package/models/Payment.js
CHANGED
|
@@ -13,7 +13,6 @@ const mongoose = require('mongoose');
|
|
|
13
13
|
* - paymentStatus
|
|
14
14
|
* - paymentAmount
|
|
15
15
|
* - paymentCurrency
|
|
16
|
-
* - paymentMethod
|
|
17
16
|
* - paymentDate
|
|
18
17
|
* - paymentTime
|
|
19
18
|
* - paymentDetails
|
|
@@ -40,9 +39,10 @@ const mongoose = require('mongoose');
|
|
|
40
39
|
* paymentCurrency:
|
|
41
40
|
* type: string
|
|
42
41
|
* description: Currency of payment
|
|
43
|
-
*
|
|
42
|
+
* paymentMethodId:
|
|
44
43
|
* type: string
|
|
45
|
-
*
|
|
44
|
+
* nullable: true
|
|
45
|
+
* description: Reference to payment method type (PaymentType)
|
|
46
46
|
* paymentDate:
|
|
47
47
|
* type: string
|
|
48
48
|
* format: date
|
|
@@ -72,7 +72,7 @@ const mongoose = require('mongoose');
|
|
|
72
72
|
* paymentStatus: "succeeded"
|
|
73
73
|
* paymentAmount: 150.00
|
|
74
74
|
* paymentCurrency: "USD"
|
|
75
|
-
*
|
|
75
|
+
* paymentMethodId: "507f1f77bcf86cd799439020"
|
|
76
76
|
* totalPrice: 150.00
|
|
77
77
|
* createdAt: "2025-12-07T10:30:00.000Z"
|
|
78
78
|
* updatedAt: "2025-12-07T10:30:00.000Z"
|
|
@@ -106,9 +106,11 @@ const paymentSchema = new mongoose.Schema(
|
|
|
106
106
|
type: String,
|
|
107
107
|
required: true,
|
|
108
108
|
},
|
|
109
|
-
|
|
110
|
-
type:
|
|
111
|
-
required:
|
|
109
|
+
paymentMethodId: {
|
|
110
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
111
|
+
required: false,
|
|
112
|
+
default: null,
|
|
113
|
+
ref: 'PaymentType',
|
|
112
114
|
},
|
|
113
115
|
paymentDate: {
|
|
114
116
|
type: Date,
|
|
@@ -127,57 +129,7 @@ const paymentSchema = new mongoose.Schema(
|
|
|
127
129
|
required: true,
|
|
128
130
|
default: 0,
|
|
129
131
|
},
|
|
130
|
-
|
|
131
|
-
brand: {
|
|
132
|
-
type: String,
|
|
133
|
-
required: true,
|
|
134
|
-
},
|
|
135
|
-
last4: {
|
|
136
|
-
type: String,
|
|
137
|
-
required: true,
|
|
138
|
-
},
|
|
139
|
-
exp_month: {
|
|
140
|
-
type: Number,
|
|
141
|
-
required: true,
|
|
142
|
-
},
|
|
143
|
-
exp_year: {
|
|
144
|
-
type: Number,
|
|
145
|
-
required: true,
|
|
146
|
-
},
|
|
147
|
-
funding: {
|
|
148
|
-
type: String,
|
|
149
|
-
required: true,
|
|
150
|
-
},
|
|
151
|
-
country: {
|
|
152
|
-
type: String,
|
|
153
|
-
required: true,
|
|
154
|
-
},
|
|
155
|
-
name: {
|
|
156
|
-
type: String,
|
|
157
|
-
required: true,
|
|
158
|
-
},
|
|
159
|
-
address_line1: {
|
|
160
|
-
type: String,
|
|
161
|
-
required: true,
|
|
162
|
-
},
|
|
163
|
-
address_line2: {
|
|
164
|
-
type: String,
|
|
165
|
-
required: true,
|
|
166
|
-
},
|
|
167
|
-
address_city: {
|
|
168
|
-
type: String,
|
|
169
|
-
required: true,
|
|
170
|
-
},
|
|
171
|
-
ccvVerified: {
|
|
172
|
-
type: Boolean,
|
|
173
|
-
required: true,
|
|
174
|
-
default: false,
|
|
175
|
-
},
|
|
176
|
-
ccv: {
|
|
177
|
-
type: String,
|
|
178
|
-
required: true
|
|
179
|
-
}
|
|
180
|
-
},
|
|
132
|
+
// transactions field removed: Transactions are no longer tracked as a separate model
|
|
181
133
|
timestamps: {
|
|
182
134
|
type: Date,
|
|
183
135
|
required: true,
|
package/models/Subscription.js
CHANGED
|
@@ -33,6 +33,10 @@ const mongoose = require('mongoose');
|
|
|
33
33
|
* paymentTypeId:
|
|
34
34
|
* type: string
|
|
35
35
|
* description: Reference to payment type
|
|
36
|
+
* paymentIntentId:
|
|
37
|
+
* type: string
|
|
38
|
+
* nullable: true
|
|
39
|
+
* description: Reference to payment intent (can be null)
|
|
36
40
|
* reductionOfferId:
|
|
37
41
|
* type: string
|
|
38
42
|
* description: Reference to reduction offer
|
|
@@ -59,6 +63,7 @@ const mongoose = require('mongoose');
|
|
|
59
63
|
* storeId: "507f1f77bcf86cd799439012"
|
|
60
64
|
* planId: "507f1f77bcf86cd799439013"
|
|
61
65
|
* paymentAmount: 99.99
|
|
66
|
+
* paymentIntentId: "507f1f77bcf86cd799439099"
|
|
62
67
|
* status: "active"
|
|
63
68
|
* startDate: "2025-12-01T00:00:00.000Z"
|
|
64
69
|
* endDate: "2026-12-01T00:00:00.000Z"
|
|
@@ -94,6 +99,12 @@ const subscriptionSchema = new mongoose.Schema(
|
|
|
94
99
|
required: false,
|
|
95
100
|
ref: 'PaymentType',
|
|
96
101
|
},
|
|
102
|
+
paymentIntentId: {
|
|
103
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
104
|
+
required: false,
|
|
105
|
+
ref: 'Payment',
|
|
106
|
+
default: null,
|
|
107
|
+
},
|
|
97
108
|
reductionOfferId: {
|
|
98
109
|
type: mongoose.Schema.Types.ObjectId,
|
|
99
110
|
required: false,
|
|
@@ -15,6 +15,10 @@ const mongoose = require('mongoose');
|
|
|
15
15
|
* discount:
|
|
16
16
|
* type: number
|
|
17
17
|
* description: Discount amount or percentage
|
|
18
|
+
* discountType:
|
|
19
|
+
* type: string
|
|
20
|
+
* enum: [percentage, amount]
|
|
21
|
+
* description: Type of discount (percentage or fixed amount)
|
|
18
22
|
* isActive:
|
|
19
23
|
* type: boolean
|
|
20
24
|
* default: false
|
|
@@ -28,6 +32,7 @@ const mongoose = require('mongoose');
|
|
|
28
32
|
* example:
|
|
29
33
|
* id: "507f1f77bcf86cd799439011"
|
|
30
34
|
* discount: 20
|
|
35
|
+
* discountType: "percentage"
|
|
31
36
|
* isActive: true
|
|
32
37
|
* createdAt: "2025-11-01T10:30:00.000Z"
|
|
33
38
|
* updatedAt: "2025-12-01T15:45:00.000Z"
|
|
@@ -38,6 +43,11 @@ const subscriptionOfferSchema = new mongoose.Schema(
|
|
|
38
43
|
type: Number,
|
|
39
44
|
required: true,
|
|
40
45
|
},
|
|
46
|
+
discountType: {
|
|
47
|
+
type: String,
|
|
48
|
+
required: true,
|
|
49
|
+
enum: ['percentage', 'amount'],
|
|
50
|
+
},
|
|
41
51
|
isActive: {
|
|
42
52
|
type: Boolean,
|
|
43
53
|
required: true,
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @swagger
|
|
5
|
+
* components:
|
|
6
|
+
* schemas:
|
|
7
|
+
* Transaction:
|
|
8
|
+
* type: object
|
|
9
|
+
* required:
|
|
10
|
+
* - paymentId
|
|
11
|
+
* - amount
|
|
12
|
+
* - status
|
|
13
|
+
* properties:
|
|
14
|
+
* id:
|
|
15
|
+
* type: string
|
|
16
|
+
* description: The transaction identifier
|
|
17
|
+
* paymentId:
|
|
18
|
+
* type: string
|
|
19
|
+
* description: Reference to the payment
|
|
20
|
+
* amount:
|
|
21
|
+
* type: number
|
|
22
|
+
* description: Transaction amount
|
|
23
|
+
* paymentMethodId:
|
|
24
|
+
* type: string
|
|
25
|
+
* nullable: true
|
|
26
|
+
* description: Reference to payment method type (PaymentType)
|
|
27
|
+
* status:
|
|
28
|
+
* type: string
|
|
29
|
+
* enum: [pending, succeeded, failed, refunded, canceled]
|
|
30
|
+
* description: Transaction status
|
|
31
|
+
* gatewayTransactionId:
|
|
32
|
+
* type: string
|
|
33
|
+
* nullable: true
|
|
34
|
+
* description: Provider transaction identifier (can be null)
|
|
35
|
+
* transactionDate:
|
|
36
|
+
* type: string
|
|
37
|
+
* format: date-time
|
|
38
|
+
* description: Date and time of the transaction
|
|
39
|
+
* metadata:
|
|
40
|
+
* type: object
|
|
41
|
+
* nullable: true
|
|
42
|
+
* description: Extra transaction metadata (can be null)
|
|
43
|
+
* createdAt:
|
|
44
|
+
* type: string
|
|
45
|
+
* format: date-time
|
|
46
|
+
* updatedAt:
|
|
47
|
+
* type: string
|
|
48
|
+
* format: date-time
|
|
49
|
+
* example:
|
|
50
|
+
* id: "507f1f77bcf86cd799439111"
|
|
51
|
+
* paymentId: "507f1f77bcf86cd799439011"
|
|
52
|
+
* amount: 100.0
|
|
53
|
+
* currency: "USD"
|
|
54
|
+
* paymentMethodId: "507f1f77bcf86cd799439020"
|
|
55
|
+
* status: "succeeded"
|
|
56
|
+
* gatewayTransactionId: "pi_3QX..."
|
|
57
|
+
* transactionDate: "2025-12-07T10:30:00.000Z"
|
|
58
|
+
*/
|
|
59
|
+
const transactionSchema = new mongoose.Schema(
|
|
60
|
+
{
|
|
61
|
+
paymentId: {
|
|
62
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
63
|
+
ref: 'Payment',
|
|
64
|
+
required: true,
|
|
65
|
+
},
|
|
66
|
+
amount: {
|
|
67
|
+
type: Number,
|
|
68
|
+
required: true,
|
|
69
|
+
},
|
|
70
|
+
paymentMethodId: {
|
|
71
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
72
|
+
required: false,
|
|
73
|
+
default: null,
|
|
74
|
+
ref: 'PaymentType',
|
|
75
|
+
},
|
|
76
|
+
status: {
|
|
77
|
+
type: String,
|
|
78
|
+
enum: ['pending', 'succeeded', 'failed', 'refunded', 'canceled'],
|
|
79
|
+
required: true,
|
|
80
|
+
default: 'pending',
|
|
81
|
+
},
|
|
82
|
+
gatewayTransactionId: {
|
|
83
|
+
type: String,
|
|
84
|
+
required: false,
|
|
85
|
+
default: null,
|
|
86
|
+
},
|
|
87
|
+
transactionDate: {
|
|
88
|
+
type: Date,
|
|
89
|
+
required: true,
|
|
90
|
+
default: Date.now,
|
|
91
|
+
},
|
|
92
|
+
metadata: {
|
|
93
|
+
type: Object,
|
|
94
|
+
required: false,
|
|
95
|
+
default: null,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{ timestamps: true }
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
// Indexes for performance optimization
|
|
102
|
+
transactionSchema.index({ paymentId: 1, createdAt: -1 });
|
|
103
|
+
transactionSchema.index({ status: 1, createdAt: -1 });
|
|
104
|
+
|
|
105
|
+
module.exports = mongoose.model('Transaction', transactionSchema);
|
package/models/index.js
CHANGED
|
@@ -22,6 +22,7 @@ const User = require('./User');
|
|
|
22
22
|
const Order = require('./Order');
|
|
23
23
|
const Bill = require('./Bill');
|
|
24
24
|
const Payment = require('./Payment');
|
|
25
|
+
const Transaction = require('./Transaction');
|
|
25
26
|
const Store = require('./Store');
|
|
26
27
|
const Offer = require('./Offer');
|
|
27
28
|
const Category = require('./Category');
|
|
@@ -58,6 +59,7 @@ module.exports = {
|
|
|
58
59
|
Order,
|
|
59
60
|
Bill,
|
|
60
61
|
Payment,
|
|
62
|
+
Transaction,
|
|
61
63
|
Store,
|
|
62
64
|
Offer,
|
|
63
65
|
Category,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "database-connector",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "MongoDB models package with Mongoose schemas for e-commerce applications. Includes User, Product, Store, Order and more with built-in validation and virtual properties.",
|
|
5
5
|
"main": "models/index.js",
|
|
6
6
|
"scripts": {
|