arpakitlib 1.8.320__py3-none-any.whl → 1.8.326__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.

@@ -20,6 +20,8 @@ def include_fastapi_routers_from_dir(
20
20
  exclude_filenames = ["__init__.py"]
21
21
 
22
22
  for root, _, files in os.walk(base_dir):
23
+ files.sort()
24
+
23
25
  for filename in files:
24
26
  if not filename.endswith(".py") or filename in exclude_filenames:
25
27
  continue
@@ -273,7 +273,7 @@ class SQLAlchemyDb:
273
273
  self._logger.info("alembic tables data were removed")
274
274
 
275
275
  def ensure_check_constraints(self):
276
- from arpakitlib.ar_ensure_sqlalchemy_check_constraints import ensure_sqlalchemy_check_constraints
276
+ from arpakitlib.ar_sqlalchemy_ensure_check_constraints import ensure_sqlalchemy_check_constraints
277
277
  ensure_sqlalchemy_check_constraints(base_=self.base_dbm, engine=self.engine)
278
278
 
279
279
  def drop_check_constraints(self):
arpakitlib/ar_str_util.py CHANGED
@@ -107,7 +107,7 @@ def remove_tags_and_html(string: str) -> str:
107
107
 
108
108
  def raise_if_string_blank(string: str) -> str:
109
109
  if not string:
110
- raise ValueError("not string")
110
+ raise ValueError("string is blank")
111
111
  return string
112
112
 
113
113
 
@@ -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())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: arpakitlib
3
- Version: 1.8.320
3
+ Version: 1.8.326
4
4
  Summary: arpakitlib
5
5
  License-Expression: Apache-2.0
6
6
  License-File: LICENSE
@@ -388,7 +388,6 @@ arpakitlib/ar_clone_pydantic_model_fields.py,sha256=5i77NGEjnY2ppk_Ot179egQGNDvg
388
388
  arpakitlib/ar_datetime_util.py,sha256=3Pw8ljsBKkkEUCmu1PsnJqNeG5bVLqtpsUGaztJF8jQ,1432
389
389
  arpakitlib/ar_dict_util.py,sha256=oet-9AJEjQZfG_EI82BuYW0jdW2NQxKjPXol_nfTXjw,447
390
390
  arpakitlib/ar_encrypt_decrypt_util.py,sha256=GhWnp7HHkbhwFVVCzO1H07m-5gryr4yjWsXjOaNQm1Y,520
391
- arpakitlib/ar_ensure_sqlalchemy_check_constraints.py,sha256=gqZTPSCAPUMRiXcmv9xls5S8YkUAg-gwFIEvqQsJ_JM,5437
392
391
  arpakitlib/ar_enumeration_util.py,sha256=XoFInWtGzbIr6fJq0un5nettaDfOLAyY84ovwj7n_7g,3030
393
392
  arpakitlib/ar_exception_util.py,sha256=3hZKsj34TZVdmd4JAQz7w515smWqB8o3gTwAEjuMdnI,408
394
393
  arpakitlib/ar_file_storage_in_dir_util.py,sha256=Zh922S6-aIy0p_Fen8GTTrGpixpPQ6c-wFLukiSK4Ck,4091
@@ -398,6 +397,7 @@ arpakitlib/ar_generate_connection_url_util.py,sha256=sU55IA0v3TZ5PzJgc01Q9cABIzF
398
397
  arpakitlib/ar_generate_simple_code.py,sha256=EkrebrTi7sArSRAuxvN5BPm_A0-dFSCZgdoJhx5kPhk,344
399
398
  arpakitlib/ar_hash_util.py,sha256=Iqy6KBAOLBQMFLWv676boI5sV7atT2B-fb7aCdHOmIQ,340
400
399
  arpakitlib/ar_http_request_util.py,sha256=PCUtGOQIvNScrLqD_9Z8LqT-7a-lP2y-Y-CH5vGdn7Q,7663
400
+ arpakitlib/ar_include_fastapi_routers_from_dir_util.py,sha256=Umg16sPQC6R-T8FD7mlmqP1TbgH-_v2eDasrZJzImQM,1606
401
401
  arpakitlib/ar_ip_util.py,sha256=aEAa1Hvobh9DWX7cmBAPLqnXSTiKe2hRk-WJaiKMaI8,1009
402
402
  arpakitlib/ar_json_db_util.py,sha256=5nELpAY1_5_iTN4nMcutQtJQ5Nt52-xiKELxEH65RkY,7240
403
403
  arpakitlib/ar_json_util.py,sha256=jnVfpQ6QSDq8NgIlh_6ZzXDveOiybr7QSQkXutE7d2s,2676
@@ -422,13 +422,14 @@ arpakitlib/ar_settings_util.py,sha256=FeQQkuVrLVYkFAIg3Wy6ysyTt_sqLTX0REAe60gbM3
422
422
  arpakitlib/ar_sleep_util.py,sha256=ggaj7ML6QK_ADsHMcyu6GUmUpQ_9B9n-SKYH17h-9lM,1045
423
423
  arpakitlib/ar_sqladmin_util.py,sha256=SEoaowAPF3lhxPsNjwmOymNJ55Ty9rmzvsDm7gD5Ceo,861
424
424
  arpakitlib/ar_sqlalchemy_drop_check_constraints.py,sha256=uVktYLjNHrMPWQAq8eBpapShPKbLb3LrRBnnss3gaYY,3624
425
- arpakitlib/ar_sqlalchemy_util.py,sha256=_7sGYLgKAq_YYVuphyc9yXlaGbV-FTmLI2uEnNwBmjE,16040
426
- arpakitlib/ar_str_util.py,sha256=2lGpnXDf2h1cBZpVf5i1tX_HCv5iBd6IGnrCw4QWWlY,4350
425
+ arpakitlib/ar_sqlalchemy_ensure_check_constraints.py,sha256=gqZTPSCAPUMRiXcmv9xls5S8YkUAg-gwFIEvqQsJ_JM,5437
426
+ arpakitlib/ar_sqlalchemy_util.py,sha256=8sHbUS9BgM13iTFrqxLuCpGYmLXPQMx4aqQb-aY8HrM,16040
427
+ arpakitlib/ar_str_util.py,sha256=6KlLL-SB8gzK-6gwQEd3zuYbRvtjd9HFpJ9-xHbkH6U,4355
427
428
  arpakitlib/ar_type_util.py,sha256=Cs_tef-Fc5xeyAF54KgISCsP11NHyzIsglm4S3Xx7iM,4049
428
429
  arpakitlib/ar_uppercase_env_keys.py,sha256=BsUCJhfchBIav0AE54_tVgYcE4p1JYoWdPGCHWZnROA,2790
429
- arpakitlib/include_fastapi_routers_from_dir.py,sha256=2QefsH_P3fHGfv-mAUzq1DDSDpYHWiP3Lco3f9jc2V0,1584
430
- arpakitlib-1.8.320.dist-info/METADATA,sha256=MRu1SbvEmE9xo48sKTaUB5O8EzOZNk2iHpC_O0xrZZI,3804
431
- arpakitlib-1.8.320.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
432
- arpakitlib-1.8.320.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
433
- arpakitlib-1.8.320.dist-info/licenses/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
434
- arpakitlib-1.8.320.dist-info/RECORD,,
430
+ arpakitlib/ar_yookassa_api_client_util.py,sha256=Mst07IblAJmU98HfOfJqT_RRfnuGrIB1UOQunGGWO8I,5264
431
+ arpakitlib-1.8.326.dist-info/METADATA,sha256=G_G4IUXDYld3qHeF8I_e7jqFm6ICAp-Hr7ZunkHA8Cw,3804
432
+ arpakitlib-1.8.326.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
433
+ arpakitlib-1.8.326.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
434
+ arpakitlib-1.8.326.dist-info/licenses/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
435
+ arpakitlib-1.8.326.dist-info/RECORD,,