Skip to content

Commit

Permalink
Merge branch 'v1.9.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
ThiefMaster committed Oct 9, 2017
2 parents 2bec643 + a9f374b commit 8ca67f9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 50 deletions.
14 changes: 6 additions & 8 deletions indico/modules/events/payment/models/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,25 +233,23 @@ def create_next(cls, registration, amount, currency, action, provider=None, data
new_transaction = PaymentTransaction(amount=amount, currency=currency,
provider=provider, data=data)
registration.transaction = new_transaction
double_payment = False
try:
next_status = TransactionStatusTransition.next(previous_transaction, action, provider)
except InvalidTransactionStatus as e:
Logger.get('payment').exception("%s (data received: %r)", e, data)
return None, None
return None
except InvalidManualTransactionAction as e:
Logger.get('payment').exception("Invalid manual action code '%s' on initial status (data received: %r)",
e, data)
return None, None
return None
except InvalidTransactionAction as e:
Logger.get('payment').exception("Invalid action code '%s' on initial status (data received: %r)", e, data)
return None, None
return None
except IgnoredTransactionAction as e:
Logger.get('payment').warning("%s (data received: %r)", e, data)
return None, None
return None
except DoublePaymentTransaction:
next_status = TransactionStatus.successful
double_payment = True
Logger.get('payment').warning("Received successful payment for an already paid registration")
Logger.get('payment').info("Received successful payment for an already paid registration")
new_transaction.status = next_status
return new_transaction, double_payment
return new_transaction
14 changes: 2 additions & 12 deletions indico/modules/events/payment/models/transactions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,8 @@ def test_manual(dummy_transaction, provider, expected):


def test_create_next(creation_params):
transaction, double_payment = PaymentTransaction.create_next(**creation_params)
transaction = PaymentTransaction.create_next(**creation_params)
assert isinstance(transaction, PaymentTransaction)
assert not double_payment


@pytest.mark.parametrize('exception', (
Expand All @@ -179,18 +178,9 @@ def test_create_next(creation_params):
def test_create_next_with_exception(caplog, mocker, creation_params, exception):
mocker.patch.object(TransactionStatusTransition, 'next')
TransactionStatusTransition.next.side_effect = exception('TEST_EXCEPTION')
transaction, double_payment = PaymentTransaction.create_next(**creation_params)
transaction = PaymentTransaction.create_next(**creation_params)
log = extract_logs(caplog, one=True, name='indico.payment')
assert transaction is None
assert double_payment is None
assert 'TEST_EXCEPTION' in log.message
if log.exc_info:
assert log.exc_info[0] == exception


def test_create_next_double_payment(caplog, creation_params):
creation_params['registration'].transaction = MagicMock(status=TransactionStatus.successful)
_, double_payment = PaymentTransaction.create_next(**creation_params)
log = extract_logs(caplog, one=True, name='indico.payment').message
assert 'already paid' in log
assert double_payment
9 changes: 0 additions & 9 deletions indico/modules/events/payment/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@
from indico.core.notifications import email_sender, make_email


@email_sender
def notify_double_payment(registration):
event = registration.registration_form.event
to = event.creator.email
body = render_template('events/payment/emails/double_payment_email_to_manager.txt', event=event,
registration=registration)
return make_email(to, subject='Double payment detected', body=body)


@email_sender
def notify_amount_inconsistency(registration, amount, currency):
event = registration.registration_form.event
Expand Down

This file was deleted.

8 changes: 3 additions & 5 deletions indico/modules/events/payment/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ def register_transaction(registration, amount, currency, action, provider=None,
:param data: arbitrary JSON-serializable data specific to the
transaction's provider
"""
new_transaction, double_payment = PaymentTransaction.create_next(registration=registration, action=action,
amount=amount, currency=currency,
provider=provider, data=data)
new_transaction = PaymentTransaction.create_next(registration=registration, action=action,
amount=amount, currency=currency,
provider=provider, data=data)
if new_transaction:
db.session.flush()
if double_payment:
notify_double_payment(registration)
if new_transaction.status == TransactionStatus.successful:
registration.update_state(paid=True)
elif new_transaction.status == TransactionStatus.cancelled:
Expand Down
17 changes: 7 additions & 10 deletions indico/modules/events/payment/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,21 @@
from indico.modules.events.payment.util import register_transaction


@pytest.mark.parametrize(('new', 'double', 'status'), (
(False, False, None),
(True, True, TransactionStatus.successful),
(True, False, TransactionStatus.successful),
(True, False, TransactionStatus.pending)
@pytest.mark.parametrize(('new', 'status'), (
(False, None),
(True, TransactionStatus.successful),
(True, TransactionStatus.successful),
(True, TransactionStatus.pending)
))
def test_register_transaction(mocker, new, double, status):
def test_register_transaction(mocker, new, status):
mocker.patch('indico.modules.events.payment.util.db')
mocker.patch('indico.modules.events.payment.util.notify_registration_state_update')
ndp = mocker.patch('indico.modules.events.payment.util.notify_double_payment')
cn = mocker.patch.object(PaymentTransaction, 'create_next')
registration = MagicMock()
db_transaction = MagicMock(status=status) if new else None
cn.return_value = db_transaction, double
cn.return_value = db_transaction
transaction = register_transaction(registration, None, None, None)
if new:
assert transaction is db_transaction
assert ndp.called == double
else:
assert transaction is None
assert not ndp.called

0 comments on commit 8ca67f9

Please sign in to comment.