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, the stage.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 arguments batch_mode, batch_reference_id and access_token:

  • api_version will make sure the call is made to a specified API version (cannot be used together with batch_mode)
  • timeout specifies a connection timeout in seconds for the call (cannot be used together with batch_mode)
  • access_token will make sure the call is made with this access_token, also use it to set authorization param in batch_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 without batch_mode set to True
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)
oauth2[source]

OAuth2 call instance.

app[source]

App call instance

user[source]

User call instance

account[source]

Account call instance

checkout[source]

Checkout call instance

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

batch[source]

Batch call instance

call(uri, params=None, access_token=None, api_version=None, timeout=None)[source]

Calls wepay.com/v2/uri with params and returns the JSON response as a python dict. The optional access_token parameter takes precedence over instance’s access_token if it is set. Essentially this is the place for all api calls.

Parameters:
  • uri (str) – API uri to call
  • params (dict) – parameters to include in the call
  • access_token (str) – access_token to use for the call.
  • api_version (str) – allows to create a call to specific version of API
  • timeout (float) – a way to specify a call timeout in seconds. If None will use WePay.timeout.
Returns:

WePay response as documented per call

Return type:

dict

Raises:

WePayClientError

Raises:

WePayServerError

Raises:

WePayConnectionError