arpakitlib 1.8.320__py3-none-any.whl → 1.8.322__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.
Potentially problematic release.
This version of arpakitlib might be problematic. Click here for more details.
- arpakitlib/ar_yookassa_api_client_util.py +175 -0
- arpakitlib/include_fastapi_routers_from_dir.py +2 -0
- {arpakitlib-1.8.320.dist-info → arpakitlib-1.8.322.dist-info}/METADATA +1 -1
- {arpakitlib-1.8.320.dist-info → arpakitlib-1.8.322.dist-info}/RECORD +7 -6
- {arpakitlib-1.8.320.dist-info → arpakitlib-1.8.322.dist-info}/WHEEL +0 -0
- {arpakitlib-1.8.320.dist-info → arpakitlib-1.8.322.dist-info}/entry_points.txt +0 -0
- {arpakitlib-1.8.320.dist-info → arpakitlib-1.8.322.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import logging
|
|
5
|
+
import uuid
|
|
6
|
+
from datetime import timedelta
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
import aiohttp
|
|
10
|
+
import requests
|
|
11
|
+
from arpakitlib.ar_dict_util import combine_dicts
|
|
12
|
+
from arpakitlib.ar_enumeration_util import Enumeration
|
|
13
|
+
from arpakitlib.ar_http_request_util import sync_make_http_request, async_make_http_request
|
|
14
|
+
from arpakitlib.ar_type_util import raise_for_type
|
|
15
|
+
|
|
16
|
+
"""
|
|
17
|
+
https://yookassa.ru/developers/api
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class YookassaAPIClient:
|
|
22
|
+
class PaymentStatuses(Enumeration):
|
|
23
|
+
pending = "pending"
|
|
24
|
+
waiting_for_capture = "waiting_for_capture"
|
|
25
|
+
succeeded = "succeeded"
|
|
26
|
+
canceled = "canceled"
|
|
27
|
+
|
|
28
|
+
def __init__(self, *, secret_key: str, shop_id: int):
|
|
29
|
+
super().__init__()
|
|
30
|
+
self.secret_key = secret_key
|
|
31
|
+
self.shop_id = shop_id
|
|
32
|
+
self.headers = {"Content-Type": "application/json"}
|
|
33
|
+
self._logger = logging.getLogger(f"{self.__class__.__name__}-{shop_id}")
|
|
34
|
+
|
|
35
|
+
def _sync_make_http_request(
|
|
36
|
+
self,
|
|
37
|
+
*,
|
|
38
|
+
method: str,
|
|
39
|
+
url: str,
|
|
40
|
+
headers: dict[str, Any] | None = None,
|
|
41
|
+
**kwargs
|
|
42
|
+
) -> requests.Response:
|
|
43
|
+
return sync_make_http_request(
|
|
44
|
+
method=method,
|
|
45
|
+
url=url,
|
|
46
|
+
headers=combine_dicts(self.headers, (headers if headers is not None else {})),
|
|
47
|
+
max_tries_=3,
|
|
48
|
+
raise_for_status_=True,
|
|
49
|
+
timeout_=timedelta(seconds=3),
|
|
50
|
+
not_raise_for_statuses_=[404],
|
|
51
|
+
auth=(self.shop_id, self.secret_key),
|
|
52
|
+
enable_logging_=False,
|
|
53
|
+
**kwargs
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
async def _async_make_http_request(
|
|
57
|
+
self,
|
|
58
|
+
*,
|
|
59
|
+
method: str = "GET",
|
|
60
|
+
url: str,
|
|
61
|
+
headers: dict[str, Any] | None = None,
|
|
62
|
+
**kwargs
|
|
63
|
+
) -> aiohttp.ClientResponse:
|
|
64
|
+
return await async_make_http_request(
|
|
65
|
+
method=method,
|
|
66
|
+
url=url,
|
|
67
|
+
headers=combine_dicts(self.headers, (headers if headers is not None else {})),
|
|
68
|
+
max_tries_=3,
|
|
69
|
+
raise_for_status_=True,
|
|
70
|
+
not_raise_for_statuses_=[404],
|
|
71
|
+
timeout_=timedelta(seconds=3),
|
|
72
|
+
auth=aiohttp.BasicAuth(login=str(self.shop_id), password=self.secret_key),
|
|
73
|
+
enable_logging_=False,
|
|
74
|
+
**kwargs
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
def sync_create_payment(self, *, json_body: dict[str, Any]) -> dict[str, Any]:
|
|
78
|
+
|
|
79
|
+
"""
|
|
80
|
+
json_body example
|
|
81
|
+
json_body = {
|
|
82
|
+
"amount": {
|
|
83
|
+
"value": "2.0",
|
|
84
|
+
"currency": "RUB"
|
|
85
|
+
},
|
|
86
|
+
"description": "description",
|
|
87
|
+
"confirmation": {
|
|
88
|
+
"type": "redirect",
|
|
89
|
+
"return_url": f"https://t.me/{get_tg_bot_username()}",
|
|
90
|
+
"locale": "ru_RU"
|
|
91
|
+
},
|
|
92
|
+
"capture": True,
|
|
93
|
+
"metadata": {},
|
|
94
|
+
"merchant_customer_id": ""
|
|
95
|
+
}
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
response = self._sync_make_http_request(
|
|
99
|
+
method="POST",
|
|
100
|
+
url="https://api.yookassa.ru/v3/payments",
|
|
101
|
+
headers={"Idempotence-Key": str(uuid.uuid4())},
|
|
102
|
+
json=json_body,
|
|
103
|
+
)
|
|
104
|
+
json_data = response.json()
|
|
105
|
+
response.raise_for_status()
|
|
106
|
+
return json_data
|
|
107
|
+
|
|
108
|
+
def sync_get_payment(self, *, payment_id: str) -> dict[str, Any] | None:
|
|
109
|
+
raise_for_type(payment_id, str)
|
|
110
|
+
response = self._sync_make_http_request(
|
|
111
|
+
method="GET",
|
|
112
|
+
url=f"https://api.yookassa.ru/v3/payments/{payment_id}",
|
|
113
|
+
headers=self.headers
|
|
114
|
+
)
|
|
115
|
+
json_data = response.json()
|
|
116
|
+
if response.status_code == 404:
|
|
117
|
+
return None
|
|
118
|
+
response.raise_for_status()
|
|
119
|
+
return json_data
|
|
120
|
+
|
|
121
|
+
async def async_create_payment(self, *, json_body: dict[str, Any]) -> dict[str, Any]:
|
|
122
|
+
|
|
123
|
+
"""
|
|
124
|
+
json_body example
|
|
125
|
+
json_body = {
|
|
126
|
+
"amount": {
|
|
127
|
+
"value": "2.0",
|
|
128
|
+
"currency": "RUB"
|
|
129
|
+
},
|
|
130
|
+
"description": "description",
|
|
131
|
+
"confirmation": {
|
|
132
|
+
"type": "redirect",
|
|
133
|
+
"return_url": f"https://t.me/{get_tg_bot_username()}",
|
|
134
|
+
"locale": "ru_RU"
|
|
135
|
+
},
|
|
136
|
+
"capture": True,
|
|
137
|
+
"metadata": {},
|
|
138
|
+
"merchant_customer_id": ""
|
|
139
|
+
}
|
|
140
|
+
"""
|
|
141
|
+
|
|
142
|
+
response = await self._async_make_http_request(
|
|
143
|
+
method="POST",
|
|
144
|
+
url="https://api.yookassa.ru/v3/payments",
|
|
145
|
+
headers={"Idempotence-Key": str(uuid.uuid4())},
|
|
146
|
+
json=json_body,
|
|
147
|
+
)
|
|
148
|
+
json_data = await response.json()
|
|
149
|
+
response.raise_for_status()
|
|
150
|
+
return json_data
|
|
151
|
+
|
|
152
|
+
async def async_get_payment(self, *, payment_id: str) -> dict[str, Any] | None:
|
|
153
|
+
raise_for_type(payment_id, str)
|
|
154
|
+
response = await self._async_make_http_request(
|
|
155
|
+
method="GET",
|
|
156
|
+
url=f"https://api.yookassa.ru/v3/payments/{payment_id}",
|
|
157
|
+
)
|
|
158
|
+
json_data = await response.json()
|
|
159
|
+
if response.status == 404:
|
|
160
|
+
return None
|
|
161
|
+
response.raise_for_status()
|
|
162
|
+
return json_data
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def __example():
|
|
166
|
+
pass
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
async def __async_example():
|
|
170
|
+
pass
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
if __name__ == '__main__':
|
|
174
|
+
__example()
|
|
175
|
+
asyncio.run(__async_example())
|
|
@@ -426,9 +426,10 @@ arpakitlib/ar_sqlalchemy_util.py,sha256=_7sGYLgKAq_YYVuphyc9yXlaGbV-FTmLI2uEnNwB
|
|
|
426
426
|
arpakitlib/ar_str_util.py,sha256=2lGpnXDf2h1cBZpVf5i1tX_HCv5iBd6IGnrCw4QWWlY,4350
|
|
427
427
|
arpakitlib/ar_type_util.py,sha256=Cs_tef-Fc5xeyAF54KgISCsP11NHyzIsglm4S3Xx7iM,4049
|
|
428
428
|
arpakitlib/ar_uppercase_env_keys.py,sha256=BsUCJhfchBIav0AE54_tVgYcE4p1JYoWdPGCHWZnROA,2790
|
|
429
|
-
arpakitlib/
|
|
430
|
-
arpakitlib
|
|
431
|
-
arpakitlib-1.8.
|
|
432
|
-
arpakitlib-1.8.
|
|
433
|
-
arpakitlib-1.8.
|
|
434
|
-
arpakitlib-1.8.
|
|
429
|
+
arpakitlib/ar_yookassa_api_client_util.py,sha256=Mst07IblAJmU98HfOfJqT_RRfnuGrIB1UOQunGGWO8I,5264
|
|
430
|
+
arpakitlib/include_fastapi_routers_from_dir.py,sha256=Umg16sPQC6R-T8FD7mlmqP1TbgH-_v2eDasrZJzImQM,1606
|
|
431
|
+
arpakitlib-1.8.322.dist-info/METADATA,sha256=7I4FON25AN9tOuK2iozXNi4M_4F3t1FJkbpfWCFrO08,3804
|
|
432
|
+
arpakitlib-1.8.322.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
433
|
+
arpakitlib-1.8.322.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
|
|
434
|
+
arpakitlib-1.8.322.dist-info/licenses/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
|
|
435
|
+
arpakitlib-1.8.322.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|