arpakitlib 1.8.272__py3-none-any.whl → 1.8.274__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.
- arpakitlib/ar_safe_func.py +2 -0
- {arpakitlib-1.8.272.dist-info → arpakitlib-1.8.274.dist-info}/METADATA +1 -1
- {arpakitlib-1.8.272.dist-info → arpakitlib-1.8.274.dist-info}/RECORD +6 -7
- arpakitlib/ar_yookassa_api_client_util.py +0 -189
- {arpakitlib-1.8.272.dist-info → arpakitlib-1.8.274.dist-info}/WHEEL +0 -0
- {arpakitlib-1.8.272.dist-info → arpakitlib-1.8.274.dist-info}/entry_points.txt +0 -0
- {arpakitlib-1.8.272.dist-info → arpakitlib-1.8.274.dist-info}/licenses/LICENSE +0 -0
arpakitlib/ar_safe_func.py
CHANGED
@@ -55,9 +55,11 @@ def sync_safely_run_func(*, sync_func, args: tuple | None = None, kwargs: dict |
|
|
55
55
|
kwargs=kwargs
|
56
56
|
)
|
57
57
|
except Exception as exception:
|
58
|
+
duration = now_utc_dt() - func_start_dt
|
58
59
|
return SafeFuncResult(
|
59
60
|
has_exception=True,
|
60
61
|
exception=exception,
|
62
|
+
duration=duration,
|
61
63
|
func_name=sync_func.__name__,
|
62
64
|
args=args,
|
63
65
|
kwargs=kwargs
|
@@ -421,7 +421,7 @@ arpakitlib/ar_really_validate_email.py,sha256=HBfhyiDB3INI6Iq6hR2WOMKA5wVWWRl0Qu
|
|
421
421
|
arpakitlib/ar_really_validate_url.py,sha256=aaSPVMbz2DSqlC2yk2g44-kTIiHlITfJwIG97L-Y93U,1309
|
422
422
|
arpakitlib/ar_retry_func_util.py,sha256=LB4FJRsu2cssnPw6X8bCEcaGpQsXhkLkgeU37w1t9fU,2250
|
423
423
|
arpakitlib/ar_run_cmd_util.py,sha256=D_rPavKMmWkQtwvZFz-Io5Ak8eSODHkcFeLPzNVC68g,1072
|
424
|
-
arpakitlib/ar_safe_func.py,sha256=
|
424
|
+
arpakitlib/ar_safe_func.py,sha256=JQNaM3q4Z6nUE8bDfzXNBGkWSXm0PZ-GMMvu6UWUIYk,2400
|
425
425
|
arpakitlib/ar_schedule_uust_api_client_util.py,sha256=rXI2_3OTaIBgR-GixM1Ti-Ue1f9nOcO3EUpYRqdGpYM,6973
|
426
426
|
arpakitlib/ar_settings_util.py,sha256=Y5wi_cmsjDjfJpM0VJHjbo0NoVPKfypKaD1USowwDtQ,1327
|
427
427
|
arpakitlib/ar_sleep_util.py,sha256=ggaj7ML6QK_ADsHMcyu6GUmUpQ_9B9n-SKYH17h-9lM,1045
|
@@ -430,9 +430,8 @@ arpakitlib/ar_sqlalchemy_drop_check_constraints.py,sha256=XEqnMrIwSYasW_UOJ8xU-J
|
|
430
430
|
arpakitlib/ar_sqlalchemy_util.py,sha256=nUDCxhu0l8P0eBCdLyXej3_yLvBlB3LrGhMWzAekm5E,16532
|
431
431
|
arpakitlib/ar_str_util.py,sha256=2lGpnXDf2h1cBZpVf5i1tX_HCv5iBd6IGnrCw4QWWlY,4350
|
432
432
|
arpakitlib/ar_type_util.py,sha256=Cs_tef-Fc5xeyAF54KgISCsP11NHyzIsglm4S3Xx7iM,4049
|
433
|
-
arpakitlib/
|
434
|
-
arpakitlib-1.8.
|
435
|
-
arpakitlib-1.8.
|
436
|
-
arpakitlib-1.8.
|
437
|
-
arpakitlib-1.8.
|
438
|
-
arpakitlib-1.8.272.dist-info/RECORD,,
|
433
|
+
arpakitlib-1.8.274.dist-info/METADATA,sha256=DkmB9WE7rAJWz12KECqyBl4VfMb7wBSlwXyREuCwcB4,3983
|
434
|
+
arpakitlib-1.8.274.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
435
|
+
arpakitlib-1.8.274.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
|
436
|
+
arpakitlib-1.8.274.dist-info/licenses/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
|
437
|
+
arpakitlib-1.8.274.dist-info/RECORD,,
|
@@ -1,189 +0,0 @@
|
|
1
|
-
# arpakit
|
2
|
-
|
3
|
-
from __future__ import annotations
|
4
|
-
|
5
|
-
import asyncio
|
6
|
-
import logging
|
7
|
-
import uuid
|
8
|
-
from datetime import timedelta
|
9
|
-
from typing import Optional, Any
|
10
|
-
|
11
|
-
import aiohttp
|
12
|
-
import requests
|
13
|
-
|
14
|
-
from arpakitlib.ar_dict_util import combine_dicts
|
15
|
-
from arpakitlib.ar_enumeration_util import Enumeration
|
16
|
-
from arpakitlib.ar_http_request_util import sync_make_http_request, async_make_http_request
|
17
|
-
from arpakitlib.ar_type_util import raise_for_type
|
18
|
-
|
19
|
-
_ARPAKIT_LIB_MODULE_VERSION = "3.0"
|
20
|
-
|
21
|
-
"""
|
22
|
-
https://yookassa.ru/developers/api
|
23
|
-
"""
|
24
|
-
|
25
|
-
|
26
|
-
class YookassaPaymentStatuses(Enumeration):
|
27
|
-
pending = "pending"
|
28
|
-
waiting_for_capture = "waiting_for_capture"
|
29
|
-
succeeded = "succeeded"
|
30
|
-
canceled = "canceled"
|
31
|
-
|
32
|
-
|
33
|
-
class YookassaAPIException(Exception):
|
34
|
-
pass
|
35
|
-
|
36
|
-
|
37
|
-
class YookassaAPIClient:
|
38
|
-
def __init__(self, *, secret_key: str, shop_id: int):
|
39
|
-
super().__init__()
|
40
|
-
self.secret_key = secret_key
|
41
|
-
self.shop_id = shop_id
|
42
|
-
self.headers = {"Content-Type": "application/json"}
|
43
|
-
self.timeout_ = timedelta(seconds=3)
|
44
|
-
self._logger = logging.getLogger(self.__class__.__name__)
|
45
|
-
|
46
|
-
def _sync_make_http_request(
|
47
|
-
self,
|
48
|
-
*,
|
49
|
-
method: str,
|
50
|
-
url: str,
|
51
|
-
headers: dict[str, Any] | None = None,
|
52
|
-
**kwargs
|
53
|
-
) -> requests.Response:
|
54
|
-
return sync_make_http_request(
|
55
|
-
method=method,
|
56
|
-
url=url,
|
57
|
-
headers=combine_dicts(self.headers, (headers if headers is not None else {})),
|
58
|
-
max_tries_=5,
|
59
|
-
raise_for_status_=True,
|
60
|
-
timeout_=self.timeout_,
|
61
|
-
not_raise_for_statuses_=[404],
|
62
|
-
auth=(self.shop_id, self.secret_key),
|
63
|
-
**kwargs
|
64
|
-
)
|
65
|
-
|
66
|
-
def sync_create_payment(
|
67
|
-
self,
|
68
|
-
json_body: dict[str, Any]
|
69
|
-
) -> dict[str, Any]:
|
70
|
-
|
71
|
-
"""
|
72
|
-
json_body example
|
73
|
-
json_body = {
|
74
|
-
"amount": {
|
75
|
-
"value": "2.0",
|
76
|
-
"currency": "RUB"
|
77
|
-
},
|
78
|
-
"description": "description",
|
79
|
-
"confirmation": {
|
80
|
-
"type": "redirect",
|
81
|
-
"return_url": f"https://t.me/{get_tg_bot_username()}",
|
82
|
-
"locale": "ru_RU"
|
83
|
-
},
|
84
|
-
"capture": True,
|
85
|
-
"metadata": {},
|
86
|
-
"merchant_customer_id": ""
|
87
|
-
}
|
88
|
-
"""
|
89
|
-
|
90
|
-
response = self._sync_make_http_request(
|
91
|
-
method="POST",
|
92
|
-
url="https://api.yookassa.ru/v3/payments",
|
93
|
-
headers={"Idempotence-Key": str(uuid.uuid4())},
|
94
|
-
json=json_body,
|
95
|
-
)
|
96
|
-
json_data = response.json()
|
97
|
-
response.raise_for_status()
|
98
|
-
return json_data
|
99
|
-
|
100
|
-
def sync_get_payment(self, payment_id: str) -> dict[str, Any] | None:
|
101
|
-
raise_for_type(payment_id, str)
|
102
|
-
response = self._sync_make_http_request(
|
103
|
-
method="GET",
|
104
|
-
url=f"https://api.yookassa.ru/v3/payments/{payment_id}",
|
105
|
-
headers=self.headers
|
106
|
-
)
|
107
|
-
json_data = response.json()
|
108
|
-
if response.status_code == 404:
|
109
|
-
return None
|
110
|
-
response.raise_for_status()
|
111
|
-
return json_data
|
112
|
-
|
113
|
-
async def _async_make_http_request(
|
114
|
-
self,
|
115
|
-
*,
|
116
|
-
method: str = "GET",
|
117
|
-
url: str,
|
118
|
-
headers: dict[str, Any] | None = None,
|
119
|
-
**kwargs
|
120
|
-
) -> aiohttp.ClientResponse:
|
121
|
-
return await async_make_http_request(
|
122
|
-
method=method,
|
123
|
-
url=url,
|
124
|
-
headers=combine_dicts(self.headers, (headers if headers is not None else {})),
|
125
|
-
max_tries_=5,
|
126
|
-
raise_for_status_=True,
|
127
|
-
not_raise_for_statuses_=[404],
|
128
|
-
timeout_=self.timeout_,
|
129
|
-
auth=aiohttp.BasicAuth(login=str(self.shop_id), password=self.secret_key),
|
130
|
-
**kwargs
|
131
|
-
)
|
132
|
-
|
133
|
-
async def async_create_payment(
|
134
|
-
self, json_body: dict[str, Any]
|
135
|
-
) -> dict[str, Any]:
|
136
|
-
|
137
|
-
"""
|
138
|
-
json_body example
|
139
|
-
json_body = {
|
140
|
-
"amount": {
|
141
|
-
"value": "2.0",
|
142
|
-
"currency": "RUB"
|
143
|
-
},
|
144
|
-
"description": "description",
|
145
|
-
"confirmation": {
|
146
|
-
"type": "redirect",
|
147
|
-
"return_url": f"https://t.me/{get_tg_bot_username()}",
|
148
|
-
"locale": "ru_RU"
|
149
|
-
},
|
150
|
-
"capture": True,
|
151
|
-
"metadata": {},
|
152
|
-
"merchant_customer_id": ""
|
153
|
-
}
|
154
|
-
"""
|
155
|
-
|
156
|
-
response = await self._async_make_http_request(
|
157
|
-
method="POST",
|
158
|
-
url="https://api.yookassa.ru/v3/payments",
|
159
|
-
headers={"Idempotence-Key": str(uuid.uuid4())},
|
160
|
-
json=json_body,
|
161
|
-
)
|
162
|
-
json_data = await response.json()
|
163
|
-
response.raise_for_status()
|
164
|
-
return json_data
|
165
|
-
|
166
|
-
async def async_get_payment(self, payment_id: str) -> Optional[dict[str, Any]]:
|
167
|
-
raise_for_type(payment_id, str)
|
168
|
-
response = await self._async_make_http_request(
|
169
|
-
method="GET",
|
170
|
-
url=f"https://api.yookassa.ru/v3/payments/{payment_id}",
|
171
|
-
)
|
172
|
-
json_data = await response.json()
|
173
|
-
if response.status == 404:
|
174
|
-
return None
|
175
|
-
response.raise_for_status()
|
176
|
-
return json_data
|
177
|
-
|
178
|
-
|
179
|
-
def __example():
|
180
|
-
pass
|
181
|
-
|
182
|
-
|
183
|
-
async def __async_example():
|
184
|
-
pass
|
185
|
-
|
186
|
-
|
187
|
-
if __name__ == '__main__':
|
188
|
-
__example()
|
189
|
-
asyncio.run(__async_example())
|
File without changes
|
File without changes
|
File without changes
|