python kipo kpg库使使用kipo网关建立支付变得容易。
kipo-kpg的Python项目详细描述
python kipo kpg库:使用kipo轻松付款
python kipo kpg库使使用kipo网关建立支付变得容易。
安装
将kipokpg文件添加到项目中
或者干脆跑
pip install kipo-kpg
快速入门和示例
初始化kipo kpg并从kipo服务器请求购物密钥。
fromKipoKPGimportKipoKPG""" Initial Kipo Library and craete object from KipoKPG class Merchant key is merchant phone number"""kipo=KipoKPG("YOUR MERCHANT KEY")""" Replace "YOUR CALLBACK URL" and "AMOUNT" with what you want kpg_initiate return a Dictionary Successful - {"status": True, "shopping_key": SHOPING_KEY} Failed - {"status": false, "message": ERROR_CODE}"""kpg_initiate=kipo.kpg_initiate(AMOUNT,'YOUR CALLBACK URL')ifkpg_initiate['status']:""" Store kpg_initiate["shopping_key"] to session to verfiy payment after user came back from gateway Call render_form function to render a html form and send user to Kipo KPG Gateway (you can create this form manually where you want - form example is at the end of Quick Start """kipo.render_form(kpg_initiate['shopping_key'])else:""" Show error to user You can call getErrorMessage and send error code to that as input and get error message kipo.get_error_message(ERROR_CODE) """
用户返回callback url
后验证付款""" Replace "SHOPPING_KEY" with your SHOPPING_KEY that you taken from Initiate function kpg_inquery return a dictionary for result Successful - {"status": True, "referent_code": REFERENT_CODE} Failed - {"status": False, "message": ERROR_CODE}"""kpg_inquery=kipo.kpg_inquery(SHOPPING_KEY)
# Get shopping key after kpg_initiate calledkipo.get_shopping_key()
# Get referent code after kpg_inquery calledkipo.get_referent_code()
属性
""" URL of Kipo server - https://kpg.kipopay.com:8091/V1.0/processors/json/ This server create shopping key and """kipo.request_url""" URL of Kipo KPG - http://webgate.kipopay.com/ Shopping key must post to this url with SK name"""kipo.kipo_webgate_url
将用户传输到kpg的html表单
<formid="kipopay-gateway"method="post"action="KIPO_WEBGATE_URL"style="display: none;"><inputtype="hidden"id="sk"name="sk"value="SHOPING_KEY"/></form><scriptlanguage="javascript">document.forms['kipopay-gateway'].submit();</script>