125 lines
5.0 KiB
Dart
125 lines
5.0 KiB
Dart
/// Database schema for click_payment table.
|
|
///
|
|
/// Stores Cliq wallet payment transactions for manual verification.
|
|
///
|
|
/// SQL (MySQL):
|
|
/// ```sql
|
|
/// CREATE TABLE click_payment (
|
|
/// id INT AUTO_INCREMENT PRIMARY KEY,
|
|
/// user_id VARCHAR(64) NOT NULL COMMENT 'Passenger ID from passengers table',
|
|
/// user_type VARCHAR(20) NOT NULL DEFAULT 'passenger',
|
|
/// amount DECIMAL(10,2) NOT NULL,
|
|
/// currency VARCHAR(6) NOT NULL DEFAULT 'JOD',
|
|
/// click_phone VARCHAR(20) NOT NULL COMMENT 'Phone number used for Cliq invoice',
|
|
/// invoice_number VARCHAR(64) NOT NULL UNIQUE COMMENT 'Unique invoice reference',
|
|
/// cliq_alias VARCHAR(64) NOT NULL COMMENT 'Cliq wallet alias for payment',
|
|
/// invoice_status ENUM('pending','completed','failed','expired') NOT NULL DEFAULT 'pending',
|
|
/// proof_text TEXT DEFAULT NULL COMMENT 'Bank SMS proof pasted by user',
|
|
/// proof_image VARCHAR(256) DEFAULT NULL COMMENT 'Screenshot path (optional)',
|
|
/// verified_by VARCHAR(64) DEFAULT NULL COMMENT 'Admin who verified manually',
|
|
/// verified_at DATETIME DEFAULT NULL,
|
|
/// created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
/// updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
/// INDEX idx_user (user_id),
|
|
/// INDEX idx_status (invoice_status),
|
|
/// INDEX idx_invoice (invoice_number)
|
|
/// );
|
|
/// ```
|
|
class ClickPaymentSchema {
|
|
static const String tableName = 'click_payment';
|
|
|
|
static const String createTable = '''
|
|
CREATE TABLE click_payment (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
user_id VARCHAR(64) NOT NULL,
|
|
user_type VARCHAR(20) NOT NULL DEFAULT 'passenger',
|
|
amount DECIMAL(10,2) NOT NULL,
|
|
currency VARCHAR(6) NOT NULL DEFAULT 'JOD',
|
|
click_phone VARCHAR(20) NOT NULL,
|
|
invoice_number VARCHAR(64) NOT NULL UNIQUE,
|
|
cliq_alias VARCHAR(64) NOT NULL,
|
|
invoice_status ENUM('pending','completed','failed','expired') NOT NULL DEFAULT 'pending',
|
|
proof_text TEXT DEFAULT NULL,
|
|
proof_image VARCHAR(256) DEFAULT NULL,
|
|
verified_by VARCHAR(64) DEFAULT NULL,
|
|
verified_at DATETIME DEFAULT NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
INDEX idx_user (user_id),
|
|
INDEX idx_status (invoice_status),
|
|
INDEX idx_invoice (invoice_number)
|
|
)
|
|
''';
|
|
|
|
/// Map a JSON response from the API to a typed object.
|
|
final int? id;
|
|
final String userId;
|
|
final String userType;
|
|
final double amount;
|
|
final String currency;
|
|
final String clickPhone;
|
|
final String invoiceNumber;
|
|
final String cliqAlias;
|
|
final String invoiceStatus;
|
|
final String? proofText;
|
|
final String? proofImage;
|
|
final String? verifiedBy;
|
|
final DateTime? verifiedAt;
|
|
final DateTime? createdAt;
|
|
final DateTime? updatedAt;
|
|
|
|
const ClickPaymentSchema({
|
|
this.id,
|
|
required this.userId,
|
|
this.userType = 'passenger',
|
|
required this.amount,
|
|
this.currency = 'JOD',
|
|
required this.clickPhone,
|
|
required this.invoiceNumber,
|
|
required this.cliqAlias,
|
|
this.invoiceStatus = 'pending',
|
|
this.proofText,
|
|
this.proofImage,
|
|
this.verifiedBy,
|
|
this.verifiedAt,
|
|
this.createdAt,
|
|
this.updatedAt,
|
|
});
|
|
|
|
factory ClickPaymentSchema.fromJson(Map<String, dynamic> json) {
|
|
return ClickPaymentSchema(
|
|
id: json['id'] is int ? json['id'] : int.tryParse(json['id']?.toString() ?? ''),
|
|
userId: json['user_id']?.toString() ?? '',
|
|
userType: json['user_type']?.toString() ?? 'passenger',
|
|
amount: (json['amount'] is num) ? (json['amount'] as num).toDouble() : double.tryParse(json['amount']?.toString() ?? '0') ?? 0,
|
|
currency: json['currency']?.toString() ?? 'JOD',
|
|
clickPhone: json['click_phone']?.toString() ?? '',
|
|
invoiceNumber: json['invoice_number']?.toString() ?? '',
|
|
cliqAlias: json['cliq_alias']?.toString() ?? '',
|
|
invoiceStatus: json['invoice_status']?.toString() ?? 'pending',
|
|
proofText: json['proof_text']?.toString(),
|
|
proofImage: json['proof_image']?.toString(),
|
|
verifiedBy: json['verified_by']?.toString(),
|
|
verifiedAt: json['verified_at'] != null ? DateTime.tryParse(json['verified_at'].toString()) : null,
|
|
createdAt: json['created_at'] != null ? DateTime.tryParse(json['created_at'].toString()) : null,
|
|
updatedAt: json['updated_at'] != null ? DateTime.tryParse(json['updated_at'].toString()) : null,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
if (id != null) 'id': id,
|
|
'user_id': userId,
|
|
'user_type': userType,
|
|
'amount': amount,
|
|
'currency': currency,
|
|
'click_phone': clickPhone,
|
|
'invoice_number': invoiceNumber,
|
|
'cliq_alias': cliqAlias,
|
|
'invoice_status': invoiceStatus,
|
|
if (proofText != null) 'proof_text': proofText,
|
|
if (proofImage != null) 'proof_image': proofImage,
|
|
if (verifiedBy != null) 'verified_by': verifiedBy,
|
|
if (verifiedAt != null) 'verified_at': verifiedAt!.toIso8601String(),
|
|
};
|
|
}
|