Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to return full response on transfer #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions payeer_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ class PayeerAPIException(Exception):
class PayeerAPI:
"""Payeer API Client"""

def __init__(self, account, apiId, apiPass):
def __init__(self, account, apiId, apiPass, timeout = None):
"""
:param account: Your account number in the Payeer system. Example: P1000000
:param apiId: The API user’s ID; given out when adding the API
:param apiPass: The API user's secret key
:param timeout: timeout for requests
"""
validate_wallet(account)
self.account = account
self.apiId = apiId
self.apiPass = apiPass
self.timeout = timeout
self.api_url = 'https://payeer.com/ajax/api/api.php'
self.auth_data = {'account': self.account, 'apiId': self.apiId, 'apiPass': self.apiPass}
self.auth_check()
Expand All @@ -33,7 +35,7 @@ def request(self, **kwargs):
data = self.auth_data
if kwargs:
data.update(kwargs)
resp = requests.post(url=self.api_url, data=data).json()
resp = requests.post(url=self.api_url, data=data, timeout=self.timeout).json()
error = resp.get('errors')
if error:
raise PayeerAPIException(error)
Expand Down Expand Up @@ -99,7 +101,8 @@ def shop_order_info(self, shop_id, order_id):
return self.request(action='shopOrderInfo', shopId=shop_id, orderId=order_id)

def transfer(self, sum, to, cur_in='USD', cur_out='USD',
comment=None, protect=None, protect_period=None, protect_code=None):
comment=None, protect=None, protect_period=None, protect_code=None,
return_full_response = False):
"""
Transferring Funds
:param sum: amount withdrawn (the amount deposited will be calculated automatically, factoring in all fees from the recipient)
Expand All @@ -110,7 +113,8 @@ def transfer(self, sum, to, cur_in='USD', cur_out='USD',
: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
:param return_full_response: return full system resopnce on exit
:return: True if the payment is successful (full response in json if return_full_response)
"""
validate_wallet(to)
data = {'action': 'transfer', 'sum': sum, 'to': to, 'curIn': cur_in, 'curOut': cur_out}
Expand All @@ -120,7 +124,9 @@ def transfer(self, sum, to, cur_in='USD', cur_out='USD',
if protect_period: data['protectPeriod'] = protect_period
if protect_code: data['protectCode'] = protect_code
resp = self.request(**data)
if resp.get('historyId', 0) > 0:
if return_full_response:
return resp
elif resp.get('historyId', 0) > 0:
return True
else:
return False
Expand Down