wepay.api
Module¶
This module was designed to help making WePay API calls.
-
class
wepay.api.
WePay
(production=True, access_token=None, api_version=None, timeout=30, silent=None, use_requests=None)[source]¶ A full client for the WePay API.
Parameters: - production (bool) – When
False
, thestage.wepay.com
API server will be used instead of the default production. - access_token (str) – The access token associated with your application.
- api_version (str) – sets default version of API which will be accepting calls. It is also possible to specify different version per API call, since all calls accept a keyword argument api_version as well. More on API versioning.
- timeout (float) – time in seconds before HTTPS call request will timeout. Also can be changed on per call basis.
- silent (bool) – if set to None (default) will print
WePayWarning
if production=True and raise them otherwise. Set it to True to stop parameter validation and suppress all warnings, or False to raise all warnings. - use_requests (bool) – set to False in order to explicitly turn off requests library usage and fallback to urllib
Instance of this class contains attributes, which correspond to WePay objects and should be used to perform API calls. If a WePay object has a lookup call, corresponding attribute will also be callable. Example:
>>> api = WePay(production=False, access_token=WEPAY_ACCESS_TOKEN) >>> response = api.account.create('Test Account', 'Short Description') >>> api.account(response['account_id'])
Each method that performs an API call accepts all required parameters as positional arguments, optional parameters as keyword arguments, as well as one or more keyword arguments that are used to control behavior of a call. All these methods accept keyword arguments
api_version
,timeout
and if documented also possible keyword argumentsbatch_mode
,batch_reference_id
andaccess_token
:api_version
will make sure the call is made to a specified API version (cannot be used together withbatch_mode
)timeout
specifies a connection timeout in seconds for the call (cannot be used together withbatch_mode
)access_token
will make sure the call is made with this access_token, also use it to set authorization param inbatch_mode
.batch_mode
instead of performing an actual call to WePay, a method will return a dictionary that is ready to be added to /batch/create, namely to calls list parameter.batch.create
batch_reference_id
will set reference_id param in a batch call, it is an error to use it withoutbatch_mode
set toTrue
- Batch mode usage example:
>>> api = WePay(production=False, access_token=WEPAY_ACCESS_TOKEN) >>> calls = [] >>> calls.append(api.account.create('Test Account', 'Short Description', batch_mode=True, access_token='STAGE_...', batch_reference_id='c1')) >>> calls.append(api.checkout(12345, batch_mode=True)) >>> api.batch.create(CLIENT_ID, CLIENT_SECRET, calls)
-
preapproval
[source]¶ Preapproval
call instance
-
withdrawal
[source]¶ Withdrawal
call instance
-
credit_card
[source]¶ CreditCard
call instance
-
subscription_plan
[source]¶ SubscriptionPlan
call instance
-
subscription
[source]¶ Subscription
call instance
-
subscription_charge
[source]¶ SubscriptionCharge
call instance
-
call
(uri, params=None, access_token=None, api_version=None, timeout=None)[source]¶ Calls wepay.com/v2/
uri
withparams
and returns the JSON response as a python dict. The optionalaccess_token
parameter takes precedence over instance’saccess_token
if it is set. Essentially this is the place for all api calls.Parameters: Returns: WePay response as documented per call
Return type: Raises: Raises: Raises:
- production (bool) – When