Phase 1 - JWT Auth Foundation: - Replace token auth with djangorestframework-simplejwt - POST /api/v1/admin/auth/login/ - returns access + refresh JWT - POST /api/v1/auth/refresh/ - JWT refresh - GET /api/v1/auth/me/ - current admin profile - GET /api/v1/health/ - DB health check - Add ledger app to INSTALLED_APPS Phase 2 - Dashboard Metrics API: - GET /api/v1/dashboard/metrics/ - revenue, partners, events, tickets - GET /api/v1/dashboard/revenue/ - 7-day revenue vs payouts chart data - GET /api/v1/dashboard/activity/ - last 10 platform events feed - GET /api/v1/dashboard/actions/ - KYC queue, flagged events, pending payouts DB Indexes (dashboard query optimisation): - RazorpayTransaction: status, captured_at - Partner: status, kyc_compliance_status - Event: event_status, start_date, created_date - Booking: created_date - PaymentTransaction: payment_type, payment_transaction_status, payment_transaction_date Infra: - Add Dockerfile for eventify-backend container - Add simplejwt to requirements.txt - All 4 dashboard views use IsAuthenticated permission class
85 lines
3.6 KiB
Python
85 lines
3.6 KiB
Python
from django.db import models
|
|
from django.contrib.auth import get_user_model
|
|
import uuid
|
|
|
|
User = get_user_model()
|
|
|
|
# Create your models here.
|
|
class PaymentGateway(models.Model):
|
|
payment_gateway_id = models.CharField(max_length=250)
|
|
payment_gateway_name = models.CharField(max_length=250)
|
|
payment_gateway_description = models.TextField()
|
|
payment_gateway_logo = models.ImageField(upload_to='payment_gateways/', blank=True, null=True)
|
|
payment_gateway_url = models.URLField(blank=True, null=True)
|
|
payment_gateway_api_key = models.CharField(max_length=250)
|
|
payment_gateway_api_secret = models.CharField(max_length=250)
|
|
payment_gateway_api_url = models.URLField(blank=True, null=True)
|
|
payment_gateway_api_version = models.CharField(max_length=250)
|
|
payment_gateway_api_method = models.CharField(max_length=250)
|
|
|
|
is_active = models.BooleanField(default=True)
|
|
|
|
created_date = models.DateField(auto_now_add=True)
|
|
updated_date = models.DateField(auto_now=True)
|
|
|
|
gateway_priority = models.IntegerField(default=0)
|
|
|
|
def __str__(self):
|
|
return self.payment_gateway_name
|
|
|
|
def __save__(self):
|
|
if not self.payment_gateway_id:
|
|
self.payment_gateway_id = str(uuid.uuid4().hex[:10]).upper()
|
|
super().save(*args, **kwargs)
|
|
|
|
class PaymentGatewayCredentials(models.Model):
|
|
payment_gateway = models.ForeignKey(PaymentGateway, on_delete=models.CASCADE)
|
|
payment_gateway_credentials_value = models.TextField()
|
|
created_date = models.DateField(auto_now_add=True)
|
|
updated_date = models.DateField(auto_now=True)
|
|
|
|
def __str__(self):
|
|
return self.payment_gateway.payment_gateway_name + " - " + self.payment_gateway_credentials_value
|
|
|
|
|
|
class PaymentTransaction(models.Model):
|
|
payment_transaction_id = models.CharField(max_length=250)
|
|
payment_type = models.CharField(max_length=250, db_index=True, choices=[
|
|
('credit', 'Credit'),
|
|
('debit', 'Debit'),
|
|
('transfer', 'Transfer'),
|
|
('other', 'Other'),
|
|
])
|
|
payment_sub_type = models.CharField(max_length=250, choices=[
|
|
('online', 'Online'),
|
|
('offline', 'Offline'),
|
|
('other', 'Other'),
|
|
])
|
|
payment_gateway = models.ForeignKey(PaymentGateway, on_delete=models.CASCADE)
|
|
payment_transaction_amount = models.DecimalField(max_digits=10, decimal_places=2)
|
|
payment_transaction_currency = models.CharField(max_length=10)
|
|
payment_transaction_status = models.CharField(max_length=250, db_index=True, choices=[
|
|
('pending', 'Pending'),
|
|
('completed', 'Completed'),
|
|
('failed', 'Failed'),
|
|
('refunded', 'Refunded'),
|
|
('cancelled', 'Cancelled'),
|
|
])
|
|
payment_transaction_date = models.DateField(auto_now_add=True, db_index=True)
|
|
payment_transaction_time = models.TimeField(auto_now_add=True)
|
|
payment_transaction_notes = models.TextField(blank=True, null=True)
|
|
payment_transaction_raw_data = models.JSONField(blank=True, null=True)
|
|
payment_transaction_response = models.JSONField(blank=True, null=True)
|
|
payment_transaction_error = models.JSONField(blank=True, null=True)
|
|
|
|
last_updated_date = models.DateField(blank=True, null=True)
|
|
last_updated_time = models.TimeField(blank=True, null=True)
|
|
last_updated_by = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True)
|
|
|
|
def __str__(self):
|
|
return self.payment_gateway.payment_gateway_name + " - " + self.payment_transaction_id
|
|
|
|
def __save__(self):
|
|
if not self.payment_transaction_id:
|
|
self.payment_transaction_id = str(self.payment_gateway.payment_gateway_name[:3].upper()) + str(uuid.uuid4().hex[:10]).upper()
|
|
super().save(*args, **kwargs) |