-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af788bc
commit 1c0d449
Showing
42 changed files
with
870 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from .account.account import Account | ||
from .account.balance_details import BalanceDetails | ||
|
||
from .operation.operation import Operation | ||
|
||
from yoomoney.operation_details.operation_details import OperationDetails | ||
from yoomoney.operation_details.digital_bonus import DigitalBonus | ||
from yoomoney.operation_details.digital_product import DigitalProduct | ||
from yoomoney.operation_details.digital_good import DigitalGood | ||
|
||
from .history.history import History | ||
|
||
from .authorize.authorize import Authorize | ||
|
||
from .quickpay.quickpay import Quickpay | ||
|
||
from .client import Client | ||
|
||
__all__ = [ | ||
'Client', | ||
'Account', | ||
'BalanceDetails', | ||
'Operation', | ||
'History', | ||
'Authorize', | ||
"OperationDetails", | ||
"DigitalBonus", | ||
"DigitalProduct", | ||
"DigitalGood", | ||
"Quickpay", | ||
] |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import requests | ||
import json | ||
from typing import TYPE_CHECKING, Optional, List | ||
|
||
from yoomoney_async.account.balance_details import BalanceDetails | ||
from yoomoney_async.account.card import Card | ||
from yoomoney_async.exceptions import InvalidToken | ||
|
||
class Account: | ||
|
||
def __init__(self, | ||
base_url: str = None, | ||
token: str = None, | ||
method: str = None, | ||
|
||
): | ||
|
||
self.__private_method = method | ||
|
||
self.__private_base_url = base_url | ||
self.__private_token = token | ||
|
||
data = self._request() | ||
|
||
if len(data) != 0: | ||
self.account = data['account'] | ||
self.balance = data['balance'] | ||
self.currency = data['currency'] | ||
self.account_status = data['account_status'] | ||
self.account_type = data['account_type'] | ||
|
||
self.balance_details = BalanceDetails() | ||
if 'balance_details' in data: | ||
if 'available' in data['balance_details']: | ||
self.balance_details.available = float(data['balance_details']['available']) | ||
if 'blocked' in data['balance_details']: | ||
self.balance_details.blocked = float(data['balance_details']['blocked']) | ||
if 'debt' in data['balance_details']: | ||
self.balance_details.debt = float(data['balance_details']['debt']) | ||
if 'deposition_pending' in data['balance_details']: | ||
self.balance_details.deposition_pending = float(data['balance_details']['deposition_pending']) | ||
if 'total' in data['balance_details']: | ||
self.balance_details.total = float(data['balance_details']['total']) | ||
if 'hold' in data['balance_details']: | ||
self.balance_details.hold = float(data['balance_details']['hold']) | ||
|
||
self.cards_linked = [] | ||
if 'cards_linked' in data: | ||
for card_linked in data['cards_linked']: | ||
card = Card(pan_fragment=card_linked['pan_fragment'], type=card_linked['type']) | ||
self.cards_linked.append(card) | ||
else: | ||
raise InvalidToken() | ||
|
||
def _request(self): | ||
|
||
access_token = str(self.__private_token) | ||
url = self.__private_base_url + self.__private_method | ||
|
||
headers = { | ||
'Authorization': 'Bearer ' + str(access_token), | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
} | ||
|
||
response = requests.request("POST", url, headers=headers) | ||
|
||
return response.json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
|
||
class BalanceDetails: | ||
def __init__(self, | ||
total: float = None, | ||
available: float = None, | ||
deposition_pending: float = None, | ||
blocked: float = None, | ||
debt: float = None, | ||
hold: float = None, | ||
): | ||
|
||
self.total = total | ||
|
||
self.available = available | ||
|
||
self.deposition_pending = deposition_pending | ||
|
||
self.blocked = blocked | ||
|
||
self.debt = debt | ||
|
||
self.hold = hold | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
|
||
|
||
class Card: | ||
def __init__(self, | ||
pan_fragment: str = None, | ||
type: str = None, | ||
): | ||
self.pan_fragment = pan_fragment | ||
self.type = type | ||
|
Empty file.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from typing import List | ||
import requests | ||
|
||
from yoomoney_async.exceptions import ( | ||
InvalidRequest, | ||
UnauthorizedClient, | ||
InvalidGrant, | ||
EmptyToken | ||
) | ||
|
||
class Authorize: | ||
def __init__( | ||
self, | ||
client_id: str, | ||
redirect_uri: str, | ||
scope: List[str] | ||
): | ||
|
||
url = "https://yoomoney.ru/oauth/authorize?client_id={client_id}&response_type=code" \ | ||
"&redirect_uri={redirect_uri}&scope={scope}".format(client_id=client_id, | ||
redirect_uri=redirect_uri, | ||
scope='%20'.join([str(elem) for elem in scope]), | ||
) | ||
|
||
headers = { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
} | ||
|
||
response = requests.request("POST", url, headers=headers) | ||
|
||
if response.status_code == 200: | ||
print("Visit this website and confirm the application authorization request:") | ||
print(response.url) | ||
|
||
code = str(input("Enter redirected url (https://yourredirect_uri?code=XXXXXXXXXXXXX) or just code: ")) | ||
try: | ||
code = code[code.index("code=") + 5:].replace(" ","") | ||
except: | ||
pass | ||
|
||
url = "https://yoomoney.ru/oauth/token?code={code}&client_id={client_id}&" \ | ||
"grant_type=authorization_code&redirect_uri={redirect_uri}".format(code=str(code), | ||
client_id=client_id, | ||
redirect_uri=redirect_uri, | ||
) | ||
|
||
response = requests.request("POST", url, headers=headers) | ||
|
||
if "error" in response.json(): | ||
error = response.json()["error"] | ||
if error == "invalid_request": | ||
raise InvalidRequest() | ||
elif error == "unauthorized_client": | ||
raise UnauthorizedClient() | ||
elif error == "invalid_grant": | ||
raise InvalidGrant() | ||
|
||
if response.json()['access_token'] == "": | ||
raise EmptyToken() | ||
|
||
print("Your access token:") | ||
print(response.json()['access_token']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import datetime | ||
from yoomoney_async.history.history import History | ||
|
||
class Client: | ||
def __init__(self, | ||
token: str = None, | ||
base_url: str = None, | ||
): | ||
|
||
if base_url is None: | ||
self.base_url = "https://yoomoney.ru/api/" | ||
|
||
if token is not None: | ||
self.token = token | ||
|
||
async def operation_history(self, | ||
type: str = None, | ||
label: str = None, | ||
from_date: datetime.datetime = None, | ||
till_date: datetime.datetime = None, | ||
start_record: str = None, | ||
records: int = None, | ||
details: bool = None, | ||
): | ||
method = "operation-history" | ||
return await History(base_url=self.base_url, | ||
token=self.token, | ||
method=method, | ||
type=type, | ||
label=label, | ||
from_date=from_date, | ||
till_date=till_date, | ||
start_record=start_record, | ||
records=records, | ||
details=details, | ||
).start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
|
||
|
||
class YooMoneyError(Exception): | ||
"""Basic class""" | ||
|
||
|
||
class InvalidToken(YooMoneyError): | ||
|
||
message = "Token is not valid, or does not have the appropriate rights" | ||
def __init__(self, ): | ||
super().__init__(self.message) | ||
|
||
|
||
class IllegalParamType(YooMoneyError): | ||
|
||
message = "Invalid parameter value 'type'" | ||
def __init__(self, ): | ||
super().__init__(self.message) | ||
|
||
class IllegalParamStartRecord(YooMoneyError): | ||
|
||
message = "Invalid parameter value 'start_record'" | ||
def __init__(self, ): | ||
super().__init__(self.message) | ||
|
||
|
||
class IllegalParamRecords(YooMoneyError): | ||
|
||
message = "Invalid parameter value 'records'" | ||
def __init__(self, ): | ||
super().__init__(self.message) | ||
|
||
class IllegalParamLabel(YooMoneyError): | ||
|
||
message = "Invalid parameter value 'label'" | ||
def __init__(self, ): | ||
super().__init__(self.message) | ||
|
||
class IllegalParamFromDate(YooMoneyError): | ||
|
||
message = "Invalid parameter value 'from_date'" | ||
def __init__(self, ): | ||
super().__init__(self.message) | ||
|
||
|
||
class IllegalParamTillDate(YooMoneyError): | ||
|
||
message = "Invalid parameter value 'till_date'" | ||
def __init__(self, ): | ||
super().__init__(self.message) | ||
|
||
class IllegalParamOperationId(YooMoneyError): | ||
|
||
message = "Invalid parameter value 'operation_id'" | ||
def __init__(self, ): | ||
super().__init__(self.message) | ||
|
||
class TechnicalError(YooMoneyError): | ||
|
||
message = "Technical error, try calling the operation again later" | ||
def __init__(self, ): | ||
super().__init__(self.message) | ||
|
||
class InvalidRequest(YooMoneyError): | ||
|
||
message = "Required query parameters are missing or have incorrect or invalid values" | ||
def __init__(self, ): | ||
super().__init__(self.message) | ||
|
||
class UnauthorizedClient(YooMoneyError): | ||
|
||
message = "Invalid parameter value 'client_id' or 'client_secret', or the application" \ | ||
" does not have the right to request authorization (for example, YooMoney blocked it 'client_id')" | ||
def __init__(self, ): | ||
super().__init__(self.message) | ||
|
||
class InvalidGrant(YooMoneyError): | ||
|
||
message = "In issue 'access_token' denied. YuMoney did not issue a temporary token, " \ | ||
"the token is expired, or this temporary token has already been issued " \ | ||
"'access_token' (repeated request for an authorization token with the same temporary token)" | ||
def __init__(self, ): | ||
super().__init__(self.message) | ||
|
||
class EmptyToken(YooMoneyError): | ||
|
||
message = "Response token is empty. Repeated request for an authorization token" | ||
def __init__(self, ): | ||
super().__init__(self.message) |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.