37 lines
1.4 KiB
Python
37 lines
1.4 KiB
Python
from django.conf import settings
|
|
from django.db import models
|
|
|
|
from apps.bookings.models import Booking
|
|
|
|
|
|
class PaymentProvider(models.TextChoices):
|
|
HYPERPAY = "hyperpay", "HyperPay"
|
|
PAYTABS = "paytabs", "PayTabs"
|
|
MOYASAR = "moyasar", "Moyasar"
|
|
TAP = "tap", "Tap"
|
|
AMAZON_PAYMENT_SERVICES = "amazon_payment_services", "Amazon Payment Services"
|
|
CHECKOUT = "checkout", "Checkout.com"
|
|
OTHER = "other", "Other"
|
|
|
|
|
|
class PaymentStatus(models.TextChoices):
|
|
CREATED = "created", "Created"
|
|
AUTHORIZED = "authorized", "Authorized"
|
|
CAPTURED = "captured", "Captured"
|
|
FAILED = "failed", "Failed"
|
|
REFUNDED = "refunded", "Refunded"
|
|
|
|
|
|
class Payment(models.Model):
|
|
booking = models.ForeignKey(Booking, on_delete=models.CASCADE, related_name="payments")
|
|
provider = models.CharField(max_length=50, choices=PaymentProvider.choices)
|
|
status = models.CharField(max_length=20, choices=PaymentStatus.choices, default=PaymentStatus.CREATED)
|
|
amount = models.DecimalField(max_digits=10, decimal_places=2)
|
|
currency = models.CharField(max_length=10, default=getattr(settings, "DEFAULT_CURRENCY", "SAR"))
|
|
external_id = models.CharField(max_length=200, blank=True)
|
|
metadata = models.JSONField(default=dict, blank=True)
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
def __str__(self):
|
|
return f"{self.provider} {self.amount} {self.currency}"
|