Skip to content
Browse files

Implement MollieIdealPaymentEvent.

By subscribing to this event, we can be notified of updated payment
information.
  • Loading branch information...
1 parent f33fdec commit ec93f1c14cd25fd4dc4e7e3b35c83d41a93881d4 Mark van Lent committed Apr 3, 2012
View
4 README.rst
@@ -205,6 +205,10 @@ interfaces. And obviously you can give it any name you want.)
Then use ``<object>/absolute_url/@@report_payment_status`` as the
``report_url`` when requesting the payment URL.
+The view also emits an event: ``MollieIdealPaymentEvent``. So by
+implementing a subscriber in your own package, you can get a
+notification if the payment information of an object is updated.
+
More information
================
View
3 collective/mollie/browser/report.py
@@ -1,5 +1,7 @@
+from zope.event import notify
from zope.publisher.browser import BrowserView
+from collective.mollie.events import MollieIdealPaymentEvent
from collective.mollie.interfaces import IMollieIdealPayment
@@ -20,5 +22,6 @@ def __call__(self):
return message
adapted.get_payment_status()
+ notify(MollieIdealPaymentEvent(self.context))
self.request.response.setStatus(200)
return 'OK'
View
10 collective/mollie/events.py
@@ -0,0 +1,10 @@
+from zope.interface import implements
+
+from collective.mollie.interfaces import IMollieIdealPaymentEvent
+
+
+class MollieIdealPaymentEvent(object):
+ implements(IMollieIdealPaymentEvent)
+
+ def __init__(self, obj):
+ self.obj = obj
View
6 collective/mollie/interfaces.py
@@ -87,3 +87,9 @@ def get_payment_url(partner_id, bank_id, amount, message,
def get_payment_status():
"""Retrieve and return the payment status."""
+
+
+class IMollieIdealPaymentEvent(Interface):
+ """An event signalling that Mollie an iDeal payment has been processed."""
+
+ obj = Attribute('The object the payment was processed for.')
View
15 collective/mollie/tests/test_unit.py
@@ -3,6 +3,7 @@
from mock import MagicMock
+from zope.component import eventtesting
from zope.component import getMultiAdapter
from zope.component import getUtility
from zope.publisher.browser import TestRequest
@@ -11,6 +12,7 @@
from collective.mollie.ideal import MollieAPIError
from collective.mollie.interfaces import IMollieIdeal
from collective.mollie.interfaces import IMollieIdealPayment
+from collective.mollie.interfaces import IMollieIdealPaymentEvent
from collective.mollie.testing import COLLECTIVE_MOLLIE_INTEGRATION_TESTING
from collective.mollie.testing import Foo
@@ -337,9 +339,11 @@ def setUp(self):
self.adapted = IMollieIdealPayment(self.foo)
self.adapted._partner_id = '999999'
self.adapted.transaction_id = '482d599bbcc7795727650330ad65fe9b'
+ eventtesting.setUp()
def tearDown(self):
self.ideal._do_request = self.ideal.old_do_request
+ eventtesting.clearEvents()
def test_missing_transaction_id(self):
"""Check missing transaction_id is invalid."""
@@ -377,3 +381,14 @@ def test_correct_processing(self):
name='report_payment_status')
report_payment_view()
self.assertTrue(self.adapted.payed)
+
+ def test_payment_event(self):
+ """Check that the MollieIdealPaymentEvent was fired."""
+ request = TestRequest(
+ form=dict(transaction_id=self.adapted.transaction_id))
+ report_payment_view = getMultiAdapter((self.foo, request),
+ name='report_payment_status')
+ report_payment_view()
+ payment_events = [event for event in eventtesting.getEvents()
+ if IMollieIdealPaymentEvent.providedBy(event)]
+ self.assertTrue(len(payment_events) > 0)

0 comments on commit ec93f1c

Please sign in to comment.
Something went wrong with that request. Please try again.