Commit e5b9bfac authored by Łukasz Nowak's avatar Łukasz Nowak

Implement getFormString.

parent 5e770080
import zope
import hashlib
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.XMLObject import XMLObject
......@@ -47,7 +48,40 @@ class PayzenService(XMLObject):
# proposed methods
def getFormString(self, document, **kw):
"""Returns form string of against passed document"""
"""Returns unterminated form for current document
The responsiblity of the caller is to finish the form."""
self.Base_checkConsistency()
content_kw = dict()
content_kw['vads_action_mode'] = self.getPayzenVadsActionMode()
content_kw['vads_amount'] = int(document.getTotalPrice() * 100)
integration_tool = self.restrictedTraverse(self.getIntegrationSite())
content_kw['vads_currency'] = integration_tool.getMappingFromCategory(
'resource/currency_module/%s' % document.getPriceCurrencyReference()
).split('/')[-1]
content_kw['vads_ctx_mode'] = self.getPayzenVadsCtxMode()
content_kw['vads_page_action'] = self.getPayzenVadsPageAction()
content_kw['vads_payment_config'] = document\
.Base_getPayzenServicePaymentConfig()
content_kw['vads_site_id'] = self.getServiceUsername()
# date as YYYYMMDDHHMMSS
content_kw['vads_trans_date'] = document.getStartDate().strftime(
'%Y%m%d%H%M%S')
content_kw['vads_trans_id'] = document.Base_getPayzenTransId()
content_kw['vads_version'] = self.getPayzenVadsVersion()
# all data are completed, now it is time to create signature
sorted_keys = content_kw.keys()
sorted_keys.sort()
signature = ''
form = '<FORM METHOD="POST" ACTION="%s">\n' % self.getLinkUrlString()
for k in sorted_keys:
v = str(content_kw[k])
signature += v + '+'
form += '<INPUT TYPE="HIDDEN" NAME="%s" VALUE="%s">\n' % (k, v)
signature += self.getServicePassword()
form += '<INPUT TYPE="HIDDEN" NAME="signature" VALUE="%s">' % \
hashlib.sha1(signature).hexdigest()
return form
def getSignature(self, document):
"""Returns signature for current document"""
......
<?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>_body</string> </key>
<value> <string>"""Returns vads_payment_config for current document\n
\n
Default implementation returns single payment operation (SINGLE)\n
\n
It is possible to configure it on application level.\n
"""\n
\n
return "SINGLE"\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getPayzenServicePaymentConfig</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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>_body</string> </key>
<value> <string>"""Script shall return payzen compatible transaction id"""\n
\n
return context.getReference()\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getPayzenTransId</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
17
\ No newline at end of file
18
\ No newline at end of file
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