帮助创建mobilpay在线支付所需xml的库
mobilp的Python项目详细描述
移动电话
mobilpy帮助您实现所需的一切 mobilPay的在线支付 解决方案。步骤:-创建帐户-获得批准-创建商家 -下载密钥(私有和公共)-复制签名(仅 字符串)
note您将拥有两个私钥:用于测试和生产。这个 公钥是相同的。
安装
要安装库,请运行:
pip install mobilpy
使用量
frommobilpyimportClient# the signature for your accountsignature='DLAN-1R5V-19EN-XXXX-NFJA'# the path to the public keypublic_key="./sandbox.DLAN-1R5V-19EN-XXXX-NFJA.public.cer"# the private_keyprivate_key="./sandbox.DLAN-1R5V-19EN-XXXX-NFJA.private.key"client=Client(signature=signature,public_key=public_key,private_key=private_key)# optional dict containing details about the customer# if they are sent, the customer will have a short checkout by skipping the second step in the payment flowbilling_details={"first_name":"","last_name":"","address":"","phone":"","email":""}# optional dict with details that you would need internally# these are returned when the webhook is calledparams={"subscription_id":"","basket_id":"",etc.}options={"order_id":""# int/string, max 64 length"currency":"RON",# string, RON or other"amount":1,# float, between 0.10 and 99999"customer_id":"",# int/string"details":"",# string, description for this transaction"billing":billing_details,# dict, OPTIONAL"params":params,# dict, OPTIONAL,# the webhook where the response from mobilPay will be sent"confirm_url":"",# the url where the user will be redirected"return_url":""}response=client.create_payment_data(**options)
response是一个dict,它有两个键:env_key和data。 这些需要在前端使用,并向mobilpay提出请求。
例如,html可能如下所示:
<formaction="http://sandboxsecure.mobilpay.ro"method="post"><inputtype="hidden"name="env_key"value="{{ env_key }}"><inputtype="hidden"name="data"value="{{ data }}"><inputtype="submit"value="Send"></form>
表单的post url是:-测试: http://sandboxsecure.mobilpay.ro-生产: https://secure.mobilpay.ro
webhook
mobilpay将对您设置为的url发出POST请求 confirm_url。mobilpy有一些方法可以帮助您解析它并提供 回应。
post=# get the post dataenv_key=post.get('env_key')data=post.get('data')client=Client(signature=signature,public_key=public_key,private_key=private_key)request_xml=client.decrypt_message(env_key,data)request_object=client.parse_request_xml(request_xml)# do some magic
为了检查交易是否成功,您需要检查 error_code和action:
transaction_successful=request_object.get('error_code')=='0'andrequest_object.get('action')=='confirmed'iftransaction_successful:# everything is ok
创建响应
你需要让mobilpay知道你的终端是否一切正常或者 奇怪的事情发生了。如果一切正常,您可以创建一个响应 像这样:
message="All good captain"response_xml=client.create_reponse(message=message)
如果出现错误:
# message that will help you debug. it will appear in your dashboardmessage="Everything is on fire"# this can be "1" (temporary error) or "2" (permanent error)error_type="1"# your internal error code. a number maybe. OPTIONALerror_code=''response_xml=client.create_reponse(message=message,error_type=error_type,error_code=error_code)
响应不需要加密。只需用xml响应。
计入
如果交易是从仪表板贷记的,则MobilPay将 新webhookPOST。您可以查看:
# if the transaction was credited from mobilpayifrequest_object.get('action')=='credit':# do something# return a reponse
待办事项
一些仍然需要做的事情: -测试 -依赖项太多:pyopenssl和pycrypto -迁移到pycryptome(不维护pycrypto) -添加对以下项的支持:不稳定,重复 -可能会添加预填的信用卡数据支付?
免责声明
此库与MobilPay没有任何关联