courseworx/backend/plugins/financial-plugin/models/Transaction.js
mmabdalla 5477297914 v2.0.2 - Complete Plugin Architecture System and Multi-Currency Implementation
Major Features Added:
- Complete Plugin Architecture System with financial plugin
- Multi-currency support with exchange rates
- Course type system (online, classroom, hybrid)
- Attendance tracking and QR code scanning
- Classroom sessions management
- Course sections and content management
- Professional video player with authentication
- Secure media serving system
- Shopping cart and checkout system
- Financial dashboard and earnings tracking
- Trainee progress tracking
- User notes and assignments system

Backend Infrastructure:
- Plugin loader and registry system
- Multi-currency database models
- Secure media middleware
- Course access middleware
- Financial plugin with payment processing
- Database migrations for new features
- API endpoints for all new functionality

Frontend Components:
- Course management interface
- Content creation and editing
- Section management with drag-and-drop
- Professional video player
- QR scanner for attendance
- Shopping cart and checkout flow
- Financial dashboard
- Plugin management interface
- Trainee details and progress views

This represents a major evolution of CourseWorx from a basic LMS to a comprehensive educational platform with plugin architecture.
2025-09-14 04:20:37 +03:00

115 lines
2.5 KiB
JavaScript

/**
* Transaction Model for Financial Plugin
*
* This model handles payment transactions including
* gateway responses, fees, and processing status.
*/
const { DataTypes } = require('sequelize');
module.exports = (sequelize) => {
const Transaction = sequelize.define('FinancialTransaction', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
orderId: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'financial_orders',
key: 'id',
onDelete: 'CASCADE'
}
},
amount: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
validate: {
min: 0
}
},
gatewayFee: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
defaultValue: 0.00,
validate: {
min: 0
}
},
platformFee: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
defaultValue: 0.00,
validate: {
min: 0
}
},
status: {
type: DataTypes.ENUM('pending', 'completed', 'failed', 'refunded'),
allowNull: false,
defaultValue: 'pending'
},
gatewayResponse: {
type: DataTypes.JSONB,
allowNull: true
},
webhookData: {
type: DataTypes.JSONB,
allowNull: true
},
processedAt: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 'financial_transactions',
timestamps: true,
indexes: [
{
fields: ['orderId']
},
{
fields: ['status']
}
]
});
// Instance methods
Transaction.prototype.markAsCompleted = function(gatewayResponse) {
this.status = 'completed';
this.gatewayResponse = gatewayResponse;
this.processedAt = new Date();
return this.save();
};
Transaction.prototype.markAsFailed = function(gatewayResponse) {
this.status = 'failed';
this.gatewayResponse = gatewayResponse;
this.processedAt = new Date();
return this.save();
};
Transaction.prototype.markAsRefunded = function() {
this.status = 'refunded';
this.processedAt = new Date();
return this.save();
};
// Static methods
Transaction.findByOrder = function(orderId) {
return this.findAll({
where: { orderId },
order: [['createdAt', 'DESC']]
});
};
Transaction.getTotalFees = function(orderId) {
return this.sum('gatewayFee', {
where: { orderId, status: 'completed' }
});
};
return Transaction;
};