pixelarraythirdparty 1.0.3__py3-none-any.whl → 1.0.4__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.
@@ -10,7 +10,7 @@ PixelArray 第三方微服务客户端
10
10
  - user: 用户管理模块
11
11
  """
12
12
 
13
- __version__ = "1.0.3"
13
+ __version__ = "1.0.4"
14
14
  __author__ = "Lu qi"
15
15
  __email__ = "qi.lu@pixelarrayai.com"
16
16
 
@@ -1,9 +1,12 @@
1
1
  import requests
2
+ import aiohttp
2
3
  from typing import Dict, Any, Optional, Tuple
4
+ import asyncio
3
5
 
4
6
 
5
7
  class Client:
6
8
  """基础认证类,提供公共的 API key 认证和请求方法"""
9
+
7
10
  def __init__(self, api_key: str):
8
11
  self.base_url = "https://thirdparty.pixelarrayai.com"
9
12
  self.api_key = api_key
@@ -20,3 +23,25 @@ class Client:
20
23
  if resp.status_code == 200 and resp.json().get("success") is True:
21
24
  return resp.json().get("data", {}), True
22
25
  return {}, False
26
+
27
+
28
+ class AsyncClient:
29
+ def __init__(self, api_key: str):
30
+ self.base_url = "https://thirdparty.pixelarrayai.com"
31
+ self.api_key = api_key
32
+ self.headers = {
33
+ "Content-Type": "application/json",
34
+ "X-API-Key": self.api_key,
35
+ }
36
+
37
+ async def _request(self, method: str, url: str, **kwargs) -> Tuple[Dict[str, Any], bool]:
38
+ async with aiohttp.ClientSession() as session:
39
+ req_method = getattr(session, method.lower())
40
+ async with req_method(
41
+ f"{self.base_url}{url}", headers=self.headers, **kwargs
42
+ ) as resp:
43
+ if resp.status == 200:
44
+ result = await resp.json()
45
+ if result.get("success") is True:
46
+ return result.get("data", {}), True
47
+ return {}, False
@@ -1,4 +1,4 @@
1
- from pixelarraythirdparty.client import Client
1
+ from pixelarraythirdparty.client import Client, AsyncClient
2
2
 
3
3
 
4
4
  class OrderManager(Client):
@@ -108,3 +108,98 @@ class OrderManager(Client):
108
108
  if not success:
109
109
  return {}, False
110
110
  return data, True
111
+
112
+
113
+ class OrderManagerAsync(AsyncClient):
114
+ async def create_order(
115
+ self,
116
+ product_id: str,
117
+ body: str = None,
118
+ remark: str = None,
119
+ payment_channel: str = "WECHAT",
120
+ ):
121
+ data = {
122
+ "product_id": product_id,
123
+ "body": body,
124
+ "remark": remark,
125
+ "payment_channel": payment_channel,
126
+ }
127
+ data, success = await self._request("POST", "/api/orders/create", json=data)
128
+ if not success:
129
+ return {}, False
130
+ return data, True
131
+
132
+ async def list_order(
133
+ self,
134
+ page: int = 1,
135
+ page_size: int = 10,
136
+ payment_status: str = None,
137
+ out_trade_no: str = None,
138
+ ):
139
+ params = {
140
+ "page": page,
141
+ "page_size": page_size,
142
+ "payment_status": payment_status,
143
+ "out_trade_no": out_trade_no,
144
+ }
145
+ data, success = await self._request("GET", "/api/orders/list", params=params)
146
+ if not success:
147
+ return {}, False
148
+ return data, True
149
+
150
+ async def get_order_detail(self, out_trade_no: str):
151
+ data, success = await self._request("GET", f"/api/orders/{out_trade_no}")
152
+ if not success:
153
+ return {}, False
154
+ return data, True
155
+
156
+ async def update_order_status(self, out_trade_no: str, payment_status: str):
157
+ data = {"payment_status": payment_status}
158
+ data, success = await self._request(
159
+ "PUT", f"/api/orders/{out_trade_no}/status", json=data
160
+ )
161
+ if not success:
162
+ return {}, False
163
+ return data, True
164
+
165
+ async def delete_order(self, out_trade_no: str):
166
+ data, success = await self._request("DELETE", f"/api/orders/{out_trade_no}")
167
+ if not success:
168
+ return {}, False
169
+ return data, True
170
+
171
+ async def get_order_stats(self):
172
+ data, success = await self._request("GET", "/api/orders/stats/summary")
173
+ if not success:
174
+ return {}, False
175
+ return data, True
176
+
177
+ async def generate_qr_code(
178
+ self, out_trade_no: str, payment_channel: str = "WECHAT"
179
+ ):
180
+ if payment_channel == "WECHAT":
181
+ url = "/api/orders/wx_pay/generate_qr_code"
182
+ elif payment_channel == "ALIPAY":
183
+ url = "/api/orders/ali_pay/generate_qr_code"
184
+ else:
185
+ raise ValueError("Invalid payment channel")
186
+ data, success = await self._request(
187
+ "POST", url, json={"out_trade_no": out_trade_no}
188
+ )
189
+ if not success:
190
+ return {}, False
191
+ return data, True
192
+
193
+ async def refund_order(self, out_trade_no: str, payment_channel: str = "WECHAT"):
194
+ if payment_channel == "WECHAT":
195
+ url = "/api/orders/wx_pay/refund"
196
+ elif payment_channel == "ALIPAY":
197
+ url = "/api/orders/ali_pay/refund"
198
+ else:
199
+ raise ValueError("Invalid payment channel")
200
+ data, success = await self._request(
201
+ "POST", url, json={"out_trade_no": out_trade_no}
202
+ )
203
+ if not success:
204
+ return {}, False
205
+ return data, True
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pixelarraythirdparty
3
- Version: 1.0.3
3
+ Version: 1.0.4
4
4
  Summary: PixelArray 第三方微服务客户端
5
5
  Author-email: Lu qi <qi.lu@pixelarrayai.com>
6
6
  License-Expression: MIT
@@ -1,15 +1,15 @@
1
- pixelarraythirdparty/__init__.py,sha256=TYuj96ZwZ4VXhB9Xn4KoEWpoJVsChUjzoWSRZONmC-U,458
2
- pixelarraythirdparty/client.py,sha256=dJlIrMlr1M4AGHvaLw191uaPnQbQ12_BGx8DTDTPkZQ,802
1
+ pixelarraythirdparty/__init__.py,sha256=EShklfQHjt1FKP_lKD4GTfwFXZCueZt31qiGnQN6oh8,458
2
+ pixelarraythirdparty/client.py,sha256=r63EDeyPhf3Y1sORW24tDSIqo2c8E3pwbik7r0Xy5zo,1678
3
3
  pixelarraythirdparty/celery/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  pixelarraythirdparty/celery/celery.py,sha256=Oaa7pBztL-FM0X5NSCjjfZP80AUsnnme5Z3RxXIJsZg,1178
5
5
  pixelarraythirdparty/order/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- pixelarraythirdparty/order/order.py,sha256=kmJNAvfiXxhjOhRbD3JTl1saE8aetMZ0TFR9NjPsaIM,3208
6
+ pixelarraythirdparty/order/order.py,sha256=77UYvDteQdkVvEVG588ehmN5C9bpGAYkJsLpZqCH1Mg,6336
7
7
  pixelarraythirdparty/product/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  pixelarraythirdparty/product/product.py,sha256=eHU0VKal1QpJs6F4_VxLoBYeeqQ19elEogH2Qpw7IDo,3029
9
9
  pixelarraythirdparty/user/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  pixelarraythirdparty/user/user.py,sha256=tbcFsrNEdWz4op7V_zJ5o8neBuI4ogl4dgHS-uSIAX0,2155
11
- pixelarraythirdparty-1.0.3.dist-info/licenses/LICENSE,sha256=O-g1dUr0U50rSIvmWE9toiVkSgFpVt72_MHITbWvAqA,1067
12
- pixelarraythirdparty-1.0.3.dist-info/METADATA,sha256=_BcKEA0W8joCfUZcvDqyKBkBXKGyWUwIDVI16boT7s4,993
13
- pixelarraythirdparty-1.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
- pixelarraythirdparty-1.0.3.dist-info/top_level.txt,sha256=dzG2Ut8j7noUqj_0ZQjcIDAeHYCh_9WtlxjAxtoyufo,21
15
- pixelarraythirdparty-1.0.3.dist-info/RECORD,,
11
+ pixelarraythirdparty-1.0.4.dist-info/licenses/LICENSE,sha256=O-g1dUr0U50rSIvmWE9toiVkSgFpVt72_MHITbWvAqA,1067
12
+ pixelarraythirdparty-1.0.4.dist-info/METADATA,sha256=nefI-ENI5vYKvBvGGNFc5aakZh7ptR12S6a7Yk7DpSY,993
13
+ pixelarraythirdparty-1.0.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
+ pixelarraythirdparty-1.0.4.dist-info/top_level.txt,sha256=dzG2Ut8j7noUqj_0ZQjcIDAeHYCh_9WtlxjAxtoyufo,21
15
+ pixelarraythirdparty-1.0.4.dist-info/RECORD,,