inital commit
This commit is contained in:
40
payment/models.py
Normal file
40
payment/models.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class PaymentRecord(models.Model):
|
||||
class Status(models.TextChoices):
|
||||
REQUIRES_PAYMENT = "requires_payment", "Requires Payment"
|
||||
PROCESSING = "processing", "Processing"
|
||||
SUCCEEDED = "succeeded", "Succeeded"
|
||||
FAILED = "failed", "Failed"
|
||||
REFUNDED = "refunded", "Refunded"
|
||||
|
||||
booking = models.ForeignKey("booking.Booking", on_delete=models.CASCADE, related_name="payments")
|
||||
stripe_payment_intent_id = models.CharField(max_length=255, unique=True)
|
||||
stripe_charge_id = models.CharField(max_length=255, blank=True)
|
||||
amount = models.DecimalField(max_digits=10, decimal_places=2)
|
||||
currency = models.CharField(max_length=8, default="usd")
|
||||
status = models.CharField(max_length=32, choices=Status.choices, default=Status.REQUIRES_PAYMENT)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ("-created_at",)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"Payment {self.stripe_payment_intent_id} ({self.status})"
|
||||
|
||||
|
||||
class WebhookEvent(models.Model):
|
||||
stripe_event_id = models.CharField(max_length=255, unique=True)
|
||||
event_type = models.CharField(max_length=120)
|
||||
payload = models.JSONField(default=dict)
|
||||
processed = models.BooleanField(default=False)
|
||||
processed_at = models.DateTimeField(null=True, blank=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ("-created_at",)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.event_type} ({self.stripe_event_id})"
|
||||
Reference in New Issue
Block a user