from django.db import models VV_PRODUCT_SKU = "VV" class Country(models.Model): country_id = models.IntegerField(primary_key=True) name_de = models.CharField(max_length=255) name_fr = models.CharField(max_length=255) name_it = models.CharField(max_length=255) def __str__(self): return f"{self.name_de} ({self.country_id})" class Meta: verbose_name = "Country" verbose_name_plural = "Countries" ordering = ["country_id"] class BillingAddress(models.Model): """ Draft of a billing address for a purchase from the shop. """ user = models.ForeignKey("core.User", on_delete=models.CASCADE) # user first_name = models.CharField(max_length=255, blank=True) last_name = models.CharField(max_length=255, blank=True) street = models.CharField(max_length=255, blank=True) street_number = models.CharField(max_length=255, blank=True) postal_code = models.CharField(max_length=255, blank=True) city = models.CharField(max_length=255, blank=True) country = models.CharField(max_length=255, blank=True) # company (optional) company_name = models.CharField(max_length=255, blank=True) company_street = models.CharField(max_length=255, blank=True) company_street_number = models.CharField(max_length=255, blank=True) company_postal_code = models.CharField(max_length=255, blank=True) company_city = models.CharField(max_length=255, blank=True) company_country = models.CharField(max_length=255, blank=True) class Product(models.Model): sku = models.CharField(max_length=255, primary_key=True) price = models.IntegerField() # 10_00 = 10.00 CHF name = models.CharField(max_length=255) description = models.CharField(max_length=255) class CheckoutState(models.TextChoices): """ The state of a checkout process transaction. 1) We use the `autoSettle` feature of DataTrans! Therefore, there are less possible states: -> https://docs.datatrans.ch/docs/after-the-payment -> https://api-reference.datatrans.ch/#tag/v1transactions/operation/status 2) Difference between `settled` and `transmitted`: - https://www.datatrans.ch/en/know-how/faq/#what-does-the-status-transaction-settled-or-settledtransmitted-mean 3) Related relevant code:init_transaction and get_transaction_state in shop/services.py """ INITIALIZED = "initialized" SETTLED = "settled" TRANSMITTED = "transmitted" CANCELED = "canceled" FAILED = "failed" class CheckoutInformation(models.Model): user = models.ForeignKey("core.User", on_delete=models.PROTECT) # immutable product information at time of purchase product_sku = models.CharField(max_length=255) product_price = models.IntegerField() # 10_00 = 10.00 CHF product_name = models.CharField(max_length=255) product_description = models.CharField(max_length=255) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) state = models.CharField( max_length=50, choices=CheckoutState.choices, ) invoice_transmitted_at = models.DateTimeField(blank=True, null=True) transaction_id = models.CharField(max_length=255) # end user (required) first_name = models.CharField(max_length=255) last_name = models.CharField(max_length=255) street = models.CharField(max_length=255) street_number = models.CharField(max_length=255) postal_code = models.CharField(max_length=255) city = models.CharField(max_length=255) country = models.CharField(max_length=255) # company (optional) company_name = models.CharField(max_length=255, blank=True) company_street = models.CharField(max_length=255, blank=True) company_street_number = models.CharField(max_length=255, blank=True) company_postal_code = models.CharField(max_length=255, blank=True) company_city = models.CharField(max_length=255, blank=True) company_country = models.CharField(max_length=255, blank=True) # webhook metadata webhook_history = models.JSONField(default=list)