From adfaf3952ab939daf25d802e018c483be97103e1 Mon Sep 17 00:00:00 2001 From: lolkofka Date: Wed, 7 Aug 2024 01:25:19 +0300 Subject: [PATCH 1/3] add method get_pay_url --- README.md | 7 +++ src/aaio/AAIO.py | 123 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 90 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index ff6dc92..eb04d53 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,13 @@ from aaio import AAIO async def main(): client = AAIO('MERCHANT ID', 'SECRET KEY', 'API KEY') + payment_url = await client.get_pay_url(100, 'my_order_id', 'My order description', 'qiwi', 'support@aaio.so', + 'referral code', currency='USD', + language='en') + print(payment_url['url']) # Prints payment url for customer + + # its recomended methon, but you can use this + payment_url = client.create_payment(100, 'my_order_id', 'My order description', 'qiwi', 'support@aaio.so', 'referral code', currency='USD', language='en') diff --git a/src/aaio/AAIO.py b/src/aaio/AAIO.py index 8c20c4e..59111fd 100644 --- a/src/aaio/AAIO.py +++ b/src/aaio/AAIO.py @@ -35,7 +35,7 @@ class AAIO: API for https://aaio.so/ """ - + def __init__(self, merchant_id: str, secret_1: str, secret_2: str, api_key: str, default_currency: str = 'RUB', base_url: str = 'https://aaio.so'): """ @@ -49,14 +49,14 @@ def __init__(self, merchant_id: str, secret_1: str, secret_2: str, api_key: str, default_currency: If not set - RUB, but can be overwritten for each request (Optional) base_url: Base URL for requests (Optional) """ - + self._default_currency = default_currency self._merchant_id = merchant_id self._api_key = api_key self._secret_1 = secret_1 self._secret_2 = secret_2 self._base_url = base_url - + def __generate_sign(self, amount: float, order_id: str, currency: str) -> str: """ Generates sign for payment creation @@ -70,7 +70,7 @@ def __generate_sign(self, amount: float, order_id: str, currency: str) -> str: Returns: SHA-256 sign """ - + params = f':'.join([ self._merchant_id, str(amount), @@ -80,7 +80,7 @@ def __generate_sign(self, amount: float, order_id: str, currency: str) -> str: ]) sign = hashlib.sha256(params.encode('utf-8')).hexdigest() return sign - + def create_payment(self, amount: float, order_id: str, description: str = None, method: str = None, email: str = None, referral: str = None, us_key: str = None, currency: str = None, @@ -103,7 +103,7 @@ def create_payment(self, amount: float, order_id: str, description: str = None, Returns: Payment URL """ - + if not currency: currency = self._default_currency params = { @@ -119,14 +119,56 @@ def create_payment(self, amount: float, order_id: str, description: str = None, 'referral': referral, 'us_key': us_key } - + return f'{self._base_url}/merchant/pay?' + urlencode({k: v for k, v in params.items() if v is not None}) + + async def get_pay_url(self, amount: float, order_id: str, description: str = None, method: str = None, + email: str = None, + referral: str = None, us_key: str = None, currency: str = None, + language: str = 'ru') -> dict: + """ + Creates payment URL, recomended method + See https://wiki.aaio.so/priem-platezhei/sozdanie-zakaza-zaprosom-rekomenduem for more detailed information + + Args: + amount: Payment amount + order_id: Your order id + description: Payment description (Optional) + method: Payment method, can be overwritten by customer (Optional) + email: Client E-Mail (Optional) + referral: Referral code for cookies (Optional) + us_key: Custom parameters (Optional) + currency: Payment currency, default - default client currency (Optional) + language: Page language (Optional) + Returns: dict {"type": "...", "url": "https://......"} + """ + + if not currency: + currency = self._default_currency + params = { + 'merchant_id': self._merchant_id, + 'amount': amount, + 'currency': currency, + 'order_id': order_id, + 'sign': self.__generate_sign(amount, order_id, currency), + 'desc': description, + 'lang': language, + 'method': method, + 'email': email, + 'referral': referral, + 'us_key': us_key + } + + response = await self.__create_request('/merchant/get_pay_url', params) + + return response + async def get_ips(self) -> List[str]: response = await self.__create_request('/api/public/ips') - + return response['list'] - + async def get_payment_info(self, order_id: str) -> PaymentInfo: """ Creates a request for get payment information @@ -138,16 +180,16 @@ async def get_payment_info(self, order_id: str) -> PaymentInfo: Returns: Model from response JSON """ - + params = { 'merchant_id': self._merchant_id, 'order_id': order_id } - + response = await self.__create_request('/api/info-pay', params) - + return PaymentInfo(**response) - + async def get_balances(self) -> Balance: """ Creates a request for get balances of user @@ -155,11 +197,11 @@ async def get_balances(self) -> Balance: Returns: Model from response JSON """ - + response = await self.__create_request('/api/balance') - + return Balance(**response) - + async def create_payoff(self, method: str, amount: float, wallet: str, payoff_id: str = '', commission_type: int = 0) -> CreatePayoff: """ @@ -176,7 +218,7 @@ async def create_payoff(self, method: str, amount: float, wallet: str, payoff_id Returns: Model from response JSON """ - + params = { 'my_id': payoff_id, 'method': method, @@ -184,11 +226,11 @@ async def create_payoff(self, method: str, amount: float, wallet: str, payoff_id 'wallet': wallet, 'commission_type': commission_type } - + response = await self.__create_request('/api/create-payoff', params) - + return CreatePayoff(**response) - + async def get_payoff_sbp_banks(self) -> PayoffSbpBanks: """ Returns a list of available banks for payoff @@ -196,9 +238,9 @@ async def get_payoff_sbp_banks(self) -> PayoffSbpBanks: Returns: list of banks """ response = await self.__create_request('/api/sbp-banks-payoff') - + return PayoffSbpBanks(**response) - + async def get_payoff_info(self, payoff_id: str = None, aaio_id: str = None) -> PayoffInfo: """ Creates a request for get payoff information @@ -213,16 +255,16 @@ async def get_payoff_info(self, payoff_id: str = None, aaio_id: str = None) -> P Returns: Model from response JSON """ - + params = { 'my_id': payoff_id, 'id': aaio_id } - + response = await self.__create_request('/api/info-payoff', params) - + return PayoffInfo(**response) - + async def get_payoff_rates(self) -> PayoffRates: """ Creates a request for get rates for payoff @@ -231,11 +273,11 @@ async def get_payoff_rates(self) -> PayoffRates: Returns: Model from response JSON """ - + response = await self.__create_request('/api/rates-payoff') - + return PayoffRates(**response) - + async def get_payoff_methods(self) -> PayoffMethods: """ Creates a request for get available payoff methods @@ -244,11 +286,11 @@ async def get_payoff_methods(self) -> PayoffMethods: Returns: Model from response JSON """ - + response = await self.__create_request('/api/methods-payoff') - + return PayoffMethods(**response) - + async def get_payment_methods(self) -> PaymentMethods: """ Creates a request for get available payment methods @@ -257,15 +299,15 @@ async def get_payment_methods(self) -> PaymentMethods: Returns: Model from response JSON """ - + params = { 'merchant_id': self._merchant_id } - + response = await self.__create_request('/api/methods-pay', params) - + return PaymentMethods(**response) - + async def __create_request(self, uri: str, params: dict = None) -> Optional[dict]: """ Creates a request to base URL and adds URI @@ -277,15 +319,16 @@ async def __create_request(self, uri: str, params: dict = None) -> Optional[dict Returns: Model from response JSON """ - + if params is None: params = {} - + headers = { 'Accept': 'application/json', + 'Content-Type': 'application/x-www-form-urlencoded', 'X-Api-Key': self._api_key } - + async with aiohttp.ClientSession(self._base_url) as session: async with session.post(uri, headers=headers, data={k: v for k, v in params.items() if v is not None}) as r: @@ -294,7 +337,7 @@ async def __create_request(self, uri: str, params: dict = None) -> Optional[dict return response else: raise AAIOBadRequest(response['code'], response['message']) - + def is_valid_payment_webhook(self, data: PaymentWebhookData) -> bool: return hashlib.sha256( f'{self._merchant_id}:{data.amount}:{self._secret_2}:{data.order_id}'.encode()).hexdigest() == data.sign From b098da65cd3d6eb57d6f76ed136d8dddbb4eed1e Mon Sep 17 00:00:00 2001 From: lolkofka Date: Wed, 7 Aug 2024 01:34:53 +0300 Subject: [PATCH 2/3] fix date --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eb04d53..3930f32 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ aaio.so return a pydantic's models for each response. Please write about all problems related to the library to [issues](https://github.com/kewldan/AAIO/issues) -API is up-to-date as of *01 March 2024*. +API is up-to-date as of *07 August 2024*. * PyPl - https://pypi.org/project/aaio/ * Github - https://github.com/kewldan/AAIO From bf03826c680f7ace6a63d0b233e96b2d48aee911 Mon Sep 17 00:00:00 2001 From: kewldan Date: Wed, 7 Aug 2024 01:55:45 +0300 Subject: [PATCH 3/3] v1.4.0 --- .gitignore | 1 + README.md | 10 +- pyproject.toml | 9 +- src/aaio/__init__.py | 15 +- src/aaio/{AAIO.py => client.py} | 176 ++++++++---------- src/aaio/exceptions/__init__.py | 1 + .../{aaio_bad_request.py => bad_request.py} | 2 +- src/aaio/models/__init__.py | 10 + src/aaio/{types => models}/balance.py | 0 src/aaio/{types => models}/create_payoff.py | 0 src/aaio/{types => models}/payment_info.py | 0 src/aaio/{types => models}/payment_methods.py | 0 src/aaio/{types => models}/payment_webhook.py | 0 src/aaio/{types => models}/payoff_info.py | 0 src/aaio/{types => models}/payoff_methods.py | 0 src/aaio/{types => models}/payoff_rates.py | 0 .../{types => models}/payoff_sbp_banks.py | 0 src/aaio/{types => models}/payoff_webhook.py | 0 src/aaio/utils.py | 16 ++ 19 files changed, 122 insertions(+), 118 deletions(-) rename src/aaio/{AAIO.py => client.py} (82%) create mode 100644 src/aaio/exceptions/__init__.py rename src/aaio/exceptions/{aaio_bad_request.py => bad_request.py} (83%) create mode 100644 src/aaio/models/__init__.py rename src/aaio/{types => models}/balance.py (100%) rename src/aaio/{types => models}/create_payoff.py (100%) rename src/aaio/{types => models}/payment_info.py (100%) rename src/aaio/{types => models}/payment_methods.py (100%) rename src/aaio/{types => models}/payment_webhook.py (100%) rename src/aaio/{types => models}/payoff_info.py (100%) rename src/aaio/{types => models}/payoff_methods.py (100%) rename src/aaio/{types => models}/payoff_rates.py (100%) rename src/aaio/{types => models}/payoff_sbp_banks.py (100%) rename src/aaio/{types => models}/payoff_webhook.py (100%) create mode 100644 src/aaio/utils.py diff --git a/.gitignore b/.gitignore index 35f156c..8846dd5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /src/aaio.egg-info /dist/ /site/ +main.py \ No newline at end of file diff --git a/README.md b/README.md index 3930f32..2e29ae8 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ ## About -This library is a wrapper for the https://aaio.so API **from enthusiasts**. All methods are described and all types are +This library is a wrapper for the https://aaio.so API **from enthusiast**. All methods are described and all types are **explicitly** defined. Methods that create requests to aaio.so return a pydantic's models for each response. Please write about all problems related to the library @@ -79,17 +79,21 @@ from aaio import AAIO async def main(): client = AAIO('MERCHANT ID', 'SECRET KEY', 'API KEY') + + + # New way to create payments payment_url = await client.get_pay_url(100, 'my_order_id', 'My order description', 'qiwi', 'support@aaio.so', 'referral code', currency='USD', language='en') print(payment_url['url']) # Prints payment url for customer - # its recomended methon, but you can use this + # DEPRECATED METHOD payment_url = client.create_payment(100, 'my_order_id', 'My order description', 'qiwi', 'support@aaio.so', 'referral code', currency='USD', language='en') - print(payment_url) # Prints payment url for customer + print(payment_url) + ################### asyncio.run(main()) diff --git a/pyproject.toml b/pyproject.toml index 825b6ef..2d00dea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,13 @@ [build-system] -requires = ["setuptools>=61.0"] -build-backend = "setuptools.build_meta" +requires = ["hatchling"] +build-backend = "hatchling.build" + +[tool.hatch.build.targets.wheel] +packages = ["src/aaio"] [project] name = "aaio" -version = "1.3.1" +version = "1.4.0" description = "Async AAIO api wrapper for python" readme = "README.md" authors = [{ name = "kewldan", email = "kewldanil1@gmail.com" }] diff --git a/src/aaio/__init__.py b/src/aaio/__init__.py index a8bdb06..fb0b774 100644 --- a/src/aaio/__init__.py +++ b/src/aaio/__init__.py @@ -1,11 +1,4 @@ -from .AAIO import create_invoice, is_valid_payoff_webhook, AAIO -from .exceptions.aaio_bad_request import AAIOBadRequest -from .types.balance import Balance -from .types.create_payoff import CreatePayoff -from .types.payment_info import PaymentInfo -from .types.payment_methods import PaymentMethods, PaymentMethod, PaymentMethodAmounts -from .types.payment_webhook import PaymentWebhookData -from .types.payoff_info import PayoffInfo -from .types.payoff_methods import PayoffMethods, PayoffMethod -from .types.payoff_rates import PayoffRates -from .types.payoff_webhook import PayoffWebhookData +from .client import AAIO +from .exceptions import AAIOBadRequest +from .models import * +from .utils import create_invoice, is_valid_payoff_webhook diff --git a/src/aaio/AAIO.py b/src/aaio/client.py similarity index 82% rename from src/aaio/AAIO.py rename to src/aaio/client.py index 59111fd..28f065f 100644 --- a/src/aaio/AAIO.py +++ b/src/aaio/client.py @@ -1,31 +1,13 @@ import hashlib -from typing import Optional, List +import logging +from typing import List, Optional from urllib.parse import urlencode import aiohttp -from aaio.exceptions.aaio_bad_request import AAIOBadRequest -from aaio.types.balance import Balance -from aaio.types.create_payoff import CreatePayoff -from aaio.types.payment_info import PaymentInfo -from aaio.types.payment_methods import PaymentMethods -from aaio.types.payment_webhook import PaymentWebhookData -from aaio.types.payoff_info import PayoffInfo -from aaio.types.payoff_methods import PayoffMethods -from aaio.types.payoff_rates import PayoffRates -from aaio.types.payoff_sbp_banks import PayoffSbpBanks -from aaio.types.payoff_webhook import PayoffWebhookData - - -async def create_invoice(payment_url: str): - async with aiohttp.ClientSession() as session: - async with session.get(payment_url) as request: - return request.url - - -def is_valid_payoff_webhook(data: PayoffWebhookData, secret_key: str) -> bool: - return hashlib.sha256( - f'{data.id}:{secret_key}:{data.amount_down}'.encode()).hexdigest() == data.sign +from .exceptions import AAIOBadRequest +from .models import PaymentInfo, Balance, CreatePayoff, PayoffSbpBanks, PayoffInfo, PayoffRates, PayoffMethods, \ + PaymentMethods, PaymentWebhookData class AAIO: @@ -35,7 +17,7 @@ class AAIO: API for https://aaio.so/ """ - + def __init__(self, merchant_id: str, secret_1: str, secret_2: str, api_key: str, default_currency: str = 'RUB', base_url: str = 'https://aaio.so'): """ @@ -49,14 +31,14 @@ def __init__(self, merchant_id: str, secret_1: str, secret_2: str, api_key: str, default_currency: If not set - RUB, but can be overwritten for each request (Optional) base_url: Base URL for requests (Optional) """ - + self._default_currency = default_currency self._merchant_id = merchant_id self._api_key = api_key self._secret_1 = secret_1 self._secret_2 = secret_2 self._base_url = base_url - + def __generate_sign(self, amount: float, order_id: str, currency: str) -> str: """ Generates sign for payment creation @@ -70,7 +52,7 @@ def __generate_sign(self, amount: float, order_id: str, currency: str) -> str: Returns: SHA-256 sign """ - + params = f':'.join([ self._merchant_id, str(amount), @@ -80,13 +62,31 @@ def __generate_sign(self, amount: float, order_id: str, currency: str) -> str: ]) sign = hashlib.sha256(params.encode('utf-8')).hexdigest() return sign - + + def __generate_payment_params(self, amount: float, order_id: str, description: str = None, method: str = None, + email: str = None, + referral: str = None, us_key: str = None, currency: str = None, + language: str = 'ru'): + return { + 'merchant_id': self._merchant_id, + 'amount': amount, + 'currency': currency, + 'order_id': order_id, + 'sign': self.__generate_sign(amount, order_id, currency or self._default_currency), + 'desc': description, + 'lang': language, + 'method': method, + 'email': email, + 'referral': referral, + 'us_key': us_key + } + def create_payment(self, amount: float, order_id: str, description: str = None, method: str = None, email: str = None, referral: str = None, us_key: str = None, currency: str = None, language: str = 'ru') -> str: """ - Creates payment URL (Not a request) + Generates payment URL (DEPRECATED) See https://wiki.aaio.so/priem-platezhei/sozdanie-zakaza for more detailed information Args: @@ -103,31 +103,20 @@ def create_payment(self, amount: float, order_id: str, description: str = None, Returns: Payment URL """ - - if not currency: - currency = self._default_currency - params = { - 'merchant_id': self._merchant_id, - 'amount': amount, - 'currency': currency, - 'order_id': order_id, - 'sign': self.__generate_sign(amount, order_id, currency), - 'desc': description, - 'lang': language, - 'method': method, - 'email': email, - 'referral': referral, - 'us_key': us_key - } - + + logging.warning('This method is deprecated, consider using create_pay method instead') + + params = self.__generate_payment_params(amount, order_id, description, method, email, referral, us_key, + currency, language) + return f'{self._base_url}/merchant/pay?' + urlencode({k: v for k, v in params.items() if v is not None}) - + async def get_pay_url(self, amount: float, order_id: str, description: str = None, method: str = None, email: str = None, referral: str = None, us_key: str = None, currency: str = None, language: str = 'ru') -> dict: """ - Creates payment URL, recomended method + Creates payment URL See https://wiki.aaio.so/priem-platezhei/sozdanie-zakaza-zaprosom-rekomenduem for more detailed information Args: @@ -143,32 +132,19 @@ async def get_pay_url(self, amount: float, order_id: str, description: str = Non Returns: dict {"type": "...", "url": "https://......"} """ - - if not currency: - currency = self._default_currency - params = { - 'merchant_id': self._merchant_id, - 'amount': amount, - 'currency': currency, - 'order_id': order_id, - 'sign': self.__generate_sign(amount, order_id, currency), - 'desc': description, - 'lang': language, - 'method': method, - 'email': email, - 'referral': referral, - 'us_key': us_key - } - + + params = self.__generate_payment_params(amount, order_id, description, method, email, referral, us_key, + currency, language) + response = await self.__create_request('/merchant/get_pay_url', params) - + return response - + async def get_ips(self) -> List[str]: response = await self.__create_request('/api/public/ips') - + return response['list'] - + async def get_payment_info(self, order_id: str) -> PaymentInfo: """ Creates a request for get payment information @@ -180,16 +156,16 @@ async def get_payment_info(self, order_id: str) -> PaymentInfo: Returns: Model from response JSON """ - + params = { 'merchant_id': self._merchant_id, 'order_id': order_id } - + response = await self.__create_request('/api/info-pay', params) - + return PaymentInfo(**response) - + async def get_balances(self) -> Balance: """ Creates a request for get balances of user @@ -197,11 +173,11 @@ async def get_balances(self) -> Balance: Returns: Model from response JSON """ - + response = await self.__create_request('/api/balance') - + return Balance(**response) - + async def create_payoff(self, method: str, amount: float, wallet: str, payoff_id: str = '', commission_type: int = 0) -> CreatePayoff: """ @@ -218,7 +194,7 @@ async def create_payoff(self, method: str, amount: float, wallet: str, payoff_id Returns: Model from response JSON """ - + params = { 'my_id': payoff_id, 'method': method, @@ -226,11 +202,11 @@ async def create_payoff(self, method: str, amount: float, wallet: str, payoff_id 'wallet': wallet, 'commission_type': commission_type } - + response = await self.__create_request('/api/create-payoff', params) - + return CreatePayoff(**response) - + async def get_payoff_sbp_banks(self) -> PayoffSbpBanks: """ Returns a list of available banks for payoff @@ -238,9 +214,9 @@ async def get_payoff_sbp_banks(self) -> PayoffSbpBanks: Returns: list of banks """ response = await self.__create_request('/api/sbp-banks-payoff') - + return PayoffSbpBanks(**response) - + async def get_payoff_info(self, payoff_id: str = None, aaio_id: str = None) -> PayoffInfo: """ Creates a request for get payoff information @@ -255,16 +231,16 @@ async def get_payoff_info(self, payoff_id: str = None, aaio_id: str = None) -> P Returns: Model from response JSON """ - + params = { 'my_id': payoff_id, 'id': aaio_id } - + response = await self.__create_request('/api/info-payoff', params) - + return PayoffInfo(**response) - + async def get_payoff_rates(self) -> PayoffRates: """ Creates a request for get rates for payoff @@ -273,11 +249,11 @@ async def get_payoff_rates(self) -> PayoffRates: Returns: Model from response JSON """ - + response = await self.__create_request('/api/rates-payoff') - + return PayoffRates(**response) - + async def get_payoff_methods(self) -> PayoffMethods: """ Creates a request for get available payoff methods @@ -286,11 +262,11 @@ async def get_payoff_methods(self) -> PayoffMethods: Returns: Model from response JSON """ - + response = await self.__create_request('/api/methods-payoff') - + return PayoffMethods(**response) - + async def get_payment_methods(self) -> PaymentMethods: """ Creates a request for get available payment methods @@ -299,15 +275,15 @@ async def get_payment_methods(self) -> PaymentMethods: Returns: Model from response JSON """ - + params = { 'merchant_id': self._merchant_id } - + response = await self.__create_request('/api/methods-pay', params) - + return PaymentMethods(**response) - + async def __create_request(self, uri: str, params: dict = None) -> Optional[dict]: """ Creates a request to base URL and adds URI @@ -319,16 +295,16 @@ async def __create_request(self, uri: str, params: dict = None) -> Optional[dict Returns: Model from response JSON """ - + if params is None: params = {} - + headers = { 'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded', 'X-Api-Key': self._api_key } - + async with aiohttp.ClientSession(self._base_url) as session: async with session.post(uri, headers=headers, data={k: v for k, v in params.items() if v is not None}) as r: @@ -337,7 +313,7 @@ async def __create_request(self, uri: str, params: dict = None) -> Optional[dict return response else: raise AAIOBadRequest(response['code'], response['message']) - + def is_valid_payment_webhook(self, data: PaymentWebhookData) -> bool: return hashlib.sha256( f'{self._merchant_id}:{data.amount}:{self._secret_2}:{data.order_id}'.encode()).hexdigest() == data.sign diff --git a/src/aaio/exceptions/__init__.py b/src/aaio/exceptions/__init__.py new file mode 100644 index 0000000..cb150bc --- /dev/null +++ b/src/aaio/exceptions/__init__.py @@ -0,0 +1 @@ +from .bad_request import AAIOBadRequest diff --git a/src/aaio/exceptions/aaio_bad_request.py b/src/aaio/exceptions/bad_request.py similarity index 83% rename from src/aaio/exceptions/aaio_bad_request.py rename to src/aaio/exceptions/bad_request.py index 367fb61..8415192 100644 --- a/src/aaio/exceptions/aaio_bad_request.py +++ b/src/aaio/exceptions/bad_request.py @@ -1,4 +1,4 @@ -class AAIOBadRequest(BaseException): +class AAIOBadRequest(Exception): def __init__(self, code: int, message: str) -> None: self.code = code self.message = message diff --git a/src/aaio/models/__init__.py b/src/aaio/models/__init__.py new file mode 100644 index 0000000..23e2a30 --- /dev/null +++ b/src/aaio/models/__init__.py @@ -0,0 +1,10 @@ +from .balance import Balance +from .create_payoff import CreatePayoff +from .payment_info import PaymentInfo +from .payment_methods import PaymentMethods, PaymentMethod, PaymentMethodAmounts +from .payment_webhook import PaymentWebhookData +from .payoff_info import PayoffInfo +from .payoff_methods import PayoffMethods, PayoffMethod +from .payoff_rates import PayoffRates +from .payoff_sbp_banks import PayoffSbpBanks, SbpBank +from .payoff_webhook import PayoffWebhookData diff --git a/src/aaio/types/balance.py b/src/aaio/models/balance.py similarity index 100% rename from src/aaio/types/balance.py rename to src/aaio/models/balance.py diff --git a/src/aaio/types/create_payoff.py b/src/aaio/models/create_payoff.py similarity index 100% rename from src/aaio/types/create_payoff.py rename to src/aaio/models/create_payoff.py diff --git a/src/aaio/types/payment_info.py b/src/aaio/models/payment_info.py similarity index 100% rename from src/aaio/types/payment_info.py rename to src/aaio/models/payment_info.py diff --git a/src/aaio/types/payment_methods.py b/src/aaio/models/payment_methods.py similarity index 100% rename from src/aaio/types/payment_methods.py rename to src/aaio/models/payment_methods.py diff --git a/src/aaio/types/payment_webhook.py b/src/aaio/models/payment_webhook.py similarity index 100% rename from src/aaio/types/payment_webhook.py rename to src/aaio/models/payment_webhook.py diff --git a/src/aaio/types/payoff_info.py b/src/aaio/models/payoff_info.py similarity index 100% rename from src/aaio/types/payoff_info.py rename to src/aaio/models/payoff_info.py diff --git a/src/aaio/types/payoff_methods.py b/src/aaio/models/payoff_methods.py similarity index 100% rename from src/aaio/types/payoff_methods.py rename to src/aaio/models/payoff_methods.py diff --git a/src/aaio/types/payoff_rates.py b/src/aaio/models/payoff_rates.py similarity index 100% rename from src/aaio/types/payoff_rates.py rename to src/aaio/models/payoff_rates.py diff --git a/src/aaio/types/payoff_sbp_banks.py b/src/aaio/models/payoff_sbp_banks.py similarity index 100% rename from src/aaio/types/payoff_sbp_banks.py rename to src/aaio/models/payoff_sbp_banks.py diff --git a/src/aaio/types/payoff_webhook.py b/src/aaio/models/payoff_webhook.py similarity index 100% rename from src/aaio/types/payoff_webhook.py rename to src/aaio/models/payoff_webhook.py diff --git a/src/aaio/utils.py b/src/aaio/utils.py new file mode 100644 index 0000000..099c18a --- /dev/null +++ b/src/aaio/utils.py @@ -0,0 +1,16 @@ +import hashlib + +import aiohttp + +from .models import PayoffWebhookData + + +async def create_invoice(payment_url: str): + async with aiohttp.ClientSession() as session: + async with session.get(payment_url) as request: + return request.url + + +def is_valid_payoff_webhook(data: PayoffWebhookData, secret_key: str) -> bool: + return hashlib.sha256( + f'{data.id}:{secret_key}:{data.amount_down}'.encode()).hexdigest() == data.sign