Commit 9b2eb2f9 authored by Boxiang Sun's avatar Boxiang Sun

slapos_subscription_request: Add wechat payment simulation pages

parent 3bd5249c
......@@ -9,8 +9,20 @@ class WechatException(Exception):
super(WechatException, self).__init__(msg)
# RapidSpace Wechat acocunt configuration
APP_ID = "" # Wechat public account appid
class Single(object):
_instance = None
PAYMENT_DONE = False
def __new__(cls, *args, **kw):
if cls._instance is None:
cls._instance = object.__new__(cls, *args, **kw)
return cls._instance
def __init__(self):
pass
def finishThePayment(self):
self.APP_ID = "XXX"
APP_ID = "wxadebca31430703b0" # Wechat public account appid
MCH_ID = "" # Wechat merchant account ID
API_KEY = "" # Wechat merchant platform(pay.weixin.qq.com) -->账户设置 -->API安全 -->密钥设置
......@@ -125,7 +137,7 @@ def getWechatQRCodeURL(self, order_id, price, amount):
result_code = result_dict_content['result_code']
if result_code=="SUCCESS":
code_url = result_dict_content['code_url']
return code_url
return "weixin://wxpay/bizpayurl/up?pr=NwY5Mz9&groupid=00"
else:
print("Error description: {0}".format(result_dict_content.get("err_code_des")))
else:
......@@ -190,6 +202,8 @@ def queryWechatOrderStatus(self, dict_content):
- transaction_id (str): wechat order number, use this in higher priority, it will return in the payment notify callback
- out_trade_no(str): The order ID used inside ERP5, less than 32 characters, digits, alphabets, and "_-|*@", unique in ERP5
'''
if APP_ID == "XXX":
return "SUCCESS"
if "transaction_id" not in dict_content and "out_trade_no" not in dict_content:
raise WechatException("transaction_id or out_trade_no is needed for query the Wechat Order")
......@@ -204,7 +218,8 @@ def queryWechatOrderStatus(self, dict_content):
sign = calculateSign(params, API_KEY)
params["sign"] = sign
# xml_str = convert_dict_to_xml(params)
return "SUCCESS"
return None
# return "SUCCESS"
# result = urllib2.Request(QUERY_URL, data=xml_str)
# result_data = urllib2.urlopen(result)
# result_read = result_data.read()
......
......@@ -46,8 +46,9 @@
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple>
<string>W: 15, 0: Cannot decode using encoding "ascii", unexpected byte at position 63 (invalid-encoded-data)</string>
<string>W: 86, 2: Unreachable code (unreachable)</string>
<string>W: 27, 0: Cannot decode using encoding "ascii", unexpected byte at position 63 (invalid-encoded-data)</string>
<string>W: 98, 2: Unreachable code (unreachable)</string>
<string>W:139, 6: Unused variable \'code_url\' (unused-variable)</string>
</tuple>
</value>
</item>
......
web_site = context.getWebSiteValue()
base_url = web_site.absolute_url()
# portal = context.getPortalObject()
# subscription_request = portal.subscription_request_module.get(trade_no)
context.Base_finishThePayment()
# if not subscription_request:
# raise Exception("Order not found")
# subscription_request.confirmed()
return context.REQUEST.RESPONSE.redirect("%s/gadget_rapid_page_order_wechat_simulation_confirm.html/" % base_url)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>trade_no</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Anonymous</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_WechatPaymentSimulation</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>finishThePayment</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>WechatUtils</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_finishThePayment</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
# inspired by Pack_generateCode128BarcodeImage in sanef-evl project
code_url = code_url + "&trade_no=" + trade_no
return context.Base_generateBarcodeImage('qrcode', code_url)
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>code_url</string> </value>
<value> <string>code_url, trade_no</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
# Example code:
# Import a standard function, and get the HTML request and response objects.
from Products.PythonScripts.standard import html_quote
request = container.REQUEST
response = request.response
# Return a string identifying this script.
print "This is the", script.meta_type, '"%s"' % script.getId(),
if script.title:
print "(%s)" % html_quote(script.title),
print "in", container.absolute_url()
return printed
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_redirectWechatPaymentSuccessPage</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -46,7 +46,6 @@ if batch_mode:
if payment_mode == "wechat":
portal = context.getPortalObject()
code_url = portal.Base_getWechatCodeURL(subscription_request.getId(), payment.PaymentTransaction_getTotalPayablePrice(), user_input_dict["amount"])
code_url = "weixin://wxpay/bizpayurl/up?pr=NwY5Mz9&groupid=00"
web_site = context.getWebSiteValue()
base_url = web_site.absolute_url()
return context.REQUEST.RESPONSE.redirect(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment