200 lines
2.5 KiB
JavaScript
200 lines
2.5 KiB
JavaScript
const config = require('../../config');
|
|
const providers = config.providers;
|
|
const crypto = require('crypto');
|
|
const bcrypt = require('bcrypt');
|
|
const moment = require('moment');
|
|
|
|
module.exports = function(sequelize, DataTypes) {
|
|
const payment_intents = sequelize.define(
|
|
'payment_intents',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
intent_reference: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
currency: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"USD",
|
|
|
|
|
|
"EUR",
|
|
|
|
|
|
"GBP",
|
|
|
|
|
|
"NGN",
|
|
|
|
|
|
"KES"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
amount: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"requires_payment_method",
|
|
|
|
|
|
"requires_confirmation",
|
|
|
|
|
|
"requires_action",
|
|
|
|
|
|
"processing",
|
|
|
|
|
|
"succeeded",
|
|
|
|
|
|
"canceled",
|
|
|
|
|
|
"failed"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
provider_intent_id: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
return_url: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
created_at_time: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
confirmed_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
payment_intents.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.payment_intents.hasMany(db.payment_events, {
|
|
as: 'payment_events_payment_intent',
|
|
foreignKey: {
|
|
name: 'payment_intentId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.payment_intents.belongsTo(db.payment_providers, {
|
|
as: 'provider',
|
|
foreignKey: {
|
|
name: 'providerId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.payment_intents.belongsTo(db.wallet_accounts, {
|
|
as: 'wallet_account',
|
|
foreignKey: {
|
|
name: 'wallet_accountId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.payment_intents.belongsTo(db.funding_requests, {
|
|
as: 'funding_request',
|
|
foreignKey: {
|
|
name: 'funding_requestId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.payment_intents.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.payment_intents.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return payment_intents;
|
|
};
|
|
|
|
|