Commit e08a7f43 authored by Romain Courteaud's avatar Romain Courteaud

Send an email when creating a Payment Transaction

parent 36368395
...@@ -58,21 +58,49 @@ if (context.getPaymentMode() != \'payzen\'):\n ...@@ -58,21 +58,49 @@ if (context.getPaymentMode() != \'payzen\'):\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
ticket = context.PaymentTransaction_addPayzenTicket()\n ticket = context.PaymentTransaction_addPayzenTicket()\n
\n \n
site_message = portal.event_module.newContent(\n # site_message = portal.event_module.newContent(\n
portal_type=\'Site Message\',\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 start_date=DateTime(),\n
destination_value=context.getDestinationSectionValue(),\n destination_value=context.getDestinationSectionValue(),\n
follow_up=ticket.getRelativeUrl(),\n follow_up=ticket.getRelativeUrl(),\n
source_value=context.getSourceSectionValue(),\n source_value=context.getSourceSectionValue(),\n
title=\'Invoice payment requested\',\n
resource=ticket.getResource(),\n resource=ticket.getResource(),\n
title="Payment requested",\n # # XXX Hardcoded script provided by another bt5\n
# XXX Hardcoded script provided by another bt5\n # text_content=\'Please pay your payment by clicking <a \'\\\n
text_content=\'Please pay your payment by clicking <a \'\\\n # \'href="%s/PaymentTransaction_redirectToManualPayzenPayment">here</a>.\' % \\\n
\'href="%s/PaymentTransaction_redirectToManualPayzenPayment">here</a>.\' % \\\n # context.getRelativeUrl(),\n
context.getRelativeUrl(),\n text_content="""\n
)\n Dear user,\n
site_message.start(comment=\'Requested manual payment.\')\n \n
return site_message\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
mail_message.start(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> ]]></string> </value>
......
...@@ -5,6 +5,7 @@ from Products.SlapOS.tests.testSlapOSMixin import \ ...@@ -5,6 +5,7 @@ from Products.SlapOS.tests.testSlapOSMixin import \
from DateTime import DateTime from DateTime import DateTime
from zExceptions import Unauthorized from zExceptions import Unauthorized
from Products.ERP5Type.tests.utils import createZODBPythonScript from Products.ERP5Type.tests.utils import createZODBPythonScript
import difflib
class TestSlapOSPaymentTransaction_sendManualPayzenPaymentUrl(testSlapOSMixin): class TestSlapOSPaymentTransaction_sendManualPayzenPaymentUrl(testSlapOSMixin):
...@@ -25,6 +26,11 @@ class TestSlapOSPaymentTransaction_sendManualPayzenPaymentUrl(testSlapOSMixin): ...@@ -25,6 +26,11 @@ class TestSlapOSPaymentTransaction_sendManualPayzenPaymentUrl(testSlapOSMixin):
None) None)
def test_sendManualPayzenPaymentUrl_payzen_payment(self): 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") person1 = self.portal.person_module.newContent(portal_type="Person")
person2 = self.portal.person_module.newContent(portal_type="Person") person2 = self.portal.person_module.newContent(portal_type="Person")
transaction = self.createPaymentTransaction() transaction = self.createPaymentTransaction()
...@@ -36,18 +42,30 @@ class TestSlapOSPaymentTransaction_sendManualPayzenPaymentUrl(testSlapOSMixin): ...@@ -36,18 +42,30 @@ class TestSlapOSPaymentTransaction_sendManualPayzenPaymentUrl(testSlapOSMixin):
event = transaction.PaymentTransaction_sendManualPayzenPaymentUrl() event = transaction.PaymentTransaction_sendManualPayzenPaymentUrl()
after_date = DateTime() after_date = DateTime()
ticket = transaction.PaymentTransaction_addPayzenTicket() ticket = transaction.PaymentTransaction_addPayzenTicket()
self.assertEquals(event.getPortalType(), 'Site Message') self.assertEquals(event.getPortalType(), 'Mail Message')
self.assertTrue(event.getStartDate() >= before_date) self.assertTrue(event.getStartDate() >= before_date)
self.assertTrue(event.getStopDate() <= after_date) self.assertTrue(event.getStopDate() <= after_date)
self.assertEquals(event.getTitle(), "Invoice payment requested")
self.assertEquals(event.getDestination(), self.assertEquals(event.getDestination(),
transaction.getDestinationSection()) transaction.getDestinationSection())
self.assertEquals(event.getSourceSection(), self.assertEquals(event.getSourceSection(),
transaction.getSource()) transaction.getSource())
self.assertEquals(event.getTextContent(), expected_text_content = """
'Please pay your payment by clicking <a href="' + \ Dear user,
transaction.getRelativeUrl() + \
'/PaymentTransaction_redirectToManualPayzenPayment">here</a>.') A new invoice has been generated.
self.assertEquals(event.getSimulationState(), 'started') 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(), self.assertEquals(event.getFollowUp(),
ticket.getRelativeUrl()) ticket.getRelativeUrl())
......
110 111
\ 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