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

Switch to new way.

Grab payments in confirmed and started state and analyse thier status against
payzen interface.

Start to use CRM in order to manage payments and its status with payzen.
parent 90883ef4
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Alarm" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>active_sense_method_id</string> </key>
<value> <string>Alarm_updatePayzenConfirmedPaymentTransaction</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>vifib_payzen_update_confirmed_payment</string> </value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_minute</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_minute_frequency</string> </key>
<value> <int>5</int> </value>
</item>
<item>
<key> <string>periodicity_month</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_month_day</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_start_date</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1288051200.0</float>
<string>GMT</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>periodicity_week</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Alarm</string> </value>
</item>
<item>
<key> <string>sense_method_id</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Handles confirmed Payment Transactions with PayZen interface</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -8,7 +8,7 @@
<dictionary>
<item>
<key> <string>active_sense_method_id</string> </key>
<value> <string>Alarm_updatePayzenPaymentTransaction</string> </value>
<value> <string>Alarm_updatePayzenStartedPaymentTransaction</string> </value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -18,11 +18,11 @@
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>payzen_update_payment_transaction</string> </value>
<value> <string>vifib_payzen_update_started_payment</string> </value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
......@@ -89,7 +89,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Updates Payment Transactions accorind with PayZen interface</string> </value>
<value> <string>Handles started Payment Transactions with PayZen interface</string> </value>
</item>
</dictionary>
</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>portal = context.getPortalObject()\n
portal.portal_catalog.searchAndActivate(\n
portal_type="Payment Transaction", \n
simulation_state=["confirmed"],\n
causality_state=["solved"],\n
method_id=\'PaymentTransaction_updateStatus\',\n
packet_size=1, # just one to minimise errors\n
activate_kw={\'tag\': tag}\n
)\n
context.activate(after_tag=tag).getId()\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>tag, fixit, params</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_updatePayzenConfirmedPaymentTransaction</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -53,7 +53,8 @@
<value> <string>portal = context.getPortalObject()\n
portal.portal_catalog.searchAndActivate(\n
portal_type="Payment Transaction", \n
simulation_state=["planned", "confirmed"],\n
simulation_state=["started"],\n
causality_state=["solved"],\n
method_id=\'PaymentTransaction_updateStatus\',\n
packet_size=1, # just one to minimise errors\n
activate_kw={\'tag\': tag}\n
......@@ -67,7 +68,7 @@ context.activate(after_tag=tag).getId()\n
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_updatePayzenPaymentTransaction</string> </value>
<value> <string>Alarm_updatePayzenStartedPaymentTransaction</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -50,32 +50,96 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from DateTime import DateTime\n
<value> <string encoding="cdata"><![CDATA[
from DateTime import DateTime\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(), validation_state=\'validated\')\n
tag = \'ticket_creation_%s\' % transaction.getUid()\n
activate_kw={\'tag\': tag}\n
if ticket is None and 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\' % 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(title=\'Transaction %s cannot be updated, because of service error: %s\' % (context.getTitle(), e), portal_type=\'Payzen Event\', source_value=service, destination_value=context).confirm()\n
return\n
\n
if context.getSimulationState() not in [\'planned\', \'confirmed\']:\n
return\n
\n
transaction_id = portal.restrictedTraverse(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
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(portal_type=\'Site Message\',\n
default_follow_up_uid=ticket.getUid())\n
if site_message is None and portal.portal_activities.countMessageWithTag(tag) == 0:\n
site_message = portal.event_module.newContent(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 href="%s/AccountingTransaction_startPayment">here</a>.\' % transaction.getRelativeUrl(),\n
activate_kw=activate_kw)\n
site_message.start(comment=\'Requested manual payment.\')\n
\n
if transaction_id is not None:\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
elif context.PaymentTransaction_getPreviousPayzenId() is not None and context.getSimulationState() == \'planned\':\n
state = context.getSimulationState()\n
if state == \'confirmed\':\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(title=\'Transaction %s Payzen registration\' % context.getTitle(), portal_type=\'Payzen Event\', source_value=service, destination_value=context).registerPayzen()\n
</string> </value>
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(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
if transaction_id is None:\n
# manual payment shall be done\n
# check if there is open ticket if not open it\n
createRequestManualPaymentTicket(context)\n
else:\n
# so the payment is registered in payzen\n
portal.system_event_module.newContent(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
# not paid yet and shall be, lets open ticket\n
addTicket(context)\n
else:\n
raise NotImplementedError(\'State %s is not supported\' % state)\n
]]></string> </value>
</item>
<item>
<key> <string>_params</string> </key>
......
72
\ No newline at end of file
73
\ No newline at end of file
portal_alarms/payzen_update_payment_transaction
\ No newline at end of file
portal_alarms/vifib_payzen_update_confirmed_payment
portal_alarms/vifib_payzen_update_started_payment
\ 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