Skip to content

Commit

Permalink
v1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kewldan committed Mar 1, 2024
1 parent 9cc4915 commit 98f5006
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 18 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 *06 February 2024*.
API is up-to-date as of *01 March 2024*.

* PyPl - https://pypi.org/project/aaio/
* Github - https://github.com/kewldan/AAIO
Expand Down Expand Up @@ -78,11 +78,11 @@ from aaio import AAIO


async def main():
client = AAIO('MERCHANT ID', 'SECRET KEY', 'API KEY')
payment_url = client.create_payment(100, 'my_order_id', 'My order description', 'qiwi', '[email protected]',
'referral code', currency='USD',
language='en')
print(payment_url) # Prints payment url for customer
client = AAIO('MERCHANT ID', 'SECRET KEY', 'API KEY')
payment_url = client.create_payment(100, 'my_order_id', 'My order description', 'qiwi', '[email protected]',
'referral code', currency='USD',
language='en')
print(payment_url) # Prints payment url for customer


asyncio.run(main())
Expand All @@ -97,18 +97,18 @@ from aaio import AAIO


async def main():
client = AAIO('MERCHANT ID', 'SECRET KEY', 'API KEY')
payoff = await client.create_payoff('qiwi', 100.35, '79998887766', 'my_payoff_id')
print(payoff.status) # in_progress
client = AAIO('MERCHANT ID', 'SECRET KEY', 'API KEY')
payoff = await client.create_payoff('qiwi', 100.35, '79998887766', 'my_payoff_id')
print(payoff.status) # in_progress


asyncio.run(main())
```

## Contact

E-Mail - [email protected]
Telegram - [@kewldan](https://t.me/kewldan)
* E-Mail - [email protected]
* Telegram - [@kewldan](https://t.me/kewldan)

## License

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "aaio"
version = "1.3.0"
version = "1.3.1"
description = "Async AAIO api wrapper for python"
readme = "README.md"
authors = [{ name = "kewldan", email = "[email protected]" }]
Expand Down
21 changes: 17 additions & 4 deletions src/aaio/AAIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
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):
Expand All @@ -21,6 +23,11 @@ async def create_invoice(payment_url: str):
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


class AAIO:
"""
AAIO client for API interaction
Expand All @@ -29,14 +36,15 @@ class AAIO:
API for https://aaio.so/
"""

def __init__(self, merchant_id: str, secret: str, api_key: str, default_currency: str = 'RUB',
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'):
"""
Creates instance of one AAIO merchant API client
Args:
merchant_id: Merchant ID from https://aaio.so/cabinet
secret: 1st secret key from https://aaio.so/cabinet
secret_1: 1st secret key from https://aaio.so/cabinet
secret_2: 2nd secret key from https://aaio.so/cabinet
api_key: API key from https://aaio.so/cabinet/api
default_currency: If not set - RUB, but can be overwritten for each request (Optional)
base_url: Base URL for requests (Optional)
Expand All @@ -45,7 +53,8 @@ def __init__(self, merchant_id: str, secret: str, api_key: str, default_currency
self._default_currency = default_currency
self._merchant_id = merchant_id
self._api_key = api_key
self._secret = secret
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:
Expand All @@ -66,7 +75,7 @@ def __generate_sign(self, amount: float, order_id: str, currency: str) -> str:
self._merchant_id,
str(amount),
currency,
self._secret,
self._secret_1,
order_id
])
sign = hashlib.sha256(params.encode('utf-8')).hexdigest()
Expand Down Expand Up @@ -285,3 +294,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
5 changes: 3 additions & 2 deletions src/aaio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from .AAIO import AAIO
from .AAIO import create_invoice
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
20 changes: 20 additions & 0 deletions src/aaio/types/payment_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import Literal

from pydantic import BaseModel


class PaymentWebhookData(BaseModel):
merchant_id: str
invoice_id: str
order_id: str
amount: float
currency: Literal['RUB', 'UAH', 'EUR', 'USD']
profit: float
commission: float
commission_client: float
commission_type: str
sign: str
method: str
desc: str
email: str
us_key: str
23 changes: 23 additions & 0 deletions src/aaio/types/payoff_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from typing import Literal

from pydantic import BaseModel


class PayoffWebhookData(BaseModel):
id: str
my_id: str
method: str
bank: str
wallet: str
amount: float
amount_in_currency: float
amount_currency: str
amount_rate: float
amount_down: float
commission: float
commission_type: Literal[0, 1]
status: Literal['cancel', 'success']
cancel_message: str | None = None
date: str
complete_date: str
sign: str

0 comments on commit 98f5006

Please sign in to comment.