python-terminusgps 1.7.1__py3-none-any.whl → 1.9.0__py3-none-any.whl
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.
Potentially problematic release.
This version of python-terminusgps might be problematic. Click here for more details.
- {python_terminusgps-1.7.1.dist-info → python_terminusgps-1.9.0.dist-info}/METADATA +3 -1
- {python_terminusgps-1.7.1.dist-info → python_terminusgps-1.9.0.dist-info}/RECORD +10 -7
- terminusgps/authorizenet/auth.py +20 -6
- terminusgps/authorizenet/profiles/addresses.py +83 -0
- terminusgps/authorizenet/profiles/base.py +62 -0
- terminusgps/authorizenet/profiles/customers.py +109 -0
- terminusgps/authorizenet/profiles/payments.py +118 -0
- terminusgps/settings.py +5 -1
- terminusgps/test.py +0 -55
- {python_terminusgps-1.7.1.dist-info → python_terminusgps-1.9.0.dist-info}/WHEEL +0 -0
- {python_terminusgps-1.7.1.dist-info → python_terminusgps-1.9.0.dist-info}/licenses/COPYING +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-terminusgps
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.9.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://app.terminusgps.com/docs/apps/python-terminusgps/index.html
|
|
6
6
|
Project-URL: Repository, https://github.com/terminusgps/python-terminusgps
|
|
@@ -16,4 +16,6 @@ Requires-Dist: argparse>=1.4.0
|
|
|
16
16
|
Requires-Dist: authorizenet>=1.1.5
|
|
17
17
|
Requires-Dist: boto3>=1.34.144
|
|
18
18
|
Requires-Dist: django>=5.1.5
|
|
19
|
+
Requires-Dist: intuit-oauth>=1.2.6
|
|
20
|
+
Requires-Dist: python-quickbooks>=0.9.10
|
|
19
21
|
Requires-Dist: python-wialon>=1.2.4
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
terminusgps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
terminusgps/settings.py,sha256=
|
|
3
|
-
terminusgps/test.py,sha256=SmvDgRMqLnj_t29eWbckYjK7e9n-Yy-oWwlbN3IdhqE,2004
|
|
2
|
+
terminusgps/settings.py,sha256=fxU6VuJVJaB_tHcIksH-3XPrFQHRD57nW7_9vMsZ6Ag,394
|
|
4
3
|
terminusgps/authorizenet/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
terminusgps/authorizenet/auth.py,sha256=
|
|
4
|
+
terminusgps/authorizenet/auth.py,sha256=yznomWGTRbFiTDiugsRw1HqxJAV4aJKZFN3Bzdt_V8E,1119
|
|
5
|
+
terminusgps/authorizenet/profiles/addresses.py,sha256=NEm-qxz1wFxnLxd24OqQhHb6AU-C3JRRZOqNgQEN1Xw,3369
|
|
6
|
+
terminusgps/authorizenet/profiles/base.py,sha256=LIPDK78HqzYanoZF_gtbmLBEB_YF_MM7CNWvharPrMk,1974
|
|
7
|
+
terminusgps/authorizenet/profiles/customers.py,sha256=vAD-bxUcNvAoIEQDdnu3QESiHPAjEV1g1i5l0tY5lVk,4536
|
|
8
|
+
terminusgps/authorizenet/profiles/payments.py,sha256=peNCn395s1Evk8iK9C9nrk2MsWw8ZHX2-oSgVhNwM1U,5408
|
|
6
9
|
terminusgps/aws/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
10
|
terminusgps/aws/secrets.py,sha256=kgRA77rs0mD4berWRLkPtJLOe4Grf--o5f8NzwQqXCk,360
|
|
8
11
|
terminusgps/wialon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -19,7 +22,7 @@ terminusgps/wialon/items/route.py,sha256=qOHPN_rejwiGqvwWzlwmUIAIyc3lKavCalf8ki6
|
|
|
19
22
|
terminusgps/wialon/items/unit.py,sha256=wzcLa0adMTKX6rtO4Vz6ntaxgY50rLk2KK_VBXlW_lQ,4680
|
|
20
23
|
terminusgps/wialon/items/unit_group.py,sha256=1yc7ldPIgGbtiTj0djRDWmt6Q9K_VT9sxOaioasbbLY,5212
|
|
21
24
|
terminusgps/wialon/items/user.py,sha256=bkcMw_YiocaMuhP_pBfB7apjAZwnsOzGScnGkn8Ybbw,6107
|
|
22
|
-
python_terminusgps-1.
|
|
23
|
-
python_terminusgps-1.
|
|
24
|
-
python_terminusgps-1.
|
|
25
|
-
python_terminusgps-1.
|
|
25
|
+
python_terminusgps-1.9.0.dist-info/METADATA,sha256=GX0YsG8twa1YTK8fievu8BuFdpnZ5a7DZk8iQvw6S1I,958
|
|
26
|
+
python_terminusgps-1.9.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
27
|
+
python_terminusgps-1.9.0.dist-info/licenses/COPYING,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
28
|
+
python_terminusgps-1.9.0.dist-info/RECORD,,
|
terminusgps/authorizenet/auth.py
CHANGED
|
@@ -4,18 +4,32 @@ from authorizenet.constants import constants
|
|
|
4
4
|
from django.conf import ImproperlyConfigured, settings
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
def settings_required(settings_list: list[str]):
|
|
8
|
+
def decorator(func):
|
|
9
|
+
def wrapped(*args, **kwargs):
|
|
10
|
+
for setting_name in settings_list:
|
|
11
|
+
if not hasattr(settings, setting_name):
|
|
12
|
+
raise ImproperlyConfigured(f"'{setting_name}' setting is required.")
|
|
13
|
+
return func(*args, **kwargs)
|
|
14
|
+
|
|
15
|
+
return wrapped
|
|
16
|
+
|
|
17
|
+
return decorator
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@settings_required(["MERCHANT_AUTH_LOGIN_ID", "MERCHANT_AUTH_TRANSACTION_KEY"])
|
|
7
21
|
def get_merchant_auth() -> merchantAuthenticationType:
|
|
8
|
-
if not hasattr(settings, "MERCHANT_AUTH_LOGIN_ID"):
|
|
9
|
-
raise ImproperlyConfigured("'MERCHANT_AUTH_LOGIN_ID' is required.")
|
|
10
|
-
if not hasattr(settings, "MERCHANT_AUTH_TRANSACTION_KEY"):
|
|
11
|
-
raise ImproperlyConfigured("'MERCHANT_AUTH_TRANSACTION_KEY' is required.")
|
|
12
22
|
return merchantAuthenticationType(
|
|
13
23
|
name=str(settings.MERCHANT_AUTH_LOGIN_ID),
|
|
14
24
|
transactionKey=str(settings.MERCHANT_AUTH_TRANSACTION_KEY),
|
|
15
25
|
)
|
|
16
26
|
|
|
17
27
|
|
|
28
|
+
@settings_required(["DEBUG"])
|
|
18
29
|
def get_environment() -> str:
|
|
19
|
-
if not hasattr(settings, "DEBUG"):
|
|
20
|
-
raise ImproperlyConfigured("'DEBUG' is required.")
|
|
21
30
|
return constants.SANDBOX if settings.DEBUG else constants.PRODUCTION
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@settings_required(["DEBUG"])
|
|
34
|
+
def get_validation_mode() -> str:
|
|
35
|
+
return "testMode" if settings.DEBUG else "liveMode"
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from authorizenet.apicontractsv1 import (
|
|
2
|
+
createCustomerShippingAddressRequest,
|
|
3
|
+
customerAddressType,
|
|
4
|
+
deleteCustomerShippingAddressRequest,
|
|
5
|
+
updateCustomerShippingAddressRequest,
|
|
6
|
+
getCustomerShippingAddressRequest,
|
|
7
|
+
getCustomerShippingAddressResponse,
|
|
8
|
+
)
|
|
9
|
+
from authorizenet.apicontrollers import (
|
|
10
|
+
createCustomerShippingAddressController,
|
|
11
|
+
deleteCustomerShippingAddressController,
|
|
12
|
+
getCustomerShippingAddressController,
|
|
13
|
+
updateCustomerShippingAddressController,
|
|
14
|
+
)
|
|
15
|
+
from terminusgps.authorizenet.profiles.base import AuthorizenetCustomerProfileBase
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AddressProfile(AuthorizenetCustomerProfileBase):
|
|
19
|
+
def create(self, **kwargs) -> int:
|
|
20
|
+
shipping_addr = kwargs.get("shipping_addr")
|
|
21
|
+
|
|
22
|
+
if not shipping_addr:
|
|
23
|
+
raise ValueError("'shipping_addr' is required on creation.")
|
|
24
|
+
|
|
25
|
+
if not isinstance(shipping_addr, customerAddressType):
|
|
26
|
+
raise TypeError(
|
|
27
|
+
f"'shipping_addr' must be customerAddressType, got '{type(shipping_addr)}'."
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
return self._authorizenet_create_shipping_address(shipping_addr)
|
|
31
|
+
|
|
32
|
+
def delete(self) -> None:
|
|
33
|
+
self._authorizenet_delete_shipping_address()
|
|
34
|
+
|
|
35
|
+
def update(self, shipping_addr: customerAddressType) -> None:
|
|
36
|
+
self._authorizenet_update_shipping_address(shipping_addr)
|
|
37
|
+
|
|
38
|
+
def get_details(self) -> dict:
|
|
39
|
+
return self._authorizenet_get_shipping_address()
|
|
40
|
+
|
|
41
|
+
def _authorizenet_create_shipping_address(self, addr: customerAddressType) -> int:
|
|
42
|
+
request = createCustomerShippingAddressRequest(
|
|
43
|
+
merchantAuthentication=self.merchantAuthentication,
|
|
44
|
+
customerProfileId=self.customerProfileId,
|
|
45
|
+
address=addr,
|
|
46
|
+
default=self.default,
|
|
47
|
+
)
|
|
48
|
+
controller = createCustomerShippingAddressController(request)
|
|
49
|
+
response = self.execute_controller(controller)
|
|
50
|
+
return int(response.get("customerAddressId"))
|
|
51
|
+
|
|
52
|
+
def _authorizenet_update_shipping_address(self, addr: customerAddressType) -> None:
|
|
53
|
+
assert self.id, "'id' was not set."
|
|
54
|
+
addr.customerAddressId = self.id
|
|
55
|
+
request = updateCustomerShippingAddressRequest(
|
|
56
|
+
merchantAuthentication=self.merchantAuthentication,
|
|
57
|
+
customerProfileId=self.customerProfileId,
|
|
58
|
+
address=addr,
|
|
59
|
+
default=self.default,
|
|
60
|
+
)
|
|
61
|
+
controller = updateCustomerShippingAddressController(request)
|
|
62
|
+
self.execute_controller(controller)
|
|
63
|
+
|
|
64
|
+
def _authorizenet_get_shipping_address(self) -> dict:
|
|
65
|
+
assert self.id, "'id' was not set."
|
|
66
|
+
request = getCustomerShippingAddressRequest(
|
|
67
|
+
merchantAuthentication=self.merchantAuthentication,
|
|
68
|
+
customerProfileId=self.customerProfileId,
|
|
69
|
+
customerAddressId=self.id,
|
|
70
|
+
)
|
|
71
|
+
controller = getCustomerShippingAddressController(request)
|
|
72
|
+
response = self.execute_controller(controller)
|
|
73
|
+
return response
|
|
74
|
+
|
|
75
|
+
def _authorizenet_delete_shipping_address(self) -> None:
|
|
76
|
+
assert self.id, "'id' was not set."
|
|
77
|
+
request = deleteCustomerShippingAddressRequest(
|
|
78
|
+
merchantAuthentication=self.merchantAuthentication,
|
|
79
|
+
customerProfileId=self.customerProfileId,
|
|
80
|
+
customerAddressId=self.id,
|
|
81
|
+
)
|
|
82
|
+
controller = deleteCustomerShippingAddressController(request)
|
|
83
|
+
self.execute_controller(controller)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from authorizenet.apicontractsv1 import merchantAuthenticationType
|
|
2
|
+
from ..auth import get_environment, get_merchant_auth, get_validation_mode
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class AuthorizenetProfileBase:
|
|
6
|
+
def __init__(
|
|
7
|
+
self, merchant_id: int | str, id: int | str | None = None, **kwargs
|
|
8
|
+
) -> None:
|
|
9
|
+
self.merchant_id = merchant_id
|
|
10
|
+
self.id = str(id) if id else str(self.create(**kwargs))
|
|
11
|
+
|
|
12
|
+
def __str__(self) -> str:
|
|
13
|
+
return f"#{self.id}"
|
|
14
|
+
|
|
15
|
+
@property
|
|
16
|
+
def environment(self) -> str:
|
|
17
|
+
return get_environment()
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def merchantAuthentication(self) -> merchantAuthenticationType:
|
|
21
|
+
return get_merchant_auth()
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
def validationMode(self) -> str:
|
|
25
|
+
return get_validation_mode()
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def merchantCustomerId(self) -> str:
|
|
29
|
+
return str(self.merchant_id)
|
|
30
|
+
|
|
31
|
+
def create(self, **kwargs) -> int:
|
|
32
|
+
raise NotImplementedError("Subclasses must implement this method.")
|
|
33
|
+
|
|
34
|
+
def execute_controller(self, controller):
|
|
35
|
+
controller.setenvironment(self.environment)
|
|
36
|
+
controller.execute()
|
|
37
|
+
response = controller.getresponse()
|
|
38
|
+
if response.messages.resultCode != "Ok":
|
|
39
|
+
raise ValueError(response.messages.message[0]["text"].text)
|
|
40
|
+
return response
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class AuthorizenetCustomerProfileBase(AuthorizenetProfileBase):
|
|
44
|
+
def __init__(
|
|
45
|
+
self, customer_profile_id: int | str, default: bool = False, **kwargs
|
|
46
|
+
) -> None:
|
|
47
|
+
if isinstance(customer_profile_id, str) and not customer_profile_id.isdigit():
|
|
48
|
+
raise ValueError(
|
|
49
|
+
f"'customer_profile_id' must be a digit, got '{customer_profile_id}'."
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
self._default = default
|
|
53
|
+
self.customer_profile_id = customer_profile_id
|
|
54
|
+
return super().__init__(**kwargs)
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def customerProfileId(self) -> str:
|
|
58
|
+
return str(self.customer_profile_id)
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def default(self) -> str:
|
|
62
|
+
return str(self._default).lower()
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
from authorizenet.apicontrollers import (
|
|
2
|
+
createCustomerProfileController,
|
|
3
|
+
deleteCustomerProfileController,
|
|
4
|
+
getCustomerProfileController,
|
|
5
|
+
updateCustomerProfileController,
|
|
6
|
+
)
|
|
7
|
+
from authorizenet.apicontractsv1 import (
|
|
8
|
+
customerProfileType,
|
|
9
|
+
createCustomerProfileRequest,
|
|
10
|
+
deleteCustomerProfileRequest,
|
|
11
|
+
getCustomerProfileRequest,
|
|
12
|
+
updateCustomerProfileRequest,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
from terminusgps.authorizenet.profiles.base import AuthorizenetProfileBase
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class CustomerProfile(AuthorizenetProfileBase):
|
|
19
|
+
def create(self, **kwargs) -> int:
|
|
20
|
+
"""
|
|
21
|
+
Creates the customer profile.
|
|
22
|
+
|
|
23
|
+
:param email: An email address for the customer profile.
|
|
24
|
+
:type email: :py:obj:`str`
|
|
25
|
+
:param desc: A description describing the customer profile. Optional.
|
|
26
|
+
:type desc: :py:obj:`str` | :py:obj:`None`
|
|
27
|
+
:returns: The new customer profile id.
|
|
28
|
+
:rtype: :py:obj:`int`
|
|
29
|
+
|
|
30
|
+
"""
|
|
31
|
+
if not kwargs.get("email"):
|
|
32
|
+
raise ValueError("'email' is required for creation.")
|
|
33
|
+
|
|
34
|
+
return self._authorizenet_create_customer_profile(
|
|
35
|
+
kwargs["email"], kwargs.get("desc", "")
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def update(self, email: str, desc: str = "") -> None:
|
|
39
|
+
"""Updates the customer profile."""
|
|
40
|
+
return self._authorizenet_update_customer_profile(email, desc)
|
|
41
|
+
|
|
42
|
+
def delete(self) -> None:
|
|
43
|
+
"""Deletes the customer profile."""
|
|
44
|
+
return self._authorizenet_delete_customer_profile()
|
|
45
|
+
|
|
46
|
+
def get_payment_profiles(self) -> list[dict] | None:
|
|
47
|
+
"""Retrieves the customer profile's payment profiles list."""
|
|
48
|
+
profiles = self._authorizenet_get_customer_profile(issuer_info=False).get(
|
|
49
|
+
"paymentProfiles"
|
|
50
|
+
)
|
|
51
|
+
return profiles if profiles else None
|
|
52
|
+
|
|
53
|
+
def get_shipping_addresses(self) -> list[dict] | None:
|
|
54
|
+
"""Retrieves the customer profile's shipping address list."""
|
|
55
|
+
addresses = self._authorizenet_get_customer_profile(issuer_info=False).get(
|
|
56
|
+
"shipToList"
|
|
57
|
+
)
|
|
58
|
+
return addresses if addresses else None
|
|
59
|
+
|
|
60
|
+
def _authorizenet_create_customer_profile(self, email: str, desc: str = "") -> int:
|
|
61
|
+
"""Executes a :py:obj:`~authorizenet.apicontractsv1.createCustomerProfileRequest` using the Authorize.NET API."""
|
|
62
|
+
request = createCustomerProfileRequest(
|
|
63
|
+
merchantAuthentication=self.merchantAuthentication,
|
|
64
|
+
profile=customerProfileType(
|
|
65
|
+
merchantCustomerId=self.merchantCustomerId,
|
|
66
|
+
email=email,
|
|
67
|
+
description=desc,
|
|
68
|
+
),
|
|
69
|
+
)
|
|
70
|
+
controller = createCustomerProfileController(request)
|
|
71
|
+
response = self.execute_controller(controller)
|
|
72
|
+
return int(response.customerProfileId)
|
|
73
|
+
|
|
74
|
+
def _authorizenet_delete_customer_profile(self) -> None:
|
|
75
|
+
"""Executes a :py:obj:`~authorizenet.apicontractsv1.deleteCustomerProfileRequest` using the Authorize.NET API."""
|
|
76
|
+
assert self.id, "'id' was not set."
|
|
77
|
+
request = deleteCustomerProfileRequest(
|
|
78
|
+
merchantAuthentication=self.merchantAuthentication,
|
|
79
|
+
customerProfileId=str(self.id),
|
|
80
|
+
)
|
|
81
|
+
controller = deleteCustomerProfileController(request)
|
|
82
|
+
self.execute_controller(controller)
|
|
83
|
+
|
|
84
|
+
def _authorizenet_get_customer_profile(self, issuer_info: bool = True) -> dict:
|
|
85
|
+
"""Executes a :py:obj:`~authorizenet.apicontractsv1.getCustomerProfileRequest` using the Authorize.NET API."""
|
|
86
|
+
assert self.id, "'id' was not set."
|
|
87
|
+
request = getCustomerProfileRequest(
|
|
88
|
+
merchantAuthentication=self.merchantAuthentication,
|
|
89
|
+
customerProfileId=self.id,
|
|
90
|
+
includeIssuerInfo=str(issuer_info).lower(),
|
|
91
|
+
)
|
|
92
|
+
controller = getCustomerProfileController(request)
|
|
93
|
+
response = self.execute_controller(controller)
|
|
94
|
+
return response
|
|
95
|
+
|
|
96
|
+
def _authorizenet_update_customer_profile(self, email: str, desc: str = "") -> None:
|
|
97
|
+
"""Executes an :py:obj:`~authorizenet.apicontractsv1.updateCustomerProfileRequest` using the Authorize.NET API."""
|
|
98
|
+
assert self.id, "'id' was not set."
|
|
99
|
+
request = updateCustomerProfileRequest(
|
|
100
|
+
merchantAuthentication=self.merchantAuthentication,
|
|
101
|
+
profile=customerProfileType(
|
|
102
|
+
merchantCustomerId=self.merchantCustomerId,
|
|
103
|
+
email=email,
|
|
104
|
+
description=desc,
|
|
105
|
+
customerProfileId=self.id,
|
|
106
|
+
),
|
|
107
|
+
)
|
|
108
|
+
controller = updateCustomerProfileController(request)
|
|
109
|
+
self.execute_controller(controller)
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
from authorizenet.apicontractsv1 import (
|
|
2
|
+
createCustomerPaymentProfileRequest,
|
|
3
|
+
customerAddressType,
|
|
4
|
+
deleteCustomerPaymentProfileRequest,
|
|
5
|
+
getCustomerPaymentProfileRequest,
|
|
6
|
+
paymentProfile,
|
|
7
|
+
paymentType,
|
|
8
|
+
validateCustomerPaymentProfileRequest,
|
|
9
|
+
updateCustomerPaymentProfileRequest,
|
|
10
|
+
)
|
|
11
|
+
from authorizenet.apicontrollers import (
|
|
12
|
+
createCustomerPaymentProfileController,
|
|
13
|
+
deleteCustomerPaymentProfileController,
|
|
14
|
+
getCustomerPaymentProfileController,
|
|
15
|
+
updateCustomerPaymentProfileController,
|
|
16
|
+
validateCustomerPaymentProfileController,
|
|
17
|
+
)
|
|
18
|
+
from terminusgps.authorizenet.profiles.base import AuthorizenetCustomerProfileBase
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class PaymentProfile(AuthorizenetCustomerProfileBase):
|
|
22
|
+
def create(self, **kwargs) -> int:
|
|
23
|
+
billing_addr = kwargs.get("billing_addr")
|
|
24
|
+
payment = kwargs.get("payment")
|
|
25
|
+
if not billing_addr:
|
|
26
|
+
raise ValueError("'billing_addr' is required on creation.")
|
|
27
|
+
if not payment:
|
|
28
|
+
raise ValueError("'payment' is required on creation.")
|
|
29
|
+
|
|
30
|
+
if not isinstance(billing_addr, customerAddressType):
|
|
31
|
+
raise TypeError(
|
|
32
|
+
f"'billing_addr' must be customerAddressType, got '{type(billing_addr)}'"
|
|
33
|
+
)
|
|
34
|
+
if not isinstance(payment, paymentType):
|
|
35
|
+
raise TypeError(
|
|
36
|
+
f"'payment' must be customerAddressType, got '{type(payment)}'"
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
return self._authorizenet_create_payment_profile(billing_addr, payment)
|
|
40
|
+
|
|
41
|
+
def update(self, billing_addr: customerAddressType, payment: paymentType) -> None:
|
|
42
|
+
self._authorizenet_update_payment_profile(billing_addr, payment)
|
|
43
|
+
|
|
44
|
+
def delete(self) -> None:
|
|
45
|
+
self._authorizenet_delete_payment_profile()
|
|
46
|
+
|
|
47
|
+
def get_details(self, issuer_info: bool = False) -> dict:
|
|
48
|
+
return self._authorizenet_get_payment_profile(issuer_info)
|
|
49
|
+
|
|
50
|
+
def _authorizenet_create_payment_profile(
|
|
51
|
+
self, billing_addr: customerAddressType, payment: paymentType
|
|
52
|
+
) -> int:
|
|
53
|
+
"""Executes a :py:obj:`~authorizenet.apicontractsv1.createCustomerPaymentProfileRequest` using the Authorize.NET API."""
|
|
54
|
+
request = createCustomerPaymentProfileRequest(
|
|
55
|
+
merchantAuthentication=self.merchantAuthentication,
|
|
56
|
+
customerProfileId=self.customerProfileId,
|
|
57
|
+
paymentProfile=paymentProfile(
|
|
58
|
+
billTo=billing_addr, payment=payment, default=self.default
|
|
59
|
+
),
|
|
60
|
+
validationMode=self.validationMode,
|
|
61
|
+
)
|
|
62
|
+
controller = createCustomerPaymentProfileController(request)
|
|
63
|
+
response = self.execute_controller(controller)
|
|
64
|
+
return int(response.get("customerPaymentProfileId"))
|
|
65
|
+
|
|
66
|
+
def _authorizenet_update_payment_profile(
|
|
67
|
+
self, billing_addr: customerAddressType, payment: paymentType
|
|
68
|
+
) -> None:
|
|
69
|
+
"""Executes an :py:obj:`~authorizenet.apicontractsv1.updateCustomerPaymentProfileRequest` using the Authorize.NET API."""
|
|
70
|
+
assert self.id, "'id' was not set."
|
|
71
|
+
request = updateCustomerPaymentProfileRequest(
|
|
72
|
+
merchantAuthentication=self.merchantAuthentication,
|
|
73
|
+
customerProfileId=self.customerProfileId,
|
|
74
|
+
paymentProfile=paymentProfile(
|
|
75
|
+
billTo=billing_addr,
|
|
76
|
+
payment=payment,
|
|
77
|
+
defaultPaymentProfile=self.default,
|
|
78
|
+
customerPaymentProfileId=self.id,
|
|
79
|
+
),
|
|
80
|
+
validationMode=self.validationMode,
|
|
81
|
+
)
|
|
82
|
+
controller = updateCustomerPaymentProfileController(request)
|
|
83
|
+
self.execute_controller(controller)
|
|
84
|
+
|
|
85
|
+
def _authorizenet_get_payment_profile(self, issuer_info: bool = False) -> dict:
|
|
86
|
+
"""Executes a :py:obj:`~authorizenet.apicontractsv1.getCustomerPaymentProfileRequest` using the Authorize.NET API."""
|
|
87
|
+
assert self.id, "'id' was not set."
|
|
88
|
+
request = getCustomerPaymentProfileRequest(
|
|
89
|
+
merchantAuthentication=self.merchantAuthentication,
|
|
90
|
+
customerProfileId=self.customerProfileId,
|
|
91
|
+
customerPaymentProfileId=self.id,
|
|
92
|
+
includeIssuerInfo=str(issuer_info).lower(),
|
|
93
|
+
)
|
|
94
|
+
controller = getCustomerPaymentProfileController(request)
|
|
95
|
+
return self.execute_controller(controller)
|
|
96
|
+
|
|
97
|
+
def _authorizenet_validate_payment_profile(self) -> None:
|
|
98
|
+
"""Executes a :py:obj:`~authorizenet.apicontractsv1.validateCustomerPaymentProfileRequest` using the Authorize.NET API."""
|
|
99
|
+
assert self.id, "'id' was not set."
|
|
100
|
+
request = validateCustomerPaymentProfileRequest(
|
|
101
|
+
merchantAuthentication=self.merchantAuthentication,
|
|
102
|
+
customerProfileId=self.customerProfileId,
|
|
103
|
+
customerPaymentProfileId=self.id,
|
|
104
|
+
validationMode=self.validationMode,
|
|
105
|
+
)
|
|
106
|
+
controller = validateCustomerPaymentProfileController(request)
|
|
107
|
+
self.execute_controller(controller)
|
|
108
|
+
|
|
109
|
+
def _authorizenet_delete_payment_profile(self) -> None:
|
|
110
|
+
"""Executes a :py:obj:`~authorizenet.apicontractsv1.deleteCustomerPaymentProfileRequest` using the Authorize.NET API."""
|
|
111
|
+
assert self.id, "'id' was not set."
|
|
112
|
+
request = deleteCustomerPaymentProfileRequest(
|
|
113
|
+
merchantAuthentication=self.merchantAuthentication,
|
|
114
|
+
customerProfileId=self.customerProfileId,
|
|
115
|
+
customerPaymentProfileId=self.id,
|
|
116
|
+
)
|
|
117
|
+
controller = deleteCustomerPaymentProfileController(request)
|
|
118
|
+
self.execute_controller(controller)
|
terminusgps/settings.py
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
from os import getenv
|
|
2
2
|
|
|
3
|
-
DEBUG =
|
|
3
|
+
DEBUG = True
|
|
4
4
|
SECRET_KEY = "xem*6no%8d9%^qzt2f3x3ar-uq4_+7h9myc$t0!+4%bj5us6f)"
|
|
5
5
|
WIALON_ADMIN_ID = getenv("WIALON_ADMIN_ID")
|
|
6
6
|
WIALON_TOKEN = getenv("WIALON_TOKEN")
|
|
7
|
+
MERCHANT_AUTH_LOGIN_ID = getenv("MERCHANT_AUTH_LOGIN_ID")
|
|
8
|
+
MERCHANT_AUTH_TRANSACTION_KEY = getenv("MERCHANT_AUTH_TRANSACTION_KEY")
|
|
9
|
+
QB_CLIENT_ID = getenv("QB_CLIENT_ID")
|
|
10
|
+
QB_CLIENT_SECRET = getenv("QB_CLIENT_ID")
|
terminusgps/test.py
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
from django.utils import timezone
|
|
2
|
-
from terminusgps.wialon.session import WialonSession
|
|
3
|
-
from terminusgps.wialon.utils import get_hw_type_id, gen_wialon_password
|
|
4
|
-
from terminusgps.wialon.items import WialonUser, WialonResource, WialonUnit
|
|
5
|
-
from terminusgps.wialon import constants
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def registration_test() -> None:
|
|
9
|
-
timestamp = f"{timezone.now():%y-%m-%d-%H:%M:%S}"
|
|
10
|
-
|
|
11
|
-
with WialonSession() as session:
|
|
12
|
-
print(f"Running test '{registration_test.__name__}' as '{session.username}'...")
|
|
13
|
-
hw_type_id = get_hw_type_id(name="Test HW", session=session)
|
|
14
|
-
|
|
15
|
-
super_user = WialonUser(
|
|
16
|
-
creator_id=session.uid,
|
|
17
|
-
name=f"super_user_{timestamp}",
|
|
18
|
-
password=gen_wialon_password(length=32),
|
|
19
|
-
session=session,
|
|
20
|
-
)
|
|
21
|
-
resource = WialonResource(
|
|
22
|
-
creator_id=super_user.id, name=f"resource_{timestamp}", session=session
|
|
23
|
-
)
|
|
24
|
-
unit = WialonUnit(
|
|
25
|
-
creator_id=session.uid,
|
|
26
|
-
name=f"test_unit_{timestamp}",
|
|
27
|
-
hw_type_id=hw_type_id,
|
|
28
|
-
session=session,
|
|
29
|
-
)
|
|
30
|
-
super_user.grant_access(unit, access_mask=constants.ACCESSMASK_UNIT_MIGRATION)
|
|
31
|
-
resource.create_account("terminusgps_ext_hist")
|
|
32
|
-
resource.migrate_unit(unit)
|
|
33
|
-
end_user = WialonUser(
|
|
34
|
-
creator_id=super_user.id,
|
|
35
|
-
name=f"end_user_{timestamp}",
|
|
36
|
-
password=gen_wialon_password(length=32),
|
|
37
|
-
session=session,
|
|
38
|
-
)
|
|
39
|
-
end_user.grant_access(unit, access_mask=constants.ACCESSMASK_UNIT_BASIC)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def account_days_test() -> None:
|
|
43
|
-
timestamp = f"{timezone.now():%y-%m-%d-%H:%M:%S}"
|
|
44
|
-
|
|
45
|
-
with WialonSession() as session:
|
|
46
|
-
print(f"Running test '{account_days_test.__name__}' as '{session.username}'...")
|
|
47
|
-
account = WialonResource(id="28990259", session=session)
|
|
48
|
-
account.set_settings_flags(0x20)
|
|
49
|
-
account.set_minimum_days(0)
|
|
50
|
-
account.add_days(30)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if __name__ == "__main__":
|
|
54
|
-
registration_test()
|
|
55
|
-
account_days_test()
|
|
File without changes
|
|
File without changes
|