diff --git a/payment_sixpay/README.md b/payment_sixpay/README.md index 9420dff..5a30549 100644 --- a/payment_sixpay/README.md +++ b/payment_sixpay/README.md @@ -8,6 +8,10 @@ they are automatically sent back to Indico. ## Changelog +### 3.1.2 + +- Fix error after successful payment if background confirmation already happened + ### 3.1.1 - Ignore pending transactions once they expired diff --git a/payment_sixpay/indico_payment_sixpay/controllers.py b/payment_sixpay/indico_payment_sixpay/controllers.py index 7de3edb..1d32c41 100644 --- a/payment_sixpay/indico_payment_sixpay/controllers.py +++ b/payment_sixpay/indico_payment_sixpay/controllers.py @@ -18,7 +18,7 @@ from indico.core.plugins import url_for_plugin from indico.modules.events.payment.controllers import RHPaymentBase from indico.modules.events.payment.models.transactions import TransactionAction from indico.modules.events.payment.notifications import notify_amount_inconsistency -from indico.modules.events.payment.util import get_active_payment_plugins, register_transaction +from indico.modules.events.payment.util import TransactionStatus, get_active_payment_plugins, register_transaction from indico.modules.events.registration.models.registrations import Registration from indico.web.flask.util import url_for from indico.web.rh import RH @@ -57,7 +57,12 @@ class RHSixpayBase(RH): self.registration = Registration.query.filter_by(uuid=request.args['token']).first() if not self.registration: raise BadRequest - self.token = self.registration.transaction.data['Init_PP_response']['Token'] + try: + self.token = self.registration.transaction.data['Init_PP_response']['Token'] + except KeyError: + # if the transaction was already recorded as successful via background notification, + # we no longer have a token in the local transaction + self.token = None class RHInitSixpayPayment(RHPaymentBase): @@ -154,7 +159,8 @@ class SixpayNotificationHandler(RHSixpayBase): def _process(self): """Process the reply from SIXPay about the transaction.""" - self._process_confirmation() + if self.token is not None: + self._process_confirmation() def _process_confirmation(self): """Process the confirmation response inside indico.""" @@ -355,9 +361,11 @@ class UserSuccessHandler(SixpayNotificationHandler): def _process(self): try: - self._process_confirmation() + if self.token is not None: + self._process_confirmation() except TransactionFailure: flash(_('Your payment could not be confirmed. Please contact the event organizers.'), 'warning') else: - flash(_('Your payment has been confirmed.'), 'success') + if self.registration.transaction.status == TransactionStatus.successful: + flash(_('Your payment has been confirmed.'), 'success') return redirect(url_for('event_registration.display_regform', self.registration.locator.registrant)) diff --git a/payment_sixpay/setup.cfg b/payment_sixpay/setup.cfg index 3ee2ca8..093c3b8 100644 --- a/payment_sixpay/setup.cfg +++ b/payment_sixpay/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = indico-plugin-payment-sixpay -version = 3.1.1 +version = 3.1.2 description = SIXPay/Saferpay payments for Indico event registration fees long_description = file: README.md long_description_content_type = text/markdown; charset=UTF-8; variant=GFM