const mongoose = require('mongoose');
const { Schema } = mongoose;
const saleSchema = new Schema({
payment: new Schema({
id: {
type: String,
},
intent: {
type: String,
},
cart: {
type: String,
},
payer: new Schema({
payment_method: {
type: String,
},
status: {
type: String,
},
payer_info: new Schema({
email: {
type: String,
index: false
},
first_name: {
type: String,
},
last_name: {
type: String,
},
payer_id: {
type: String,
},
shipping_address: new Schema({
recipient_name: {
type: String,
},
line1: {
type: String,
},
line2: {
type: String,
},
city: {
type: String,
},
state: {
type: String,
},
postal_code: {
type: String,
},
country_code: {
type: String,
},
}),
country_code: {
type: String,
}
}),
}),
transactions: [new Schema({
amount: new Schema({
total: {
type: Number,
},
currency: {
type: String,
},
details: new Schema({
subtotal: {
type: Number,
},
shipping: {
type: Number,
},
insurance: {
type: Number,
},
handling_fee: {
type: Number,
},
shipping_discount: {
type: Number,
},
discount: {
type: Number,
}
})
}),
payee: new Schema({
merchant_id: {
type: String,
},
email: {
type: String,
index: false
},
}),
description: {
type: String,
},
soft_descriptor: {
type: String,
},
item_list: new Schema({
items: [new Schema({
name: {
type: String,
},
sku: {
type: String,
},
price: {
type: Number,
},
currency: {
type: String,
},
tax: {
type: Number,
},
quantity: {
type: Number,
},
image_url: {
type: String,
},
})],
shipping_address: new Schema({
recipient_name: {
type: String,
},
line1: {
type: String,
},
line2: {
type: String,
},
city: {
type: String,
},
state: {
type: String,
},
postal_code: {
type: String,
},
country_code: {
type: String,
},
})
}),
related_resources: {
sale: new Schema({
id: {
type: String,
},
state: {
type: String,
},
amount: new Schema({
total: {
type: Number,
},
currency: {
type: String,
},
details: new Schema({
subtotal: {
type: Number,
},
shipping: {
type: Number,
},
insurance: {
type: Number,
},
handling_fee: {
type: Number,
},
shipping_discount: {
type: Number,
},
discount: {
type: Number,
}
})
}),
payment_mode: {
type: String,
},
protection_eligibility: {
type: String,
},
protection_eligibility_type: {
type: String,
},
transaction_fee: new Schema({
value: {
type: Number,
},
currency: {
type: String,
},
}),
parent_payment: {
type: String,
},
create_time: {
type: Date
},
update_time: {
type: Date
},
})
}
})],
failed_transactions: {
type: Array
},
create_time: {
type: Date
},
update_time: {
type: Date
},
httpStatusCode: {
type: Number
}
}),
query: new Schema({
paymentId: {
type: String
},
token: {
type: String
},
PayerID: {
type: String
},
}),
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'sale'
}
}, { timestamps: true });
const Sale = mongoose.model('sale', saleSchema)
module.exports = Sale;