Commit 856829c1 authored by Romain Courteaud's avatar Romain Courteaud

Drop all CRM interactions.

This will be handle by global alarm to check the user status, and not invoice
by invoice.
parent faf3fa14
<?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
support_request_template = portal.restrictedTraverse(\n
portal.portal_preferences.getPreferredSupportRequestTemplate())\n
ticket = support_request_template.Base_createCloneDocument(batch_mode=1)\n
ticket.edit(\n
source_project_value=context,\n
title=\'Payzen Transaction to check for "%s"\' % context.getDestinationSectionTitle(),\n
destination_decision_value=context.getDestinationSectionValue(),\n
start_date=DateTime(),\n
resource=portal.portal_preferences.getPreferredSupportRequestResource(),\n
)\n
ticket.validate(comment=\'New automatic ticket for %s\' % context.getTitle())\n
ticket.suspend(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 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
# resource=ticket.getResource(),\n
# title="Payment requested",\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
\n
mail_message = portal.event_module.newContent(\n
portal_type=\'Mail Message\',\n
start_date=DateTime(),\n
destination_value=context.getDestinationSectionValue(),\n
follow_up=ticket.getRelativeUrl(),\n
source_value=context.getSourceSectionValue(),\n
title=\'Invoice payment requested\',\n
resource=ticket.getResource(),\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
text_content="""\n
Dear user,\n
\n
A new invoice has been generated. \n
You can access it in your invoice section at %s.\n
\n
Do not hesitate to visit the web forum (http://community.slapos.org/forum) in case of question.\n
\n
Regards,\n
The slapos team\n
""" % portal.portal_preferences.getPreferredSlaposWebSiteUrl())\n
portal.portal_workflow.doActionFor(mail_message, \'start_action\', send_mail=True, comment=\'Requested manual payment.\')\n
mail_message.stop(comment=\'Requested manual payment.\')\n
mail_message.deliver(comment=\'Requested manual payment.\')\n
\n
return mail_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>
...@@ -59,7 +59,6 @@ if (state != \'confirmed\') or (context.getPaymentMode() != \'payzen\') or (tran ...@@ -59,7 +59,6 @@ if (state != \'confirmed\') or (context.getPaymentMode() != \'payzen\') or (tran
return\n return\n
else:\n else:\n
# Request manual payment\n # Request manual payment\n
context.PaymentTransaction_sendManualPayzenPaymentUrl()\n
context.start(comment=\'Requested manual payment\')\n context.start(comment=\'Requested manual payment\')\n
\n \n
# raise NotImplementedError\n # raise NotImplementedError\n
......
...@@ -59,15 +59,9 @@ if (state != \'started\') or (context.getPaymentMode() != \'payzen\'):\n ...@@ -59,15 +59,9 @@ if (state != \'started\') or (context.getPaymentMode() != \'payzen\'):\n
else:\n else:\n
transaction_date, transaction_id = context.PaymentTransaction_getPayzenId()\n transaction_date, transaction_id = context.PaymentTransaction_getPayzenId()\n
\n \n
if transaction_id is None:\n if transaction_id is not None:\n
# inform administrators\n
context.PaymentTransaction_addPayzenTicket()\n
else:\n
# so the payment is registered in payzen\n # so the payment is registered in payzen\n
context.PaymentTransaction_createPayzenEvent().updateStatus()\n context.PaymentTransaction_createPayzenEvent().updateStatus()\n
if context.getSimulationState() != \'stopped\':\n
# not paid yet and shall be, lets open ticket\n
context.PaymentTransaction_addPayzenTicket()\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
......
...@@ -201,24 +201,6 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P ...@@ -201,24 +201,6 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P
self.assertEquals(transaction.getSimulationState(), simulation_state) self.assertEquals(transaction.getSimulationState(), simulation_state)
self.assertEquals(transaction.getModificationDate(), modification_date) 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): def test_expected_payment(self):
new_id = self.generateNewId() new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent( transaction = self.portal.accounting_module.newContent(
...@@ -229,17 +211,12 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P ...@@ -229,17 +211,12 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P
) )
self.portal.portal_workflow._jumpToStateFor(transaction, 'confirmed') self.portal.portal_workflow._jumpToStateFor(transaction, 'confirmed')
self._simulatePaymentTransaction_sendManualPayzenPaymentUrl()
self._simulatePaymentTransaction_getTotalPayablePrice() self._simulatePaymentTransaction_getTotalPayablePrice()
try: try:
transaction.PaymentTransaction_startPayzenPayment() transaction.PaymentTransaction_startPayzenPayment()
finally: finally:
self._dropPaymentTransaction_sendManualPayzenPaymentUrl()
self._dropPaymentTransaction_getTotalPayablePrice() self._dropPaymentTransaction_getTotalPayablePrice()
self.assertEquals(transaction.getSimulationState(), 'started') self.assertEquals(transaction.getSimulationState(), 'started')
self.assertEqual(
'Visited by PaymentTransaction_sendManualPayzenPaymentUrl',
transaction.workflow_history['edit_workflow'][-1]['comment'])
class TestSlapOSPayzenUpdateStartedPayment(testSlapOSMixin): class TestSlapOSPayzenUpdateStartedPayment(testSlapOSMixin):
...@@ -275,24 +252,6 @@ class TestSlapOSPayzenUpdateStartedPayment(testSlapOSMixin): ...@@ -275,24 +252,6 @@ class TestSlapOSPayzenUpdateStartedPayment(testSlapOSMixin):
self.assertEquals(transaction.getSimulationState(), simulation_state) self.assertEquals(transaction.getSimulationState(), simulation_state)
self.assertEquals(transaction.getModificationDate(), modification_date) 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): def test_not_registered_payment(self):
new_id = self.generateNewId() new_id = self.generateNewId()
transaction = self.portal.accounting_module.newContent( transaction = self.portal.accounting_module.newContent(
...@@ -303,15 +262,8 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P ...@@ -303,15 +262,8 @@ portal_workflow.doActionFor(context, action='edit_action', comment='Visited by P
) )
self.portal.portal_workflow._jumpToStateFor(transaction, 'started') self.portal.portal_workflow._jumpToStateFor(transaction, 'started')
self._simulatePaymentTransaction_addPayzenTicket() transaction.PaymentTransaction_updateStatus()
try:
transaction.PaymentTransaction_updateStatus()
finally:
self._dropPaymentTransaction_addPayzenTicket()
self.assertEquals(transaction.getSimulationState(), 'started') self.assertEquals(transaction.getSimulationState(), 'started')
self.assertEqual(
'Visited by PaymentTransaction_addPayzenTicket',
transaction.workflow_history['edit_workflow'][-1]['comment'])
def _simulatePaymentTransaction_createPaidPayzenEvent(self): def _simulatePaymentTransaction_createPaidPayzenEvent(self):
script_name = 'PaymentTransaction_createPayzenEvent' script_name = 'PaymentTransaction_createPayzenEvent'
...@@ -369,12 +321,10 @@ return Foo() ...@@ -369,12 +321,10 @@ return Foo()
# Manually generate mapping # Manually generate mapping
transaction.PaymentTransaction_generatePayzenId() transaction.PaymentTransaction_generatePayzenId()
self._simulatePaymentTransaction_addPayzenTicket()
self._simulatePaymentTransaction_createPaidPayzenEvent() self._simulatePaymentTransaction_createPaidPayzenEvent()
try: try:
transaction.PaymentTransaction_updateStatus() transaction.PaymentTransaction_updateStatus()
finally: finally:
self._dropPaymentTransaction_addPayzenTicket()
self._dropPaymentTransaction_createPayzenEvent() self._dropPaymentTransaction_createPayzenEvent()
self.assertEqual( self.assertEqual(
'Visited by PaymentTransaction_createPayzenEvent', 'Visited by PaymentTransaction_createPayzenEvent',
...@@ -398,18 +348,13 @@ return Foo() ...@@ -398,18 +348,13 @@ return Foo()
# Manually generate mapping # Manually generate mapping
transaction.PaymentTransaction_generatePayzenId() transaction.PaymentTransaction_generatePayzenId()
self._simulatePaymentTransaction_addPayzenTicket()
self._simulatePaymentTransaction_createNotPaidPayzenEvent() self._simulatePaymentTransaction_createNotPaidPayzenEvent()
try: try:
transaction.PaymentTransaction_updateStatus() transaction.PaymentTransaction_updateStatus()
finally: finally:
self._dropPaymentTransaction_addPayzenTicket()
self._dropPaymentTransaction_createPayzenEvent() self._dropPaymentTransaction_createPayzenEvent()
self.assertEqual( self.assertEqual(
'Visited by PaymentTransaction_createPayzenEvent', 'Visited by PaymentTransaction_createPayzenEvent',
transaction.workflow_history['edit_workflow'][-2]['comment'])
self.assertEqual(
'Visited by PaymentTransaction_addPayzenTicket',
transaction.workflow_history['edit_workflow'][-1]['comment']) transaction.workflow_history['edit_workflow'][-1]['comment'])
self.assertEquals(transaction.getSimulationState(), 'started') self.assertEquals(transaction.getSimulationState(), 'started')
......
...@@ -7,111 +7,6 @@ from zExceptions import Unauthorized ...@@ -7,111 +7,6 @@ from zExceptions import Unauthorized
from Products.ERP5Type.tests.utils import createZODBPythonScript from Products.ERP5Type.tests.utils import createZODBPythonScript
import difflib import difflib
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):
for preference in \
self.portal.portal_catalog(portal_type="System Preference"):
preference = preference.getObject()
if preference.getPreferenceState() == 'global':
preference.setPreferredSlaposWebSiteUrl('http://foobar.org/')
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(), 'Mail Message')
self.assertTrue(event.getStartDate() >= before_date)
self.assertTrue(event.getStopDate() <= after_date)
self.assertEquals(event.getTitle(), "Invoice payment requested")
self.assertEquals(event.getDestination(),
transaction.getDestinationSection())
self.assertEquals(event.getSourceSection(),
transaction.getSource())
expected_text_content = """
Dear user,
A new invoice has been generated.
You can access it in your invoice section at http://foobar.org/.
Do not hesitate to visit the web forum (http://community.slapos.org/forum) in case of question.
Regards,
The slapos team
"""
self.assertEquals(event.getTextContent(), expected_text_content,
'\n'.join([x for x in difflib.unified_diff(
event.getTextContent().splitlines(),
expected_text_content.splitlines())]))
self.assertEquals(event.getSimulationState(), 'delivered')
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(), 'suspended')
self.assertEquals(ticket.getSourceProject(), transaction.getRelativeUrl())
self.assertEquals(ticket.getTitle(), 'Payzen Transaction to check for "None"')
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):
def beforeTearDown(self): def beforeTearDown(self):
......
112 113
\ 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