diff --git a/payment_paypal/indico_payment_paypal/controllers.py b/payment_paypal/indico_payment_paypal/controllers.py index 47bb534..9d332c0 100644 --- a/payment_paypal/indico_payment_paypal/controllers.py +++ b/payment_paypal/indico_payment_paypal/controllers.py @@ -92,12 +92,15 @@ class RHPaypalIPN(RH): return False def _verify_amount(self): - expected = self.registration.price + expected_amount = self.registration.price + expected_currency = self.registration.currency amount = float(request.form['mc_gross']) - if expected == amount: + currency = request.form['mc_currency'] + if expected_amount == amount and expected_currency == currency: return True - current_plugin.logger.warning("Paid amount doesn't match event's fee: {} != {}".format(amount, expected)) - notify_amount_inconsistency(self.registration, amount) + current_plugin.logger.warning("Payment doesn't match event's fee: {} {} != {} {}" + .format(amount, currency, expected_amount, expected_currency)) + notify_amount_inconsistency(self.registration, amount, currency) return False def _is_transaction_duplicated(self): diff --git a/payment_paypal/tests/controllers_test.py b/payment_paypal/tests/controllers_test.py index 0491fb7..ba34e0b 100644 --- a/payment_paypal/tests/controllers_test.py +++ b/payment_paypal/tests/controllers_test.py @@ -41,17 +41,20 @@ def test_ipn_verify_business(business, expected, dummy_event): @pytest.mark.usefixtures('request_context') -@pytest.mark.parametrize(('amount', 'expected'), ( - ('13.37', True), - ('10.00', False) +@pytest.mark.parametrize(('amount', 'currency', 'expected'), ( + ('13.37', 'EUR', True), + ('13.37', 'CHF', False), + ('10.00', 'CHF', False), + ('10.00', 'CHF', False), )) -def test_ipn_verify_amount(mocker, amount, expected): +def test_ipn_verify_amount(mocker, amount, currency, expected): nai = mocker.patch('indico_payment_paypal.controllers.notify_amount_inconsistency') rh = RHPaypalIPN() rh.event = MagicMock(id=1) rh.registration = MagicMock() rh.registration.price = 13.37 - request.form = {'mc_gross': amount} + rh.registration.currency = currency + request.form = {'mc_gross': amount, 'mc_currency': 'EUR'} with PaypalPaymentPlugin.instance.plugin_context(): assert rh._verify_amount() == expected assert nai.called == (not expected)