feat: Ignore IPN messages which pertain to events which will also be tracked via webhook
A fun discovery about IPNs is that PayPal will generate them for non-legacy transactions just as happily as it will for legacy transactions. This means that all PayPal transactions made on donate-neo
will generate at least one webhook message and zero or more IPN messages, and all recurring transactions begun on donate-paleo
will generate at least one IPN message.
This ecosystem must be simplified, and as IPN messages are themselves a legacy format, we should make this simpler by throwing out as many IPN messages as we can, and only hold onto those which will not be echoed by a webhook message. This MR intends to perform that work.
This commit adds two new early exits to tordonate.paypal.controller.process_ipn()
. First, we inspect the key-value pairs contained in the IPN message to see whether the given transaction type is recurring_payment
, and exit early if it isn't. Second, we compare the transaction series' time_created
value - which provides the date and time of the initial transaction - and check to make sure it occurred before donate-neo
launched. If not, then that transaction series will also generate a webhook message, and so we can safely ignore the IPN message about it, and exit the method early.
This commit also breaks out the "Paypal timestamp to datetime object" conversion to a separate method, since we now perform that conversion in multiple places in process_ipn()
.
Lastly, this commit adds testing for these new early exits, as well as datafiles to support the two new conditions under which an IPN message may be quietly passed on (viz., being the wrong donation type and representing a too-new recurring donation).