diff --git a/payment_paypal/indico_payment_paypal/blueprint.py b/payment_paypal/indico_payment_paypal/blueprint.py
new file mode 100644
index 0000000..114f862
--- /dev/null
+++ b/payment_paypal/indico_payment_paypal/blueprint.py
@@ -0,0 +1,29 @@
+# This file is part of Indico.
+# Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
+#
+# Indico is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3 of the
+# License, or (at your option) any later version.
+#
+# Indico is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Indico; if not, see .
+
+from __future__ import unicode_literals
+
+from indico.core.plugins import IndicoPluginBlueprint
+from indico_payment_paypal.controllers import RHPaypalIPN, RHPaypalCancel, RHPaypalSuccess
+
+
+blueprint = IndicoPluginBlueprint('payment_paypal', __name__,
+ url_prefix='/event//registration/payment/response/paypal')
+
+blueprint.add_url_rule('/cancel', 'cancel', RHPaypalCancel, methods=('GET', 'POST'))
+blueprint.add_url_rule('/success', 'success', RHPaypalSuccess, methods=('GET', 'POST'))
+# Used by PayPal to send an asynchronous notification for the transaction (pending, successful, etc)
+blueprint.add_url_rule('/ipn', 'notify', RHPaypalIPN, methods=('POST',))
diff --git a/payment_paypal/indico_payment_paypal/controllers.py b/payment_paypal/indico_payment_paypal/controllers.py
index fd30da2..11226c0 100644
--- a/payment_paypal/indico_payment_paypal/controllers.py
+++ b/payment_paypal/indico_payment_paypal/controllers.py
@@ -19,15 +19,19 @@ from __future__ import unicode_literals
from itertools import chain
import requests
-from flask import request
+from flask import request, flash, redirect
from flask_pluginengine import current_plugin
from werkzeug.exceptions import BadRequest
-from MaKaC.conference import ConferenceHolder
-from MaKaC.webinterface.rh.base import RH
from indico.modules.payment.models.transactions import PaymentTransaction, TransactionAction
from indico.modules.payment.notifications import notify_amount_inconsistency
from indico.modules.payment.util import register_transaction
+from indico.util.i18n import _
+from indico.web.flask.util import url_for
+from MaKaC.conference import ConferenceHolder
+from MaKaC.webinterface.rh.base import RH
+from MaKaC.webinterface.rh.registrationFormDisplay import RHRegistrationFormRegistrantBase
+
IPN_VERIFY_EXTRA_PARAMS = (('cmd', '_notify-validate'),)
@@ -38,7 +42,7 @@ class PaypalTransactionActionMapping(object):
'Pending': TransactionAction.pending}
-class RHPaymentEventNotify(RH):
+class RHPaypalIPN(RH):
"""Process the notification sent by the PayPal"""
def _checkParams(self):
@@ -102,3 +106,19 @@ class RHPaymentEventNotify(RH):
return False
return (transaction.data['payment_status'] == request.form.get('payment_status') and
transaction.data['txn_id'] == request.form.get('txn_id'))
+
+
+class RHPaypalSuccess(RHRegistrationFormRegistrantBase):
+ """Confirmation message after successful payment"""
+
+ def _process(self):
+ flash(_('Your payment request has been processed.'), 'success')
+ return redirect(url_for('event.confRegistrationFormDisplay', self._conf))
+
+
+class RHPaypalCancel(RHRegistrationFormRegistrantBase):
+ """Cancellation message"""
+
+ def _process(self):
+ flash(_('You cancelled the payment process.'), 'info')
+ return redirect(url_for('event.confRegistrationFormDisplay', self._conf))
diff --git a/payment_paypal/indico_payment_paypal/plugin.py b/payment_paypal/indico_payment_paypal/plugin.py
index a868059..a7f799f 100644
--- a/payment_paypal/indico_payment_paypal/plugin.py
+++ b/payment_paypal/indico_payment_paypal/plugin.py
@@ -20,12 +20,13 @@ from wtforms.fields.core import StringField
from wtforms.fields.html5 import URLField
from wtforms.validators import DataRequired
-from indico.core.plugins import IndicoPlugin, IndicoPluginBlueprint, url_for_plugin
+from indico.core.plugins import IndicoPlugin, url_for_plugin
from indico.modules.payment import PaymentPluginMixin, PaymentPluginSettingsFormBase, PaymentEventSettingsFormBase
-from indico_payment_paypal.controllers import RHPaymentEventNotify
from indico.util.i18n import _
from indico.util.string import remove_accents
+from indico_payment_paypal.blueprint import blueprint
+
class PluginSettingsForm(PaymentPluginSettingsFormBase):
url = URLField(_('API URL'), [DataRequired()], description=_('URL of the PayPal HTTP API.'))
@@ -57,11 +58,11 @@ class PaypalPaymentPlugin(PaymentPluginMixin, IndicoPlugin):
return blueprint
def adjust_payment_form_data(self, data):
- data['item_name'] = '{}: registration for {}'.format(remove_accents(data['registrant'].getFullName()),
- remove_accents(data['event'].getTitle()))
-
-
-blueprint = IndicoPluginBlueprint('payment_paypal', __name__, url_prefix='/event//registration/payment')
-
-#: Used by PayPal to send asynchronously a notification for the transaction (pending, successful, etc)
-blueprint.add_url_rule('/notify/paypal', 'notify', RHPaymentEventNotify, methods=('GET', 'POST'))
+ event = data['event']
+ registrant = data['registrant']
+ data['item_name'] = '{}: registration for {}'.format(remove_accents(registrant.getFullName()),
+ remove_accents(event.getTitle()))
+ data['return_url'] = url_for_plugin('payment_paypal.success', event, _external=True)
+ data['cancel_url'] = url_for_plugin('payment_paypal.cancel', event, _external=True)
+ data['notify_url'] = url_for_plugin('payment_paypal.notify', registrant, authkey=registrant.getRandomId(),
+ _external=True)
diff --git a/payment_paypal/indico_payment_paypal/templates/event_payment_form.html b/payment_paypal/indico_payment_paypal/templates/event_payment_form.html
index eb81a5e..e0acce2 100644
--- a/payment_paypal/indico_payment_paypal/templates/event_payment_form.html
+++ b/payment_paypal/indico_payment_paypal/templates/event_payment_form.html
@@ -11,15 +11,15 @@ Clicking on the Pay now button you will get redirected to the P