Goal
The goal of this patch is to decouple IP address validation from the actual process of transacting a sale.
Right now, if an invalid IP address is passed via the request headers, the checkout views will fail with a DataError in the Transaction.charge() call, while still creating a Transaction. It'd be better if they instead failed earlier with a ValidationError.
This is also necessary to simplify refactoring of Transaction.charge() method and checkout views, which will have to happen later due to the ongoing issue with some recurring transactions caused by SCA.
What it does
- adds a utility for validating IP addresses using Django builtin validators;
- modifies checkout views to use this validation helper before proceeding to handling the form (similarly to how reCAPTCHA is handled);
- adds a few tests that check that this validation actually works;
- modifies the currency middleware which turns out to be breaking when passed a bogus IP address.