├── LAVAPI Banner.png ├── LAVAPI ├── LAVAPI.py └── __init__.py ├── LICENSE └── README.md /LAVAPI Banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DIMFLIX/LAVAPI/662619f0041287d93c2a63023b2407749010898b/LAVAPI Banner.png -------------------------------------------------------------------------------- /LAVAPI/LAVAPI.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | import requests 3 | 4 | 5 | class LAVAPI(object): 6 | 7 | def __init__(self, key: str): 8 | """ 9 | Token from lava.ru/dashboard/settings/api 10 | :param key: Token for authorization 11 | """ 12 | 13 | self.LavaToken = key 14 | self.url = "https://api.lava.ru" 15 | self.headers = {'Authorization': key} 16 | 17 | self.ping() 18 | 19 | def ping(self) -> bool: 20 | 21 | url = self.url + "/test/ping" 22 | response = requests.get(url, headers=self.headers).json() 23 | 24 | if response["status"] == "error": 25 | raise ApiError(f"[{response['code']}] {response['message']}") 26 | return True 27 | 28 | def wallet_list(self) -> dict: 29 | return requests.get(self.url + "/wallet/list", headers=self.headers).json() 30 | 31 | def invoice_create(self, sum: float, wallet_to: str, order_id: str = None, 32 | hook_url: str = None, success_url: str = None, fail_url: str = None, 33 | expire: int = None, subtract: str = None, custom_fields: str = None, 34 | comment: str = None, merchant_id: str = None, merchant_name: str = None) -> dict: 35 | """ 36 | Warning - The amount must be in RUB 37 | More detailed: https://dev.lava.ru/invoicecreate 38 | 39 | :param wallet_to: Your account number to which funds will be credited 40 | :param sum: The amount, indicating two characters after the dot 41 | :param order_id: Account number in your system Must be unique 42 | :param hook_url: Url to send the webhook (Max: 500) 43 | :param success_url: Url for forwarding after successful payment (Max: 500) 44 | :param fail_url: Url for forwarding after a failed payment (Max: 500) 45 | :param expire: Lifetime in minutes 46 | :param subtract: From whom to deduct the commission 47 | :param custom_fields: An additional field that is returned to the WebHook 48 | :param comment: Payment Comment 49 | :param merchant_id: Merchant's ID (used only in WebHook) 50 | :param merchant_name: Merchant's name (displayed in the transfer form) 51 | 52 | :return: dict 53 | """ 54 | 55 | url = self.url + "/invoice/create" 56 | data = { 57 | "wallet_to": wallet_to, 58 | "sum": sum, 59 | "comment": comment 60 | } 61 | 62 | if order_id is not None: 63 | data['order_id'] = order_id 64 | 65 | if hook_url is not None: 66 | data['hook_url'] = hook_url 67 | 68 | if success_url is not None: 69 | data['success_url'] = success_url 70 | 71 | if fail_url is not None: 72 | data['fail_url'] = fail_url 73 | 74 | if expire is not None: 75 | data['expire'] = expire 76 | 77 | if subtract is not None: 78 | data['subtract'] = subtract 79 | 80 | if custom_fields is not None: 81 | data['custom_fields'] = custom_fields 82 | 83 | if comment is not None: 84 | data['comment'] = comment 85 | 86 | if merchant_id is not None: 87 | data['merchant_id'] = merchant_id 88 | 89 | if merchant_name is not None: 90 | data['merchant_name'] = merchant_name 91 | 92 | response = requests.post(url, headers=self.headers, data=data).json() 93 | if response["status"] == "error": 94 | raise ApiError(f"[{response['code']}] {response['message']}") 95 | 96 | return response 97 | 98 | def is_paid(self, id: str = None, order_id: str = None) -> bool: 99 | """ 100 | More detailed: https://dev.lava.ru/invoiceinfo 101 | 102 | :param id: Account number in our system Required if 'order_id' is not passed 103 | :param order_id: TAccount number in our system Required if 'id' is not passed 104 | 105 | :return: bool 106 | """ 107 | 108 | data = {} 109 | 110 | if id is not None: 111 | data["id"] = id 112 | 113 | elif order_id is not None: 114 | data["order_id"] = order_id 115 | 116 | response = requests.post(self.url + '/invoice/info', headers=self.headers, data=data).json() 117 | 118 | if response["status"] == "error": 119 | ApiError(f"[{response['code']}] {response['message']}") 120 | 121 | return True 122 | 123 | def invoice_set_webhook(self, url: str) -> bool: 124 | """ 125 | More detailed: https://dev.lava.ru/invoicesetwebhook 126 | 127 | :param url: URL to which HTTP notifications will be sent 128 | 129 | :return: bool 130 | """ 131 | response = requests.post(self.url + "/invoice/set-webhook", headers=self.headers, data={"url": url}).json() 132 | 133 | if response["status"] == 'error': 134 | raise ApiError(f"[{response['code']}] {response['message']}") 135 | 136 | return True 137 | 138 | def withdraw_create(self, account: str, amount: float, service: str, wallet_to: str, order_id: str = None, 139 | hook_url: str = None, subtract: int = None, comment: str = None) -> dict: 140 | """ 141 | More detailed: https://dev.lava.ru/withdrawcreate 142 | 143 | :param account: Wallet number from which the withdrawal is made 144 | :param amount: Withdrawal amount 145 | :param service: Withdrawal service 146 | :param wallet_to: Beneficiary's account number 147 | :param order_id: Account number in your system. Must be unique 148 | :param hook_url: Url to send webhook (Max: 500) 149 | :param subtract: Where to write off the commission 150 | :param comment: Commentary on the conclusion 151 | 152 | :return: dict 153 | """ 154 | url = self.url + '/withdraw/create' 155 | data = { 156 | "account": account, 157 | "amount": amount, 158 | "service": service, 159 | "wallet_to": wallet_to, 160 | } 161 | 162 | if order_id is not None: 163 | data['order_id'] = order_id 164 | 165 | if hook_url is not None: 166 | data['hook_url'] = hook_url 167 | 168 | if subtract is not None: 169 | data['subtract'] = subtract 170 | 171 | if comment is not None: 172 | data['comment'] = comment 173 | 174 | response = requests.post(url, headers=self.headers, data=data).json() 175 | 176 | if response["status"] == 'error': 177 | raise ApiError(f"[{response['code']}] {response['message']}") 178 | 179 | return response 180 | 181 | def withdraw_info(self, id: str) -> dict: 182 | """ 183 | More detailed: https://dev.lava.ru/withdrawinfo 184 | 185 | :param id: Application number 186 | 187 | :return: dict 188 | """ 189 | url = self.url + '/withdraw/info' 190 | data = {"id": id} 191 | 192 | response = requests.post(url, headers=self.headers, data=data).json() 193 | 194 | if response["status"] == 'error': 195 | raise ApiError(f"[{response['code']}] {response['message']}") 196 | 197 | return response 198 | 199 | def transfer_create(self, account_from: str, account_to: str, amount: float, subtract: int = None, 200 | comment: str = None) -> dict: 201 | """ 202 | More detailed: https://dev.lava.ru/transfercreate 203 | 204 | :param account_from: Wallet number from which the transfer is made 205 | :param account_to: Wallet number where the transfer is made 206 | :param amount: Withdrawal amount 207 | :param subtract: Where to write off the commission 208 | :param comment: Commentary on the conclusion 209 | 210 | :return: dict 211 | """ 212 | url = self.url + '/transfer/create' 213 | data = { 214 | "account_from": account_from, 215 | "account_to": account_to, 216 | "amount": amount, 217 | } 218 | 219 | if subtract is not None: 220 | data['subtract'] = subtract 221 | 222 | if comment is not None: 223 | data['comment'] = comment 224 | 225 | response = requests.post(url, headers=self.headers, data=data).json() 226 | 227 | if response["status"] == 'error': 228 | raise ApiError(f"[{response['code']}] {response['message']}") 229 | 230 | return response 231 | 232 | def transfer_info(self, id: str) -> dict: 233 | """ 234 | More detailed: https://dev.lava.ru/transferinfo 235 | 236 | :param id: Application number 237 | 238 | :return: dict 239 | """ 240 | url = self.url + '/transfer/info' 241 | data = {"id": id} 242 | 243 | response = requests.post(url, headers=self.headers, data=data).json() 244 | 245 | if response["status"] == 'error': 246 | raise ApiError(f"[{response['code']}] {response['message']}") 247 | 248 | return response 249 | 250 | def transactions_list(self, transfer_type: str = None, account: str = None, period_start: str = None, 251 | period_end: str = None, offset: int = None, limit: int = None) -> dict: 252 | """ 253 | More detailed: https://dev.lava.ru/transactionlist 254 | 255 | :param transfer_type: Transaction type 256 | :param account: Wallet number 257 | :param period_start: From when to show transactions 258 | :param period_end: Until when to show transactions 259 | :param offset: Offset transactions 260 | :param limit: Limit (max: 50) 261 | 262 | :return: dict 263 | """ 264 | url = self.url + '/transfer/info' 265 | data = {} 266 | 267 | if transfer_type is not None: 268 | data['transfer_type'] = transfer_type 269 | 270 | if account is not None: 271 | data['account'] = account 272 | 273 | if period_start is not None: 274 | data['period_start'] = period_start 275 | 276 | if period_end is not None: 277 | data['period_end'] = period_end 278 | 279 | if offset is not None: 280 | data['offset'] = offset 281 | 282 | if limit is not None: 283 | data['limit'] = limit 284 | 285 | response = requests.post(url, headers=self.headers, data=data).json() 286 | 287 | if response["status"] == 'error': 288 | raise ApiError(f"[{response['code']}] {response['message']}") 289 | 290 | return response 291 | 292 | 293 | class ApiError(Exception): 294 | pass 295 | -------------------------------------------------------------------------------- /LAVAPI/__init__.py: -------------------------------------------------------------------------------- 1 | from .LAVAPI import LAVAPI 2 | 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 DIMFLIX 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![alt text](https://github.com/DIMFLIX-OFFICIAL/LAVAPI/blob/main/LAVAPI%20Banner.png?raw=true) 2 | 3 | 4 | Библиотека LAVAPI была создана, дабы облегчить работу c официалным [API](https://dev.lava.ru/) платежной системы LAVA. 5 | В ней представлены все методы, присутствующие в официальной документации. 6 | 7 | 8 | ## Установка 9 | 10 | Для корректной установки LAVAPI необходимо установить версию [Python](https://www.python.org/) 3.6 и выше. 11 | Далее достаточно открыть cmd и ввести простую команду: 12 | ```cmd 13 | pip install LAVAPI 14 | ``` 15 | 16 | 17 | 18 | ## Возможности 19 | 20 | • wallet_list - Список кошельков
21 | • invoice_create - Выставить счёт
22 | • is_paid - Получить информацию о счёте
23 | • invoice_set_webhook - Установка URL для WebHook
24 | • withdraw_create - Создание вывода
25 | • withdraw_info - Информация о выводе
26 | • transfer_create - Создание перевода
27 | • transfer_info - Информация о переводе
28 | • transactions_list - Список всех транзакций
29 | 30 | 31 | 32 | ## Подготовка к использованию. 33 | Для того чтобы начать пользоваться библиотекой, нужно получить Token. 34 | Его можно получить по этой [ссылке](https://lava.ru/dashboard/settings/api) 35 | 36 | 37 | 38 | 39 | ## Примеры использования 40 | ``` python 41 | from LAVAPI import LAVAPI 42 | 43 | 44 | TOKEN = "YOUR_API_KEY" 45 | api = LAVAPI(TOKEN) 46 | 47 | invoice = api.invoice_create(sum = 10.00, wallet_to = "YOR WALLET NUMBER", comment = "LAVAPI invoice_create test!") # Создать счёт 48 | invoice_check = api.is_paid(id = invoice["id"]) # Получить информацию о счете 49 | 50 | wallet_list = api.wallet_list() # Получить информацию о кошельках 51 | 52 | api.invoice_set_webhook(url="YOR URL") # Установка URL для отправки HTTP-уведомлений 53 | 54 | withdraw = api.withdraw_create(account = "YOR WALLET NUMBER", amount=1000.00, service="card", wallet_to="5221610543444123") # Создание вывода 55 | withdraw_info = api.withdraw_info(id=withdraw['id']) # Получить информацию о выводе 56 | 57 | transfer = api.transfer_create(account_from="YOR WALLET NUMBER", account_to="ANOTHER WALLET NUMBER", amount=100.00) # Создать перевод 58 | transfer_info = api.transfer_info(id=transfer["id"]) # Получить информацию о переводе 59 | 60 | transactions_list = api.transactions_list(transfer_type="withdraw", account="YOR WALLET NUMBER", limit=50, ) # Список транзакций 61 | 62 | 63 | ``` 64 | 65 | 66 | 67 | ## License 68 | 69 | GNU General Public License (GPL) 70 | --------------------------------------------------------------------------------