Package: python-openpay
Python Openpay SDKThis module is created to achieve payment via.Openpayfrom any web based platform
created byPython. Every merchant can use this SDK for its clients to handle order creation to complete payment.Installationpip install python-openpayCreation of MerchantEverymerchantobject is created by using compulsory attributejam_auth_token,country_codeand along with other two non-mandatory attributes
such as -auth_tokenandopenpay_url_modeas follows:-.fromopenpayimportMerchantmerchant=Merchant(jam_auth_token='your jam auth token',country_code="au or uk"auth_token=None,openpay_url_mode="Live")Here,openpay_url_modeis used to specify the mode of URL, such as "Live" or "Training". This is required for testing this SDK
indemoorproductionpurpose.Now amerchantcan set upsuccess,cancelandfailureurls for redirecting a client during or after payment throughopenpayas follows:-merchant.set_callback_url(callback_url=val1, cancel_url=val2, failure_url=val3)fraud altertif any fraud is taking place corresponding to a plan id then merchant can call this following functionmerchant.online_order_fraud_alert(plan_id=plan_id)Note:This is not mandatory. It will only be called if fraud occursCreation of ClientA particularmerchanthas a set ofclientsfor his site. So, when we create aclientobject then we have to
associate amerchantobject with it. Possible ways to associate aclientwithmerchantare as follows:-fromopenpayimportClientclient=Client(merchant=merchant)# association with merchantLater, we can update aclientobject usingdemographic informationas follows(res for residential and del for delivery address):-client(first_name='openpay',family_name='test',email='testdevloper007@gmail.com',res_address_1='15/520 Collins Street',res_suburb='Melbourne',res_state='Victoria',res_postcode=3000,dob='06 Jan 1985')Add just add del_ suffix likedel_address_1instead ofres_address_1foraddress, suburb and state.Another way to createclientwith two above steps in together as follows :client=Client(first_name='Test',family_name='User',email='testdevloper007@gmail.com',address_1='15/520 Collins Street',suburb='Melbourne',state='Victoria',postcode=3000,dob='06 Jan 1985',merchant=merchant)Note:Here%bMonth as locale’s abbreviated name. Jan, Feb, …, Dec. So, any validdate formatshould be
like '06 Jan 1985'. In addition,postal codeshould be of length4.Check if price is valid for payment(comes in min max range)Before initiating order, need to check if price is valid withclient.is_valid_price(price=<paymentprice>)If the status is True or error is blank in response then we can proceed further with the next callnew_online_orderOnline order creationHere,clientis going to order one or more item(s) frommerchantsite and parampurchase_priceis the sum of
item(s) prices chosen by client.client.new_online_order(purchase_price=<totalprice>,plan_creation_type="Pending")After successful execution, aplan IDis created for theclient.Check Min and Max purchase priceclient.min_max_purchase_price()This method is used to check whether thepurchase_priceis in theminimumandmaximumprice range of amerchantor not.Create online planplan_link=client.create_online_plan(order_id=<orderIDcreatedfrommerchantsite>)Openpay provides all possible plans to paypurchase_pricefor thisclient. Once a plan is chosen byclientthen Openpay
redirects him for payment.Check payment and order statusTo check payment and order status for aclient, we should call below functions withplan_idas argument respectively.client.check_payment_capture(plan_id=plan_id)client.check_order_status(plan_id=plan_id)Create refundIfmerchantwants to create anypartialrefund for a plan then he has to set argumentsplan_idandnew_purchase_priceas follows:-client.refund_status(plan_id=plan_id,new_purchase_price=<revisedpurchaseprice>)Note:Argumentnew_purchase_priceis calculated as follows:-previous purchase price - amount of price to refundIn case offullrefund, set argumentsplan_idandfull_refundas follows:-client.refund_status(plan_id=plan_id,full_return=True)Create dispatchIfmerchantwants to initiate adispatchof an order then he will following method with correspondingplan_idof that order as follows:-client.order_dispatch_plan(plan_id=plan_id)