python-terminusgps 45.3.0__tar.gz → 45.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/PKG-INFO +1 -1
  2. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/source/conf.py +1 -1
  3. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/pyproject.toml +1 -1
  4. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/authorizenet/api/payment_profiles.py +51 -23
  5. python_terminusgps-45.5.0/terminusgps/authorizenet/auth.py +38 -0
  6. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/authorizenet/controllers.py +3 -1
  7. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/authorizenet/services.py +16 -21
  8. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/uv.lock +1 -1
  9. python_terminusgps-45.3.0/terminusgps/authorizenet/auth.py +0 -56
  10. python_terminusgps-45.3.0/terminusgps/authorizenet/validators.py +0 -120
  11. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/.github/workflows/sphinx.yml +0 -0
  12. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/.gitignore +0 -0
  13. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/.python-version +0 -0
  14. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/COPYING +0 -0
  15. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/README.md +0 -0
  16. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/Makefile +0 -0
  17. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/make.bat +0 -0
  18. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/requirements.txt +0 -0
  19. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/source/authorizenet/api.rst +0 -0
  20. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/source/authorizenet/auth.rst +0 -0
  21. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/source/authorizenet/constants.rst +0 -0
  22. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/source/authorizenet/exceptions.rst +0 -0
  23. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/source/authorizenet/index.rst +0 -0
  24. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/source/authorizenet/usage.rst +0 -0
  25. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/source/index.rst +0 -0
  26. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/source/mixins.rst +0 -0
  27. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/source/validators.rst +0 -0
  28. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/source/wialon/constants.rst +0 -0
  29. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/source/wialon/exceptions.rst +0 -0
  30. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/source/wialon/index.rst +0 -0
  31. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/source/wialon/items.rst +0 -0
  32. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/source/wialon/session.rst +0 -0
  33. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/docs/source/wialon/usage.rst +0 -0
  34. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/__init__.py +0 -0
  35. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/authorizenet/__init__.py +0 -0
  36. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/authorizenet/api/__init__.py +0 -0
  37. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/authorizenet/api/address_profiles.py +0 -0
  38. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/authorizenet/api/customer_profiles.py +0 -0
  39. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/authorizenet/api/subscriptions.py +0 -0
  40. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/authorizenet/api/transactions.py +0 -0
  41. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/authorizenet/constants.py +0 -0
  42. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/default_settings.py +0 -0
  43. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/mixins.py +0 -0
  44. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/validators.py +0 -0
  45. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/wialon/__init__.py +0 -0
  46. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/wialon/constants.py +0 -0
  47. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/wialon/flags.py +0 -0
  48. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/wialon/items/__init__.py +0 -0
  49. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/wialon/items/account.py +0 -0
  50. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/wialon/items/base.py +0 -0
  51. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/wialon/items/factory.py +0 -0
  52. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/wialon/items/resource.py +0 -0
  53. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/wialon/items/retranslator.py +0 -0
  54. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/wialon/items/route.py +0 -0
  55. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/wialon/items/unit.py +0 -0
  56. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/wialon/items/unit_group.py +0 -0
  57. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/wialon/items/user.py +0 -0
  58. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/wialon/session.py +0 -0
  59. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/wialon/utils.py +0 -0
  60. {python_terminusgps-45.3.0 → python_terminusgps-45.5.0}/terminusgps/wialon/validators.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-terminusgps
3
- Version: 45.3.0
3
+ Version: 45.5.0
4
4
  Summary: Provides abstractions/utilities for working with Wialon API, Authorize.NET API, AWS API, and more.
5
5
  Project-URL: Documentation, https://terminusgps.github.io/python-terminusgps
6
6
  Project-URL: Repository, https://github.com/terminusgps/python-terminusgps
@@ -12,7 +12,7 @@ sys.path.insert(0, os.path.abspath("../../"))
12
12
  project = "python-terminusgps"
13
13
  copyright = "2025, Terminus GPS, LLC"
14
14
  author = "Terminus GPS, LLC"
15
- release = "45.3.0"
15
+ release = "45.5.0"
16
16
 
17
17
  # -- General configuration ---------------------------------------------------
18
18
  # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "python-terminusgps"
3
- version = "45.3.0"
3
+ version = "45.5.0"
4
4
  description = "Provides abstractions/utilities for working with Wialon API, Authorize.NET API, AWS API, and more."
5
5
  readme = "README.md"
6
6
  authors = [ {name = "Blake Nall", email = "blake@terminusgps.com" } ]
@@ -2,8 +2,6 @@ from authorizenet import apicontractsv1, apicontrollers
2
2
  from authorizenet.apicontrollersbase import APIOperationBase
3
3
  from lxml.objectify import ObjectifiedElement
4
4
 
5
- from terminusgps.authorizenet.auth import get_validation_mode
6
-
7
5
  __all__ = [
8
6
  "create_customer_payment_profile",
9
7
  "get_customer_payment_profile",
@@ -15,26 +13,37 @@ __all__ = [
15
13
 
16
14
  def create_customer_payment_profile(
17
15
  customer_profile_id: int,
18
- payment_profile: apicontractsv1.customerPaymentProfileType,
19
- validate: bool = True,
16
+ payment: apicontractsv1.paymentType,
17
+ address: apicontractsv1.customerAddressType,
18
+ default: bool = False,
19
+ validation: str | None = None,
20
20
  ) -> tuple[ObjectifiedElement, type[APIOperationBase]]:
21
21
  """
22
22
  `createCustomerPaymentProfileRequest <https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-payment-profile>`_.
23
23
 
24
24
  :param customer_profile_id: An Authorizenet customer profile id.
25
25
  :type customer_profile_id: int
26
- :param payment_profile: An Authorizenet payment profile element.
27
- :type payment_profile: ~authorizenet.apicontractsv1.customerPaymentProfileType
28
- :param validate: Whether to validate the payment profile. Default is True.
26
+ :param payment: An Authorizenet payment element.
27
+ :type payment: ~authorizenet.apicontractsv1.paymentType
28
+ :param address: An Authorizenet address element.
29
+ :type address: ~authorizenet.apicontractsv1.customerAddressType
30
+ :param default: Whether to set the payment profile as default. Default is :py:obj:`False`.
31
+ :type default: bool
32
+ :param validation: Validation mode to use when validating the payment profile. If not provided, the payment profile is not validated. Default is :py:obj:`None`.
33
+ :type validation: str | None
29
34
  :returns: A tuple containing an Authorizenet API request element and controller class.
30
35
  :rtype: tuple[~lxml.objectify.ObjectifiedElement, type[~authorizenet.apicontrollersbase.APIOperationBase]]
31
36
 
32
37
  """
33
38
  request = apicontractsv1.createCustomerPaymentProfileRequest()
34
39
  request.customerProfileId = str(customer_profile_id)
35
- request.paymentProfile = payment_profile
36
- if validate:
37
- request.validationMode = get_validation_mode()
40
+ request.paymentProfile = apicontractsv1.customerPaymentProfileType()
41
+ request.paymentProfile.payment = payment
42
+ request.paymentProfile.billTo = address
43
+ request.paymentProfile.defaultPaymentProfile = str(default).lower()
44
+
45
+ if validation is not None:
46
+ request.validationMode = str(validation)
38
47
  return request, apicontrollers.createCustomerPaymentProfileController
39
48
 
40
49
 
@@ -64,7 +73,7 @@ def get_customer_payment_profile(
64
73
 
65
74
 
66
75
  def validate_customer_payment_profile(
67
- customer_profile_id: int, payment_profile_id: int
76
+ customer_profile_id: int, payment_profile_id: int, validation: str
68
77
  ) -> tuple[ObjectifiedElement, type[APIOperationBase]]:
69
78
  """
70
79
  `validateCustomerPaymentProfileRequest <https://developer.authorize.net/api/reference/index.html#customer-profiles-validate-customer-payment-profile>`_.
@@ -73,6 +82,8 @@ def validate_customer_payment_profile(
73
82
  :type customer_profile_id: int
74
83
  :param payment_profile_id: An Authorizenet customer payment profile id.
75
84
  :type payment_profile_id: int
85
+ :param validation: Validation mode to use when validating the payment profile.
86
+ :type validation: str
76
87
  :returns: A tuple containing an Authorizenet API request element and controller class.
77
88
  :rtype: tuple[~lxml.objectify.ObjectifiedElement, type[~authorizenet.apicontrollersbase.APIOperationBase]]
78
89
 
@@ -80,15 +91,17 @@ def validate_customer_payment_profile(
80
91
  request = apicontractsv1.validateCustomerPaymentProfileRequest()
81
92
  request.customerProfileId = str(customer_profile_id)
82
93
  request.customerPaymentProfileId = str(payment_profile_id)
83
- request.validationMode = get_validation_mode()
94
+ request.validationMode = validation
84
95
  return request, apicontrollers.validateCustomerPaymentProfileController
85
96
 
86
97
 
87
98
  def update_customer_payment_profile(
88
99
  customer_profile_id: int,
89
100
  payment_profile_id: int,
90
- payment_profile: apicontractsv1.customerPaymentProfileType,
91
- validate: bool = True,
101
+ payment: apicontractsv1.paymentType | None = None,
102
+ address: apicontractsv1.customerAddressType | None = None,
103
+ default: bool | None = None,
104
+ validation: str | None = None,
92
105
  ) -> tuple[ObjectifiedElement, type[APIOperationBase]]:
93
106
  """
94
107
  `updateCustomerPaymentProfileRequest <https://developer.authorize.net/api/reference/index.html#customer-profiles-update-customer-payment-profile>`_.
@@ -97,22 +110,37 @@ def update_customer_payment_profile(
97
110
  :type customer_profile_id: int
98
111
  :param payment_profile_id: An Authorizenet customer payment profile id.
99
112
  :type payment_profile_id: int
100
- :param payment_profile: An Authorizenet payment profile element.
101
- :type payment_profile: ~authorizenet.apicontractsv1.customerPaymentProfileType
102
- :param validate: Whether to validate the payment profile. Default is True.
103
- :type validate: bool
113
+ :param payment: An Authorizenet payment element.
114
+ :type payment: ~authorizenet.apicontractsv1.paymentType | None
115
+ :param address: An Authorizenet address element.
116
+ :type address: ~authorizenet.apicontractsv1.customerAddressType | None
117
+ :param default: Whether to set the payment profile as default. If not provided, the payment profile's default state is not updated. Default is :py:obj:`None`.
118
+ :type default: bool | None
119
+ :param validation: Validation mode to use when validating the payment profile. If not provided, the payment profile is not validated. Default is :py:obj:`None`.
120
+ :type validation: str | None
121
+ :raises ValueError: If neither payment nor address was provided.
104
122
  :returns: A tuple containing an Authorizenet API request element and controller class.
105
123
  :rtype: tuple[~lxml.objectify.ObjectifiedElement, type[~authorizenet.apicontrollersbase.APIOperationBase]]
106
124
 
107
125
  """
108
- if not hasattr(payment_profile, "customerPaymentProfileId"):
109
- payment_profile.customerPaymentProfileId = str(payment_profile_id)
126
+ if payment is None and address is None:
127
+ raise ValueError(
128
+ f"At least one of 'payment' or 'address' is required, got '{payment}' and '{address}'."
129
+ )
110
130
 
111
131
  request = apicontractsv1.updateCustomerPaymentProfileRequest()
112
132
  request.customerProfileId = str(customer_profile_id)
113
- request.paymentProfile = payment_profile
114
- if validate:
115
- request.validationMode = get_validation_mode()
133
+ request.paymentProfile = apicontractsv1.customerPaymentProfileType()
134
+ request.paymentProfile.customerPaymentProfileId = str(payment_profile_id)
135
+
136
+ if payment is not None:
137
+ request.paymentProfile.payment = payment
138
+ if address is not None:
139
+ request.paymentProfile.billTo = address
140
+ if default is not None:
141
+ request.paymentProfile.defaultPaymentProfile = str(default).lower()
142
+ if validation is not None:
143
+ request.validationMode = str(validation)
116
144
  return request, apicontrollers.updateCustomerPaymentProfileController
117
145
 
118
146
 
@@ -0,0 +1,38 @@
1
+ from authorizenet.apicontractsv1 import merchantAuthenticationType
2
+ from django.conf import settings
3
+
4
+
5
+ def get_merchant_auth() -> merchantAuthenticationType:
6
+ """
7
+ Returns the merchant authentication information for Authorizenet API controller execution.
8
+
9
+ :returns: A merchant authentication object.
10
+ :rtype: ~authorizenet.apicontractsv1.merchantAuthenticationType
11
+
12
+ """
13
+ return merchantAuthenticationType(
14
+ name=str(settings.MERCHANT_AUTH_LOGIN_ID),
15
+ transactionKey=str(settings.MERCHANT_AUTH_TRANSACTION_KEY),
16
+ )
17
+
18
+
19
+ def get_environment() -> str:
20
+ """
21
+ Returns the environment for Authorizenet API controller execution.
22
+
23
+ :returns: An Authorizenet API environment string.
24
+ :rtype: str
25
+
26
+ """
27
+ return settings.MERCHANT_AUTH_ENVIRONMENT
28
+
29
+
30
+ def get_validation_mode() -> str:
31
+ """
32
+ Returns the validation mode for Authorizenet API controller execution.
33
+
34
+ :returns: An Authorizenet API validation string.
35
+ :rtype: str
36
+
37
+ """
38
+ return settings.MERCHANT_AUTH_VALIDATION_MODE
@@ -3,7 +3,7 @@ from lxml.objectify import ObjectifiedElement
3
3
 
4
4
 
5
5
  def execute_controller(
6
- controller: APIOperationBase,
6
+ controller: APIOperationBase, environment: str
7
7
  ) -> ObjectifiedElement | None:
8
8
  """
9
9
  Executes an Authorizenet API controller and returns its response.
@@ -19,8 +19,10 @@ def execute_controller(
19
19
  :rtype: ~lxml.objectify.ObjectifiedElement | None
20
20
 
21
21
  """
22
+ controller.setenvironment(environment)
22
23
  controller.execute()
23
24
  response = controller.getresponse()
25
+
24
26
  if response is None:
25
27
  raise AuthorizenetControllerExecutionError(
26
28
  message="Authorizenet controller response didn't exist.", code="1"
@@ -1,18 +1,14 @@
1
1
  from abc import ABC
2
2
  from functools import cached_property
3
+ from typing import Callable
3
4
 
4
- from authorizenet import apicontractsv1
5
- from authorizenet.apicontrollersbase import APIOperationBase
5
+ from authorizenet.apicontractsv1 import merchantAuthenticationType
6
6
  from django.conf import settings
7
7
  from django.core.exceptions import ImproperlyConfigured
8
8
  from lxml.objectify import ObjectifiedElement
9
9
 
10
- from terminusgps.authorizenet.auth import (
11
- get_environment,
12
- get_merchant_auth,
13
- get_validation_mode,
14
- )
15
- from terminusgps.authorizenet.controllers import execute_controller
10
+ from .auth import get_environment, get_merchant_auth, get_validation_mode
11
+ from .controllers import execute_controller
16
12
 
17
13
 
18
14
  class AuthorizenetService(ABC):
@@ -26,31 +22,30 @@ class AuthorizenetService(ABC):
26
22
  )
27
23
 
28
24
  def __init__(self) -> None:
25
+ """Raises :py:exc:`~django.core.exceptions.ImproperlyConfigured` if required settings weren't set."""
29
26
  for setting in self.REQUIRED_SETTINGS:
30
27
  if not hasattr(settings, setting):
31
28
  raise ImproperlyConfigured(f"'{setting}' setting is required.")
32
29
 
33
- def execute_controller(
34
- self, controller: APIOperationBase
35
- ) -> ObjectifiedElement:
30
+ def call_api(self, func: Callable, *args, **kwargs) -> ObjectifiedElement:
36
31
  """
37
- Executes an Authorizenet API controller.
32
+ Calls the Authorizenet API function with arguments and returns the result.
38
33
 
39
- :param controller: An Authorizenet controller.
40
- :type controller: ~authorizenet.apicontrollersbase.APIOperationBase
34
+ :param func: An Authorizenet API function.
35
+ :type func: ~typing.Callable
36
+ :param args: Positional arguments for the API call.
37
+ :param kwargs: Keyword arguments for the API call.
41
38
  :raises ~terminusgps.authorizenet.controllers.AuthorizenetControllerExecutionError: If the API call failed.
42
- :returns: The Authorizenet API controller response.
39
+ :returns: The Authorizenet API call response.
43
40
  :rtype: ~lxml.objectify.ObjectifiedElement
44
41
 
45
42
  """
46
- controller.setenvironment(self.environment)
47
- controller.setmerchantauthentication(self.merchantAuthentication)
48
- return execute_controller(controller)
43
+ request, controller_cls = func(*args, **kwargs)
44
+ request.merchantAuthentication = self.merchantAuthentication
45
+ return execute_controller(controller_cls(request), self.environment)
49
46
 
50
47
  @cached_property
51
- def merchantAuthentication(
52
- self,
53
- ) -> apicontractsv1.merchantAuthenticationType:
48
+ def merchantAuthentication(self) -> merchantAuthenticationType:
54
49
  """Merchant authentication element for Authorizenet API requests."""
55
50
  return get_merchant_auth()
56
51
 
@@ -298,7 +298,7 @@ wheels = [
298
298
 
299
299
  [[package]]
300
300
  name = "python-terminusgps"
301
- version = "45.3.0"
301
+ version = "45.5.0"
302
302
  source = { editable = "." }
303
303
  dependencies = [
304
304
  { name = "authorizenet" },
@@ -1,56 +0,0 @@
1
- from authorizenet.apicontractsv1 import merchantAuthenticationType
2
- from django.conf import settings
3
- from django.core.exceptions import ImproperlyConfigured
4
-
5
-
6
- def get_merchant_auth() -> merchantAuthenticationType:
7
- """
8
- Returns the merchant authentication information for Authorizenet API controller execution.
9
-
10
- :raises ~django.core.exceptions.ImproperlyConfigured: If the :py:data:`MERCHANT_AUTH_LOGIN_ID` or the :py:data:`MERCHANT_AUTH_TRANSACTION_KEY` settings weren't set.
11
- :returns: A merchant authentication object.
12
- :rtype: ~authorizenet.apicontractsv1.merchantAuthenticationType
13
-
14
- """
15
- if not all(
16
- [
17
- hasattr(settings, "MERCHANT_AUTH_LOGIN_ID"),
18
- hasattr(settings, "MERCHANT_AUTH_TRANSACTION_KEY"),
19
- ]
20
- ):
21
- error_msg: str = "'MERCHANT_AUTH_LOGIN_ID' and 'MERCHANT_AUTH_TRANSACTION_KEY' settings are required."
22
- raise ImproperlyConfigured(error_msg)
23
- return merchantAuthenticationType(
24
- name=str(settings.MERCHANT_AUTH_LOGIN_ID),
25
- transactionKey=str(settings.MERCHANT_AUTH_TRANSACTION_KEY),
26
- )
27
-
28
-
29
- def get_environment() -> str:
30
- """
31
- Returns the environment for Authorizenet API controller execution.
32
-
33
- :raises ~django.core.exceptions.ImproperlyConfigured: If the :py:data:`MERCHANT_AUTH_ENVIRONMENT` setting wasn't set.
34
- :returns: An Authorizenet API environment string.
35
- :rtype: str
36
-
37
- """
38
- if not hasattr(settings, "MERCHANT_AUTH_ENVIRONMENT"):
39
- error_msg: str = "'MERCHANT_AUTH_ENVIRONMENT' setting is required."
40
- raise ImproperlyConfigured(error_msg)
41
- return settings.MERCHANT_AUTH_ENVIRONMENT
42
-
43
-
44
- def get_validation_mode() -> str:
45
- """
46
- Returns the validation mode for Authorizenet API controller execution.
47
-
48
- :raises ~django.core.exceptions.ImproperlyConfigured: If the :py:data:`MERCHANT_AUTH_VALIDATION_MODE` setting wasn't set.
49
- :returns: An Authorizenet API validation string.
50
- :rtype: str
51
-
52
- """
53
- if not hasattr(settings, "MERCHANT_AUTH_VALIDATION_MODE"):
54
- error_msg: str = "'MERCHANT_AUTH_VALIDATION_MODE' setting is required."
55
- raise ImproperlyConfigured(error_msg)
56
- return settings.MERCHANT_AUTH_VALIDATION_MODE
@@ -1,120 +0,0 @@
1
- import calendar
2
- import datetime
3
-
4
- from django.core.exceptions import ValidationError
5
- from django.utils.translation import gettext_lazy as _
6
-
7
-
8
- def validate_credit_card_number(value: str) -> None:
9
- """
10
- Raises :py:exc:`~django.core.exceptions.ValidationError` if the value is an invalid credit card number.
11
-
12
- Uses the `Luhn algorithm <https://en.wikipedia.org/wiki/Luhn_algorithm>`_ to validate the credit card number.
13
-
14
- :param value: A credit card number string.
15
- :type value: :py:obj:`str`
16
- :raises ValidationError: If the value contains non-digit characters.
17
- :raises ValidationError: If the value fails the Luhn algorithm.
18
- :returns: Nothing.
19
- :rtype: :py:obj:`None`
20
-
21
- """
22
- if not value.isdigit():
23
- raise ValidationError(
24
- _("Credit card number can only contain digits. Got '%(value)s'."),
25
- code="invalid",
26
- params={"value": value},
27
- )
28
-
29
- card_number = [int(num) for num in reversed(value)]
30
- even_digits = card_number[1::2]
31
- odd_digits = card_number[0::2]
32
-
33
- checksum = 0
34
- checksum += sum(
35
- [
36
- digit * 2 if digit * 2 <= 9 else (digit * 2) % 9 or 9
37
- for digit in even_digits
38
- ]
39
- )
40
- checksum += sum([digit for digit in odd_digits])
41
-
42
- if checksum % 10 != 0:
43
- raise ValidationError(_("Invalid credit card number."), code="invalid")
44
-
45
-
46
- def validate_credit_card_expiry_month(value: str) -> None:
47
- """
48
- Raises :py:exc:`~django.core.exceptions.ValidationError` if the value is an invalid credit card expiration date month.
49
-
50
- :param value: A credit card expiration year string.
51
- :type value: :py:obj:`str`
52
- :raises ValidationError: If the value contains non-digit characters.
53
- :raises ValidationError: If the value is negative.
54
- :raises ValidationError: If the value isn't between 1-12.
55
- :returns: Nothing.
56
- :rtype: :py:obj:`None`
57
-
58
- """
59
- if not value.isdigit():
60
- raise ValidationError(
61
- _("Expiration month can only contain digits, got '%(value)s'."),
62
- code="invalid",
63
- params={"value": value},
64
- )
65
- if not int(value) > 0:
66
- raise ValidationError(
67
- _(
68
- "Expiration month can only be a positive value, got '%(value)s'."
69
- ),
70
- code="invalid",
71
- params={"value": value},
72
- )
73
-
74
- try:
75
- calendar.Month(int(value))
76
- except ValueError:
77
- raise ValidationError(
78
- _("Expiration month must be between 1-12, got '%(value)s'."),
79
- code="invalid",
80
- params={"value": value},
81
- )
82
-
83
-
84
- def validate_credit_card_expiry_year(value: str) -> None:
85
- """
86
- Raises :py:exc:`~django.core.exceptions.ValidationError` if the value is an invalid credit card expiration date year.
87
-
88
- :param value: A credit card expiration year string.
89
- :type value: :py:obj:`str`
90
- :raises ValidationError: If the value contains non-digit characters.
91
- :raises ValidationError: If the value is negative.
92
- :raises ValidationError: If the value is a year in the past.
93
- :returns: Nothing.
94
- :rtype: :py:obj:`None`
95
-
96
- """
97
- if not value.isdigit():
98
- raise ValidationError(
99
- _("Expiration year can only contain digits, got '%(value)s'."),
100
- code="invalid",
101
- params={"value": value},
102
- )
103
- if not int(value) > 0:
104
- raise ValidationError(
105
- _(
106
- "Expiration year can only be a positive value, got '%(value)s'."
107
- ),
108
- code="invalid",
109
- params={"value": value},
110
- )
111
-
112
- input_year = datetime.datetime.strptime(value, "%y").year
113
- this_year = datetime.datetime.now().year
114
-
115
- if not input_year >= this_year:
116
- raise ValidationError(
117
- _("Expiration year cannot be in the past, got '%(value)s'."),
118
- code="invalid",
119
- params={"value": value},
120
- )