Package: python-payer-api
Python package for interacting with thePayerpayments 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 anapplication/x-www-form-urlencodedcontent 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 isdjango-shop-payer-backendfor which python-payer-api was initially developed.Installationpip install python-payer-apiBasic usagefrompayer_apiimportPAYMENT_METHOD_CARD,PAYMENT_METHOD_BANK,PAYMENT_METHOD_PHONE,PAYMENT_METHOD_INVOICEfrompayer_api.postapiimportPayerPostAPIfrompayer_api.orderimport(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)printapi.get_post_data()Payment ProcessThe main flow of the payment process is as follows:Initialize aPayerPostAPIobject using the Agent ID, Key 1 and
Key 2 values supplied by Payer. Optinally settest_modeanddebug_modeand add a list ofpayment_methods.Create aPayerProcessingControlobject and add it to your API
object using theset_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 purchaseauthorize_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 aPayerOrderobject (includingPayerBuyerDetailsandPayerOrderItemobjects) and add it to your API object using theset_order()method.You can now callapi.get_post_data()for a dict of the query
parameters Payer expects. Add them as<inputtype="hidden">elements in a<form>element with methodPOSTand actionapi.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 - theauthorize_notification_urlURL, and depending on payment method
(direct / invoice) call thesettle_notification_urlURL. You will
want to implement a view or URL handler that listens on these URL’s,
for which you call thevalidate_callback_ip()andvalidate_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
eitherTRUEorFALSEusing atext/plaincontent type.Once Payer has performed its auth and settle validation it will
redirect the user the thesuccess_redirect_urlURL.