This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Python package for interacting with the Payer payments API.

The scope of this module is basically to serialize the data into XML ready for transmitting to Payer. Given order details, billing details and callback URLs it will build an XML tree, encode it according to the Payer specifications and return the encoded data along with the required key-value pairs in a dict. Payer expects this data in a POST request using an application/x-www-form-urlencoded content type.

Generating HTML, providing any type of request handlers or views needed for a successful payment procedure however, is outside the scope of this module. Such implementations are encouraged to be realized as independent modules, in relation to the frameworks, webshop modules etc. that you may be using. One such example is django-shop-payer-backend for which python-payer-api was initially developed.

Installation

pip install python-payer-api

Basic usage

from payer_api import PAYMENT_METHOD_CARD, PAYMENT_METHOD_BANK, PAYMENT_METHOD_PHONE, PAYMENT_METHOD_INVOICE
from payer_api.postapi import PayerPostAPI
from payer_api.order import (
    PayerProcessingControl,
    PayerBuyerDetails,
    PayerOrderItem,
    PayerOrder,
)

api = PayerPostAPI(
    agent_id="AGENT_ID",
    key_1="6866ef97a972ba3a2c6ff8bb2812981054770162",
    key_2="1388ac756f07b0dda2961436ba8596c7b7995e94",
    payment_methods=[PAYMENT_METHOD_CARD, PAYMENT_METHOD_BANK, PAYMENT_METHOD_PHONE, PAYMENT_METHOD_INVOICE]
)


processing_control = PayerProcessingControl(
    success_redirect_url="http://localhost/webshop/thankyou/",
    authorize_notification_url="http://localhost/webshop/auth/",
    settle_notification_url="http://localhost/webshop/settle/",
    redirect_back_to_shop_url="http://localhost/webshop/",
)

order = PayerOrder(
    order_id="123456",
    buyer_details=PayerBuyerDetails(
        first_name="John",
        last_name="Doe",
        address_line_1="1234 Main Street",
        postal_code="12345",
        city="Anywhere",
        phone_mobile="012345678",
        email="john.doe@host.com",
    ),
    order_items=[
        PayerOrderItem(
            description='A product',
            price_including_vat=123.50,
            vat_percentage=25,
            quantity=4,
        ),
        PayerOrderItem(
            description='Another product',
            price_including_vat=123.0,
            vat_percentage=12.5,
            quantity=2,
        ),
    ],
    info_lines=[
        "Shipping with 5 work days",
        "Additional line of order info",
    ]
)

api.set_order(order)
api.set_processing_control(processing_control)

print api.get_post_data()

Payment Process

The main flow of the payment process is as follows:

  1. Initialize a PayerPostAPI object using the Agent ID, Key 1 and Key 2 values supplied by Payer. Optinally set test_mode and debug_mode and add a list of payment_methods.

  2. Create a PayerProcessingControl object and add it to your API object using the set_processing_control() method. This object holds four URL’s that your site has to provide. They are:

    success_redirect_url: A “thank you” URL, displayed after completed purchase authorize_notification_url: A callback URL, described below, called when orders are authorized. settle_notification_url: A callback URL, described below, called when orders are payed. redirect_back_to_shop_url: A “cancel” or “back to shop” URL.

  3. Create a PayerOrder object (including PayerBuyerDetails and PayerOrderItem objects) and add it to your API object using the set_order() method.

  4. You can now call api.get_post_data() for a dict of the query parameters Payer expects. Add them as <input type="hidden"> elements in a <form> element with method POST and action api.get_post_url() and have the user submit the form (i.e. needs to happen in front-end).

  5. Payer will parse your order, and once the payment has been completed Payer will perform a GET request to your callback URL’s - the authorize_notification_url URL, and depending on payment method (direct / invoice) call the settle_notification_url URL. You will want to implement a view or URL handler that listens on these URL’s, for which you call the validate_callback_ip() and validate_callback_url() methods on PayerPostAPI. A couple of query parameters will be appended to the callback URL’s, from which you can extract the Order ID, selected payment method, payment ID etc. The complete list of query paramters are:

    order_id, payer_callback_type, payer_testmode, payer_payment_type, payer_added_fee, payer_merchant_reference_id, payer_payment_id, payread_payment_id.

    Depending on the validity of the requests, your view should return either TRUE or FALSE using a text/plain content type.

  6. Once Payer has performed its auth and settle validation it will redirect the user the the success_redirect_url URL.

Release History

Release History

0.1.2

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
python-payer-api-0.1.2.tar.gz (10.2 kB) Copy SHA256 Checksum SHA256 Source Feb 10, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting