# Path: src/cybersource/constants.py
# DECISION_ACCEPT = "ACCEPT"
# 
# DECISION_REVIEW = "REVIEW"
# 
# DECISION_DECLINE = "DECLINE"
# 
# DECISION_ERROR = "ERROR"


from cryptography.fernet import InvalidToken
from django.conf import settings
from django.db import models
from django.contrib.postgres.fields import HStoreField
from django.utils.translation import gettext_lazy as _
from django.utils import timezone
from oscar.core.compat import AUTH_USER_MODEL
from oscar.models.fields import NullCharField
from fernet_fields import EncryptedTextField
from .constants import (
    DECISION_ACCEPT,
    DECISION_REVIEW,
    DECISION_DECLINE,
    DECISION_ERROR,
)
import dateutil.parser
import logging
    class Meta:
        verbose_name = _("Secure Acceptance Profile")
        verbose_name_plural = _("Secure Acceptance Profiles")

    @classmethod
    def get_profile(cls, hostname):
        # Lambda function to get profiles whilst catching cryptography exceptions (in-case the Fernet key
        # unexpectedly changed, the data somehow got corrupted, etc).
        def _get_safe(**filters):
            try:
                return cls.objects.filter(**filters).first()
            except InvalidToken:
                logger.exception(
                    "Caught InvalidToken exception while retrieving profile"
                )
                return None

        # Try to get the profile for the given hostname
        profile = _get_safe(hostname__iexact=hostname)
        if profile:
            return profile

        # Fall back to the default profile
        profile = _get_safe(is_default=True)
        if profile:
            return profile

        # No default profile exists, so try and get something out of settings.
        if (
            hasattr(settings, "CYBERSOURCE_PROFILE")

# Path: src/cybersource/constants.py
# DECISION_ACCEPT = "ACCEPT"
# 
# DECISION_REVIEW = "REVIEW"
# 
# DECISION_DECLINE = "DECLINE"
# 
# DECISION_ERROR = "ERROR"


# Path: src/cybersource/models.py
from cryptography.fernet import InvalidToken
from django.conf import settings
from django.db import models
from django.contrib.postgres.fields import HStoreField
from django.utils.translation import gettext_lazy as _
from django.utils import timezone
from oscar.core.compat import AUTH_USER_MODEL
from oscar.models.fields import NullCharField
from fernet_fields import EncryptedTextField
from .constants import (
    DECISION_ACCEPT,
    DECISION_REVIEW,
    DECISION_DECLINE,
    DECISION_ERROR,
)
import dateutil.parser
import logging

    class Meta:
        verbose_name = _("Secure Acceptance Profile")
        verbose_name_plural = _("Secure Acceptance Profiles")

    @classmethod
    def get_profile(cls, hostname):
        # Lambda function to get profiles whilst catching cryptography exceptions (in-case the Fernet key
        # unexpectedly changed, the data somehow got corrupted, etc).
        def _get_safe(**filters):
            try:
                return cls.objects.filter(**filters).first()
            except InvalidToken:
                logger.exception(
                    "Caught InvalidToken exception while retrieving profile"
                )
                return None

        # Try to get the profile for the given hostname
        profile = _get_safe(hostname__iexact=hostname)
        if profile:
            return profile

        # Fall back to the default profile
        profile = _get_safe(is_default=True)
        if profile:
            return profile

        # No default profile exists, so try and get something out of settings.
        if (
            hasattr(settings, "CYBERSOURCE_PROFILE")

            and hasattr(settings, "CYBERSOURCE_ACCESS")