HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/aigenerator/AI-LG-backend/Ai_logo_generation/payment/models.py
from django.db import models
from authorization.models import CustomUser
import uuid 
from django.utils.timezone import now


class Product(models.Model):
    BILLING_PERIOD_CHOICES = [
        ('daily', 'Daily'),
        ('monthly', 'Monthly'),
        ('yearly', 'Yearly')
    ]
    
    name = models.CharField(max_length=255)
    amount = models.DecimalField(max_digits=10, decimal_places=2)
    description = models.TextField(blank=True)  # Optional field
    currency = models.CharField(max_length=3)  # ISO 4217 currency code, e.g., 'USD'
    product_id = models.CharField(default=uuid.uuid4,editable=False, unique=True)
    is_subscription = models.BooleanField(default=False)
    resolution = models.CharField(max_length=15, default="800x600")
    billing_period = models.CharField(
        max_length=10, 
        choices=BILLING_PERIOD_CHOICES, 
        blank=True, 
        null=True
    )
    is_active = models.BooleanField(default=True)

    def __str__(self):
        return self.name
class Transaction(models.Model):

    STATUS_CHOICES = [
        ('succeeded', 'Succeeded'),
        ('pending', 'Pending'),
        ('failed', 'Failed'),
    ]
    SUBSCRIPTION_STATUS_CHOICES = [
        ('active', 'Active'),
        ('cancelled', 'Cancelled'),
        ('past_due', 'Past Due'),
        ('unpaid', 'Unpaid'),
        ('incomplete', 'Incomplete'),
    ]

    customer = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
    amount = models.DecimalField(max_digits=10, decimal_places=2)
    status = models.CharField(max_length=255, choices=STATUS_CHOICES, default="pending")
    is_subscription = models.BooleanField(default=False)
    subscription_id = models.CharField(max_length=255, null=True, blank=True)  # Stripe subscription ID
    subscription_status = models.CharField(
        max_length=20, 
        choices=SUBSCRIPTION_STATUS_CHOICES, 
        null=True, 
        blank=True
    )
    subscription_start = models.DateTimeField(null=True, blank=True)
    subscription_end = models.DateTimeField(null=True, blank=True)
    invoice_id = models.CharField(max_length=255, null=True, blank=True)
    receipt_url = models.URLField(null=True, blank=True)
    product = models.ForeignKey(Product,null=True, blank=True, on_delete=models.CASCADE)
    created_at = models.DateTimeField(auto_now_add=True)
    transaction_id = models.CharField(max_length=255, null=True, blank=True) 
    transaction_date = models.DateTimeField(null=True, blank=True) 
    charge_id = models.CharField(max_length=255, null=True, blank=True) 

    def __str__(self):
        return f"Transaction {self.id} - {self.customer.email} - {self.amount} USD"
    
    logo = models.UUIDField(
        null=True, 
        blank=True,
    )