Skip to content

Commit

Permalink
First commit!
Browse files Browse the repository at this point in the history
  • Loading branch information
HK-Mattew committed Apr 27, 2024
0 parents commit c539432
Show file tree
Hide file tree
Showing 9 changed files with 411 additions and 0 deletions.
107 changes: 107 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Created by .ignore support plugin (hsz.mobi)
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
.static_storage/
.media/
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 HK-Mattew

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# AsyncIO Payeer Client

Implementation of AsyncIO Client for Payeer API.

Before use, it is advisable to familiarize yourself with the official Payeer documentation (https://payeercom.docs.apiary.io/). The application implements the interaction protocol described in this document.

## Installation

```
pip install git+https://github.com/HK-Mattew/python-payeer-asyncio
```

## Example of use

```python
from payeer_asyncio import PayeerAsyncIO
import asyncio



async def main():


payeer = PayeerAsyncIO(
account='<your-account>',
apiId='<your-api-id>',
apiPass='<your-api-pass>'
)


balance = await payeer.get_balance()

print(balance)




if __name__ == "__main__":
asyncio.run(main())
```
1 change: 1 addition & 0 deletions payeer_asyncio/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .api import PayeerAsyncIO, PayeerAPIException
187 changes: 187 additions & 0 deletions payeer_asyncio/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
from .exceptions import PayeerAPIException
from .utils.account import validate_account
from typing import (
Dict
)
import httpx
import copy




class PayeerAsyncIO:
"""Payeer API Client"""

def __init__(self, account: str, apiId: str, apiPass: str):
"""
:param account: Your account number in the Payeer. Example: P1000000
:param apiId: The API user ID; given out when adding the API
:param apiPass: The API user's secret key
"""
self.account = account
self.apiId = apiId
self.apiPass = apiPass
self.api_url = 'https://payeer.com/ajax/api/api.php'
self.auth_data = {
'account': self.account,
'apiId': self.apiId,
'apiPass': self.apiPass
}


async def request(self, **kwargs) -> Dict:
"""The main request method for Payeer API"""

data = copy.deepcopy(self.auth_data)

if kwargs:
data.update(kwargs)

async with httpx.AsyncClient() as client:
http_resp = await client.post(self.api_url, data=data)
resp_json = http_resp.json()

error = resp_json.get('errors')
if error:
raise PayeerAPIException(error)
else:
return resp_json


async def get_balance(self):
"""
Balance Check
Obtain wallet balance.
"""
return (await self.request(action='balance'))['balance']


async def check_user(self, user):
"""
Checking Existence of Account
:param user: user’s account number in the format P1000000
:return: True if exists
"""
try:
await self.request(action='checkUser', user=user)
except PayeerAPIException:
return False
return True


async def get_exchange_rate(self, output='N'):
"""
Automatic Conversion Rates
:param output: select currencies for conversion rates (N - get deposit rates Y - get withdrawal rates)
:return: dict
"""
return (await self.request(action='getExchangeRate', output=output))['rate']


async def get_pay_systems(self):
"""
Getting Available Payment Systems
:return: dict
"""
return (await self.request(action='getPaySystems'))['list']


async def get_history_info(self, history_id):
"""
Getting Information about a Transaction
:param history_id: transaction ID
:return: dict
"""
return (await self.request(action='historyInfo', historyId=history_id))['info']


async def shop_order_info(self, shop_id, order_id):
"""
Information on a Store Transaction
:param shop_id: merchant ID (m_shop)
:param order_id: transaction ID in your accounting system (m_orderid)
:return: dict
"""
return await self.request(action='shopOrderInfo', shopId=shop_id, orderId=order_id)


async def transfer(self, sum, to, cur_in='USD', cur_out='USD',
comment=None, protect=None, protect_period=None, protect_code=None):
"""
Transferring Funds
:param sum: amount withdrawn (the amount deposited will be calculated automatically, factoring in all fees from the recipient)
:param to: user’s Payeer account number or email address
:param cur_in: currency with which the withdrawal will be performed (USD, EUR, RUB)
:param cur_out: deposit currency (USD, EUR, RUB)
:param comment: comments on the transfer
:param protect: activation of transaction protection, set Y to enable
:param protect_period: protection period: 1–30 days
:param protect_code: protection code
:return: True if the payment is successful
"""
await validate_account(to)
data = {'action': 'transfer', 'sum': sum, 'to': to, 'curIn': cur_in, 'curOut': cur_out}
if comment:
data['comment'] = comment
if protect:
data['protect'] = protect
if protect_period:
data['protectPeriod'] = protect_period
if protect_code:
data['protectCode'] = protect_code

return await self.request(**data)


async def check_output(self, ps, ps_account, sum_in, cur_in='USD', cur_out='USD'):
"""
Checking Possibility of Payout
This method allows you to check the possibility of a payout without actually creating a payout
(you can get the withdrawal/reception amount or check errors in parameters)
:param ps: ID of selected payment system
:param ps_account: recipient's account number in the selected payment system
:param sum_in: amount withdrawn (the amount deposited will be calculated automatically, factoring in all fees from the recipient)
:param cur_in: currency with which the withdrawal will be performed
:param cur_out: deposit currency
:return: True if the payment is successful
"""
data = {'action': 'initOutput', 'ps': ps, 'param_ACCOUNT_NUMBER': ps_account,
'sumIn': sum_in, 'curIn': cur_in, 'curOut': cur_out}
try:
await self.request(**data)
except PayeerAPIException:
return False
return True


async def output(self, ps, ps_account, sum_in, cur_in='USD', cur_out='USD'):
"""
Payout
:param ps: ID of selected payment system
:param ps_account: recipient's account number in the selected payment system
:param sum_in: amount withdrawn (the amount deposited will be calculated automatically, factoring in all fees from the recipient)
:param cur_in: currency with which the withdrawal will be performed
:param cur_out: deposit currency
:return:
"""
data = {'action': 'output', 'ps': ps, 'param_ACCOUNT_NUMBER': ps_account,
'sumIn': sum_in, 'curIn': cur_in, 'curOut': cur_out}
return await self.request(**data)


async def history(self, **kwargs):
"""
History of transactions
:param sort: sorting by date (asc, desc)
:param count: count of records (max 1000)
:param from: begin of the period
:param to: end of the period
:param type: transaction type (incoming - incoming payments, outgoing - outgoing payments)
:param append: id of the previous transaction
:return:
"""
kwargs['action'] = 'history'
return (await self.request(**kwargs))['history']



7 changes: 7 additions & 0 deletions payeer_asyncio/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@



class PayeerAPIException(Exception):
"""Base payeer api exception class"""


8 changes: 8 additions & 0 deletions payeer_asyncio/utils/account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import re


async def validate_account(wallet):
if not re.match("^[Pp]{1}[0-9]{7,15}|.+@.+\..+$", wallet):
raise ValueError('Wrong account format!')


1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
httpx ~= 0.27
Loading

0 comments on commit c539432

Please sign in to comment.