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, 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, choices=[
|
||
|
|
('pending', 'Pending'),
|
||
|
|
('completed', 'Completed'),
|
||
|
|
('failed', 'Failed'),
|
||
|
|
('refunded', 'Refunded'),
|
||
|
|
('cancelled', 'Cancelled'),
|
||
|
|
])
|
||
|
|
payment_transaction_date = models.DateField(auto_now_add=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)
|