Paypal IPN sometimes fails to update the next scheduled payment date when recording the latest recurring payment
IPNs from Paypal do not always correctly update the next scheduled payment date of a Paypal recurring transaction. The reason is because of a seemingly broken default algorithm which is used to calculate this date.
This algorithm has a weird way of determining whether the parent IPN handler is “handling” the next scheduled date. It says that if the current next scheduled date is the same as the receive date of the incoming transaction, then it is not being “handled” by the child handler. This causes the next scheduled date to be handled by the default handler (which is what we want in the case of Paypal, since Paypal does not calculate this).
The problem with this idea is that the time is truncated from the next scheduled date, effectively setting it at midnight AEDT (for our installation). But the receive date of the transaction from Paypal is in PDT. Thus if a recurring transaction is handled by Paypal after 6am PDT (this doesn’t happen often, but maybe about 10% of the time), it effectively arrives “the following day” in AEDT, causing the above test to fail and thus not triggering the routine to handle the next scheduled date calculation. This date then gets “stuck”, since it will also not be handled in subsequent recurring transactions, as it will never again match the incoming transaction receive date.
The issue presents itself, in our case, with some two thirds of our Paypal recurring payments having "stuck" next scheduled contribution dates which are never updated. Our records show that it gets correctly updated for about 5 to 10 payments until a payment is made after midnight AEDT (6am PDT), after which updates stall and is never corrected no matter how many more payments are made.
I have a suggested fix, I'll create a PR which people can comment on.