From eff3f56df0a00308c4cc986d4cc8c807301fe286 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Mon, 10 Oct 2011 10:33:30 +0200
Subject: [PATCH] Simplify and split a bit.

Instead of doing analysis of passed dict, just accept payzen_dict, which will
be blindly applied.

Split to more methods, in order to have proper separation and being able to
test critical parts.
---
 .../DocumentTemplateItem/PayzenService.py     | 34 +++++++++++--------
 bt5/erp5_payzen_secure_payment/bt/revision    |  2 +-
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/bt5/erp5_payzen_secure_payment/DocumentTemplateItem/PayzenService.py b/bt5/erp5_payzen_secure_payment/DocumentTemplateItem/PayzenService.py
index 06009feeb4..6948d212bd 100644
--- a/bt5/erp5_payzen_secure_payment/DocumentTemplateItem/PayzenService.py
+++ b/bt5/erp5_payzen_secure_payment/DocumentTemplateItem/PayzenService.py
@@ -24,33 +24,39 @@ class PayzenService(XMLObject):
     """See Payment Service Interface Documentation"""
     pass
 
-  def navigate(self, page_template, REQUEST=None, **kw):
-    """Returns configured template used to do the payment"""
-    self.Base_checkConsistency()
-    temp_document = newTempDocument(self, 'id')
+  def _getSignature(self, field_list):
+    field_list.sort()
+    signature = ''
+    for k, v in field_list:
+      signature += v + '+'
+    signature += self.getServicePassword()
+    return hashlib.sha1(signature).hexdigest()
+
+  def _getFieldList(self, payzen_dict):
     field_list = [
       ('vads_action_mode', self.getPayzenVadsActionMode()),
       ('vads_ctx_mode', self.getPayzenVadsCtxMode()),
+      ('vads_contrib', 'ERP5'),
       ('vads_page_action', self.getPayzenVadsPageAction()),
       ('vads_payment_config', 'SINGLE'),
       ('vads_site_id', self.getServiceUsername()),
       ('vads_version', self.getPayzenVadsVersion())
     ]
     # fetch all prepared vads_ values and remove them from dict
-    for k in kw.copy():
-      if k.startswith('vads_'):
-        field_list.append((k, kw.pop(k)))
-    field_list.sort()
-    signature = ''
-    for k, v in field_list:
-      signature += v + '+'
-    signature += self.getServicePassword()
-    signature = hashlib.sha1(signature).hexdigest()
+    for k,v in payzen_dict.iteritems():
+      field_list.append((k, v))
+    signature = self._getSignature(field_list)
     field_list.append(('signature', signature))
+    return field_list
+
+  def navigate(self, page_template, payzen_dict, REQUEST=None, **kw):
+    """Returns configured template used to do the payment"""
+    self.Base_checkConsistency()
+    temp_document = newTempDocument(self, 'id')
     temp_document.edit(
       link_url_string=self.getLinkUrlString(),
       title='title',
-      field_list=field_list,
+      field_list=self._getFieldList(payzen_dict),
       # append the rest of transmitted parameters page template
       **kw
     )
diff --git a/bt5/erp5_payzen_secure_payment/bt/revision b/bt5/erp5_payzen_secure_payment/bt/revision
index 2edeafb09d..b5045cc404 100644
--- a/bt5/erp5_payzen_secure_payment/bt/revision
+++ b/bt5/erp5_payzen_secure_payment/bt/revision
@@ -1 +1 @@
-20
\ No newline at end of file
+21
\ No newline at end of file
-- 
2.30.9