├── payeer_api ├── __init__.py └── api.py ├── setup.py ├── README.rst ├── LICENSE └── .gitignore /payeer_api/__init__.py: -------------------------------------------------------------------------------- 1 | from .api import PayeerAPI, PayeerAPIException -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from os.path import join, dirname 3 | from setuptools import setup, find_packages 4 | 5 | setup(name='payeer_api', 6 | version='0.1', 7 | description='Python Payeer API client', 8 | long_description=open(join(dirname(__file__), 'README.rst'),encoding='utf8').read(), 9 | author='AshotS', 10 | author_email='sarckisyanashot@yandex.ru', 11 | url='https://github.com/AshotS/payeer_api', 12 | packages=['payeer_api'], 13 | requires=['requests'], 14 | license='MIT license', 15 | keywords="payeer", 16 | ) 17 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ================ 2 | payeer_api 3 | ================ 4 | 5 | payeer_api - Реализация клиента для Payeer API. 6 | 7 | До использования следует ознакомиться с официальной документацией 8 | Payeer (https://payeercom.docs.apiary.io/). Приложение реализует 9 | протокол взаимодействия, описанный в этом документе. 10 | 11 | Установка 12 | ========= 13 | 14 | :: 15 | 16 | $ pip install payeer_api 17 | 18 | Использование 19 | ============= 20 | 21 | Пример:: 22 | 23 | from payeer_api import PayeerAPI 24 | 25 | account = 'P1000000' 26 | api_id = '123456789' 27 | api_pass = 'KRicaFodFrgJer6' 28 | 29 | p = PayeerAPI(account, api_id, api_pass) 30 | 31 | p.get_balance() 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 AshotS 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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Python template 3 | # Byte-compiled / optimized / DLL files 4 | __pycache__/ 5 | *.py[cod] 6 | *$py.class 7 | 8 | # C extensions 9 | *.so 10 | 11 | # Distribution / packaging 12 | .Python 13 | build/ 14 | develop-eggs/ 15 | dist/ 16 | downloads/ 17 | eggs/ 18 | .eggs/ 19 | lib/ 20 | lib64/ 21 | parts/ 22 | sdist/ 23 | var/ 24 | wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | .hypothesis/ 50 | 51 | # Translations 52 | *.mo 53 | *.pot 54 | 55 | # Django stuff: 56 | *.log 57 | .static_storage/ 58 | .media/ 59 | local_settings.py 60 | 61 | # Flask stuff: 62 | instance/ 63 | .webassets-cache 64 | 65 | # Scrapy stuff: 66 | .scrapy 67 | 68 | # Sphinx documentation 69 | docs/_build/ 70 | 71 | # PyBuilder 72 | target/ 73 | 74 | # Jupyter Notebook 75 | .ipynb_checkpoints 76 | 77 | # pyenv 78 | .python-version 79 | 80 | # celery beat schedule file 81 | celerybeat-schedule 82 | 83 | # SageMath parsed files 84 | *.sage.py 85 | 86 | # Environments 87 | .env 88 | .venv 89 | env/ 90 | venv/ 91 | ENV/ 92 | env.bak/ 93 | venv.bak/ 94 | 95 | # Spyder project settings 96 | .spyderproject 97 | .spyproject 98 | 99 | # Rope project settings 100 | .ropeproject 101 | 102 | # mkdocs documentation 103 | /site 104 | 105 | # mypy 106 | .mypy_cache/ 107 | 108 | -------------------------------------------------------------------------------- /payeer_api/api.py: -------------------------------------------------------------------------------- 1 | import re 2 | import requests 3 | 4 | 5 | def validate_wallet(wallet): 6 | if not re.match('P\d{7,12}$', wallet): 7 | raise ValueError('Wrong wallet format!') 8 | 9 | 10 | class PayeerAPIException(Exception): 11 | """Base payeer api exception class""" 12 | 13 | 14 | class PayeerAPI: 15 | """Payeer API Client""" 16 | 17 | def __init__(self, account, apiId, apiPass): 18 | """ 19 | :param account: Your account number in the Payeer system. Example: P1000000 20 | :param apiId: The API user’s ID; given out when adding the API 21 | :param apiPass: The API user's secret key 22 | """ 23 | validate_wallet(account) 24 | self.account = account 25 | self.apiId = apiId 26 | self.apiPass = apiPass 27 | self.api_url = 'https://payeer.com/ajax/api/api.php' 28 | self.auth_data = {'account': self.account, 'apiId': self.apiId, 'apiPass': self.apiPass} 29 | self.auth_check() 30 | 31 | def request(self, **kwargs): 32 | """The main request method for Payeer API""" 33 | data = self.auth_data 34 | if kwargs: 35 | data.update(kwargs) 36 | resp = requests.post(url=self.api_url, data=data).json() 37 | error = resp.get('errors') 38 | if error: 39 | raise PayeerAPIException(error) 40 | else: 41 | return resp 42 | 43 | def auth_check(self): 44 | """ 45 | Authorization Check 46 | :return: True if auth is successful 47 | """ 48 | self.request() 49 | 50 | def get_balance(self): 51 | """ 52 | Balance Check 53 | Obtain wallet balance. 54 | """ 55 | return self.request(action='balance')['balance'] 56 | 57 | def check_user(self, user): 58 | """ 59 | Checking Existence of Account 60 | :param user: user’s account number in the format P1000000 61 | :return: True if exists 62 | """ 63 | try: 64 | self.request(action='checkUser', user=user) 65 | except PayeerAPIException: 66 | return False 67 | return True 68 | 69 | def get_exchange_rate(self, output='N'): 70 | """ 71 | Automatic Conversion Rates 72 | :param output: select currencies for conversion rates (N - get deposit rates Y - get withdrawal rates) 73 | :return: dict 74 | """ 75 | return self.request(action='getExchangeRate', output=output)['rate'] 76 | 77 | def get_pay_systems(self): 78 | """ 79 | Getting Available Payment Systems 80 | :return: dict 81 | """ 82 | return self.request(action='getPaySystems')['list'] 83 | 84 | def get_history_info(self, history_id): 85 | """ 86 | Getting Information about a Transaction 87 | :param history_id: transaction ID 88 | :return: dict 89 | """ 90 | return self.request(action='historyInfo', historyId=history_id)['info'] 91 | 92 | def shop_order_info(self, shop_id, order_id): 93 | """ 94 | Information on a Store Transaction 95 | :param shop_id: merchant ID (m_shop) 96 | :param order_id: transaction ID in your accounting system (m_orderid) 97 | :return: dict 98 | """ 99 | return self.request(action='shopOrderInfo', shopId=shop_id, orderId=order_id) 100 | 101 | def transfer(self, sum, to, cur_in='USD', cur_out='USD', 102 | comment=None, protect=None, protect_period=None, protect_code=None): 103 | """ 104 | Transferring Funds 105 | :param sum: amount withdrawn (the amount deposited will be calculated automatically, factoring in all fees from the recipient) 106 | :param to: user’s Payeer account number or email address 107 | :param cur_in: currency with which the withdrawal will be performed (USD, EUR, RUB) 108 | :param cur_out: deposit currency (USD, EUR, RUB) 109 | :param comment: comments on the transfer 110 | :param protect: activation of transaction protection, set Y to enable 111 | :param protect_period: protection period: 1–30 days 112 | :param protect_code: protection code 113 | :return: True if the payment is successful 114 | """ 115 | validate_wallet(to) 116 | data = {'action': 'transfer', 'sum': sum, 'to': to, 'curIn': cur_in, 'curOut': cur_out} 117 | if comment: data['comment'] = comment 118 | if protect: 119 | data['protect'] = protect 120 | if protect_period: data['protectPeriod'] = protect_period 121 | if protect_code: data['protectCode'] = protect_code 122 | resp = self.request(**data) 123 | if resp.get('historyId', 0) > 0: 124 | return True 125 | else: 126 | return False 127 | 128 | def check_output(self, ps, ps_account, sum_in, cur_in='USD', cur_out='USD'): 129 | """ 130 | Checking Possibility of Payout 131 | This method allows you to check the possibility of a payout without actually creating a payout 132 | (you can get the withdrawal/reception amount or check errors in parameters) 133 | :param ps: ID of selected payment system 134 | :param ps_account: recipient's account number in the selected payment system 135 | :param sum_in: amount withdrawn (the amount deposited will be calculated automatically, factoring in all fees from the recipient) 136 | :param cur_in: currency with which the withdrawal will be performed 137 | :param cur_out: deposit currency 138 | :return: True if the payment is successful 139 | """ 140 | data = {'action': 'initOutput', 'ps': ps, 'param_ACCOUNT_NUMBER': ps_account, 141 | 'sumIn': sum_in, 'curIn': cur_in, 'curOut': cur_out} 142 | try: 143 | self.request(**data) 144 | except PayeerAPIException: 145 | return False 146 | return True 147 | 148 | def output(self, ps, ps_account, sum_in, cur_in='USD', cur_out='USD'): 149 | """ 150 | Payout 151 | :param ps: ID of selected payment system 152 | :param ps_account: recipient's account number in the selected payment system 153 | :param sum_in: amount withdrawn (the amount deposited will be calculated automatically, factoring in all fees from the recipient) 154 | :param cur_in: currency with which the withdrawal will be performed 155 | :param cur_out: deposit currency 156 | :return: 157 | """ 158 | data = {'action': 'output', 'ps': ps, 'param_ACCOUNT_NUMBER': ps_account, 159 | 'sumIn': sum_in, 'curIn': cur_in, 'curOut': cur_out} 160 | return self.request(**data) 161 | 162 | def history(self, **kwargs): 163 | """ 164 | History of transactions 165 | :param sort: sorting by date (asc, desc) 166 | :param count: count of records (max 1000) 167 | :param from: begin of the period 168 | :param to: end of the period 169 | :param type: transaction type (incoming - incoming payments, outgoing - outgoing payments) 170 | :param append: id of the previous transaction 171 | :return: 172 | """ 173 | kwargs['action'] = 'history' 174 | return self.request(**kwargs)['history'] 175 | --------------------------------------------------------------------------------