elemento-loyalty-processing 1.0.6__tar.gz → 1.0.8__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.
- {elemento_loyalty_processing-1.0.6 → elemento_loyalty_processing-1.0.8}/PKG-INFO +1 -1
- {elemento_loyalty_processing-1.0.6 → elemento_loyalty_processing-1.0.8}/app/client.py +56 -18
- {elemento_loyalty_processing-1.0.6 → elemento_loyalty_processing-1.0.8}/app/types.py +32 -21
- {elemento_loyalty_processing-1.0.6 → elemento_loyalty_processing-1.0.8}/pyproject.toml +1 -1
- {elemento_loyalty_processing-1.0.6 → elemento_loyalty_processing-1.0.8}/MANIFEST.in +0 -0
- {elemento_loyalty_processing-1.0.6 → elemento_loyalty_processing-1.0.8}/README.md +0 -0
- {elemento_loyalty_processing-1.0.6 → elemento_loyalty_processing-1.0.8}/app/__init__.py +0 -0
- {elemento_loyalty_processing-1.0.6 → elemento_loyalty_processing-1.0.8}/elemento_loyalty_processing.egg-info/SOURCES.txt +0 -0
- {elemento_loyalty_processing-1.0.6 → elemento_loyalty_processing-1.0.8}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""RPC client services for customer app."""
|
|
2
2
|
|
|
3
|
-
import datetime
|
|
3
|
+
from datetime import datetime
|
|
4
4
|
from typing import Any
|
|
5
5
|
|
|
6
6
|
from kaiju_tools.http import RPCClientService
|
|
@@ -30,21 +30,40 @@ class ElementoLoyaltyProcessingClient(RPCClientService):
|
|
|
30
30
|
async def balance_calculate(
|
|
31
31
|
self,
|
|
32
32
|
customer: Customer.Fields | dict[str, Any],
|
|
33
|
+
items: list[Item] | list[dict[str, Any]],
|
|
33
34
|
store_id: StoreId,
|
|
34
|
-
payment_type: str,
|
|
35
|
+
payment_type: str = None,
|
|
36
|
+
points_sub: Points = 0,
|
|
37
|
+
_max_timeout: int = None,
|
|
38
|
+
_nowait: bool = False,
|
|
39
|
+
):
|
|
40
|
+
data = await self.call(
|
|
41
|
+
method="Balance.calculate",
|
|
42
|
+
params=dict(
|
|
43
|
+
customer=customer, store_id=store_id, items=items, payment_type=payment_type, points_sub=points_sub
|
|
44
|
+
),
|
|
45
|
+
max_timeout=_max_timeout,
|
|
46
|
+
nowait=_nowait,
|
|
47
|
+
)
|
|
48
|
+
return convert(data, Cart)
|
|
49
|
+
|
|
50
|
+
async def balance_set_transaction(
|
|
51
|
+
self,
|
|
52
|
+
customer: Customer.Fields | dict[str, Any],
|
|
35
53
|
items: list[Item] | list[dict[str, Any]],
|
|
36
|
-
|
|
54
|
+
source: str,
|
|
55
|
+
store_id: StoreId,
|
|
56
|
+
payment_type: str,
|
|
57
|
+
transaction_id: TransactionExtId,
|
|
37
58
|
action: str = BalanceAction.CALC.value,
|
|
38
59
|
points_sub: Points = 0,
|
|
39
|
-
|
|
40
|
-
timestamp: datetime = None,
|
|
41
|
-
meta: dict[str, Any] = None,
|
|
60
|
+
timestamp: datetime | str = None,
|
|
42
61
|
_max_timeout: int = None,
|
|
43
62
|
_nowait: bool = False,
|
|
44
|
-
) ->
|
|
63
|
+
) -> Transaction:
|
|
45
64
|
"""Call Balance.calculate_cart."""
|
|
46
65
|
data = await self.call(
|
|
47
|
-
method="Balance.
|
|
66
|
+
method="Balance.transaction.set",
|
|
48
67
|
params=dict(
|
|
49
68
|
customer=customer,
|
|
50
69
|
store_id=store_id,
|
|
@@ -52,29 +71,29 @@ class ElementoLoyaltyProcessingClient(RPCClientService):
|
|
|
52
71
|
payment_type=payment_type,
|
|
53
72
|
points_sub=points_sub,
|
|
54
73
|
transaction_id=transaction_id,
|
|
55
|
-
|
|
74
|
+
source=source,
|
|
56
75
|
timestamp=timestamp,
|
|
57
76
|
action=action,
|
|
58
|
-
meta=meta,
|
|
59
77
|
),
|
|
60
78
|
max_timeout=_max_timeout,
|
|
61
79
|
nowait=_nowait,
|
|
62
80
|
)
|
|
63
|
-
return convert(data,
|
|
81
|
+
return convert(data, Transaction)
|
|
64
82
|
|
|
65
83
|
async def balance_confirm_transaction(
|
|
66
|
-
self, transaction_id:
|
|
67
|
-
) ->
|
|
84
|
+
self, transaction_id: TransactionExtId, _max_timeout: int = None, _nowait: bool = False
|
|
85
|
+
) -> Transaction:
|
|
68
86
|
"""Call Balance.transaction.confirm."""
|
|
69
|
-
|
|
87
|
+
data = await self.call(
|
|
70
88
|
method="Balance.transaction.confirm",
|
|
71
89
|
params=dict(transaction_id=transaction_id),
|
|
72
90
|
max_timeout=_max_timeout,
|
|
73
91
|
nowait=_nowait,
|
|
74
92
|
)
|
|
93
|
+
return convert(data, Transaction)
|
|
75
94
|
|
|
76
95
|
async def balance_revert_transaction(
|
|
77
|
-
self, transaction_id:
|
|
96
|
+
self, transaction_id: TransactionExtId, _max_timeout: int = None, _nowait: bool = False
|
|
78
97
|
) -> None:
|
|
79
98
|
"""Call Balance.transaction.revert."""
|
|
80
99
|
return await self.call(
|
|
@@ -85,15 +104,34 @@ class ElementoLoyaltyProcessingClient(RPCClientService):
|
|
|
85
104
|
)
|
|
86
105
|
|
|
87
106
|
async def balance_commit_transaction(
|
|
88
|
-
self, transaction_id:
|
|
89
|
-
) ->
|
|
107
|
+
self, transaction_id: TransactionExtId, _max_timeout: int = None, _nowait: bool = False
|
|
108
|
+
) -> Transaction:
|
|
90
109
|
"""Call Balance.transaction.commit."""
|
|
91
|
-
|
|
110
|
+
data = await self.call(
|
|
92
111
|
method="Balance.transaction.commit",
|
|
93
112
|
params=dict(transaction_id=transaction_id),
|
|
94
113
|
max_timeout=_max_timeout,
|
|
95
114
|
nowait=_nowait,
|
|
96
115
|
)
|
|
116
|
+
return convert(data, Transaction)
|
|
117
|
+
|
|
118
|
+
async def balance_refund(
|
|
119
|
+
self,
|
|
120
|
+
customer_id: CustomerId,
|
|
121
|
+
source: str,
|
|
122
|
+
transaction_id: TransactionExtId,
|
|
123
|
+
positions: list[int],
|
|
124
|
+
_max_timeout: int = None,
|
|
125
|
+
_nowait: bool = False,
|
|
126
|
+
) -> Points:
|
|
127
|
+
"""Call Balance.refund."""
|
|
128
|
+
data = await self.call(
|
|
129
|
+
method="Balance.refund",
|
|
130
|
+
params=dict(customer_id=customer_id, source=source, transaction_id=transaction_id, positions=positions),
|
|
131
|
+
max_timeout=_max_timeout,
|
|
132
|
+
nowait=_nowait,
|
|
133
|
+
)
|
|
134
|
+
return Points(data)
|
|
97
135
|
|
|
98
136
|
async def balance_create_event(
|
|
99
137
|
self,
|
|
@@ -17,7 +17,6 @@ __all__ = [
|
|
|
17
17
|
"BalanceStatus",
|
|
18
18
|
"Balance",
|
|
19
19
|
"TransactionType",
|
|
20
|
-
"OrderItem",
|
|
21
20
|
"TransactionId",
|
|
22
21
|
"CustomerId",
|
|
23
22
|
"Transaction",
|
|
@@ -36,16 +35,19 @@ __all__ = [
|
|
|
36
35
|
"Points",
|
|
37
36
|
"StoreId",
|
|
38
37
|
"AppliedOffer",
|
|
38
|
+
"PointType",
|
|
39
|
+
"TransactionExtId",
|
|
39
40
|
]
|
|
40
41
|
|
|
41
42
|
DATE_MAXVALUE = date.fromisoformat("3000-01-01")
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
TransactionExtId = NewType("TransactionExtId", str)
|
|
45
|
+
TransactionId = NewType("TransactionId", int)
|
|
44
46
|
EventTypeId = NewType("EventTypeId", str)
|
|
45
47
|
ListId = NewType("ListId", int)
|
|
46
48
|
StoreId = NewType("StoreId", int)
|
|
47
49
|
OfferId = NewType("OfferId", int)
|
|
48
|
-
LifetimeId = NewType("LifetimeId",
|
|
50
|
+
LifetimeId = NewType("LifetimeId", str)
|
|
49
51
|
GroupId = NewType("GroupId", int)
|
|
50
52
|
ConditionId = NewType("ConditionId", int)
|
|
51
53
|
ActionId = NewType("ActionId", int)
|
|
@@ -88,28 +90,23 @@ class Balance(Struct):
|
|
|
88
90
|
transaction_id: TransactionId | None = None
|
|
89
91
|
|
|
90
92
|
|
|
91
|
-
class OrderItem(Struct):
|
|
92
|
-
product_id: str
|
|
93
|
-
quantity: int
|
|
94
|
-
price: Decimal
|
|
95
|
-
balance: Points
|
|
96
|
-
active: bool
|
|
97
|
-
|
|
98
|
-
|
|
99
93
|
class TransactionType(Enum):
|
|
100
94
|
ORDER = "ORDER"
|
|
101
95
|
SCRIPT = "SCRIPT"
|
|
102
96
|
|
|
103
97
|
|
|
104
|
-
class
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
98
|
+
class _PointTypeData(TypedDict, total=False):
|
|
99
|
+
func: str
|
|
100
|
+
value: Any
|
|
101
|
+
time_unit: str
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class PointType(Struct):
|
|
105
|
+
updated: datetime
|
|
106
|
+
id: LifetimeId
|
|
107
|
+
label: str
|
|
108
|
+
activation: _PointTypeData
|
|
109
|
+
expiration: _PointTypeData
|
|
113
110
|
|
|
114
111
|
|
|
115
112
|
class BalanceAction(Enum):
|
|
@@ -156,8 +153,22 @@ class Cart(Struct):
|
|
|
156
153
|
customer_message: str | None = None
|
|
157
154
|
|
|
158
155
|
|
|
156
|
+
class StoredTransaction(Struct):
|
|
157
|
+
id: TransactionId
|
|
158
|
+
created: datetime
|
|
159
|
+
customer_id: CustomerId
|
|
160
|
+
type: TransactionType
|
|
161
|
+
balance: list[int]
|
|
162
|
+
ext_id: TransactionExtId
|
|
163
|
+
source: str
|
|
164
|
+
data: dict[str, Any] = None
|
|
165
|
+
active: bool = True
|
|
166
|
+
|
|
167
|
+
|
|
159
168
|
class Transaction(Struct):
|
|
160
|
-
|
|
169
|
+
ext_id: TransactionExtId
|
|
170
|
+
id: TransactionId
|
|
171
|
+
source: str
|
|
161
172
|
order_id: str | None = None
|
|
162
173
|
customer_id: CustomerId = None
|
|
163
174
|
timestamp: datetime = None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|