Commit 32e1051b authored by Romain Courteaud's avatar Romain Courteaud

Test payzen manual payment creation.

parent 09651ea3
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Integration Base Category Mapping" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_destination_reference</string> </key>
<value> <string>source_project</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>SourceProject</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SourceProject</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Integration Base Category Mapping</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Standard Property" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_local_properties</string> </key>
<value>
<tuple>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>mode</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>string</string> </value>
</item>
</dictionary>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>elementary_type/string</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Payment Service to use with PayZen.</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>preferred_payzen_payment_service_reference_property</string> </value>
</item>
<item>
<key> <string>mode</string> </key>
<value> <string>w</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Standard Property</string> </value>
</item>
<item>
<key> <string>preference</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>property_default</string> </key>
<value> <string>python: \'\'</string> </value>
</item>
<item>
<key> <string>write_permission</string> </key>
<value> <string>Manage properties</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -51,11 +51,13 @@ ...@@ -51,11 +51,13 @@
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n <value> <string>portal = context.getPortalObject()\n
\n
portal.portal_catalog.searchAndActivate(\n portal.portal_catalog.searchAndActivate(\n
portal_type="Payment Transaction", \n portal_type="Payment Transaction", \n
simulation_state=["confirmed"],\n simulation_state=["confirmed"],\n
causality_state=["solved"],\n causality_state=["solved"],\n
method_id=\'PaymentTransaction_startExternalPayment\',\n payment_mode_uid=portal.portal_categories.payment_mode.payzen.getUid(),\n
method_id=\'PaymentTransaction_startPayzenPayment\',\n
packet_size=1, # just one to minimise errors\n packet_size=1, # just one to minimise errors\n
activate_kw={\'tag\': tag}\n activate_kw={\'tag\': tag}\n
)\n )\n
......
...@@ -50,22 +50,15 @@ ...@@ -50,22 +50,15 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>from DateTime import DateTime\n <value> <string>portal = context.getPortalObject()\n
from Products.ZSQLCatalog.SQLCatalog import Query\n
from Products.ERP5Type.DateUtils import addToDate\n
\n
portal = context.getPortalObject()\n
portal.portal_catalog.searchAndActivate(\n portal.portal_catalog.searchAndActivate(\n
portal_type="Payment Transaction", \n portal_type="Payment Transaction", \n
simulation_state=["started"],\n simulation_state=["started"],\n
causality_state=["solved"],\n causality_state=["solved"],\n
payment_mode_uid=portal.portal_categories.payment_mode.payzen.getUid(),\n
method_id=\'PaymentTransaction_updateStatus\',\n method_id=\'PaymentTransaction_updateStatus\',\n
packet_size=1, # just one to minimise errors\n packet_size=1, # just one to minimise errors\n
activate_kw={\'tag\': tag},\n activate_kw={\'tag\': tag}\n
**{\'delivery.start_date\': Query(range="max",\n
**{\'delivery.start_date\': addToDate(\n
DateTime().latestTime(),\n
to_add={\'day\': -1})} )}\n
)\n )\n
context.activate(after_tag=tag).getId()\n context.activate(after_tag=tag).getId()\n
</string> </value> </string> </value>
......
<?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>from zExceptions import Unauthorized\n
if REQUEST is not None:\n
raise Unauthorized\n
\n
if (context.getPaymentMode() != \'payzen\'):\n
return\n
\n
portal = context.getPortalObject()\n
integration_site = portal.restrictedTraverse(portal.portal_preferences.getPreferredPayzenIntegrationSite())\n
\n
ticket_relative_url = integration_site.getCategoryFromMapping(\'SourceProject/%s\' % context.getId().replace(\'-\', \'_\'))\n
if ticket_relative_url != \'source_project/%s\' % context.getId().replace(\'-\', \'_\'):\n
ticket = portal.restrictedTraverse(ticket_relative_url)\n
else:\n
ticket = portal.support_request_module.newContent(\n
portal_type=\'Support Request\',\n
source_project_value=context,\n
title=\'Payzen Transaction to check\',\n
)\n
ticket.validate(comment=\'New automatic ticket for %s\' % context.getTitle())\n
\n
try:\n
mapping = integration_site.getCategoryFromMapping(\n
\'SourceProject/%s\' % context.getId().replace(\'-\', \'_\'),\n
create_mapping_line=True,\n
create_mapping=True)\n
except ValueError:\n
pass\n
integration_site.SourceProject[context.getId().replace(\'-\', \'_\')].setDestinationReference(ticket.getRelativeUrl())\n
\n
return ticket\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>PaymentTransaction_addPayzenTicket</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>from zExceptions import Unauthorized\n
if REQUEST is not None:\n
raise Unauthorized\n
\n
portal = context.getPortalObject()\n
payment_service = portal.portal_secure_payments.find(\n
service_reference=portal.portal_preferences.getPreferredPayzenPaymentServiceReference())\n
\n
kw.update({\n
\'portal_type\': \'Payzen Event\',\n
\'source_value\': payment_service,\n
\'destination_value\': context,\n
})\n
\n
return portal.system_event_module.newContent(**kw)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>PaymentTransaction_createPayzenEvent</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>from zExceptions import Unauthorized\n
if REQUEST is not None:\n
raise Unauthorized\n
\n
portal = context.getPortalObject()\n
integration_site = portal.restrictedTraverse(portal.portal_preferences.getPreferredPayzenIntegrationSite())\n
\n
transaction_date, transaction_id = context.PaymentTransaction_getPayzenId()\n
if transaction_id is not None:\n
# XXX raise?\n
return None, None\n
\n
now = DateTime().toZone(\'UTC\')\n
today = now.asdatetime().strftime(\'%Y%m%d\')\n
\n
transaction_id = str(portal.portal_ids.generateNewId(\n
id_group=\'%s_%s\' % (integration_site.getRelativeUrl(), today),\n
id_generator=\'uid\')).zfill(6)\n
\n
mapping_id = \'%s_%s\' % (today, transaction_id)\n
# integration_site.Causality[mapping_id].setDestinationReference(context.getRelativeUrl())\n
# try:\n
# integration_site.getCategoryFromMapping(\'Causality/%s\' % mapping_id, create_mapping_line=True, create_mapping=True)\n
# except ValueError:\n
# mapping = integration_site.Causality[mapping_id]\n
# mapping.setDestinationReference(\'%s\' % context.getRelativeUrl())\n
# else:\n
# raise ValueError, "Payzen transaction_id already exists"\n
\n
try:\n
mapping = integration_site.getCategoryFromMapping(\n
\'Causality/%s\' % context.getId().replace(\'-\', \'_\'),\n
create_mapping_line=True,\n
create_mapping=True)\n
except ValueError:\n
pass\n
integration_site.Causality[context.getId().replace(\'-\', \'_\')].setDestinationReference(mapping_id)\n
\n
return context.PaymentTransaction_getPayzenId()\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>PaymentTransaction_generatePayzenId</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -50,39 +50,28 @@ ...@@ -50,39 +50,28 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>from DateTime import DateTime\n <value> <string>from zExceptions import Unauthorized\n
transaction = context\n if REQUEST is not None:\n
return None\n raise Unauthorized\n
\n \n
portal = transaction.getPortalObject()\n portal = context.getPortalObject()\n
integration_site = portal.restrictedTraverse(portal.portal_preferences.getPreferredPayzenIntegrationSite())\n integration_site = portal.restrictedTraverse(portal.portal_preferences.getPreferredPayzenIntegrationSite())\n
state_list = portal.getPortalCurrentInventoryStateList()\n
previous_transaction = portal.portal_catalog.getResultValue(\n
destination_section_uid = transaction.getDestinationSectionUid(),\n
portal_type=transaction.getPortalType(),\n
simulation_state=state_list,\n
sort_on=((\'delivery.start_date\', \'DESC\'),),\n
limit=1,\n
)\n
\n \n
if previous_transaction is None:\n payzen_id = integration_site.getCategoryFromMapping(\'Causality/%s\' % context.getId().replace(\'-\', \'_\'))\n
return None\n if payzen_id != \'causality/%s\' % context.getId().replace(\'-\', \'_\'):\n
\n date, payzen_id = payzen_id.split(\'_\', 1)\n
previous_id = None\n return DateTime(date).toZone(\'UTC\'), payzen_id\n
possible_previous_id = integration_site.getMappingFromCategory(\'causality/%s\' % previous_transaction.getRelativeUrl())\n else:\n
if possible_previous_id != \'Causality/%s\' % previous_transaction.getRelativeUrl():\n return None, None\n
previous_id = possible_previous_id.split(\'/\')[1]\n
\n
return previous_id\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string>REQUEST=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>PaymentTransaction_getPreviousPayzenId</string> </value> <value> <string>PaymentTransaction_getPayzenId</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
<?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 encoding="cdata"><![CDATA[
if (context.getPaymentMode() != \'payzen\'):\n
return\n
\n
portal = context.getPortalObject()\n
ticket = context.PaymentTransaction_addPayzenTicket()\n
\n
site_message = portal.event_module.newContent(\n
portal_type=\'Site Message\',\n
start_date=DateTime(),\n
destination_value=context.getDestinationSectionValue(),\n
follow_up=ticket.getRelativeUrl(),\n
source_value=context.getSourceSectionValue(),\n
# XXX Hardcoded script provided by another bt5\n
text_content=\'Please pay your payment by clicking <a \'\\\n
\'href="%s/PaymentTransaction_redirectToManualPayzenPayment">here</a>.\' % \\\n
context.getRelativeUrl(),\n
)\n
site_message.start(comment=\'Requested manual payment.\')\n
return site_message\n
]]></string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>PaymentTransaction_sendManualPayzenPaymentUrl</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>from DateTime import DateTime\n
portal = context.getPortalObject()\n
\n
state = context.getSimulationState()\n
if (state != \'confirmed\') or (context.getPaymentMode() != \'payzen\'):\n
return\n
else:\n
# Request manual payment\n
context.PaymentTransaction_sendManualPayzenPaymentUrl()\n
context.start(comment=\'Requested manual payment\')\n
\n
# raise NotImplementedError\n
# if context.PaymentTransaction_getPreviousPayzenId() is not None:\n
# # there is previous payment\n
# context.setStartDate(DateTime())\n
# context.updateCausalityState()\n
# portal.system_event_module.newContent(\n
# title=\'Transaction %s Payzen registration\' % context.getTitle(),\n
# portal_type=\'Payzen Event\',\n
# source_value=service,\n
# destination_value=context).registerPayzen()\n
# comment=\'Automatically duplicated in payzen.\'\n
# else:\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>PaymentTransaction_startPayzenPayment</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -50,108 +50,25 @@ ...@@ -50,108 +50,25 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string>from DateTime import DateTime\n
from DateTime import DateTime\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
service = None\n
\n
def addTicket(transaction):\n
portal = transaction.getPortalObject()\n
ticket = portal.portal_catalog.getResultValue(portal_type=\'Support Request\',\n
default_source_project_uid=transaction.getUid(),\n
validation_state=\'validated\')\n
tag = \'ticket_creation_%s\' % transaction.getUid()\n
activate_kw={\'tag\': tag}\n
if ticket is None and \\\n
portal.portal_activities.countMessageWithTag(tag) == 0:\n
ticket = portal.support_request_module.newContent(\n
portal_type=\'Support Request\',\n
source_project_uid=transaction.getUid(),\n
activate_kw=activate_kw)\n
ticket.validate(comment=\'New automatic ticket for %s\' % \\\n
transaction.getTitle())\n
return ticket\n
return None\n
\n
try:\n
service = portal.portal_secure_payments.find()\n
except ValueError, e:\n
portal.system_event_module.newContent(\n
title=\'Transaction %s cannot be updated, because of service error: %s\' % \\\n
(context.getTitle(), e), portal_type=\'Payzen Event\',\n
source_value=service, destination_value=context)\\\n
.confirm()\n
return\n
\n
def createRequestManualPaymentTicket(transaction):\n
# no previous payment\n
# shall create ticket + web message for user\n
portal = transaction.getPortalObject()\n
ticket = addTicket(context)\n
if ticket is not None:\n
tag = \'site_message_creation_%s\' % transaction.getUid()\n
activate_kw={\'tag\': tag}\n
site_message = portal.portal_catalog.getResultValue(\n
portal_type=\'Site Message\', default_follow_up_uid=ticket.getUid())\n
if site_message is None and \\\n
portal.portal_activities.countMessageWithTag(tag) == 0:\n
site_message = portal.event_module.newContent(\n
portal_type=\'Site Message\',\n
start_date=DateTime(),\n
destination_uid=transaction.getDestinationSectionUid(),\n
follow_up=ticket.getRelativeUrl(),\n
source_uid=transaction.getSourceSectionUid(),\n
text_content=\'Please pay your payment by clicking <a \'\\\n
\'href="%s/AccountingTransaction_startPayment">here</a>.\' % \\\n
transaction.getRelativeUrl(),\n
activate_kw=activate_kw)\n
site_message.start(comment=\'Requested manual payment.\')\n
\n \n
state = context.getSimulationState()\n state = context.getSimulationState()\n
if state == \'confirmed\':\n if (state != \'started\') or (context.getPaymentMode() != \'payzen\'):\n
if context.PaymentTransaction_getPreviousPayzenId() is not None:\n return\n
# there is previous payment\n else:\n
context.setStartDate(DateTime())\n transaction_date, transaction_id = context.PaymentTransaction_getPayzenId()\n
context.updateCausalityState()\n
portal.system_event_module.newContent(\n
title=\'Transaction %s Payzen registration\' % context.getTitle(),\n
portal_type=\'Payzen Event\',\n
source_value=service,\n
destination_value=context).registerPayzen()\n
comment=\'Automatically duplicated in payzen.\'\n
else:\n
createRequestManualPaymentTicket(context)\n
comment=\'Requested manual payment\'\n
context.start(comment=comment)\n
\n
elif state == \'started\':\n
transaction_id = portal.restrictedTraverse(\n
portal.portal_preferences.getPreferredPayzenIntegrationSite()\n
).getMappingFromCategory(\'causality/%s\' % context.getRelativeUrl())\n
if transaction_id != \'Causality/%s\' % context.getRelativeUrl():\n
transaction_id = transaction_id.split(\'/\')[1]\n
else:\n
transaction_id = None\n
\n \n
if transaction_id is None:\n if transaction_id is None:\n
# inform administrators\n # inform administrators\n
addTicket(context)\n context.PaymentTransaction_addPayzenTicket()\n
else:\n else:\n
# so the payment is registered in payzen\n # so the payment is registered in payzen\n
portal.system_event_module.newContent(\n context.PaymentTransaction_createPayzenEvent().updateStatus()\n
title=\'Transaction %s Payzen status update\' % context.getTitle(),\n
portal_type=\'Payzen Event\',\n
source_value=service,\n
destination_value=context).updateStatus()\n
if context.getSimulationState() != \'stopped\':\n if context.getSimulationState() != \'stopped\':\n
# not paid yet and shall be, lets open ticket\n # not paid yet and shall be, lets open ticket\n
addTicket(context)\n context.PaymentTransaction_addPayzenTicket()\n
else:\n </string> </value>
raise NotImplementedError(\'State %s is not supported\' % state)\n
]]></string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
......
...@@ -50,46 +50,50 @@ ...@@ -50,46 +50,50 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>def storeWorkflowComment(ctx, comment):\n <value> <string>from zExceptions import Unauthorized\n
if REQUEST is not None:\n
raise Unauthorized\n
\n
def storeWorkflowComment(ctx, comment):\n
portal = ctx.getPortalObject()\n portal = ctx.getPortalObject()\n
workflow_tool = portal.portal_workflow\n workflow_tool = portal.portal_workflow\n
workflow_tool.doActionFor(ctx, \'edit_action\', comment=comment)\n workflow_tool.doActionFor(ctx, \'edit_action\', comment=comment)\n
\n \n
payzen_event = state_change[\'object\']\n payzen_event = context\n
transaction = payzen_event.getDestinationValue()\n transaction = payzen_event.getDestinationValue()\n
portal = transaction.getPortalObject()\n portal = transaction.getPortalObject()\n
\n \n
from Products.DCWorkflow.DCWorkflow import ValidationFailed\n assert signature in (True, False)\n
if signature is not True:\n if signature is False:\n
# signature is wrong, bye bye\n # signature is wrong, bye bye\n
payzen_event.confirm(comment=\'Signature does not match\')\n payzen_event.confirm(comment=\'Signature does not match\')\n
return\n return\n
\n \n
transaction_code_mapping = {\n transaction_code_mapping = {\n
\'0\' : \'Initial (being treated)\',\n \'0\': \'Initial (being treated)\',\n
\'1\' : \'To be validated \',\n \'1\': \'To be validated \',\n
\'2\' : \'To be forced - Contact issuer\',\n \'2\': \'To be forced - Contact issuer\',\n
\'3\' : \'To be validated and authorized\',\n \'3\': \'To be validated and authorized\',\n
\'4\' : \'Waiting for submission\',\n \'4\': \'Waiting for submission\',\n
\'5\' : \'Waiting for authorization\',\n \'5\': \'Waiting for authorization\',\n
\'6\' : \'Submitted\',\n \'6\': \'Submitted\',\n
\'7\' : \'Expired\',\n \'7\': \'Expired\',\n
\'8\' : \'Refused\',\n \'8\': \'Refused\',\n
\'9\' : \'Cancelled\',\n \'9\': \'Cancelled\',\n
\'10\': \'Waiting\',\n \'10\': \'Waiting\',\n
\'11\': \'Being submitted\',\n \'11\': \'Being submitted\',\n
\'12\': \'Being authorized\',\n \'12\': \'Being authorized\',\n
\'13\': \'Failed\',\n \'13\': \'Failed\',\n
}\n }\n
mark_transaction_id_list = [\'0\', \'1\', \'3\', \'4\', \'5\', \'10\', \'11\', \'12\']\n
continue_transaction_id_list = [\'6\']\n
\n \n
transaction_status = data_kw[\'transactionStatus\']\n transaction_status = data_kw[\'transactionStatus\']\n
\n
transaction_status_description = transaction_code_mapping.get(transaction_status, None)\n transaction_status_description = transaction_code_mapping.get(transaction_status, None)\n
if transaction_status_description is None:\n if transaction_status_description is None:\n
payzen_event.confirm(comment=\'Unknown transactionStatus %r\' % transaction_status)\n payzen_event.confirm(comment=\'Unknown transactionStatus %r\' % transaction_status)\n
return\n return\n
integration_tool = portal.restrictedTraverse(portal.portal_preferences.getPreferredPayzenIntegrationSite())\n
mark_transaction_id_list = [\'0\', \'1\', \'3\', \'4\', \'5\', \'10\', \'11\', \'12\']\n
continue_transaction_id_list = [\'6\']\n
\n \n
isTransitionPossible = context.getPortalObject().portal_workflow.isTransitionPossible\n isTransitionPossible = context.getPortalObject().portal_workflow.isTransitionPossible\n
doActionFor = context.getPortalObject().portal_workflow.doActionFor\n doActionFor = context.getPortalObject().portal_workflow.doActionFor\n
...@@ -99,38 +103,47 @@ if transaction_status in mark_transaction_id_list:\n ...@@ -99,38 +103,47 @@ if transaction_status in mark_transaction_id_list:\n
storeWorkflowComment(transaction, \'Transaction status %s (%s) did not changed the document state\' % (transaction_status, transaction_status_description))\n storeWorkflowComment(transaction, \'Transaction status %s (%s) did not changed the document state\' % (transaction_status, transaction_status_description))\n
payzen_event.confirm()\n payzen_event.confirm()\n
payzen_event.acknowledge(comment=\'Automatic acknowledge as result of correct communication\')\n payzen_event.acknowledge(comment=\'Automatic acknowledge as result of correct communication\')\n
if isTransitionPossible(transaction, \'confirm_action\'):\n if isTransitionPossible(transaction, \'confirm\'):\n
doActionFor(transaction, \'confirm_action\', comment=\'Confirmed as really saw in PayZen.\')\n transaction.confirm(comment=\'Confirmed as really saw in PayZen.\')\n
\n \n
elif transaction_status in continue_transaction_id_list:\n elif transaction_status in continue_transaction_id_list:\n
# Check authAmount and authDevise and if match, stop transaction\n # Check authAmount and authDevise and if match, stop transaction\n
auth_amount = int(data_kw[\'authAmount\'])\n auth_amount = int(data_kw[\'authAmount\'])\n
auth_devise = data_kw[\'authDevise\']\n auth_devise = data_kw[\'authDevise\']\n
transaction_amount = int(round((transaction.PaymentTransaction_getTotalPayablePrice() * -100), 2))\n transaction_amount = int(round((transaction.PaymentTransaction_getTotalPayablePrice() * -100), 2))\n
\n
if transaction_amount != auth_amount:\n if transaction_amount != auth_amount:\n
payzen_event.confirm(comment=\'Received amount (%r) does not match stored on transaction (%r)\'% (auth_amount, transaction_amount))\n payzen_event.confirm(comment=\'Received amount (%r) does not match stored on transaction (%r)\'% (auth_amount, transaction_amount))\n
return\n return\n
\n
transaction_devise = transaction.getResourceValue().Currency_getIntegrationMapping()\n transaction_devise = transaction.getResourceValue().Currency_getIntegrationMapping()\n
if transaction_devise != auth_devise:\n if transaction_devise != auth_devise:\n
payzen_event.confirm(comment=\'Received devise (%r) does not match stored on transaction (%r)\'% (auth_devise, transaction_devise))\n payzen_event.confirm(comment=\'Received devise (%r) does not match stored on transaction (%r)\'% (auth_devise, transaction_devise))\n
return\n return\n
\n
comment = \'PayZen considered as paid.\'\n comment = \'PayZen considered as paid.\'\n
for action in (\'confirm_action\', \'start_action\', \'stop_action\'):\n if isTransitionPossible(transaction, \'confirm\'):\n
if isTransitionPossible(transaction, action):\n transaction.confirm(comment=comment)\n
doActionFor(transaction, action, comment=comment)\n if isTransitionPossible(transaction, \'start\'):\n
transaction.start(comment=comment)\n
if isTransitionPossible(transaction, \'stop\'):\n
transaction.stop(comment=comment)\n
\n
if transaction.getSimulationState() == \'stopped\':\n if transaction.getSimulationState() == \'stopped\':\n
payzen_event.confirm()\n payzen_event.confirm()\n
payzen_event.acknowledge(comment=\'Automatic acknowledge as result of correct communication\')\n payzen_event.acknowledge(comment=\'Automatic acknowledge as result of correct communication\')\n
else:\n else:\n
payzen_event.confirm(comment=\'Expected to put transaction in stopped state, but achieved only %s state\' % transaction.getSimulationState())\n payzen_event.confirm(comment=\'Expected to put transaction in stopped state, but achieved only %s state\' % transaction.getSimulationState())\n
\n
else:\n else:\n
payzen_event.confirm(comment=\'Transaction status %r (%r) is not supported\' % (transaction_status, transaction_status_description))\n payzen_event.confirm(comment=\'Transaction status %r (%r) is not supported\' \\\n
% (transaction_status, transaction_status_description))\n
return\n return\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>state_change, data_kw, signature</string> </value> <value> <string>data_kw, signature, REQUEST=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -94,6 +94,7 @@ ...@@ -94,6 +94,7 @@
<value> <value>
<list> <list>
<string>my_preferred_payzen_integration_site</string> <string>my_preferred_payzen_integration_site</string>
<string>my_preferred_payzen_payment_service_reference</string>
</list> </list>
</value> </value>
</item> </item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>items</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_preferred_payzen_payment_service_reference</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_category</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Preferred PayZen Payment Service</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: [(\'\', \'\')] + [(x.getTitle(), x.getReference()) for x in here.portal_catalog(portal_type=\'Payzen Service\', sort_on=((\'title\', \'ASC\'),),checked_permission=\'View\')]</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
# Copyright (c) 2002-2012 Nexedi SA and Contributors. All Rights Reserved.
import transaction
from Products.SlapOS.tests.testSlapOSMixin import \
testSlapOSMixin
from Products.ERP5Type.tests.utils import createZODBPythonScript
from Products.ERP5Type.tests.backportUnittest import skip
import json
from DateTime import DateTime
class TestSlapOSPayzenUpdateConfirmedPayment(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
def _simulatePaymentTransaction_startPayzenPayment(self):
script_name = 'PaymentTransaction_startPayzenPayment'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\n'
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by PaymentTransaction_startPayzenPayment') """ )
transaction.commit()
def _dropPaymentTransaction_startPayzenPayment(self):
script_name = 'PaymentTransaction_startPayzenPayment'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_alarm_confirmed_solved_payzen(self):
new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
payment_mode="payzen",
)
self.portal.portal_workflow._jumpToStateFor(transaction, 'confirmed')
self.portal.portal_workflow._jumpToStateFor(transaction, 'solved')
self.tic()
self._simulatePaymentTransaction_startPayzenPayment()
try:
self.portal.portal_alarms.slapos_payzen_update_confirmed_payment.activeSense()
self.tic()
finally:
self._dropPaymentTransaction_startPayzenPayment()
self.tic()
self.assertEqual(
'Visited by PaymentTransaction_startPayzenPayment',
transaction.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_not_confirmed(self):
new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
payment_mode="payzen",
)
self.portal.portal_workflow._jumpToStateFor(transaction, 'solved')
self.tic()
self._simulatePaymentTransaction_startPayzenPayment()
try:
self.portal.portal_alarms.slapos_payzen_update_confirmed_payment.activeSense()
self.tic()
finally:
self._dropPaymentTransaction_startPayzenPayment()
self.tic()
self.assertNotEqual(
'Visited by PaymentTransaction_startPayzenPayment',
transaction.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_not_solved(self):
new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
payment_mode="payzen",
)
self.portal.portal_workflow._jumpToStateFor(transaction, 'confirmed')
self.tic()
self._simulatePaymentTransaction_startPayzenPayment()
try:
self.portal.portal_alarms.slapos_payzen_update_confirmed_payment.activeSense()
self.tic()
finally:
self._dropPaymentTransaction_startPayzenPayment()
self.tic()
self.assertNotEqual(
'Visited by PaymentTransaction_startPayzenPayment',
transaction.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_not_payzen(self):
new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
)
self.portal.portal_workflow._jumpToStateFor(transaction, 'confirmed')
self.portal.portal_workflow._jumpToStateFor(transaction, 'solved')
self.tic()
self._simulatePaymentTransaction_startPayzenPayment()
try:
self.portal.portal_alarms.slapos_payzen_update_confirmed_payment.activeSense()
self.tic()
finally:
self._dropPaymentTransaction_startPayzenPayment()
self.tic()
self.assertNotEqual(
'Visited by PaymentTransaction_startPayzenPayment',
transaction.workflow_history['edit_workflow'][-1]['comment'])
def test_not_confirmed_payment(self):
new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
payment_mode="payzen",
)
simulation_state = transaction.getSimulationState()
modification_date = transaction.getModificationDate()
transaction.PaymentTransaction_startPayzenPayment()
self.assertEquals(transaction.getSimulationState(), simulation_state)
self.assertEquals(transaction.getModificationDate(), modification_date)
def test_not_payzen_payment(self):
new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
)
self.portal.portal_workflow._jumpToStateFor(transaction, 'confirmed')
simulation_state = transaction.getSimulationState()
modification_date = transaction.getModificationDate()
transaction.PaymentTransaction_startPayzenPayment()
self.assertEquals(transaction.getSimulationState(), simulation_state)
self.assertEquals(transaction.getModificationDate(), modification_date)
def _simulatePaymentTransaction_sendManualPayzenPaymentUrl(self):
script_name = 'PaymentTransaction_sendManualPayzenPaymentUrl'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\n'
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by PaymentTransaction_sendManualPayzenPaymentUrl') """ )
transaction.commit()
def _dropPaymentTransaction_sendManualPayzenPaymentUrl(self):
script_name = 'PaymentTransaction_sendManualPayzenPaymentUrl'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_expected_payment(self):
new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
payment_mode="payzen",
)
self.portal.portal_workflow._jumpToStateFor(transaction, 'confirmed')
self.portal.portal_workflow._jumpToStateFor(transaction, 'solved')
self._simulatePaymentTransaction_sendManualPayzenPaymentUrl()
try:
transaction.PaymentTransaction_startPayzenPayment()
finally:
self._dropPaymentTransaction_sendManualPayzenPaymentUrl()
self.assertEquals(transaction.getSimulationState(), 'started')
self.assertEqual(
'Visited by PaymentTransaction_sendManualPayzenPaymentUrl',
transaction.workflow_history['edit_workflow'][-1]['comment'])
class TestSlapOSPayzenUpdateStartedPayment(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
def test_not_started_payment(self):
new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
payment_mode="payzen",
)
simulation_state = transaction.getSimulationState()
modification_date = transaction.getModificationDate()
transaction.PaymentTransaction_updateStatus()
self.assertEquals(transaction.getSimulationState(), simulation_state)
self.assertEquals(transaction.getModificationDate(), modification_date)
def test_not_payzen_payment(self):
new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
)
self.portal.portal_workflow._jumpToStateFor(transaction, 'started')
simulation_state = transaction.getSimulationState()
modification_date = transaction.getModificationDate()
transaction.PaymentTransaction_updateStatus()
self.assertEquals(transaction.getSimulationState(), simulation_state)
self.assertEquals(transaction.getModificationDate(), modification_date)
def _simulatePaymentTransaction_addPayzenTicket(self):
script_name = 'PaymentTransaction_addPayzenTicket'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\n'
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by PaymentTransaction_addPayzenTicket') """ )
transaction.commit()
def _dropPaymentTransaction_addPayzenTicket(self):
script_name = 'PaymentTransaction_addPayzenTicket'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_not_registered_payment(self):
new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
payment_mode="payzen",
)
self.portal.portal_workflow._jumpToStateFor(transaction, 'started')
self.portal.portal_workflow._jumpToStateFor(transaction, 'solved')
self._simulatePaymentTransaction_addPayzenTicket()
try:
transaction.PaymentTransaction_updateStatus()
finally:
self._dropPaymentTransaction_addPayzenTicket()
self.assertEquals(transaction.getSimulationState(), 'started')
self.assertEqual(
'Visited by PaymentTransaction_addPayzenTicket',
transaction.workflow_history['edit_workflow'][-1]['comment'])
def _simulatePaymentTransaction_createPaidPayzenEvent(self):
script_name = 'PaymentTransaction_createPayzenEvent'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\n'
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by PaymentTransaction_createPayzenEvent')
class Foo:
def updateStatus(self):
context.stop()
return Foo()
""" )
transaction.commit()
def _simulatePaymentTransaction_createNotPaidPayzenEvent(self):
script_name = 'PaymentTransaction_createPayzenEvent'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\n'
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by PaymentTransaction_createPayzenEvent')
class Foo:
def updateStatus(self):
pass
return Foo()
""" )
transaction.commit()
def _dropPaymentTransaction_createPayzenEvent(self):
script_name = 'PaymentTransaction_createPayzenEvent'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_paid_payment(self):
new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
payment_mode="payzen",
start_date=DateTime(),
)
self.portal.portal_workflow._jumpToStateFor(transaction, 'started')
self.portal.portal_workflow._jumpToStateFor(transaction, 'solved')
# Manually generate mapping
transaction.PaymentTransaction_generatePayzenId()
self._simulatePaymentTransaction_addPayzenTicket()
self._simulatePaymentTransaction_createPaidPayzenEvent()
try:
transaction.PaymentTransaction_updateStatus()
finally:
self._dropPaymentTransaction_addPayzenTicket()
self._dropPaymentTransaction_createPayzenEvent()
self.assertEqual(
'Visited by PaymentTransaction_createPayzenEvent',
transaction.workflow_history['edit_workflow'][-1]['comment'])
self.assertEqual(
None,
transaction.workflow_history['edit_workflow'][-2]['comment'])
self.assertEquals(transaction.getSimulationState(), 'stopped')
def test_not_paid_payment(self):
new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
payment_mode="payzen",
start_date=DateTime(),
)
self.portal.portal_workflow._jumpToStateFor(transaction, 'started')
self.portal.portal_workflow._jumpToStateFor(transaction, 'solved')
# Manually generate mapping
transaction.PaymentTransaction_generatePayzenId()
self._simulatePaymentTransaction_addPayzenTicket()
self._simulatePaymentTransaction_createNotPaidPayzenEvent()
try:
transaction.PaymentTransaction_updateStatus()
finally:
self._dropPaymentTransaction_addPayzenTicket()
self._dropPaymentTransaction_createPayzenEvent()
self.assertEqual(
'Visited by PaymentTransaction_createPayzenEvent',
transaction.workflow_history['edit_workflow'][-2]['comment'])
self.assertEqual(
'Visited by PaymentTransaction_addPayzenTicket',
transaction.workflow_history['edit_workflow'][-1]['comment'])
self.assertEquals(transaction.getSimulationState(), 'started')
def _simulatePaymentTransaction_updateStatus(self):
script_name = 'PaymentTransaction_updateStatus'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\n'
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by PaymentTransaction_updateStatus') """ )
transaction.commit()
def _dropPaymentTransaction_updateStatus(self):
script_name = 'PaymentTransaction_updateStatus'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_alarm_started_solved_payzen(self):
new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
payment_mode="payzen",
)
self.portal.portal_workflow._jumpToStateFor(transaction, 'started')
self.portal.portal_workflow._jumpToStateFor(transaction, 'solved')
self.tic()
self._simulatePaymentTransaction_updateStatus()
try:
self.portal.portal_alarms.slapos_payzen_update_started_payment.activeSense()
self.tic()
finally:
self._dropPaymentTransaction_updateStatus()
self.tic()
self.assertEqual(
'Visited by PaymentTransaction_updateStatus',
transaction.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_not_started(self):
new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
payment_mode="payzen",
)
self.portal.portal_workflow._jumpToStateFor(transaction, 'solved')
self.tic()
self._simulatePaymentTransaction_updateStatus()
try:
self.portal.portal_alarms.slapos_payzen_update_started_payment.activeSense()
self.tic()
finally:
self._dropPaymentTransaction_updateStatus()
self.tic()
self.assertNotEqual(
'Visited by PaymentTransaction_updateStatus',
transaction.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_not_solved(self):
new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
payment_mode="payzen",
)
self.portal.portal_workflow._jumpToStateFor(transaction, 'started')
self.tic()
self._simulatePaymentTransaction_updateStatus()
try:
self.portal.portal_alarms.slapos_payzen_update_started_payment.activeSense()
self.tic()
finally:
self._dropPaymentTransaction_updateStatus()
self.tic()
self.assertNotEqual(
'Visited by PaymentTransaction_updateStatus',
transaction.workflow_history['edit_workflow'][-1]['comment'])
def test_alarm_not_payzen(self):
new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
)
self.portal.portal_workflow._jumpToStateFor(transaction, 'started')
self.portal.portal_workflow._jumpToStateFor(transaction, 'solved')
self.tic()
self._simulatePaymentTransaction_updateStatus()
try:
self.portal.portal_alarms.slapos_payzen_update_started_payment.activeSense()
self.tic()
finally:
self._dropPaymentTransaction_updateStatus()
self.tic()
self.assertNotEqual(
'Visited by PaymentTransaction_updateStatus',
transaction.workflow_history['edit_workflow'][-1]['comment'])
...@@ -2,6 +2,96 @@ ...@@ -2,6 +2,96 @@
import transaction import transaction
from Products.SlapOS.tests.testSlapOSMixin import \ from Products.SlapOS.tests.testSlapOSMixin import \
testSlapOSMixin testSlapOSMixin
from DateTime import DateTime
from zExceptions import Unauthorized
class TestSlapOSPaymentTransaction_sendManualPayzenPaymentUrl(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
def createPaymentTransaction(self):
new_id = self.generateNewId()
return self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
)
def test_sendManualPayzenPaymentUrl_not_payzen_payment(self):
transaction = self.createPaymentTransaction()
self.assertEquals(transaction.PaymentTransaction_sendManualPayzenPaymentUrl(),
None)
def test_sendManualPayzenPaymentUrl_payzen_payment(self):
person1 = self.portal.person_module.newContent(portal_type="Person")
person2 = self.portal.person_module.newContent(portal_type="Person")
transaction = self.createPaymentTransaction()
transaction.edit(
destination_section_value=person1,
source_section_value=person2,
payment_mode="payzen")
before_date = DateTime()
event = transaction.PaymentTransaction_sendManualPayzenPaymentUrl()
after_date = DateTime()
ticket = transaction.PaymentTransaction_addPayzenTicket()
self.assertEquals(event.getPortalType(), 'Site Message')
self.assertTrue(event.getStartDate() >= before_date)
self.assertTrue(event.getStopDate() <= after_date)
self.assertEquals(event.getDestination(),
transaction.getDestinationSection())
self.assertEquals(event.getSourceSection(),
transaction.getSource())
self.assertEquals(event.getTextContent(),
'Please pay your payment by clicking <a href="' + \
transaction.getRelativeUrl() + \
'/PaymentTransaction_redirectToManualPayzenPayment">here</a>.')
self.assertEquals(event.getSimulationState(), 'started')
self.assertEquals(event.getFollowUp(),
ticket.getRelativeUrl())
class TestSlapOSPaymentTransaction_addPayzenTicket(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
def createPaymentTransaction(self):
new_id = self.generateNewId()
return self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
)
def test_addPayzenTicket_not_payzen_payment(self):
transaction = self.createPaymentTransaction()
self.assertEquals(transaction.PaymentTransaction_addPayzenTicket(), None)
def test_addPayzenTicket_payzen_payment(self):
transaction = self.createPaymentTransaction()
transaction.edit(payment_mode="payzen")
ticket = transaction.PaymentTransaction_addPayzenTicket()
self.assertEquals(ticket.getPortalType(), 'Support Request')
self.assertEquals(ticket.getSimulationState(), 'validated')
self.assertEquals(ticket.getSourceProject(), transaction.getRelativeUrl())
self.assertEquals(ticket.getTitle(), 'Payzen Transaction to check')
def test_addPayzenTicket_do_not_duplicate_ticket(self):
transaction = self.createPaymentTransaction()
transaction.edit(payment_mode="payzen")
ticket = transaction.PaymentTransaction_addPayzenTicket()
ticket2 = transaction.PaymentTransaction_addPayzenTicket()
self.assertEquals(ticket.getRelativeUrl(), ticket2.getRelativeUrl())
def test_addPayzenTicket_REQUEST_disallowed(self):
date = DateTime()
transaction = self.createPaymentTransaction()
self.assertRaises(
Unauthorized,
transaction.PaymentTransaction_addPayzenTicket,
REQUEST={})
class TestSlapOSCurrency_getIntegrationMapping(testSlapOSMixin): class TestSlapOSCurrency_getIntegrationMapping(testSlapOSMixin):
...@@ -12,7 +102,7 @@ class TestSlapOSCurrency_getIntegrationMapping(testSlapOSMixin): ...@@ -12,7 +102,7 @@ class TestSlapOSCurrency_getIntegrationMapping(testSlapOSMixin):
currency = self.portal.currency_module.EUR currency = self.portal.currency_module.EUR
self.assertEquals(currency.Currency_getIntegrationMapping(), '978') self.assertEquals(currency.Currency_getIntegrationMapping(), '978')
def test_notIntegratedCurrency(self): def test_getIntegrationMapping_notIntegratedCurrency(self):
new_id = self.generateNewId() new_id = self.generateNewId()
currency = self.portal.currency_module.newContent( currency = self.portal.currency_module.newContent(
portal_type='Currency', portal_type='Currency',
...@@ -22,3 +112,464 @@ class TestSlapOSCurrency_getIntegrationMapping(testSlapOSMixin): ...@@ -22,3 +112,464 @@ class TestSlapOSCurrency_getIntegrationMapping(testSlapOSMixin):
self.assertRaises( self.assertRaises(
AssertionError, AssertionError,
currency.Currency_getIntegrationMapping) currency.Currency_getIntegrationMapping)
class TestSlapOSAccountingTransaction_updateStartDate(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
def createPaymentTransaction(self):
new_id = self.generateNewId()
return self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
)
def test_date_changed(self):
date = DateTime("2001/01/01")
transaction = self.createPaymentTransaction()
transaction.AccountingTransaction_updateStartDate(date)
self.assertEquals(transaction.getStartDate(), date)
def test_REQUEST_disallowed(self):
date = DateTime()
transaction = self.createPaymentTransaction()
self.assertRaises(
Unauthorized,
transaction.AccountingTransaction_updateStartDate,
date, REQUEST={})
class TestSlapOSPaymentTransaction_getPayzenId(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
def createPaymentTransaction(self):
new_id = self.generateNewId()
return self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
)
def test_getPayzenId_newPaymentTransaction(self):
transaction = self.createPaymentTransaction()
self.assertEquals(transaction.PaymentTransaction_getPayzenId(), (None, None))
def test_getPayzenId_mappedPaymentTransaction(self):
transaction = self.createPaymentTransaction()
transaction_date, payzen_id = transaction.PaymentTransaction_generatePayzenId()
transaction_date2, payzen_id2 = transaction.PaymentTransaction_getPayzenId()
self.assertEquals(payzen_id, payzen_id2)
self.assertEquals(transaction_date, transaction_date2)
def test_getPayzenId_manualMappedPaymentTransaction(self):
transaction = self.createPaymentTransaction()
integration_site = self.portal.restrictedTraverse(
self.portal.portal_preferences.getPreferredPayzenIntegrationSite())
try:
mapping = integration_site.getCategoryFromMapping(
'Causality/%s' % transaction.getId().replace('-', '_'),
create_mapping_line=True,
create_mapping=True)
except ValueError:
pass
integration_site.Causality[transaction.getId().replace('-', '_')].\
setDestinationReference("20010101_123456")
transaction_date, payzen_id = transaction.PaymentTransaction_getPayzenId()
self.assertEquals(payzen_id, "123456")
self.assertEquals(transaction_date, DateTime("20010101"))
def test_getPayzenId_REQUEST_disallowed(self):
date = DateTime()
transaction = self.createPaymentTransaction()
self.assertRaises(
Unauthorized,
transaction.PaymentTransaction_getPayzenId,
REQUEST={})
class TestSlapOSPaymentTransaction_generatePayzenId(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
def createPaymentTransaction(self):
new_id = self.generateNewId()
return self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
)
def test_generatePayzenId_newPaymentTransaction(self):
transaction = self.createPaymentTransaction()
transaction_url = transaction.getId().replace('-', '_')
integration_site = self.portal.restrictedTraverse(
self.portal.portal_preferences.getPreferredPayzenIntegrationSite())
# Integration tool returns category value as mapping if nothing is set
mapping = integration_site.getCategoryFromMapping(
'Causality/%s' % transaction_url)
self.assertEquals(mapping, 'causality/%s' % transaction_url)
category = integration_site.getMappingFromCategory(mapping)
self.assertEquals(category, 'Causality/%s' % transaction_url)
transaction_date, payzen_id = transaction.PaymentTransaction_generatePayzenId()
mapping = integration_site.getCategoryFromMapping(
'Causality/%s' % transaction_url)
self.assertEquals(mapping, "%s_%s" % (
transaction_date.asdatetime().strftime('%Y%m%d'), payzen_id))
category = integration_site.getMappingFromCategory('causality/%s' % mapping)
# XXX Not indexed yet
# self.assertEquals(category, 'Causality/%s' % transaction_url)
self.assertNotEquals(payzen_id, None)
self.assertEquals(len(payzen_id), 6)
self.assertEquals(str(int(payzen_id)).zfill(6), payzen_id)
self.assertNotEquals(transaction_date, None)
self.assertEquals(transaction_date.timezone(), 'UTC')
self.assertEquals(transaction_date.asdatetime().strftime('%Y%m%d'),
DateTime().toZone('UTC').asdatetime().strftime('%Y%m%d'))
def test_generatePayzenId_mappedPaymentTransaction(self):
transaction = self.createPaymentTransaction()
transaction.PaymentTransaction_generatePayzenId()
payzen_id = transaction.PaymentTransaction_generatePayzenId()
self.assertEquals(payzen_id, (None, None))
def test_generatePayzenId_increasePaymentId(self):
transaction = self.createPaymentTransaction()
transaction2 = self.createPaymentTransaction()
date, payzen_id = transaction.PaymentTransaction_generatePayzenId()
date2, payzen_id2 = transaction2.PaymentTransaction_generatePayzenId()
self.assertEquals(date.asdatetime().strftime('%Y%m%d'),
date2.asdatetime().strftime('%Y%m%d'))
self.assertNotEquals(payzen_id, payzen_id2)
self.assertTrue(int(payzen_id) < int(payzen_id2))
def test_generatePayzenId_REQUEST_disallowed(self):
date = DateTime()
transaction = self.createPaymentTransaction()
self.assertRaises(
Unauthorized,
transaction.PaymentTransaction_generatePayzenId,
REQUEST={})
class TestSlapOSPaymentTransaction_createPayzenEvent(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
def createPaymentTransaction(self):
new_id = self.generateNewId()
return self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
)
def test_createPayzenEvent_REQUEST_disallowed(self):
date = DateTime()
transaction = self.createPaymentTransaction()
self.assertRaises(
Unauthorized,
transaction.PaymentTransaction_createPayzenEvent,
REQUEST={})
def test_createPayzenEvent_newPayment(self):
date = DateTime()
transaction = self.createPaymentTransaction()
payzen_event = transaction.PaymentTransaction_createPayzenEvent()
self.assertEquals(payzen_event.getPortalType(), "Payzen Event")
self.assertEquals(payzen_event.getSource(),
"portal_secure_payments/slapos_payzen_test")
self.assertEquals(payzen_event.getDestination(), transaction.getRelativeUrl())
def test_createPayzenEvent_kwParameter(self):
date = DateTime()
transaction = self.createPaymentTransaction()
payzen_event = transaction.PaymentTransaction_createPayzenEvent(
title='foo')
self.assertEquals(payzen_event.getPortalType(), "Payzen Event")
self.assertEquals(payzen_event.getSource(),
"portal_secure_payments/slapos_payzen_test")
self.assertEquals(payzen_event.getDestination(), transaction.getRelativeUrl())
self.assertEquals(payzen_event.getTitle(), "foo")
class TestSlapOSPayzenEvent_processUpdate(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
def createPaymentTransaction(self):
new_id = self.generateNewId()
return self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
)
def createPayzenEvent(self):
return self.portal.system_event_module.newContent(
portal_type='Payzen Event',
reference='PAY-%s' % self.generateNewId())
def test_processUpdate_REQUEST_disallowed(self):
date = DateTime()
event = self.createPayzenEvent()
self.assertRaises(
Unauthorized,
event.PayzenEvent_processUpdate,
'a', 'b',
REQUEST={})
def test_processUpdate_noTransaction(self):
date = DateTime()
event = self.createPayzenEvent()
self.assertRaises(
AttributeError,
event.PayzenEvent_processUpdate,
'a', 'b')
def test_processUpdate_signatureBoolean(self):
date = DateTime()
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
event.edit(destination_value=payment)
self.assertRaises(
AssertionError,
event.PayzenEvent_processUpdate,
'a', 'b')
def test_processUpdate_falseSignature(self):
date = DateTime()
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
event.edit(destination_value=payment)
event.PayzenEvent_processUpdate('a', False)
self.assertEquals(event.getValidationState(), "confirmed")
self.assertEqual(
'Signature does not match',
event.workflow_history['system_event_workflow'][-1]['comment'])
def test_processUpdate_wrongDataDictionnary(self):
date = DateTime()
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
event.edit(destination_value=payment)
self.assertRaises(
TypeError,
event.PayzenEvent_processUpdate,
'a', True)
def test_processUpdate_unknownTransactionStatus(self):
date = DateTime()
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
event.edit(destination_value=payment)
data_kw = {
'transactionStatus': 'foo',
}
event.PayzenEvent_processUpdate(data_kw, True)
self.assertEquals(event.getValidationState(), "confirmed")
self.assertEqual(
"Unknown transactionStatus 'foo'",
event.workflow_history['system_event_workflow'][-1]['comment'])
def test_processUpdate_notSupportedTransactionStatus(self):
date = DateTime()
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
event.edit(destination_value=payment)
data_kw = {
'transactionStatus': '2',
}
event.PayzenEvent_processUpdate(data_kw, True)
self.assertEquals(event.getValidationState(), "confirmed")
self.assertEqual(
"Transaction status '2' ('To be forced - Contact issuer') " \
"is not supported",
event.workflow_history['system_event_workflow'][-1]['comment'])
def test_processUpdate_notProcessedTransactionStatus(self):
date = DateTime()
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
payment.edit(start_date=DateTime())
event.edit(destination_value=payment)
data_kw = {
'transactionStatus': '0',
}
event.PayzenEvent_processUpdate(data_kw, True)
self.assertEquals(event.getValidationState(), "acknowledged")
self.assertEqual(
'Automatic acknowledge as result of correct communication',
event.workflow_history['system_event_workflow'][-1]['comment'])
self.assertEquals(payment.getSimulationState(), "confirmed")
self.assertEqual(
'Transaction status 0 (Initial (being treated)) did not changed ' \
'the document state',
payment.workflow_history['edit_workflow'][-1]['comment'])
self.assertEqual(
'Confirmed as really saw in PayZen.',
payment.workflow_history['accounting_workflow'][-1]['comment'])
def test_processUpdate_notProcessedTransactionStatusConfirmedPayment(self):
date = DateTime()
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
payment.edit(start_date=DateTime())
payment.confirm()
event.edit(destination_value=payment)
data_kw = {
'transactionStatus': '0',
}
event.PayzenEvent_processUpdate(data_kw, True)
def test_processUpdate_noAuthAmount(self):
date = DateTime()
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
payment.edit(start_date=DateTime())
event.edit(destination_value=payment)
data_kw = {
'transactionStatus': '6',
}
self.assertRaises(
KeyError,
event.PayzenEvent_processUpdate,
data_kw, True)
def test_processUpdate_noAuthDevise(self):
date = DateTime()
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
payment.edit(start_date=DateTime())
event.edit(destination_value=payment)
data_kw = {
'transactionStatus': '6',
'authAmount': 1,
}
self.assertRaises(
KeyError,
event.PayzenEvent_processUpdate,
data_kw, True)
def test_processUpdate_differentAmount(self):
date = DateTime()
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
payment.edit(start_date=DateTime())
event.edit(destination_value=payment)
data_kw = {
'transactionStatus': '6',
'authAmount': 1,
'authDevise': 1,
}
self.assertEquals(payment.PaymentTransaction_getTotalPayablePrice(), 0)
event.PayzenEvent_processUpdate(data_kw, True)
self.assertEquals(event.getValidationState(), "confirmed")
self.assertEqual(
'Received amount (1) does not match stored on transaction (0)',
event.workflow_history['system_event_workflow'][-1]['comment'])
def test_processUpdate_differentDevise(self):
date = DateTime()
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
payment.edit(
resource='currency_module/EUR',
start_date=DateTime())
event.edit(destination_value=payment)
data_kw = {
'transactionStatus': '6',
'authAmount': 0,
'authDevise': "dollars",
}
self.assertEquals(payment.PaymentTransaction_getTotalPayablePrice(), 0)
event.PayzenEvent_processUpdate(data_kw, True)
self.assertEquals(event.getValidationState(), "confirmed")
self.assertEqual(
"Received devise ('dollars') does not match stored on transaction ('978')",
event.workflow_history['system_event_workflow'][-1]['comment'])
def test_processUpdate_cancelledTransaction(self):
date = DateTime()
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
payment.edit(
resource='currency_module/EUR',
start_date=DateTime())
payment.cancel()
event.edit(destination_value=payment)
data_kw = {
'transactionStatus': '6',
'authAmount': 0,
'authDevise': '978',
}
event.PayzenEvent_processUpdate(data_kw, True)
self.assertEquals(event.getValidationState(), "confirmed")
self.assertEqual(
'Expected to put transaction in stopped state, but achieved only ' \
'cancelled state',
event.workflow_history['system_event_workflow'][-1]['comment'])
def test_processUpdate_defaultUseCase(self):
date = DateTime()
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
payment.edit(
resource='currency_module/EUR',
start_date=DateTime())
event.edit(destination_value=payment)
data_kw = {
'transactionStatus': '6',
'authAmount': 0,
'authDevise': '978',
}
event.PayzenEvent_processUpdate(data_kw, True)
self.assertEquals(payment.getSimulationState(), "stopped")
self.assertEquals(event.getValidationState(), "acknowledged")
self.assertEqual(
'Automatic acknowledge as result of correct communication',
event.workflow_history['system_event_workflow'][-1]['comment'])
# Copyright (c) 2002-2012 Nexedi SA and Contributors. All Rights Reserved.
from Products.SlapOS.tests.testSlapOSMixin import \
testSlapOSMixin
import transaction
from Products.ERP5Type.tests.backportUnittest import expectedFailure
from Products.ERP5Type.Errors import UnsupportedWorkflowMethod
from AccessControl.SecurityManagement import getSecurityManager, \
setSecurityManager
from DateTime import DateTime
from Products.ERP5Type.tests.utils import createZODBPythonScript
import difflib
from functools import wraps
HARDCODED_PRICE = 99.6
vads_url_cancel = 'http://example.org/cancel'
vads_url_error = 'http://example.org/error'
vads_url_referral = 'http://example.org/referral'
vads_url_refused = 'http://example.org/refused'
vads_url_success = 'http://example.org/success'
vads_url_return = 'http://example.org/return'
class TestSlapOSPayzenInterfaceWorkflow(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
def createPaymentTransaction(self):
new_id = self.generateNewId()
return self.portal.accounting_module.newContent(
portal_type='Payment Transaction',
title="Transaction %s" % new_id,
reference="TESTTRANS-%s" % new_id,
)
def createPayzenEvent(self):
return self.portal.system_event_module.newContent(
portal_type='Payzen Event',
reference='PAY-%s' % self.generateNewId())
def _simulatePaymentTransaction_getTotalPayablePrice(self):
script_name = 'PaymentTransaction_getTotalPayablePrice'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\nreturn %f' % HARDCODED_PRICE)
def _dropPaymentTransaction_getTotalPayablePrice(self):
script_name = 'PaymentTransaction_getTotalPayablePrice'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
def test_generateManualPaymentPage_mandatoryParameters(self):
event = self.createPayzenEvent()
# vads_url_cancel
self.assertRaises(TypeError, event.generateManualPaymentPage,
vads_url_error=vads_url_error,
vads_url_referral=vads_url_referral,
vads_url_refused=vads_url_refused,
vads_url_success=vads_url_success,
vads_url_return=vads_url_return,
)
# vads_url_error
self.assertRaises(TypeError, event.generateManualPaymentPage,
vads_url_cancel=vads_url_cancel,
vads_url_referral=vads_url_referral,
vads_url_refused=vads_url_refused,
vads_url_success=vads_url_success,
vads_url_return=vads_url_return,
)
# vads_url_referral
self.assertRaises(TypeError, event.generateManualPaymentPage,
vads_url_cancel=vads_url_cancel,
vads_url_error=vads_url_error,
vads_url_refused=vads_url_refused,
vads_url_success=vads_url_success,
vads_url_return=vads_url_return,
)
# vads_url_refused
self.assertRaises(TypeError, event.generateManualPaymentPage,
vads_url_cancel=vads_url_cancel,
vads_url_error=vads_url_error,
vads_url_referral=vads_url_referral,
vads_url_success=vads_url_success,
vads_url_return=vads_url_return,
)
# vads_url_success
self.assertRaises(TypeError, event.generateManualPaymentPage,
vads_url_cancel=vads_url_cancel,
vads_url_error=vads_url_error,
vads_url_referral=vads_url_referral,
vads_url_refused=vads_url_refused,
vads_url_return=vads_url_return,
)
# vads_url_return
self.assertRaises(TypeError, event.generateManualPaymentPage,
vads_url_cancel=vads_url_cancel,
vads_url_error=vads_url_error,
vads_url_referral=vads_url_referral,
vads_url_refused=vads_url_refused,
vads_url_success=vads_url_success,
)
def test_generateManualPaymentPage_noAccountingTransaction(self):
event = self.createPayzenEvent()
self.assertRaises(AttributeError, event.generateManualPaymentPage,
vads_url_cancel=vads_url_cancel,
vads_url_error=vads_url_error,
vads_url_referral=vads_url_referral,
vads_url_refused=vads_url_refused,
vads_url_success=vads_url_success,
vads_url_return=vads_url_return,
)
def test_generateManualPaymentPage_registeredTransaction(self):
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
event.edit(destination_value=payment)
transaction_date, payzen_id = payment.PaymentTransaction_generatePayzenId()
self.assertRaises(ValueError, event.generateManualPaymentPage,
vads_url_cancel=vads_url_cancel,
vads_url_error=vads_url_error,
vads_url_referral=vads_url_referral,
vads_url_refused=vads_url_refused,
vads_url_success=vads_url_success,
vads_url_return=vads_url_return,
)
def test_generateManualPaymentPage_noPaymentService(self):
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
event.edit(destination_value=payment)
self.assertRaises(AttributeError, event.generateManualPaymentPage,
vads_url_cancel=vads_url_cancel,
vads_url_error=vads_url_error,
vads_url_referral=vads_url_referral,
vads_url_refused=vads_url_refused,
vads_url_success=vads_url_success,
vads_url_return=vads_url_return,
)
def test_generateManualPaymentPage_noCurrency(self):
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
event.edit(
destination_value=payment,
source="portal_secure_payments/slapos_payzen_test",
)
self.assertRaises(AttributeError, event.generateManualPaymentPage,
vads_url_cancel=vads_url_cancel,
vads_url_error=vads_url_error,
vads_url_referral=vads_url_referral,
vads_url_refused=vads_url_refused,
vads_url_success=vads_url_success,
vads_url_return=vads_url_return,
)
def test_generateManualPaymentPage_defaultUseCase(self):
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
payment.edit(
resource="currency_module/EUR",
)
event.edit(
destination_value=payment,
source="portal_secure_payments/slapos_payzen_test",
)
before_date = DateTime()
self._simulatePaymentTransaction_getTotalPayablePrice()
try:
event.generateManualPaymentPage(
vads_url_cancel=vads_url_cancel,
vads_url_error=vads_url_error,
vads_url_referral=vads_url_referral,
vads_url_refused=vads_url_refused,
vads_url_success=vads_url_success,
vads_url_return=vads_url_return,
)
finally:
self._dropPaymentTransaction_getTotalPayablePrice()
after_date = DateTime()
# Payment start date is modified
self.assertTrue(payment.getStartDate() >= before_date)
self.assertTrue(payment.getStopDate() <= after_date)
# Payment is registered
transaction_date, transaction_id = \
payment.PaymentTransaction_getPayzenId()
self.assertNotEquals(transaction_date, None)
self.assertNotEquals(transaction_id, None)
# Event state
self.assertEquals(event.getValidationState(), "acknowledged")
data_dict = {
'vads_language': 'en',
'vads_url_cancel': vads_url_cancel,
'vads_url_error': vads_url_error,
'vads_url_referral': vads_url_referral,
'vads_url_refused': vads_url_refused,
'vads_url_success': vads_url_success,
'vads_url_return': vads_url_return,
'vads_trans_date': payment.getStartDate().toZone('UTC')\
.asdatetime().strftime('%Y%m%d%H%M%S'),
'vads_amount': str(int(HARDCODED_PRICE * -100)),
'vads_currency': 978,
'vads_trans_id': transaction_id,
'vads_site_id': 'foo',
}
# Calculate the signature...
self.portal.portal_secure_payments.slapos_payzen_test._getFieldList(data_dict)
data_dict['action'] = 'https://secure.payzen.eu/vads-payment/'
expected_html_page = \
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w'\
'3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n<html xmlns="http://www.w3.or'\
'g/1999/xhtml" xml:lang="en" lang="en">\n<head>\n <meta http-equiv="Co'\
'ntent-Type" content="text/html; charset=utf-8" />\n <meta http-equiv='\
'"Content-Script-Type" content="text/javascript" />\n <meta http-equiv'\
'="Content-Style-Type" content="text/css" />\n <title>title</title>\n<'\
'/head>\n<body onload="document.payment.submit();">\n<form method="POST'\
'" id="payment" name="payment"\n action="%(action)s">\n\n <input '\
'type="hidden" name="vads_url_return"\n value="'\
'%(vads_url_return)s">\n\n\n <input type="hidden" name="vads_site_id" '\
'value="%(vads_site_id)s">\n\n\n <input type="hidden" name="vads_url_e'\
'rror"\n value="%(vads_url_error)s">\n\n\n <input type="hidden'\
'" name="vads_trans_id" value="%(vads_trans_id)s">\n\n\n <input type="'\
'hidden" name="vads_action_mode"\n value="INTERACTIVE">\n\n\n '\
'<input type="hidden" name="vads_url_success"\n value="'\
'%(vads_url_success)s">\n\n\n <input type="hidden" name="vads_url_refe'\
'rral"\n value="%(vads_url_referral)s">\n\n\n <input type="hid'\
'den" name="vads_page_action"\n value="PAYMENT">\n\n\n <input '\
'type="hidden" name="vads_trans_date"\n value="'\
'%(vads_trans_date)s">\n\n\n <input type="hidden" name="vads_url_refus'\
'ed"\n value="%(vads_url_refused)s">\n\n\n <input type="hidden'\
'" name="vads_url_cancel"\n value="%(vads_url_cancel)s">\n\n\n '\
' <input type="hidden" name="vads_ctx_mode" value="TEST">\n\n\n <input '\
'type="hidden" name="vads_payment_config"\n value="SINGLE">\n\n'\
'\n <input type="hidden" name="vads_contrib" value="ERP5">\n\n\n <inp'\
'ut type="hidden" name="signature"\n value="%(signature)s">\n\n'\
'\n <input type="hidden" name="vads_language" value="%(vads_language)s">\n\n\n <inpu'\
't type="hidden" name="vads_currency" value="%(vads_currency)s">\n\n\n '\
' <input type="hidden" name="vads_amount" value="%(vads_amount)s">\n\n\n'\
' <input type="hidden" name="vads_version" value="V2">\n\n<input type="s'\
'ubmit" value="Click to pay">\n</form>\n</body>\n</html>' % data_dict
# Event message state
event_message_list = event.contentValues(portal_type="Payzen Event Message")
self.assertEquals(len(event_message_list), 1)
message = event_message_list[0]
self.assertEqual(message.getTitle(), 'Shown Page')
self.assertEqual(message.getTextContent(), expected_html_page,
'\n'.join([q for q in difflib.unified_diff(expected_html_page.split('\n'),
message.getTextContent().split('\n'))]))
def test_updateStatus_noAccountingTransaction(self):
event = self.createPayzenEvent()
self.assertRaises(AttributeError, event.updateStatus)
def test_updateStatus_notRegisteredTransaction(self):
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
event.edit(
destination_value=payment,
)
self.assertRaises(ValueError, event.updateStatus)
def test_updateStatus_noPaymentService(self):
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
event.edit(
destination_value=payment,
)
transaction_date, payzen_id = payment.PaymentTransaction_generatePayzenId()
self.assertRaises(AttributeError, event.updateStatus)
def mockSoapGetInfo(self, method_to_call, expected_args, result_tuple):
payment_service = self.portal.portal_secure_payments.slapos_payzen_test
def mocksoad_getInfo(arg1, arg2):
self.assertEquals(arg1, expected_args[0])
self.assertEquals(arg2, expected_args[1])
return result_tuple
setattr(payment_service, 'soap_getInfo', mocksoad_getInfo)
try:
return method_to_call()
finally:
del payment_service.soap_getInfo
def _simulatePayzenEvent_processUpdate(self):
script_name = 'PayzenEvent_processUpdate'
if script_name in self.portal.portal_skins.custom.objectIds():
raise ValueError('Precondition failed: %s exists in custom' % script_name)
createZODBPythonScript(self.portal.portal_skins.custom,
script_name,
'*args, **kwargs',
'# Script body\n'
"""portal_workflow = context.portal_workflow
portal_workflow.doActionFor(context, action='edit_action', comment='Visited by PayzenEvent_processUpdate') """ )
transaction.commit()
def _dropPayzenEvent_processUpdate(self):
script_name = 'PayzenEvent_processUpdate'
if script_name in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_name)
transaction.commit()
def test_updateStatus_defaultUseCase(self):
event = self.createPayzenEvent()
payment = self.createPaymentTransaction()
event.edit(
destination_value=payment,
source="portal_secure_payments/slapos_payzen_test",
)
transaction_date, transaction_id = \
payment.PaymentTransaction_generatePayzenId()
mocked_data_kw = 'mocked_data_kw'
mocked_signature = 'mocked_signature'
mocked_sent_text = 'mocked_sent_text'
mocked_received_text = 'mocked_received_text'
self._simulatePayzenEvent_processUpdate()
try:
self.mockSoapGetInfo(
event.updateStatus,
(transaction_date.toZone('UTC').asdatetime(), transaction_id),
(mocked_data_kw, mocked_signature, mocked_sent_text, mocked_received_text),
)
finally:
self._dropPayzenEvent_processUpdate()
event_message_list = event.contentValues(portal_type="Payzen Event Message")
self.assertEquals(len(event_message_list), 2)
sent_message = [x for x in event_message_list \
if x.getTitle() == 'Sent SOAP'][0]
self.assertEquals(sent_message.getTextContent(), mocked_sent_text)
received_message = [x for x in event_message_list \
if x.getTitle() == 'Received SOAP'][0]
self.assertEquals(received_message.getPredecessor(),
sent_message.getRelativeUrl())
self.assertEquals(received_message.getTextContent(), mocked_received_text)
self.assertEqual(
'Visited by PayzenEvent_processUpdate',
event.workflow_history['edit_workflow'][-1]['comment'])
<?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>from DateTime import DateTime\n
payzen_event = state_change[\'object\']\n
\n
# Get required arguments\n
kwargs = state_change.kwargs\n
\n
# Required args\n
# Raise TypeError if all parameters are not provided\n
try:\n
vads_url_cancel = kwargs[\'vads_url_cancel\']\n
vads_url_error = kwargs[\'vads_url_error\']\n
vads_url_referral = kwargs[\'vads_url_referral\']\n
vads_url_refused = kwargs[\'vads_url_refused\']\n
vads_url_success = kwargs[\'vads_url_success\']\n
vads_url_return = kwargs[\'vads_url_return\']\n
except KeyError:\n
raise TypeError, "PayzenEvent_generateNavigationPage takes exactly 6 arguments"\n
\n
payment_transaction = payzen_event.getDestinationValue(portal_type="Payment Transaction")\n
now = DateTime()\n
payment_transaction.AccountingTransaction_updateStartDate(now)\n
\n
transaction_date, transaction_id = payment_transaction.PaymentTransaction_generatePayzenId()\n
if transaction_id is None:\n
raise ValueError, "Transaction already registered"\n
\n
payzen_event.confirm()\n
payzen_event.acknowledge(comment=\'Automatic acknowledge as result of correct communication\')\n
\n
today = now.toZone(\'UTC\').asdatetime().strftime(\'%Y%m%d\')\n
payzen_dict = {\n
\'vads_currency\': payment_transaction.getResourceValue().Currency_getIntegrationMapping(),\n
\'vads_amount\': str(int(round((payment_transaction.PaymentTransaction_getTotalPayablePrice() * -100), 0))),\n
\'vads_trans_date\': now.toZone(\'UTC\').asdatetime().strftime(\'%Y%m%d%H%M%S\'),\n
\'vads_trans_id\': transaction_id,\n
\'vads_language\': \'en\',\n
\'vads_url_cancel\': vads_url_cancel,\n
\'vads_url_error\': vads_url_error,\n
\'vads_url_referral\': vads_url_referral,\n
\'vads_url_refused\': vads_url_refused,\n
\'vads_url_success\': vads_url_success,\n
\'vads_url_return\': vads_url_return,\n
}\n
\n
payment_service = payzen_event.getSourceValue(portal_type="Payzen Service")\n
html_document = payment_service.navigate(\n
page_template=\'payzen_payment\',\n
pay=\'Click to pay\',\n
payzen_dict=payzen_dict,\n
)\n
payzen_event.newContent(\n
title=\'Shown Page\',\n
portal_type=\'Payzen Event Message\',\n
text_content=html_document,\n
)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>PayzenEvent_generateNavigationPage</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -55,13 +55,10 @@ ...@@ -55,13 +55,10 @@
In order to not transmit sensitive information the registration is done by looking the newest\n In order to not transmit sensitive information the registration is done by looking the newest\n
payzen related transaction for destination_section and doing its duplicate"""\n payzen related transaction for destination_section and doing its duplicate"""\n
\n \n
raise NotImplementedError\n
\n
from DateTime import DateTime\n from DateTime import DateTime\n
payzen_event = state_change[\'object\']\n payzen_event = state_change[\'object\']\n
transaction = payzen_event.getDestinationValue()\n transaction = payzen_event.getDestinationValue()\n
portal = transaction.getPortalObject()\n portal = transaction.getPortalObject()\n
integration_site = portal.restrictedTraverse(portal.portal_preferences.getPreferredPayzenIntegrationSite())\n
service = portal.portal_secure_payments.find()\n service = portal.portal_secure_payments.find()\n
\n \n
previous_id = transaction.PaymentTransaction_getPreviousPayzenId()\n previous_id = transaction.PaymentTransaction_getPreviousPayzenId()\n
...@@ -69,25 +66,10 @@ if previous_id is None:\n ...@@ -69,25 +66,10 @@ if previous_id is None:\n
payzen_event.confirm(comment=\'No previous id found\')\n payzen_event.confirm(comment=\'No previous id found\')\n
return\n return\n
\n \n
previous_date, previous_id = previous_id.split(\'_\')\n transaction_date, transaction_id = transaction.PaymentTransaction_generatePayzenId()\n
today = DateTime().toZone(\'UTC\').asdatetime().strftime(\'%Y%m%d\')\n if transaction_id is None:\n
transaction_id = str(portal.portal_ids.generateNewId(\n
id_group=\'%s_%s\' % (service.getRelativeUrl(), today),\n
id_generator=\'uid\')).zfill(6)\n
\n
mapping_id = \'%s_%s\' % (today, transaction_id)\n
\n
if not integration_site.getMappingFromCategory(\'causality/%s\' % transaction.getRelativeUrl()) == \'Causality/%s\' % transaction.getRelativeUrl():\n
raise ValueError(\'Transaction already mapped in integration tool.\')\n raise ValueError(\'Transaction already mapped in integration tool.\')\n
\n \n
try:\n
integration_site.getCategoryFromMapping(\'Causality/%s\' % mapping_id, create_mapping_line=True, create_mapping=True)\n
except ValueError:\n
mapping = integration_site.Causality[mapping_id]\n
mapping.setDestinationReference(\'causality/%s\' % transaction.getRelativeUrl())\n
else:\n
raise ValueError(\'Key %s already found.\' % mapping_id)\n
\n
# do causality mapping in integration_site between transaction.getRelativeUrl and today + transaction_id\n # do causality mapping in integration_site between transaction.getRelativeUrl and today + transaction_id\n
payzen_dict = {}\n payzen_dict = {}\n
payzen_dict.update(\n payzen_dict.update(\n
...@@ -95,7 +77,7 @@ payzen_dict.update(\n ...@@ -95,7 +77,7 @@ payzen_dict.update(\n
amount=str(int(round((transaction.PaymentTransaction_getTotalPayablePrice() * -100), 0))),\n amount=str(int(round((transaction.PaymentTransaction_getTotalPayablePrice() * -100), 0))),\n
presentationDate=transaction.getStartDate().toZone(\'UTC\').asdatetime(),\n presentationDate=transaction.getStartDate().toZone(\'UTC\').asdatetime(),\n
newTransactionId=transaction_id,\n newTransactionId=transaction_id,\n
transmissionDate=DateTime(previous_date).toZone(\'UTC\').asdatetime(),\n transmissionDate=transaction_date.asdatetime(),\n
transactionId=previous_id\n transactionId=previous_id\n
)\n )\n
\n \n
......
...@@ -50,24 +50,29 @@ ...@@ -50,24 +50,29 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>raise NotImplementedError\n <value> <string>payzen_event = state_change[\'object\']\n
\n payment_transaction = payzen_event.getDestinationValue(portal_type="Payment Transaction")\n
payzen_event = state_change[\'object\']\n
payment_transaction = payzen_event.getDestinationValue()\n
portal = payment_transaction.getPortalObject()\n portal = payment_transaction.getPortalObject()\n
service = portal.portal_secure_payments.find()\n
integration_tool = portal.restrictedTraverse(portal.portal_preferences.getPreferredPayzenIntegrationSite())\n
\n \n
transaction_id = integration_tool.getMappingFromCategory(\'causality/%s\' % payment_transaction.getRelativeUrl())\n transaction_date, transaction_id = payment_transaction.PaymentTransaction_getPayzenId()\n
if transaction_id == \'Causality/%s\' % payment_transaction.getRelativeUrl():\n if transaction_id is None:\n
raise ValueError(\'Transaction not registered in payzen integration tool\')\n raise ValueError(\'Transaction not registered in payzen integration tool\')\n
transaction_id = transaction_id.split(\'/\')[1]\n
transmissionDate, transactionId = transaction_id.split(\'_\')\n
\n \n
data_kw, signature, sent_text, received_text = service.soap_getInfo(DateTime(transmissionDate).toZone(\'UTC\').asdatetime(), transactionId)\n payment_service = payzen_event.getSourceValue(portal_type="Payzen Service")\n
sent = payzen_event.newContent(title=\'Sent SOAP\', portal_type=\'Payzen Event Message\', text_content=sent_text)\n data_kw, signature, sent_text, received_text = payment_service.soap_getInfo(\n
received = payzen_event.newContent(title=\'Received SOAP\', portal_type=\'Payzen Event Message\', text_content=received_text, predecessor_value=sent)\n transaction_date.toZone(\'UTC\').asdatetime(),\n
context.PayzenEvent_processUpdate(state_change, data_kw, signature)\n transaction_id)\n
\n
sent = payzen_event.newContent(\n
title=\'Sent SOAP\', \n
portal_type=\'Payzen Event Message\', \n
text_content=sent_text)\n
received = payzen_event.newContent(\n
title=\'Received SOAP\', \n
portal_type=\'Payzen Event Message\', \n
text_content=received_text, \n
predecessor_value=sent)\n
payzen_event.PayzenEvent_processUpdate(data_kw, signature)\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
......
...@@ -22,10 +22,7 @@ ...@@ -22,10 +22,7 @@
<key> <string>transitions</string> </key> <key> <string>transitions</string> </key>
<value> <value>
<tuple> <tuple>
<string>register_payzen</string> <string>generate_manual_payment_page</string>
<string>report_error</string>
<string>report_success</string>
<string>start_payment</string>
<string>update_status</string> <string>update_status</string>
</tuple> </tuple>
</value> </value>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="TransitionDefinition" module="Products.DCWorkflow.Transitions"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>actbox_category</string> </key>
<value> <string>workflow</string> </value>
</item>
<item>
<key> <string>actbox_icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_url</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>after_script_name</string> </key>
<value> <string>PayzenEvent_generateNavigationPage</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>generate_manual_payment_page</string> </value>
</item>
<item>
<key> <string>new_state_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>script_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -2,3 +2,4 @@ slapos_accounting ...@@ -2,3 +2,4 @@ slapos_accounting
erp5_tiosafe_core erp5_tiosafe_core
erp5_system_event erp5_system_event
erp5_payzen_secure_payment erp5_payzen_secure_payment
erp5_crm
\ No newline at end of file
87 88
\ No newline at end of file \ No newline at end of file
...@@ -4,6 +4,7 @@ portal_integrations/slapos_payzen_test_integration ...@@ -4,6 +4,7 @@ portal_integrations/slapos_payzen_test_integration
portal_integrations/slapos_payzen_test_integration/Causality portal_integrations/slapos_payzen_test_integration/Causality
portal_integrations/slapos_payzen_test_integration/Resource portal_integrations/slapos_payzen_test_integration/Resource
portal_integrations/slapos_payzen_test_integration/Resource/** portal_integrations/slapos_payzen_test_integration/Resource/**
portal_integrations/slapos_payzen_test_integration/SourceProject
portal_secure_payments/slapos_payzen_test portal_secure_payments/slapos_payzen_test
portal_secure_payments/slapos_payzen_test/** portal_secure_payments/slapos_payzen_test/**
sale_trade_condition_module/payzen_sale_trade_condition sale_trade_condition_module/payzen_sale_trade_condition
\ No newline at end of file
testSlapOSPayzenSkins testSlapOSPayzenSkins
testSlapOSPayzenAlarm
testSlapOSPayzenWorkflow
\ No newline at end of file
...@@ -52,72 +52,30 @@ ...@@ -52,72 +52,30 @@
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string># TODO: Return configured web page in case of system issues.\n <value> <string># TODO: Return configured web page in case of system issues.\n
from ZTUtils import make_query\n from ZTUtils import make_query\n
from DateTime import DateTime\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
service = portal.portal_secure_payments.find()\n
integration_site = portal.restrictedTraverse(portal.portal_preferences.getPreferredPayzenIntegrationSite())\n
\n \n
now = DateTime()\n transaction_date, transaction_id = payment.PaymentTransaction_getPayzenId()\n
today = now.toZone(\'UTC\').asdatetime().strftime(\'%Y%m%d\')\n if transaction_id is not None:\n
current_today = today\n
transaction_id = None\n
current_id = None\n
if integration_site.getMappingFromCategory(\'causality/%s\' % context.getRelativeUrl()) != \'Causality/%s\' % context.getRelativeUrl():\n
current_id = integration_site.getMappingFromCategory(\'causality/%s\' % context.getRelativeUrl())\n
current_today, transaction_id = current_id.split(\'_\')\n
\n
if current_id is not None:\n
message = context.Base_translateString("Payment already registered.")\n message = context.Base_translateString("Payment already registered.")\n
return context.getWebSiteValue().Base_redirect(keep_items={\'portal_status_message\': message})\n return context.getWebSiteValue().Base_redirect(keep_items={\'portal_status_message\': message})\n
\n \n
system_event_kw = {\n callback_websection = context.getWebSiteValue().payzen_callback\n
\'portal_type\': \'Payzen Event\',\n
\'source_value\': service,\n
\'destination_value\': context,\n
}\n
system_event = portal.system_event_module.newContent(title=\'User navigation script for %s\' % context.getTitle(), **system_event_kw)\n
\n
transaction_id = str(portal.portal_ids.generateNewId(\n
id_group=\'%s_%s\' % (service.getRelativeUrl(), today),\n
id_generator=\'uid\')).zfill(6)\n
\n
mapping_id = \'%s_%s\' % (today, transaction_id)\n
try:\n
integration_site.getCategoryFromMapping(\'Causality/%s\' % mapping_id, create_mapping_line=True, create_mapping=True)\n
except ValueError:\n
mapping = integration_site.Causality[mapping_id]\n
mapping.setDestinationReference(\'causality/%s\' % context.getRelativeUrl())\n
if current_today != today:\n
# Cleanup as integration site does not support multiple mappings to with external site\n
integration_site.Causality.deleteContent(current_id.split(\'/\')[1])\n
else:\n
system_event.confirm(comment=\'Key %s already found!\' % mapping_id)\n
return \'There was system issue\'\n
\n
\n
context.AccountingTransaction_updateStartDate(now)\n
context.updateCausalityState()\n
callback = context.getWebSiteValue().payzen_callback\n
query = make_query(dict(transaction=context.getRelativeUrl()))\n query = make_query(dict(transaction=context.getRelativeUrl()))\n
payzen_dict = {}\n \n
payzen_dict.update(\n system_event = context.PaymentTransaction_createPayzenEvent(\n
vads_currency=integration_site.getMappingFromCategory(\'resource/currency_module/%s\' % context.getResourceReference()).split(\'/\')[-1],\n title=\'User navigation script for %s\' % context.getTitle()\n
vads_amount=str(int(round((context.PaymentTransaction_getTotalPayablePrice() * -100), 0))),\n
vads_trans_date=now.toZone(\'UTC\').asdatetime().strftime(\'%Y%m%d%H%M%S\'),\n
vads_trans_id=transaction_id,\n
vads_language=\'en\',\n
vads_url_cancel=callback.cancel.absolute_url() + \'?\' + query,\n
vads_url_error=callback.error.absolute_url() + \'?\' + query,\n
vads_url_referral=callback.referral.absolute_url() + \'?\' + query,\n
vads_url_refused=callback.refused.absolute_url() + \'?\' + query,\n
vads_url_success=callback.success.absolute_url() + \'?\' + query,\n
vads_url_return=getattr(callback, \'return\').absolute_url() + \'?\' + query\n
)\n )\n
system_event.confirm()\n system_event.generateManualPaymentPage(\n
result = service.navigate(page_template=\'payzen_payment\', pay=\'Click to pay\', payzen_dict=payzen_dict)\n vads_url_cancel=\'%s?%s\' % (callback_websection.cancel.absolute_url(), query),\n
system_event.newContent(title=\'Shown Page\', portal_type=\'Payzen Event Message\', text_content=result)\n vads_url_error=\'%s?%s\' % (callback_websection.error.absolute_url(), query),\n
system_event.acknowledge(comment=\'Automatic acknowledge as result of correct communication\')\n vads_url_referral=\'%s?%s\' % (callback_websection.referral.absolute_url(), query),\n
return result\n vads_url_refused=\'%s?%s\' % (callback_websection.refused.absolute_url(), query),\n
vads_url_success=\'%s?%s\' % (callback_websection.success.absolute_url(), query),\n
vads_url_return=\'%s?%s\' % (getattr(callback_websection, \'return\').absolute_url(), query),\n
)\n
\n
return system_event.contentValues(\n
portal_type="Payzen Event Message")[0].getTextContent()\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
...@@ -126,7 +84,7 @@ return result\n ...@@ -126,7 +84,7 @@ return result\n
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>AccountingTransaction_startPayment</string> </value> <value> <string>PaymentTransaction_redirectToManualPayzenPayment</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
8 9
\ No newline at end of file \ 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