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

WIP: Stabilise PayZen integration.

Avoid using started state, as it is impossible for customer to move Payment
Transaction into this state.

Just use planned and confirmed states and synchronously try to move to confirmed
when user tries to access the transaction.

Support a case when customer will leave Vifib.net site but will not finish the payment.
In such case just propose him to pay again the transaction, and if required, setup
newer PayZen integration id (eg. in case of big, like a day, delay).

In case if transaction was proposed to be paid and user sucessfully paid it before
update immediately transaction status.
parent 09f12d8e
...@@ -89,7 +89,7 @@ ...@@ -89,7 +89,7 @@
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>Register planned Payment Transaction in payzen</string> </value> <value> <string>Register planned Payment Transaction in PayZen</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>context.getPortalObject().portal_workflow.doActionFor(context, \'confirm_action\', comment=\'Transaction waiting for update from PayZen\')\n <value> <string>context.getPortalObject().portal_workflow.doActionFor(context, \'confirm_action\', comment=\'Transaction synchronised with PayZen\')\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
......
...@@ -50,9 +50,17 @@ ...@@ -50,9 +50,17 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n <value> <string>from DateTime import DateTime\n
portal = context.getPortalObject()\n
if context.getSimulationState() != \'planned\':\n if context.getSimulationState() != \'planned\':\n
return\n return\n
previous_id = context.PaymentTransaction_getPreviousPayzenId()\n
if previous_id is None:\n
# nothing to do yet\n
return\n
\n
context.setStartDate(DateTime())\n
context.updateCausalityState()\n
service = portal.portal_secure_payments.find()\n service = portal.portal_secure_payments.find()\n
portal.system_event_module.newContent(title=\'Transaction %s Payzen registration\' % context.getTitle(), portal_type=\'Payzen Event\', source_value=service, destination_value=context).registerPayzen()\n portal.system_event_module.newContent(title=\'Transaction %s Payzen registration\' % context.getTitle(), portal_type=\'Payzen Event\', source_value=service, destination_value=context).registerPayzen()\n
</string> </value> </string> </value>
......
...@@ -50,7 +50,9 @@ ...@@ -50,7 +50,9 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>context.getPortalObject().portal_workflow.doActionFor(context, \'start_action\', comment=\'Transaction considered as paid by PayZen\')\n <value> <string>portal_workflow = context.getPortalObject().portal_workflow\n
if portal_workflow.isTransitionPossible(context, \'stopAction\'):\n
portal_workflow.doActionFor(context, \'stop_action\', comment=\'Transaction considered as paid by PayZen\')\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n <value> <string>portal = context.getPortalObject()\n
if context.getSimulationState() not in [\'confirmed\', \'started\']:\n if context.getSimulationState() not in [\'planned\', \'confirmed\']:\n
return\n return\n
service = portal.portal_secure_payments.find()\n service = portal.portal_secure_payments.find()\n
portal.system_event_module.newContent(title=\'Transaction %s Payzen status update\' % context.getTitle(), portal_type=\'Payzen Event\', source_value=service, destination_value=context).updateStatus()\n portal.system_event_module.newContent(title=\'Transaction %s Payzen status update\' % context.getTitle(), portal_type=\'Payzen Event\', source_value=service, destination_value=context).updateStatus()\n
......
...@@ -50,16 +50,24 @@ ...@@ -50,16 +50,24 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>context.getPortalObject().portal_workflow.doActionFor(context, \'start_action\', comment=\'Transaction confirmed to exists on PayZen side\')\n <value> <string>if simulation_state_list is None:\n
simulation_state_list = [\'planned\', \'confirmed\', \'started\', \'stopped\', \'delivered\']\n
person = context\n
\n
return context.portal_catalog.countResults(\n
portal_type=\'Payment Transaction\',\n
simulation_state=simulation_state_list,\n
default_destination_section_uid=person.getUid(),\n
)[0][0]\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>simulation_state_list=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>PaymentTransaction_start</string> </value> <value> <string>Person_countPayment</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -54,12 +54,13 @@ ...@@ -54,12 +54,13 @@
\n \n
payment_transaction = context.portal_catalog.getResultValue(\n payment_transaction = context.portal_catalog.getResultValue(\n
portal_type=\'Payment Transaction\',\n portal_type=\'Payment Transaction\',\n
simulation_state=[\'planned\', \'confirmed\'],\n simulation_state=\'planned\',\n
causality_state=\'solved\',\n
default_destination_section_uid=person.getUid(),\n default_destination_section_uid=person.getUid(),\n
sort_on=((\'creation_date\', \'ASC\'), )\n sort_on=((\'creation_date\', \'ASC\'), )\n
)\n )\n
\n \n
if payment_transaction is not None and payment_transaction.getSimulationState() in [\'planned\', \'confirmed\']:\n if payment_transaction is not None and payment_transaction.getSimulationState() in [\'planned\'] and payment_transaction.getCausalityState() in [\'solved\']:\n
return payment_transaction\n return payment_transaction\n
return None\n return None\n
</string> </value> </string> </value>
......
...@@ -98,11 +98,9 @@ if transaction_status in mark_transaction_id_list:\n ...@@ -98,11 +98,9 @@ if transaction_status in mark_transaction_id_list:\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 transaction.getSimulationState() == \'planned\':\n if transaction.getSimulationState() == \'planned\':\n
transaction.confirm()\n transaction.confirm()\n
if transaction.getSimulationState() == \'confirmed\':\n
transaction.PaymentTransaction_start()\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, start 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
......
61 62
\ No newline at end of file \ No newline at end of file
...@@ -53,24 +53,34 @@ ...@@ -53,24 +53,34 @@
<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 DateTime import DateTime\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
if context.getSimulationState() != \'planned\':\n
message = context.Base_translateString("Payment already registered.")\n
return context.getWebSiteValue().Base_redirect(keep_items={\'portal_status_message\': message})\n
\n \n
previous_id = context.PaymentTransaction_getPreviousPayzenId()\n previous_id = context.PaymentTransaction_getPreviousPayzenId()\n
\n \n
if context.getSimulationState() == \'planned\' and previous_id is not None:\n now = DateTime()\n
# och, it was possible to register this transaction\n today = now.toZone(\'UTC\').asdatetime().strftime(\'%Y%m%d\')\n
context.PaymentTransaction_registerPayzen()\n current_today = today\n
message = context.Base_translateString("Payment was automatically registered to PayZen system.")\n transaction_id = None\n
return context.getWebSiteValue().Base_redirect(keep_items={\'portal_status_message\': message})\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 \n
if context.getSimulationState() == \'confirmed\':\n \n
# let\'s try to update state\n if transaction_id is not None:\n
context.PaymentTransaction_updateStatus()\n context.PaymentTransaction_updateStatus()\n
if context.getSimulationState() == \'started\':\n elif previous_id is not None:\n
message = context.Base_translateString("Payment was automatically registered to PayZen system.")\n context.PaymentTransaction_registerPayzen()\n
return context.getWebSiteValue().Base_redirect(keep_items={\'portal_status_message\': message})\n
\n \n
service = portal.portal_secure_payments.find()\n if context.getSimulationState() == \'confirmed\':\n
integration_site = portal.restrictedTraverse(portal.portal_preferences.getPreferredPayzenIntegrationSite())\n message = context.Base_translateString("Payment was automatically registered to PayZen system.")\n
return context.getWebSiteValue().Base_redirect(keep_items={\'portal_status_message\': message})\n
\n
system_event_kw = {\n system_event_kw = {\n
\'portal_type\': \'Payzen Event\',\n \'portal_type\': \'Payzen Event\',\n
\'source_value\': service,\n \'source_value\': service,\n
...@@ -78,15 +88,8 @@ system_event_kw = {\n ...@@ -78,15 +88,8 @@ system_event_kw = {\n
}\n }\n
system_event = portal.system_event_module.newContent(title=\'User navigation script\', **system_event_kw)\n system_event = portal.system_event_module.newContent(title=\'User navigation script\', **system_event_kw)\n
\n \n
now = DateTime()\n if today != current_today or integration_site.getMappingFromCategory(\'causality/%s\' % context.getRelativeUrl()) == \'Causality/%s\' % context.getRelativeUrl():\n
today = now.toZone(\'UTC\').asdatetime().strftime(\'%Y%m%d\')\n # new or too old transaction\n
previous_today = today\n
if integration_site.getMappingFromCategory(\'causality/%s\' % context.getRelativeUrl()) != \'Causality/%s\' % context.getRelativeUrl():\n
mapping_id = integration_site.getMappingFromCategory(\'causality/%s\' % context.getRelativeUrl())\n
previous_today, transaction_id = mapping_id.split(\'_\')\n
\n
\n
if today != previous_today or integration_site.getMappingFromCategory(\'causality/%s\' % context.getRelativeUrl()) == \'Causality/%s\' % context.getRelativeUrl():\n
transaction_id = str(portal.portal_ids.generateNewId(\n transaction_id = str(portal.portal_ids.generateNewId(\n
id_group=\'%s_%s\' % (service.getRelativeUrl(), today),\n id_group=\'%s_%s\' % (service.getRelativeUrl(), today),\n
id_generator=\'uid\')).zfill(6)\n id_generator=\'uid\')).zfill(6)\n
...@@ -97,14 +100,15 @@ if today != previous_today or integration_site.getMappingFromCategory(\'causalit ...@@ -97,14 +100,15 @@ if today != previous_today or integration_site.getMappingFromCategory(\'causalit
except ValueError:\n except ValueError:\n
mapping = integration_site.Causality[mapping_id]\n mapping = integration_site.Causality[mapping_id]\n
mapping.setDestinationReference(\'causality/%s\' % context.getRelativeUrl())\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 else:\n
system_event.confirm(comment=\'Key %s already found!\' % mapping_id)\n system_event.confirm(comment=\'Key %s already found!\' % mapping_id)\n
return \'There was system issue\'\n return \'There was system issue\'\n
\n \n
context.setStartDate(now)\n context.setStartDate(now)\n
if context.getSimulationState() != \'confirmed\':\n context.updateCausalityState()\n
context.PaymentTransaction_confirm()\n
\n
payzen_dict = {}\n payzen_dict = {}\n
payzen_dict.update(\n payzen_dict.update(\n
vads_currency=integration_site.getMappingFromCategory(\'resource/currency_module/%s\' % context.getResourceReference()).split(\'/\')[-1],\n vads_currency=integration_site.getMappingFromCategory(\'resource/currency_module/%s\' % context.getResourceReference()).split(\'/\')[-1],\n
......
...@@ -146,7 +146,9 @@ ...@@ -146,7 +146,9 @@
</item> </item>
<item> <item>
<key> <string>enabled</string> </key> <key> <string>enabled</string> </key>
<value> <string></string> </value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item> </item>
<item> <item>
<key> <string>external_validator</string> </key> <key> <string>external_validator</string> </key>
...@@ -302,4 +304,21 @@ Registration Payment is begin processed. It will take some time. ...@@ -302,4 +304,21 @@ Registration Payment is begin processed. It will take some time.
</dictionary> </dictionary>
</pickle> </pickle>
</record> </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 encoding="cdata"><![CDATA[
python: here.ERP5Site_getAuthenticatedMemberPersonValue().Person_countPayment([\'confirmed\']) > 0
]]></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData> </ZopeData>
...@@ -312,7 +312,11 @@ Registration Payment Information are being updated. Please wait a while. ...@@ -312,7 +312,11 @@ Registration Payment Information are being updated. Please wait a while.
<dictionary> <dictionary>
<item> <item>
<key> <string>_text</string> </key> <key> <string>_text</string> </key>
<value> <string>python: here.ERP5Site_getAuthenticatedMemberPersonValue().Person_getOutstandingPayment() is None</string> </value> <value> <string encoding="cdata"><![CDATA[
python: (here.ERP5Site_getAuthenticatedMemberPersonValue().Person_countPayment() == 0 or here.ERP5Site_getAuthenticatedMemberPersonValue().Person_countPayment([\'planned\']) > 0) and here.ERP5Site_getAuthenticatedMemberPersonValue().Person_getOutstandingPayment() is None
]]></string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
366 367
\ 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