pixelarraythirdparty 1.0.2__tar.gz → 1.0.4__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.
Files changed (23) hide show
  1. {pixelarraythirdparty-1.0.2 → pixelarraythirdparty-1.0.4}/PKG-INFO +1 -1
  2. {pixelarraythirdparty-1.0.2 → pixelarraythirdparty-1.0.4}/pixelarraythirdparty/__init__.py +1 -1
  3. pixelarraythirdparty-1.0.4/pixelarraythirdparty/client.py +47 -0
  4. pixelarraythirdparty-1.0.4/pixelarraythirdparty/order/order.py +205 -0
  5. {pixelarraythirdparty-1.0.2 → pixelarraythirdparty-1.0.4}/pixelarraythirdparty.egg-info/PKG-INFO +1 -1
  6. {pixelarraythirdparty-1.0.2 → pixelarraythirdparty-1.0.4}/pixelarraythirdparty.egg-info/SOURCES.txt +0 -1
  7. {pixelarraythirdparty-1.0.2 → pixelarraythirdparty-1.0.4}/pyproject.toml +1 -1
  8. pixelarraythirdparty-1.0.2/pixelarraythirdparty/client.py +0 -22
  9. pixelarraythirdparty-1.0.2/pixelarraythirdparty/order/order.py +0 -92
  10. pixelarraythirdparty-1.0.2/pixelarraythirdparty/order/pay.py +0 -44
  11. {pixelarraythirdparty-1.0.2 → pixelarraythirdparty-1.0.4}/LICENSE +0 -0
  12. {pixelarraythirdparty-1.0.2 → pixelarraythirdparty-1.0.4}/MANIFEST.in +0 -0
  13. {pixelarraythirdparty-1.0.2 → pixelarraythirdparty-1.0.4}/pixelarraythirdparty/celery/__init__.py +0 -0
  14. {pixelarraythirdparty-1.0.2 → pixelarraythirdparty-1.0.4}/pixelarraythirdparty/celery/celery.py +0 -0
  15. {pixelarraythirdparty-1.0.2 → pixelarraythirdparty-1.0.4}/pixelarraythirdparty/order/__init__.py +0 -0
  16. {pixelarraythirdparty-1.0.2 → pixelarraythirdparty-1.0.4}/pixelarraythirdparty/product/__init__.py +0 -0
  17. {pixelarraythirdparty-1.0.2 → pixelarraythirdparty-1.0.4}/pixelarraythirdparty/product/product.py +0 -0
  18. {pixelarraythirdparty-1.0.2 → pixelarraythirdparty-1.0.4}/pixelarraythirdparty/user/__init__.py +0 -0
  19. {pixelarraythirdparty-1.0.2 → pixelarraythirdparty-1.0.4}/pixelarraythirdparty/user/user.py +0 -0
  20. {pixelarraythirdparty-1.0.2 → pixelarraythirdparty-1.0.4}/pixelarraythirdparty.egg-info/dependency_links.txt +0 -0
  21. {pixelarraythirdparty-1.0.2 → pixelarraythirdparty-1.0.4}/pixelarraythirdparty.egg-info/requires.txt +0 -0
  22. {pixelarraythirdparty-1.0.2 → pixelarraythirdparty-1.0.4}/pixelarraythirdparty.egg-info/top_level.txt +0 -0
  23. {pixelarraythirdparty-1.0.2 → pixelarraythirdparty-1.0.4}/setup.cfg +0 -0
@@ -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
@@ -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
 
@@ -0,0 +1,47 @@
1
+ import requests
2
+ import aiohttp
3
+ from typing import Dict, Any, Optional, Tuple
4
+ import asyncio
5
+
6
+
7
+ class Client:
8
+ """基础认证类,提供公共的 API key 认证和请求方法"""
9
+
10
+ def __init__(self, api_key: str):
11
+ self.base_url = "https://thirdparty.pixelarrayai.com"
12
+ self.api_key = api_key
13
+ self.headers = {
14
+ "Content-Type": "application/json",
15
+ "X-API-Key": self.api_key,
16
+ }
17
+
18
+ def _request(self, method: str, url: str, **kwargs) -> Tuple[Dict[str, Any], bool]:
19
+ """统一的请求方法"""
20
+ resp = requests.request(
21
+ method, f"{self.base_url}{url}", headers=self.headers, **kwargs
22
+ )
23
+ if resp.status_code == 200 and resp.json().get("success") is True:
24
+ return resp.json().get("data", {}), True
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
@@ -0,0 +1,205 @@
1
+ from pixelarraythirdparty.client import Client, AsyncClient
2
+
3
+
4
+ class OrderManager(Client):
5
+ def create_order(
6
+ self,
7
+ product_id: str,
8
+ body: str = None,
9
+ remark: str = None,
10
+ payment_channel: str = "WECHAT",
11
+ ):
12
+ data = {
13
+ "product_id": product_id,
14
+ "body": body,
15
+ "remark": remark,
16
+ "payment_channel": payment_channel,
17
+ }
18
+ data, success = self._request("POST", "/api/orders/create", json=data)
19
+ if not success:
20
+ return {}, False
21
+ return data, True
22
+
23
+ def list_order(
24
+ self,
25
+ page: int = 1,
26
+ page_size: int = 10,
27
+ payment_status: str = None,
28
+ out_trade_no: str = None,
29
+ ):
30
+ params = {
31
+ "page": page,
32
+ "page_size": page_size,
33
+ "payment_status": payment_status,
34
+ "out_trade_no": out_trade_no,
35
+ }
36
+ data, success = self._request("GET", "/api/orders/list", params=params)
37
+ if not success:
38
+ return {}, False
39
+ return data, True
40
+
41
+ def get_order_detail(self, out_trade_no: str):
42
+ data, success = self._request("GET", f"/api/orders/{out_trade_no}")
43
+ if not success:
44
+ return {}, False
45
+ return data, True
46
+
47
+ def update_order_status(
48
+ self,
49
+ out_trade_no: str,
50
+ payment_status: str,
51
+ ):
52
+ data = {
53
+ "payment_status": payment_status,
54
+ }
55
+ data, success = self._request(
56
+ "PUT", f"/api/orders/{out_trade_no}/status", json=data
57
+ )
58
+ if not success:
59
+ return {}, False
60
+ return data, True
61
+
62
+ def delete_order(self, out_trade_no: str):
63
+ data, success = self._request("DELETE", f"/api/orders/{out_trade_no}")
64
+ if not success:
65
+ return {}, False
66
+ return data, True
67
+
68
+ def get_order_stats(self):
69
+ data, success = self._request("GET", "/api/orders/stats/summary")
70
+ if not success:
71
+ return {}, False
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
@@ -12,7 +12,6 @@ pixelarraythirdparty/celery/__init__.py
12
12
  pixelarraythirdparty/celery/celery.py
13
13
  pixelarraythirdparty/order/__init__.py
14
14
  pixelarraythirdparty/order/order.py
15
- pixelarraythirdparty/order/pay.py
16
15
  pixelarraythirdparty/product/__init__.py
17
16
  pixelarraythirdparty/product/product.py
18
17
  pixelarraythirdparty/user/__init__.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pixelarraythirdparty"
7
- version = "1.0.2"
7
+ version = "1.0.4"
8
8
  authors = [
9
9
  {name = "Lu qi", email = "qi.lu@pixelarrayai.com"},
10
10
  ]
@@ -1,22 +0,0 @@
1
- import requests
2
- from typing import Dict, Any, Optional, Tuple
3
-
4
-
5
- class Client:
6
- """基础认证类,提供公共的 API key 认证和请求方法"""
7
- def __init__(self, api_key: str):
8
- self.base_url = "https://thirdparty.pixelarrayai.com"
9
- self.api_key = api_key
10
- self.headers = {
11
- "Content-Type": "application/json",
12
- "X-API-Key": self.api_key,
13
- }
14
-
15
- def _request(self, method: str, url: str, **kwargs) -> Tuple[Dict[str, Any], bool]:
16
- """统一的请求方法"""
17
- resp = requests.request(
18
- method, f"{self.base_url}{url}", headers=self.headers, **kwargs
19
- )
20
- if resp.status_code == 200 and resp.json().get("success") is True:
21
- return resp.json().get("data", {}), True
22
- return {}, False
@@ -1,92 +0,0 @@
1
- from pixelarraythirdparty.client import Client
2
-
3
-
4
- class OrderManager(Client):
5
- def create_order(
6
- self,
7
- product_name: str,
8
- product_id: str,
9
- amount: float,
10
- body: str,
11
- remark: str,
12
- payment_channel: str,
13
- ):
14
- data = {
15
- "product_name": product_name,
16
- "product_id": product_id,
17
- "amount": amount,
18
- "body": body,
19
- "remark": remark,
20
- "payment_channel": payment_channel,
21
- }
22
- data, success = self._request("POST", "/api/orders/create", json=data)
23
- if not success:
24
- return {}, False
25
- return data, True
26
-
27
- def list_order(
28
- self,
29
- page: int = 1,
30
- page_size: int = 10,
31
- payment_status: str = None,
32
- order_no: str = None,
33
- ):
34
- params = {
35
- "page": page,
36
- "page_size": page_size,
37
- "payment_status": payment_status,
38
- "order_no": order_no,
39
- }
40
- data, success = self._request("GET", "/api/orders/list", params=params)
41
- if not success:
42
- return {}, False
43
- return data, True
44
-
45
- def get_order_detail(self, order_no: str):
46
- data, success = self._request("GET", f"/api/orders/{order_no}")
47
- if not success:
48
- return {}, False
49
- return data, True
50
-
51
- def update_order(
52
- self,
53
- order_no: str,
54
- 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
- ):
65
- data = {
66
- "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
- }
77
- data, success = self._request("PUT", f"/api/orders/{order_no}", json=data)
78
- if not success:
79
- return {}, False
80
- return data, True
81
-
82
- def delete_order(self, order_no: str):
83
- data, success = self._request("DELETE", f"/api/orders/{order_no}")
84
- if not success:
85
- return {}, False
86
- return data, True
87
-
88
- def get_order_stats(self):
89
- data, success = self._request("GET", "/api/orders/stats/summary")
90
- if not success:
91
- return {}, False
92
- return data, True
@@ -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