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:
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.
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.
Create a PayerOrder object (including PayerBuyerDetails and PayerOrderItem objects) and add it to your API object using the set_order() method.
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).
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.
Once Payer has performed its auth and settle validation it will redirect the user the the success_redirect_url URL.
Metadata
Release files for python-payer-api 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| python-payer-api-0.1.2.tar.gz | 10.2 kB | Without provenance | Details |
Release files / python-payer-api-0.1.2.tar.gz
| Download URL | python-payer-api-0.1.2.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
70147b8a3a58a9e63150f15b25926b6f25508f607a8f936844323276fc0b83fb
|
|
BLAKE2b-256 checksum How to use checksums |
d1ff9e887ab95ebadf703f80e8007007b4748c50a6dfe81ea427d05f04326053
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for python-payer-api 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.