mirror of
https://github.com/lucaspalomodevelop/indico-plugins.git
synced 2026-03-17 01:04:55 +00:00
Payment/PayPal: use local success/cancel endpoints
They were removed from the core since they belong into the plugins. Also some refactoring (separate blueprint module, better RH names)
This commit is contained in:
parent
9d9c5cfe6a
commit
4dc8fa3cb1
29
payment_paypal/indico_payment_paypal/blueprint.py
Normal file
29
payment_paypal/indico_payment_paypal/blueprint.py
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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/<confId>/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',))
|
||||
@ -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))
|
||||
|
||||
@ -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/<confId>/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)
|
||||
|
||||
@ -11,15 +11,15 @@ Clicking on the <strong>Pay now</strong> button you will get redirected to the P
|
||||
<dd>
|
||||
<form action="{{ settings.url }}" method="POST">
|
||||
<input type="hidden" name="cmd" value="_xclick">
|
||||
<input type="hidden" name="business" value="{{ event_settings.business}}">
|
||||
<input type="hidden" name="business" value="{{ event_settings.business }}">
|
||||
<input type="hidden" name="item_name" value="{{ item_name }}">
|
||||
<input type="hidden" name="amount" value="{{ amount }}">
|
||||
<input type="hidden" name="currency_code" value="{{ currency }}">
|
||||
<input type="hidden" name="charset" value="utf-8">
|
||||
<input type="hidden" name="invoice" value="{{ event.getId() }}_{{ registrant.getId() }}">
|
||||
<input type="hidden" name="return" value="{{ url_for('payment.event_payment_return', event, _external=True) }}">
|
||||
<input type="hidden" name="cancel_return" value="{{ url_for('payment.event_payment_cancel', event, _external=True) }}">
|
||||
<input type="hidden" name="notify_url" value="{{ url_for_plugin('payment_paypal.notify', registrant, authkey=registrant.getRandomId(), _external=True) }}">
|
||||
<input type="hidden" name="return" value="{{ return_url }}">
|
||||
<input type="hidden" name="cancel_return" value="{{ cancel_url }}">
|
||||
<input type="hidden" name="notify_url" value="{{ notify_url }}">
|
||||
<input type="image" name="submit" src="https://www.paypalobjects.com/webstatic/en_US/btn/btn_paynow_86x21.png" alt="PayPal - The safer, easier way to pay online">
|
||||
</form>
|
||||
</dd>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user