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 @@
</item>
<item>
<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>
</dictionary>
</pickle>
......
......@@ -50,7 +50,7 @@
</item>
<item>
<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>
</item>
<item>
......
......@@ -50,9 +50,17 @@
</item>
<item>
<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
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
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>
......
......@@ -50,7 +50,9 @@
</item>
<item>
<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>
</item>
<item>
......
......@@ -51,7 +51,7 @@
<item>
<key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n
if context.getSimulationState() not in [\'confirmed\', \'started\']:\n
if context.getSimulationState() not in [\'planned\', \'confirmed\']:\n
return\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
......
......@@ -50,16 +50,24 @@
</item>
<item>
<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>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
<value> <string>simulation_state_list=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>PaymentTransaction_start</string> </value>
<value> <string>Person_countPayment</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -54,12 +54,13 @@
\n
payment_transaction = context.portal_catalog.getResultValue(\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
sort_on=((\'creation_date\', \'ASC\'), )\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 None\n
</string> </value>
......
......@@ -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
if transaction.getSimulationState() == \'planned\':\n
transaction.confirm()\n
if transaction.getSimulationState() == \'confirmed\':\n
transaction.PaymentTransaction_start()\n
\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_devise = data_kw[\'authDevise\']\n
transaction_amount = int(round((transaction.PaymentTransaction_getTotalPayablePrice() * -100), 2))\n
......
61
\ No newline at end of file
62
\ No newline at end of file
......@@ -53,24 +53,34 @@
<value> <string># TODO: Return configured web page in case of system issues.\n
from DateTime import DateTime\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
previous_id = context.PaymentTransaction_getPreviousPayzenId()\n
\n
if context.getSimulationState() == \'planned\' and previous_id is not None:\n
# och, it was possible to register this transaction\n
now = DateTime()\n
today = now.toZone(\'UTC\').asdatetime().strftime(\'%Y%m%d\')\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
\n
if transaction_id is not None:\n
context.PaymentTransaction_updateStatus()\n
elif previous_id is not None:\n
context.PaymentTransaction_registerPayzen()\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
if context.getSimulationState() == \'confirmed\':\n
# let\'s try to update state\n
context.PaymentTransaction_updateStatus()\n
if context.getSimulationState() == \'started\':\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
service = portal.portal_secure_payments.find()\n
integration_site = portal.restrictedTraverse(portal.portal_preferences.getPreferredPayzenIntegrationSite())\n
\n
system_event_kw = {\n
\'portal_type\': \'Payzen Event\',\n
\'source_value\': service,\n
......@@ -78,15 +88,8 @@ system_event_kw = {\n
}\n
system_event = portal.system_event_module.newContent(title=\'User navigation script\', **system_event_kw)\n
\n
now = DateTime()\n
today = now.toZone(\'UTC\').asdatetime().strftime(\'%Y%m%d\')\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
if today != current_today or integration_site.getMappingFromCategory(\'causality/%s\' % context.getRelativeUrl()) == \'Causality/%s\' % context.getRelativeUrl():\n
# new or too old transaction\n
transaction_id = str(portal.portal_ids.generateNewId(\n
id_group=\'%s_%s\' % (service.getRelativeUrl(), today),\n
id_generator=\'uid\')).zfill(6)\n
......@@ -97,14 +100,15 @@ if today != previous_today or integration_site.getMappingFromCategory(\'causalit
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
context.setStartDate(now)\n
if context.getSimulationState() != \'confirmed\':\n
context.PaymentTransaction_confirm()\n
\n
context.updateCausalityState()\n
payzen_dict = {}\n
payzen_dict.update(\n
vads_currency=integration_site.getMappingFromCategory(\'resource/currency_module/%s\' % context.getResourceReference()).split(\'/\')[-1],\n
......
......@@ -146,7 +146,9 @@
</item>
<item>
<key> <string>enabled</string> </key>
<value> <string></string> </value>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>external_validator</string> </key>
......@@ -302,4 +304,21 @@ Registration Payment is begin processed. It will take some time.
</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 encoding="cdata"><![CDATA[
python: here.ERP5Site_getAuthenticatedMemberPersonValue().Person_countPayment([\'confirmed\']) > 0
]]></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -312,7 +312,11 @@ Registration Payment Information are being updated. Please wait a while.
<dictionary>
<item>
<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>
</dictionary>
</pickle>
......
366
\ No newline at end of file
367
\ 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