帮助创建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_keydata。 这些需要在前端使用,并向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_codeaction

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没有任何关联

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java试图使用JavaFX2实现“插入符号浏览”   三个给定集合中两个集合的java交集?   数组如何在java中从csv文件的元素集中随机选择?   java从变量插入到Jtable,从DB插入   java如何在静态方法的末尾返回变量   java另一个JPA问题   java收藏家。按两列分组不起作用   将java值改为下一个千,而不是最近的千   JavaSpringDataREST:如何通过另一个对象的键进行搜索?   java Spring MVC:HTTP Status 404/SimpleMVC/WEB_INF/HelloPage。jsp   java应用程序光盘在OpenJdk中可用吗?   java在数组中的特定点添加字符   java如何用Mockito模拟方法调用   java从JList获取数据   我们可以在Java中搜索不同IMAP电子邮件帐户中的电子邮件吗?   计算表达式的数学Java算法   未构建Maven的java服务器组件   java调用部署在远程计算机上的会话bean的方法   java XML:迭代地获取每个节点元素的节点值或文本内容