apple / app-store-server-library-node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to best clear failed notifications from getNotificationHistory

darvelo opened this issue · comments

The onlyFailures option of getNotificationHistory seems very useful to try to recover from missed notifications, but it's still a bit unclear to me how to clear a failed notification from the history if my server managed to successfully process it from the received list.

It's also a bit unclear how to ensure that I don't process a notification failure from the past in such a way that I use the data to overwrite the data from a notification that came after it, such as updating my database with auto-renewing subscription data using the failed notification where a more recent notification was successfully processed by my server with different auto-renewing subscription data.

This is all still very new to me, so my apologies if I'm somehow missing the mark here.

Hello @darvelo if a notification is successfully received by your server during a retry, the value will be removed from the response when onlyFailures is set to true. If your server never receives the notification successfully during the retry period, then the notification will remain in the failure history for the approximately six months that notifications are retained.

For your question about ordering of notifications, generally that would require looking at the signed transaction info and determining based on fields like purchaseDate the order of the underlying purchases. Looking at the signedDate will give you a sense of when the notification was generated (retries for V2 notifications do not change this time) and allow you to order, for a given transactionId, which is the most recent. Note that a notification will always contain, as of the signedDate, the most recent version of a transaction.

Hi @alexanderjordanbaker! So would this mean that, given I have a database table that holds the last seen signedDate for a transaction from App Store Server Notifications or from StoreKit 2, that if I receive a failed notification from onlyFailures with the same transactionId but with an earlier signedDate than the one I have in my database, that I can ignore and skip processing that failed notification?

Sorry I took so long to reply, it's taken a while to fully wrap my head around everything and implement it.

I decided to do just this, checking the signedDate and only overwriting my database record if the date is newer or if a server notification on that date hasn't been processed yet for that transactionId. This leaves room for the app client to be able to send the transaction first and the notification to update the record afterward, or vice-versa.