73 lines
1.8 KiB
Python
73 lines
1.8 KiB
Python
from decimal import Decimal
|
|
from uuid import uuid4
|
|
|
|
from django.db import models
|
|
from django.utils.text import gettext_lazy as _
|
|
|
|
|
|
def set_default_metadata():
|
|
return {"items": [], "response": None}
|
|
|
|
|
|
class PaymentTransaction(models.Model):
|
|
class StatusChoices(models.TextChoices):
|
|
PAID = "PAI", _("Pagado")
|
|
PENDING = "PEN", _("Pendiente")
|
|
ERROR = "ERR", _("Error")
|
|
|
|
hash = models.UUIDField(verbose_name=_("Hash"), default=uuid4, db_index=True)
|
|
|
|
status = models.CharField(
|
|
max_length=3,
|
|
default=StatusChoices.PENDING,
|
|
choices=StatusChoices.choices,
|
|
verbose_name=_("Estado"),
|
|
)
|
|
amount = models.DecimalField(
|
|
max_digits=8,
|
|
decimal_places=2,
|
|
default=Decimal("0"),
|
|
verbose_name=_("Cantidad a pagar"),
|
|
)
|
|
|
|
creation_date = models.DateTimeField(
|
|
auto_now_add=True, verbose_name=_("Fecha de creación")
|
|
)
|
|
last_modification_date = models.DateTimeField(
|
|
auto_now=True, verbose_name=_("Fecha de última modificación")
|
|
)
|
|
|
|
contact_email = models.EmailField(
|
|
blank=True, null=True, verbose_name=_("Email de contacto")
|
|
)
|
|
observations = models.CharField(
|
|
max_length=255,
|
|
default="",
|
|
blank=True,
|
|
null=True,
|
|
verbose_name=_("Observaciones"),
|
|
)
|
|
|
|
metadata = models.JSONField(
|
|
default=set_default_metadata, verbose_name=_("Metadata")
|
|
)
|
|
"""
|
|
Metadata example:
|
|
{
|
|
"items": [{
|
|
"id": 1000,
|
|
"type": "type",
|
|
"amount_to_pay": 10.00,
|
|
"amount_to_pay_int": 1000,
|
|
}],
|
|
}
|
|
"""
|
|
|
|
@property
|
|
def amount_integer(self) -> int:
|
|
return int(self.amount * 100)
|
|
|
|
class Meta:
|
|
verbose_name = _("Pago de pedido en Redsys")
|
|
verbose_name_plural = _("Pagos de pedidos en Redsys")
|