Skip to content

Commit

Permalink
Implement MollieIdealPaymentEvent.
Browse files Browse the repository at this point in the history
By subscribing to this event, we can be notified of updated payment
information.
  • Loading branch information
Mark van Lent committed Apr 3, 2012
1 parent f33fdec commit ec93f1c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.rst
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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 Then use ``<object>/absolute_url/@@report_payment_status`` as the
``report_url`` when requesting the payment URL. ``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 More information
================ ================
Expand Down
3 changes: 3 additions & 0 deletions collective/mollie/browser/report.py
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,7 @@
from zope.event import notify
from zope.publisher.browser import BrowserView from zope.publisher.browser import BrowserView


from collective.mollie.events import MollieIdealPaymentEvent
from collective.mollie.interfaces import IMollieIdealPayment from collective.mollie.interfaces import IMollieIdealPayment




Expand All @@ -20,5 +22,6 @@ def __call__(self):
return message return message


adapted.get_payment_status() adapted.get_payment_status()
notify(MollieIdealPaymentEvent(self.context))
self.request.response.setStatus(200) self.request.response.setStatus(200)
return 'OK' return 'OK'
10 changes: 10 additions & 0 deletions collective/mollie/events.py
Original file line number Original file line Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions collective/mollie/interfaces.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -87,3 +87,9 @@ def get_payment_url(partner_id, bank_id, amount, message,


def get_payment_status(): def get_payment_status():
"""Retrieve and return the 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.')
15 changes: 15 additions & 0 deletions collective/mollie/tests/test_unit.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


from mock import MagicMock from mock import MagicMock


from zope.component import eventtesting
from zope.component import getMultiAdapter from zope.component import getMultiAdapter
from zope.component import getUtility from zope.component import getUtility
from zope.publisher.browser import TestRequest from zope.publisher.browser import TestRequest
Expand All @@ -11,6 +12,7 @@
from collective.mollie.ideal import MollieAPIError from collective.mollie.ideal import MollieAPIError
from collective.mollie.interfaces import IMollieIdeal from collective.mollie.interfaces import IMollieIdeal
from collective.mollie.interfaces import IMollieIdealPayment 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 COLLECTIVE_MOLLIE_INTEGRATION_TESTING
from collective.mollie.testing import Foo from collective.mollie.testing import Foo


Expand Down Expand Up @@ -337,9 +339,11 @@ def setUp(self):
self.adapted = IMollieIdealPayment(self.foo) self.adapted = IMollieIdealPayment(self.foo)
self.adapted._partner_id = '999999' self.adapted._partner_id = '999999'
self.adapted.transaction_id = '482d599bbcc7795727650330ad65fe9b' self.adapted.transaction_id = '482d599bbcc7795727650330ad65fe9b'
eventtesting.setUp()


def tearDown(self): def tearDown(self):
self.ideal._do_request = self.ideal.old_do_request self.ideal._do_request = self.ideal.old_do_request
eventtesting.clearEvents()


def test_missing_transaction_id(self): def test_missing_transaction_id(self):
"""Check missing transaction_id is invalid.""" """Check missing transaction_id is invalid."""
Expand Down Expand Up @@ -377,3 +381,14 @@ def test_correct_processing(self):
name='report_payment_status') name='report_payment_status')
report_payment_view() report_payment_view()
self.assertTrue(self.adapted.payed) 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.