Payment/PayPal: Verify currency as well

This commit is contained in:
Alejandro Avilés 2015-11-16 15:17:31 +01:00
parent fde2bee126
commit ca02fed62b
2 changed files with 15 additions and 9 deletions

View File

@ -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):

View File

@ -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)