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.comAPI 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
WePayWarningif 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,timeoutand if documented also possible keyword argumentsbatch_mode,batch_reference_idandaccess_token:api_versionwill make sure the call is made to a specified API version (cannot be used together withbatch_mode)timeoutspecifies a connection timeout in seconds for the call (cannot be used together withbatch_mode)access_tokenwill make sure the call is made with this access_token, also use it to set authorization param inbatch_mode.batch_modeinstead 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.createbatch_reference_idwill set reference_id param in a batch call, it is an error to use it withoutbatch_modeset 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]¶ Preapprovalcall instance
-
withdrawal[source]¶ Withdrawalcall instance
-
credit_card[source]¶ CreditCardcall instance
-
subscription_plan[source]¶ SubscriptionPlancall instance
-
subscription[source]¶ Subscriptioncall instance
-
subscription_charge[source]¶ SubscriptionChargecall instance
-
call(uri, params=None, access_token=None, api_version=None, timeout=None)[source]¶ Calls wepay.com/v2/
uriwithparamsand returns the JSON response as a python dict. The optionalaccess_tokenparameter takes precedence over instance’saccess_tokenif 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