elemento-loyalty-processing 1.0.6__tar.gz → 1.0.7__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: elemento-loyalty-processing
3
- Version: 1.0.6
3
+ Version: 1.0.7
4
4
  Summary: Elemento Loyalty Processing
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: kaiju-tools<3,>=2.4.9
@@ -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
- transaction_id: TransactionId,
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
- order_id: str = None,
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
- ) -> Cart:
63
+ ) -> Transaction:
45
64
  """Call Balance.calculate_cart."""
46
65
  data = await self.call(
47
- method="Balance.calculate_cart",
66
+ method="Balance.transaction.set",
48
67
  params=dict(
49
68
  customer=customer,
50
69
  store_id=store_id,
@@ -52,26 +71,26 @@ class ElementoLoyaltyProcessingClient(RPCClientService):
52
71
  payment_type=payment_type,
53
72
  points_sub=points_sub,
54
73
  transaction_id=transaction_id,
55
- order_id=order_id,
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, Cart)
81
+ return convert(data, Transaction)
64
82
 
65
83
  async def balance_confirm_transaction(
66
84
  self, transaction_id: TransactionId, _max_timeout: int = None, _nowait: bool = False
67
- ) -> None:
85
+ ) -> Transaction:
68
86
  """Call Balance.transaction.confirm."""
69
- return await self.call(
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
96
  self, transaction_id: TransactionId, _max_timeout: int = None, _nowait: bool = False
@@ -86,14 +105,33 @@ class ElementoLoyaltyProcessingClient(RPCClientService):
86
105
 
87
106
  async def balance_commit_transaction(
88
107
  self, transaction_id: TransactionId, _max_timeout: int = None, _nowait: bool = False
89
- ) -> None:
108
+ ) -> Transaction:
90
109
  """Call Balance.transaction.commit."""
91
- return await self.call(
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
- TransactionId = NewType("TransactionId", str)
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", int)
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 StoredTransaction(Struct):
105
- created: datetime
106
- customer_id: CustomerId
107
- type: TransactionType
108
- ext_id: TransactionId | None = None
109
- order_id: str | None = None
110
- active: bool = True
111
- meta: dict[str, Any] | None = None
112
- items: list[OrderItem] | None = None
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
- id: TransactionId = None
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "elemento-loyalty-processing"
3
- version = "1.0.6"
3
+ version = "1.0.7"
4
4
  description = "Elemento Loyalty Processing"
5
5
  requires-python = ">=3.11"
6
6
  dependencies = [