Changes to payment models #32

Merged
valberg merged 35 commits from benjaoming/membersystem:payment-updates into main 2024-08-03 17:55:33 +00:00
2 changed files with 22 additions and 3 deletions
Showing only changes of commit 7cc22aa0a1 - Show all commits

View file

@ -1,5 +1,5 @@
default_language_version: default_language_version:
python: python3.12 python: python3
exclude: ^.*\b(migrations)\b.*$ exclude: ^.*\b(migrations)\b.*$
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks

View file

@ -98,19 +98,23 @@ class Payment(CreatedModifiedAbstract):
description = models.CharField(max_length=1024, verbose_name=_("description")) description = models.CharField(max_length=1024, verbose_name=_("description"))
stripe_charge_id = models.CharField(max_length=255, null=True, blank=True) payment_type = models.ForeignKey("PaymentType", on_delete=models.PROTECT)
external_transaction_id = models.CharField(max_length=255, null=True, blank=True)
# stripe_charge_id = models.CharField(max_length=255, null=True, blank=True)
@property @property
def display_id(self): def display_id(self):
return str(self.id).zfill(6) return str(self.id).zfill(6)
@classmethod @classmethod
def from_order(cls, order): def from_order(cls, order, payment_type):
return cls.objects.create( return cls.objects.create(
order=order, order=order,
user=order.user, user=order.user,
amount=order.total, amount=order.total,
description=order.description, description=order.description,
payment_type=payment_type,
) )
def __str__(self) -> str: def __str__(self) -> str:
@ -119,3 +123,18 @@ class Payment(CreatedModifiedAbstract):
class Meta: class Meta:
verbose_name = _("payment") verbose_name = _("payment")
verbose_name_plural = _("payments") verbose_name_plural = _("payments")
class PaymentType(CreatedModifiedAbstract):
"""Types of payments available in the system:
- bank transfer
- card payment (specific provider)
"""
name = models.CharField(max_length=1024, verbose_name=_("description"))
description = models.TextField(max_length=2048, null=True, blank=True)
enabled = models.BooleanField(default=True)
def __str__(self) -> str:
return f"{self.name}"