Welcome to python-wepay’s documentation!

Python WePay SDK (third party)

Before using this package get yourself familiar with actual WePay API Documentation.

WePay is a great service, highly recommend it.

Contents:

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

wepay.calls.account Module

class wepay.calls.account.Account(api)[source]

The /account API calls

membership[source]

Membership call instance

__call__(account_id, **kwargs)[source]

Call documentation: /account, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
find(**kwargs)

Call documentation: /account/find, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
create(name, description, **kwargs)

Call documentation: /account/create, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
modify(account_id, **kwargs)

Call documentation: /account/modify, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
delete(account_id, **kwargs)

Call documentation: /account/delete, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
get_update_uri(account_id, **kwargs)

Call documentation: /account/get_update_uri, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
get_reserve_details(account_id, **kwargs)

Call documentation: /account/get_reserve_details, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
balance(account_id, **kwargs)

Call documentation: /account/balance, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay

Warning

This call is depricated as of API version ‘2014-01-08’.

add_bank(account_id, **kwargs)

Call documentation: /account/add_bank, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay

Warning

This call is depricated as of API version ‘2014-01-08’.

set_tax(account_id, taxes, **kwargs)

Call documentation: /account/set_tax, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay

Warning

This call is depricated as of API version ‘2014-01-08’.

get_tax(account_id, **kwargs)

Call documentation: /account/get_tax, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay

Warning

This call is depricated as of API version ‘2014-01-08’.

class wepay.calls.account.Membership(api)[source]

The /account/membership API calls

create(account_id, member_access_token, **kwargs)

Call documentation: /account/membership/create, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
modify(account_id, user_id, **kwargs)

Call documentation: /account/membership/modify, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
remove(account_id, user_id, **kwargs)

Call documentation: /account/membership/remove, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay

wepay.calls.app Module

class wepay.calls.app.App(api)[source]

The /app API calls

__call__(client_id, client_secret, **kwargs)[source]

Call documentation: /app, plus extra keyword parameter:

Parameters:
modify(client_id, client_secret, **kwargs)

Call documentation: /app/modify, plus extra keyword parameter:

Parameters:

wepay.calls.batch Module

class wepay.calls.batch.Batch(api)[source]

The /batch API calls

create(client_id, client_secret, calls, **kwargs)

Call documentation: /batch/create, plus extra keyword parameter:

Parameters:access_token (str) – will be used instead of instance’s access_token

wepay.calls.checkout Module

class wepay.calls.checkout.Checkout(api)[source]

The /checkout API calls

__call__(checkout_id, **kwargs)[source]

Call documentation: /checkout, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
find(account_id, **kwargs)

Call documentation: /checkout/find, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
create(account_id, short_description, type, amount, **kwargs)

Call documentation: /checkout/create, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
cancel(checkout_id, cancel_reason, **kwargs)

Call documentation: /checkout/cancel, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
refund(checkout_id, refund_reason, **kwargs)

Call documentation: /checkout/refund, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
capture(checkout_id, **kwargs)

Call documentation: /checkout/capture, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
modify(checkout_id, **kwargs)

Call documentation: /checkout/modify, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay

wepay.calls.credit_card Module

class wepay.calls.credit_card.CreditCard(api)[source]

The /credit_card API calls

__call__(client_id, client_secret, credit_card_id, **kwargs)[source]

Call documentation: /credit_card, plus extra keyword parameter:

Parameters:
create(client_id, cc_number, cvv, expiration_month, expiration_year, user_name, email, address, **kwargs)

Call documentation: /credit_card/create, plus extra keyword parameter:

Parameters:
authorize(client_id, client_secret, credit_card_id, **kwargs)

Call documentation: /credit_card/authorize, plus extra keyword parameter:

Parameters:
find(client_id, client_secret, **kwargs)

Call documentation: /credit_card/find, plus extra keyword parameter:

Parameters:
delete(client_id, client_secret, credit_card_id, **kwargs)

Call documentation: /credit_card/delete, plus extra keyword parameter:

Parameters:
transfer(client_id, client_secret, cc_number, expiration_month, expiration_year, user_name, email, address, **kwargs)

Call documentation: /credit_card/transfer, plus extra keyword parameter:

Parameters:

wepay.calls.oauth2 Module

class wepay.calls.oauth2.OAuth2(api)[source]

API OAuth2 Endpoints

authorize(client_id, redirect_uri, scope, state=None, user_name=None, user_email=None)[source]

Documentation: /oauth2/authorize.

Note

This is not an API call but an actual uri that you send the user to.

token(client_id, redirect_uri, client_secret, code, **kwargs)

Call documentation: /oauth2/token, plus extra keyword parameter:

Parameters:

wepay.calls.preapproval Module

class wepay.calls.preapproval.Preapproval(api)[source]

The /preapproval API calls

__call__(preapproval_id, **kwargs)[source]

Call documentation: /preapproval, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
find(**kwargs)

Call documentation: /preapproval/find, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
create(short_description, period, **kwargs)

Call documentation: /preapproval/create, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
cancel(preapproval_id, **kwargs)

Call documentation: /preapproval/cancel, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
modify(preapproval_id, **kwargs)

Call documentation: /preapproval/modify, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay

wepay.calls.subscription Module

class wepay.calls.subscription.Subscription(api)[source]

The /subscription API calls

__call__(subscription_id, **kwargs)[source]

Call documentation: /subscription, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
find(subscription_plan_id, **kwargs)

Call documentation: /subscription/find, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
create(subscription_plan_id, **kwargs)

Call documentation: /subscription/create, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
cancel(subscription_id, **kwargs)

Call documentation: /subscription/cancel, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
modify(subscription_id, **kwargs)

Call documentation: /subscription/modify, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay

wepay.calls.subscription_charge Module

class wepay.calls.subscription_charge.SubscriptionCharge(api)[source]

The /subscription_charge API calls

__call__(subscription_charge_id, **kwargs)[source]

Call documentation: /subscription_charge, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
find(subscription_id, **kwargs)

Call documentation: /subscription_charge/find, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
refund(subscription_charge_id, **kwargs)

Call documentation: /subscription_charge/refund, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay

wepay.calls.subscription_plan Module

class wepay.calls.subscription_plan.SubscriptionPlan(api)[source]

The /subscription_plan API calls

__call__(subscription_plan_id, **kwargs)[source]

Call documentation: /subscription_plan, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
find(**kwargs)

Call documentation: /subscription_plan/find, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
create(account_id, name, short_description, amount, period, **kwargs)

Call documentation: /subscription_plan/create, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
delete(subscription_plan_id, **kwargs)

Call documentation: /subscription_plan/delete, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
get_button(account_id, button_type, **kwargs)

Call documentation: /subscription_plan/get_button, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
modify(subscription_plan_id, **kwargs)

Call documentation: /subscription_plan/modify, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay

wepay.calls.user Module

class wepay.calls.user.User(api)[source]

The /user API calls

mfa[source]

Membership call instance

__call__(**kwargs)[source]

Call documentation: /user, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
modify(**kwargs)

Call documentation: /user/modify, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
register(client_id, client_secret, email, scope, first_name, last_name, original_ip, original_device, **kwargs)

Call documentation: /user/register, plus extra keyword parameter:

Parameters:

Note

This call is NOT supported by API versions older then ‘2014-01-08’.

send_confirmation(**kwargs)

Call documentation: /user/resend_confirmation, plus extra keyword parameter:

Parameters:

Note

This call is NOT supported by API versions older then ‘2014-01-08’.

class wepay.calls.user.MFA(api)[source]

The /user/mfa API calls

create(type, **kwargs)

Call documentation: /user/mfa/create, plus extra keyword parameter:

Parameters:

Call documentation: /user/mfa/validate_cookie, plus extra keyword parameter:

Parameters:
send_challenge(mfa_id, **kwargs)

Call documentation: /user/mfa/send_challenge, plus extra keyword parameter:

Parameters:
send_default_challenge(**kwargs)

Call documentation: /user/mfa/send_default_challenge, plus extra keyword parameter:

Parameters:
confirm(mfa_id, challenge, **kwargs)

Call documentation: /user/mfa/confirm, plus extra keyword parameter:

Parameters:
find(**kwargs)

Call documentation: /user/mfa/find, plus extra keyword parameter:

Parameters:
modify(mfa_id, **kwargs)

Call documentation: /user/mfa/modify, plus extra keyword parameter:

Parameters:

wepay.calls.withdrawal Module

class wepay.calls.withdrawal.Withdrawal(api)[source]

The /withdrawal API calls

__call__(withdrawal_id, **kwargs)[source]

Call documentation: /withdrawal, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
find(account_id, **kwargs)

Call documentation: /withdrawal/find, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
modify(withdrawal_id, **kwargs)

Call documentation: /withdrawal/modify, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay
create(account_id, **kwargs)

Call documentation: /withdrawal/create, plus extra keyword parameters:

Parameters:
  • access_token (str) – will be used instead of instance’s access_token, with batch_mode=True will set authorization param to it’s value.
  • batch_mode (bool) – turn on/off the batch_mode, see wepay.api.WePay
  • batch_reference_id (str) – reference_id param for batch call, see wepay.api.WePay
  • api_version (str) – WePay API version, see wepay.api.WePay

Warning

This call is depricated as of API version ‘2015-09-09’.

wepay.exceptions Module

exception wepay.exceptions.WePayError(error, error_code, error_description)[source]

Raised whenever WePay API call was not successfull. WePay API Errors Documentation

error

Generic error category. Returned by WePay.

error_code

A specific “error_code” that you can use to program responses to errors. Returned by WePay.

error_description

A human readable error_description that explains why the error happened. Returned by WePay.

exception wepay.exceptions.WePayHTTPError(http_error, status_code, error=None, error_code=None, error_description=None)[source]

This is a base http error

status_code

Error Code as specified by RFC 2616.

http_error

Instance of urllib.error.HTTPError or requests.exceptions.HTTPError, depending on the library you chose.

exception wepay.exceptions.WePayClientError(http_error, status_code, error=None, error_code=None, error_description=None)[source]

This is a 4xx type error, which, most of the time, carries important error information about the object of interest.

exception wepay.exceptions.WePayServerError(http_error, status_code, error=None, error_code=None, error_description=None)[source]

This is a 5xx type error, which, most of the time, means there is an error in implemetation or some unknown WePay Error, in latter case there is a chance there will be no error, error_code or error_description from WePay. It is recommended this exception is to be ignored or handled separatly in production.

exception wepay.exceptions.WePayConnectionError(error)[source]

Raised in case there is a problem connecting to WePay servers, for instance when request times out.

error

Original exception raised by urllib or requests library. It will be either urllib.error.URLError or a subclass of requests.exceptions.RequestExeption. See their corresponding documentation if necessary.

Installation

pip install python-wepay

Latest build

Forkme on Github: python-wepay

Quickstart Guide

This package suppose to make it easier to construct and perform API calls in a more Pythonic way rather than building dictionary with parameters and simply sending it to WePay servers.

Just like with official SDK the core of this package is wepay.WePay class, which needs to be instantiated with a valid access_token and production arguments of your WePay Application, after which API calls can be made. All methods within WePay object mimic API calls from official Documentation in the way that normally would be expected, call names are directly mapped into functions with same names moreover all required parameters are passed to functions as args and optional ones as kwargs.

Methods that can perform calls on behalf of WePay User accept optional keyword argument access_token, which will then be used instead of the one wepay.WePay class was instantiated with. Methods that can be used in a /batch/create call also accept batch_mode keyword argument, which instead of making a call will force it to return a dictionary, that can be used later to perform a wepay.WePay.batch_create() call. Additionally each call accepts api_version and timeout keyword arguments, which specify a WePay API version and connection timeout respectively. An unrecognized keyword passed to those functions will produce a warning and an actuall error from WePay, if it is in fact an unrecognized parameter.

Quick Example

>>> WEPAY_ACCESS_TOKEN = 'STAGE_243b....'
>>> WEPAY_CLIENT_ID = 123456
>>> WEPAY_CLIENT_SECRET = '1a2b3c4e5f'
>>> WEPAY_DEFAULT_SCOPE = "manage_accounts,collect_payments,view_balance,view_user,preapprove_payments,send_money"
>>> REDIRECT_URI = 'https://example.com/user/wepay/redirect'
>>> api = WePay(production=False, access_token=WEPAY_ACCESS_TOKEN)
>>> api.app(WEPAY_CLIENT_ID, WEPAY_CLIENT_SECRET)
{u'status': u'approved', u'theme_object': .....}
>>> redirect_uri = api.oauth2.authorize(WEPAY_CLIENT_ID, REDIRECT_URI, WEPAY_DEFAULT_SCOPE, user_email="user@example.com")
>>> redirect_uri
'https://stage.wepay.com/v2/oauth2/authorize?scope=manage_accounts%2C........'
>>> # Get the 'code' from url... (for detailed instructions on how to do it follow WePay documentation)
>>> response = api.oauth2.token(WEPAY_CLIENT_ID, redirect_uri, WEPAY_CLIENT_SECRET, '8c3e4aca23e1ed7.....', callback_uri='https://example.com/wepay/ipn/user')
>>> response
{u'access_token': u'STAGE_f87....', u'token_type': u'BEARER', u'user_id': 87654321}
>>> access_token = response['access_token']
>>> api.account.create("Test Account", "Account will be used to make a lot of money", access_token=access_token)
{u'account_id': 1371765417, u'account_uri': u'https://stage.wepay.com/account/1371765417'}
>>> api.checkout.create(1371765417, "Short description.....

Error Handling

Whenever you perform an API call and it results in an error, the are two possible causes:

  • either there is a problem connecting to a WePay server (internet connection is down, WePay server is down, request times out, ssl validation failed, etc.) in which case a call will raise WePayConnectionError. If the cause is timeout, consider increasing timeout value during WePay initialization or on per call basis, in particular for batch.create() call, since it can take a while for WePay to process up to 50 batched calls in one request.
  • or there is a problem processing the actual call due to a WePay documented reason or for some other unknown reason, like an implemetation error on WePay side or a malformed response for instance. In this case either WePayServerError or WePayClientError will be raised.

So far, I’ve noticed that WePayServerError's happen due to incorect usage of API (ex. unrecognized api call) or a problem with WePay, while WePayClientError's can happen anytime, for instance in case of a credit card decline. I would recommend handling them in a separate way, but you can also simply catch WePayHTTPError and handle it depending on error_code and status_code. Above mentioned exceptions also give you access to the actual HTTP Error: http_error which will carry a response body inside, hence can give some more information on the nature of the error. If you really don’t care about response body or HTTP status code, it is possible to just catch WePayError, which carries only information documented by WePay.

Also note, that depending on the library used for making calls, different types of errors will be contained in http_error and error. Refer to their documentation to find detailed information: requests or urllib

So here is an example:

from wepay import WePay
from wepay.exceptions import WePayClientError, WePayServerError, WePayConnectionError

def new_preapproval_uri(account_id, access_token):
    api = WePay(production=True, access_token=access_token, silent=True)
    try:
        response = api.preapproval.create("Good samaritan donation", 'monthly',
                                          account_id=account_id, amount=50.00)
        return response['preapproval_uri']
    except WePayClientError as exc:
        if exc.error_code == 5002:
            print "You have no permission to do that."
    except WePayServerError as exc:
        print "Oh oh, something went wrong, please contact api@wepay.com"
    except WePayConnectionError as exc:
        print "There was a problem connecting to WePay, please try again later."

So now you could use this function to create a checkout and send a user to the url to supply payment information.

>>> from myapp.settings import WEPAY_ACCOUNT_ID, WEPAY_ACCESS_TOKEN
>>> preapproval_uri = new_preapproval_uri(WEPAY_ACCOUNT_ID, WEPAY_ACCESS_TOKEN)
>>> if preapproval_uri:
>>>     # send user to this uri to finish preapproval creation process.

Customizing SDK

Let’s say you would like default values provided right away, or customize calls in some other handy way. For example you would like to supply some default values related specifically to your application and turn off objects you will never use:

from wepay import WePay, calls
from wepay.utils import cached_property

from myapp.settings import WEPAY_PRODUCTION, WEPAY_ACCESS_TOKEN, WEPAY_CLIENT_ID, WEPAY_CLIENT_SECRET


class App(calls.App):

    def __call__(self, **kwargs):
        return super(App, self).__call__(WEPAY_CLIENT_ID, WEPAY_CLIENT_SECRET, **kwargs)

    def modify(self, **kwargs):
        return super(App, self).modify(WEPAY_CLIENT_ID, WEPAY_CLIENT_SECRET, **kwargs)


class User(calls.User):

    def register(self, *args, **kwargs):
        return super(User, self).register(
            WEPAY_CLIENT_ID, WEPAY_CLIENT_SECRET, *args, **kwargs)


class Batch(calls.Batch):

    def create(self, calls, **kwargs):
        return super(Batch, self).create(
            WEPAY_CLIENT_ID, WEPAY_CLIENT_SECRET, calls, **kwargs)


class MyWePay(WePay):
    credit_card = None
    subscription_plan = None
    subscription = None
    subscription_charge = None

    def __init__(self, **kwargs):
         kwargs.setdefault('production', WEPAY_PRODUCTION)
         kwargs.setdefault('timeout', 45)
         kwargs.setdefault('access_token', WEPAY_ACCESS_TOKEN)
         kwargs['silent'] = True
         super(MyWePay, self).__init__(**kwargs)

    @cached_property
    def app(self):
        return App(self)

    @cached_property
    def user(self):
        return User(self)

    @cached_property
    def batch(self):
        return Batch(self)

This will effectively supply all of your WePay Application related info, for all of the calls you are planning on using, since other objects don’t rely on client_id or client_secret, with an exception of App level Preapprovals, of course. cached_property decorator alows lazy call initialization and, although you could use a regular property decorator, cached_property is more efficient, since it initializes a call object only once per WePay instance, instead of every time a call is performed.

Project Info

Changelog

1.5.0

  • added /account/membership/ calls.
  • added /user/mfa/ calls.
  • New API version 2015-09-09 changes are reflected in this SDK version:
    • /withrawal/create is deprecated.
  • New API version 2015-08-15 changes are reflected in this SDK version:
    • /account/create now accepts both old and new style params.
  • removed deprecated call /user/resend_confirmation.
  • /account/create and /account/modify now accept country_options and fee_schedule_slot params
  • added restricted /credit_card/transfer call.

1.4.4

  • renamed user.resend_confirmation call to user.send_confirmation.

1.4.3

  • improved documentation.

1.4.0

  • Removed backward compatibility with official Python WePay SDK.
  • introduced WePayHTTPError, which is a base exception for both WePayClientError and WePayServerError
  • added cached_property decorator.
  • changed they way calls are initialized. This change doesn’t affect the way calls are made.

1.3.5

  • Fixed and improved error handling, new exceptions: WePayClientError and WePayServerError.

1.3.4

  • Connection timeout can be specified on per call basis.

1.3.0

  • Python 3 compatible
  • Calls are made using requests library by default (if installed), falls back to urllib if requests are not installed or if WePay is initialized with use_requests=False.
  • WePayConnectionError is raised in case there is a problem connecting to WePay server, ex. timeout.
  • Addition of a full test suit.
  • Minor:
    • ‘original_ip’ and ‘original_device’ params are now optional in /credit_card/create.
    • silent mode is more flexible.
    • Moved SubscriptionPlan and SubscriptionCharge to their own modules.
    • Moved WePayWarning over to wepay.exceptions module.

1.2.0

  • New API version 2014-01-08 changes are reflected in this SDK version:
    • implemented /user/register and user/resend_confirmation calls.
    • added /account/get_update_uri and /account/get_reserve_details
    • depricated /account/add_bank, /account/balance, /account/get_tax and /account/set_tax calls.
  • restructured SDK in such a way that all API objects are separate classes, so as an example, if we have a WePay instance api = WePay() and we want to make a /account/find call, it will look like this api.account.find() instead of api.account_find() (notice . instead of _), although in this version both are equivalent, latter one is depricated and will be removed in version 1.3. Despite these changes lookup calls will be the same, ex. api.account(12345).
  • Added flexibility to use different API version per call basis. So it is now possible to make a depricated call like this: api.account.balance(1234, api_version='2011-01-15')
  • added batch_reference_id keyword argument to each call that accepts batch_mode

1.1.2

  • Added required arguments to /credit_card/create call:
    • original_ip
    • original_device

1.1.0

  • Added subscription calls:
    • /subscription_plan
    • /subscription
    • /subscription_charge
  • Few bug and spelling fixes.

1.0.0

  • Initial release

Authors

License

The MIT License (MIT)

Copyright (c) 2013 Alexey Kuleshevich

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Indices and tables