paymentwall-python

Paymentwall Python Library


License
MIT
Install
pip install paymentwall-python==1.0.8

Documentation

About Paymentwall

Paymentwall is the leading digital payments platform for globally monetizing digital goods and services. Paymentwall assists game publishers, dating sites, rewards sites, SaaS companies and many other verticals to monetize their digital content and services. Merchants can plugin Paymentwall's API to accept payments from over 100 different methods including credit cards, debit cards, bank transfers, SMS/Mobile payments, prepaid cards, eWallets, landline payments and others.

To sign up for a Paymentwall Merchant Account, click here.

Paymentwall Python Library

This library allows developers to use Paymentwall APIs (Virtual Currency, Digital Goods featuring recurring billing, and Virtual Cart).

To use Paymentwall, all you need to do is to sign up for a Paymentwall Merchant Account so you can setup an Application designed for your site. To open your merchant account and set up an application, you can sign up here.

Installation

To install using pip run:

pip install paymentwall-python

Notice: If you are using Python 2.6 please run the following command, too:

pip install ordereddict

To install from source run:

python setup.py install

Then use a code sample below.

Code Samples

Digital Goods API

Initializing Paymentwall

from paymentwall import *
Paymentwall.set_api_type(Paymentwall.API_GOODS)
Paymentwall.set_app_key('APPLICATION_KEY') # available in your merchant area
Paymentwall.set_secret_key('SECRET_KEY') # available in your merchant area

Widget Call

Web API details

The widget is a payment page hosted by Paymentwall that embeds the entire payment flow: selecting the payment method, completing the billing details, and providing customer support via the Help section. You can redirect the users to this page or embed it via iframe. Below is an example that renders an iframe with Paymentwall Widget.

product = Product(
    'product301',              # id of the product in your system 
    12.12,                     # price
    'USD',                     # currency code
    'test',                    # product name
    Product.TYPE_SUBSCRIPTION, # this is a time-based product
    1,                         # duration is 1
    Product.PERIOD_TYPE_WEEK,  #               week
    True                       # recurring
)

widget = Widget(
    'user4522',   # id of the end-user who's making the payment
    'pw',       # widget code, e.g. pw; can be picked inside of your merchant account
    [product],    # product details for Flexible Widget Call. To let users select the product on Paymentwall's end, leave this array empty
    {'email': 'user@hostname.com'}    # additional parameters
)
print(widget.get_html_code())

Pingback Processing

The Pingback is a webhook notifying about a payment being made. Pingbacks are sent via HTTP/HTTPS to your servers. To process pingbacks use the following code:

pingback = Pingback({x:y for x, y in request.args.iteritems()}, request.remote_addr)

if pingback.validate():
    product_id = pingback.get_product().get_id()
    if pingback.is_deliverable():
        # deliver the product
        pass
    elif pingback.is_cancelable():
        # withdraw the product
        pass

    print('OK') # Paymentwall expects response to be OK, otherwise the pingback will be resent

else:
    print(pingback.get_error_summary())

Virtual Currency API

Initializing Paymentwall

from paymentwall import *
Paymentwall.set_api_type(Paymentwall.API_VC)
Paymentwall.set_app_key('APPLICATION_KEY')
Paymentwall.set_secret_key('SECRET_KEY')

Widget Call

widget = Widget(
	'user40012', # id of the end-user who's making the payment
	'p1_1',      # widget code, e.g. p1; can be picked inside of your merchant account
	[],          # array of products - leave blank for Virtual Currency API
	{'email': 'user@hostname.com'} # additional parameters
)
print(widget.get_html_code())

Pingback Processing

pingback = Pingback({x:y for x, y in request.args.iteritems()}, request.remote_addr)
if pingback.validate():
    virtual_currency = pingback.get_vc_amount()
    if pingback.is_deliverable():
        # deliver the virtual currency
        pass
    elif pingback.is_cancelable():
        # withdraw the virtual currency
        pass 
  print('OK') # Paymentwall expects response to be OK, otherwise the pingback will be resent
else:
  print(pingback.get_error_summary())
end

Cart API

Initializing Paymentwall

from paymentwall import *
Paymentwall.set_api_type(Paymentwall.API_CART)
Paymentwall.set_app_key('APPLICATION_KEY')
Paymentwall.set_secret_key('SECRET_KEY')

Widget Call

widget = Widget(
	'user40012', # id of the end-user who's making the payment
	'p1_1',      # widget code, e.g. p1; can be picked inside of your merchant account
	[
		Product('product301', 3.33, 'EUR'), # first product in cart
		Product('product607', 7.77, 'EUR')  # second product in cart
	],
	{'email': 'user@hostname.com'} # additional params
)
print(widget.get_html_code())

Pingback Processing

pingback = Pingback({x:y for x, y in request.args.iteritems()}, request.remote_addr)
if pingback.validate():
    products = pingback.get_products()
    if pingback.is_deliverable():
        # deliver the virtual currency
        pass
    elif pingback.is_cancelable():
        # withdraw the virtual currency
        pass 
  print('OK') # Paymentwall expects response to be OK, otherwise the pingback will be resent
else:
  print(pingback.get_error_summary())
end