pixelarraythirdparty 1.0.2__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.2"
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,20 +1,16 @@
1
- from pixelarraythirdparty.client import Client
1
+ from pixelarraythirdparty.client import Client, AsyncClient
2
2
 
3
3
 
4
4
  class OrderManager(Client):
5
5
  def create_order(
6
6
  self,
7
- product_name: str,
8
7
  product_id: str,
9
- amount: float,
10
- body: str,
11
- remark: str,
12
- payment_channel: str,
8
+ body: str = None,
9
+ remark: str = None,
10
+ payment_channel: str = "WECHAT",
13
11
  ):
14
12
  data = {
15
- "product_name": product_name,
16
13
  "product_id": product_id,
17
- "amount": amount,
18
14
  "body": body,
19
15
  "remark": remark,
20
16
  "payment_channel": payment_channel,
@@ -29,58 +25,42 @@ class OrderManager(Client):
29
25
  page: int = 1,
30
26
  page_size: int = 10,
31
27
  payment_status: str = None,
32
- order_no: str = None,
28
+ out_trade_no: str = None,
33
29
  ):
34
30
  params = {
35
31
  "page": page,
36
32
  "page_size": page_size,
37
33
  "payment_status": payment_status,
38
- "order_no": order_no,
34
+ "out_trade_no": out_trade_no,
39
35
  }
40
36
  data, success = self._request("GET", "/api/orders/list", params=params)
41
37
  if not success:
42
38
  return {}, False
43
39
  return data, True
44
40
 
45
- def get_order_detail(self, order_no: str):
46
- data, success = self._request("GET", f"/api/orders/{order_no}")
41
+ def get_order_detail(self, out_trade_no: str):
42
+ data, success = self._request("GET", f"/api/orders/{out_trade_no}")
47
43
  if not success:
48
44
  return {}, False
49
45
  return data, True
50
46
 
51
- def update_order(
47
+ def update_order_status(
52
48
  self,
53
- order_no: str,
49
+ out_trade_no: str,
54
50
  payment_status: str,
55
- wx_order_no: str,
56
- transaction_id: str,
57
- openid: str,
58
- trade_type: str,
59
- bank_type: str,
60
- fee_type: str,
61
- is_subscribe: str,
62
- time_end: str,
63
- remark: str,
64
51
  ):
65
52
  data = {
66
53
  "payment_status": payment_status,
67
- "wx_order_no": wx_order_no,
68
- "transaction_id": transaction_id,
69
- "openid": openid,
70
- "trade_type": trade_type,
71
- "bank_type": bank_type,
72
- "fee_type": fee_type,
73
- "is_subscribe": is_subscribe,
74
- "time_end": time_end,
75
- "remark": remark,
76
54
  }
77
- data, success = self._request("PUT", f"/api/orders/{order_no}", json=data)
55
+ data, success = self._request(
56
+ "PUT", f"/api/orders/{out_trade_no}/status", json=data
57
+ )
78
58
  if not success:
79
59
  return {}, False
80
60
  return data, True
81
61
 
82
- def delete_order(self, order_no: str):
83
- data, success = self._request("DELETE", f"/api/orders/{order_no}")
62
+ def delete_order(self, out_trade_no: str):
63
+ data, success = self._request("DELETE", f"/api/orders/{out_trade_no}")
84
64
  if not success:
85
65
  return {}, False
86
66
  return data, True
@@ -90,3 +70,136 @@ class OrderManager(Client):
90
70
  if not success:
91
71
  return {}, False
92
72
  return data, True
73
+
74
+ def generate_qr_code(
75
+ self,
76
+ out_trade_no: str,
77
+ payment_channel: str = "WECHAT",
78
+ ):
79
+ if payment_channel == "WECHAT":
80
+ url = "/api/orders/wx_pay/generate_qr_code"
81
+ elif payment_channel == "ALIPAY":
82
+ url = "/api/orders/ali_pay/generate_qr_code"
83
+ else:
84
+ raise ValueError("Invalid payment channel")
85
+ data, success = self._request(
86
+ "POST",
87
+ url,
88
+ json={
89
+ "out_trade_no": out_trade_no,
90
+ },
91
+ )
92
+ if not success:
93
+ return {}, False
94
+ return data, True
95
+
96
+ def refund_order(self, out_trade_no: str, payment_channel: str = "WECHAT"):
97
+ if payment_channel == "WECHAT":
98
+ url = "/api/orders/wx_pay/refund"
99
+ elif payment_channel == "ALIPAY":
100
+ url = "/api/orders/ali_pay/refund"
101
+ else:
102
+ raise ValueError("Invalid payment channel")
103
+ data, success = self._request(
104
+ "POST",
105
+ url,
106
+ json={"out_trade_no": out_trade_no},
107
+ )
108
+ if not success:
109
+ return {}, False
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.2
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,16 +1,15 @@
1
- pixelarraythirdparty/__init__.py,sha256=WVQdADzRD3tqhJvfxOm3qUInd9L0KRW-u5u37u6xq2c,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=51KcwBGfXS9Ico_0jlwcLUqcAgc9xgRutozqtlWwyHY,2616
7
- pixelarraythirdparty/order/pay.py,sha256=Fq7HKeYS_jk9CWdPldXE5OzuHl66SHHQW4sYlG6yODM,1251
6
+ pixelarraythirdparty/order/order.py,sha256=77UYvDteQdkVvEVG588ehmN5C9bpGAYkJsLpZqCH1Mg,6336
8
7
  pixelarraythirdparty/product/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
8
  pixelarraythirdparty/product/product.py,sha256=eHU0VKal1QpJs6F4_VxLoBYeeqQ19elEogH2Qpw7IDo,3029
10
9
  pixelarraythirdparty/user/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
10
  pixelarraythirdparty/user/user.py,sha256=tbcFsrNEdWz4op7V_zJ5o8neBuI4ogl4dgHS-uSIAX0,2155
12
- pixelarraythirdparty-1.0.2.dist-info/licenses/LICENSE,sha256=O-g1dUr0U50rSIvmWE9toiVkSgFpVt72_MHITbWvAqA,1067
13
- pixelarraythirdparty-1.0.2.dist-info/METADATA,sha256=DQSV5A4aLGQ4FVKmol3IgYsZYKLLgyb2zXC4YnhLJPY,993
14
- pixelarraythirdparty-1.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
- pixelarraythirdparty-1.0.2.dist-info/top_level.txt,sha256=dzG2Ut8j7noUqj_0ZQjcIDAeHYCh_9WtlxjAxtoyufo,21
16
- pixelarraythirdparty-1.0.2.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,,
@@ -1,44 +0,0 @@
1
- from pixelarraythirdparty.client import Client
2
-
3
-
4
- class WeChatPayManager(Client):
5
- def generate_qr_code(
6
- self,
7
- out_trade_no: str,
8
- total_fee: int,
9
- body: str,
10
- product_name: str,
11
- product_id: str,
12
- ):
13
- data, success = self._request(
14
- "POST",
15
- "/api/wx_pay/generate_qr_code",
16
- json={
17
- "out_trade_no": out_trade_no,
18
- "total_fee": total_fee,
19
- "body": body,
20
- "product_name": product_name,
21
- "product_id": product_id,
22
- },
23
- )
24
- if not success:
25
- return {}, False
26
- return data, True
27
-
28
- def query_order(self, out_trade_no: str):
29
- data, success = self._request(
30
- "POST", "/api/wx_pay/query_order", json={"out_trade_no": out_trade_no}
31
- )
32
- if not success:
33
- return {}, False
34
- return data, True
35
-
36
- def refund(self, out_trade_no: str, total_fee: int):
37
- data, success = self._request(
38
- "POST",
39
- "/api/wx_pay/refund",
40
- json={"out_trade_no": out_trade_no, "total_fee": total_fee},
41
- )
42
- if not success:
43
- return {}, False
44
- return data, True