iOS IAP subscriptions/App Store Server to Server Notifications. Replacing the verifyReceipt API with unified_receipt

Viewed 491

I'm in the process of upgrading an existing iOS IAP subscription system that already makes use of App Store Server Notifications. My existing solution is using the now deprecated latest_receipt, latest_receipt_info, latest_expired_receipt and latest_expired_receipt_info fields. According to Apple, these fields are now all replaced with the single unified_receipt field.

After watching all the required WWDC videos and sifting through the little documentation available I'm still left with a few unanswered questions.

The latest_receipt_info field is documented as:

An array that contains the latest 100 in-app purchase transactions of the decoded value in latest_receipt.

This means that this array will contain the customer's entire transaction history. This will not only include the relevant subscription but also any transactional products the customer may have purchased.

My question here is how can I find the relevant transaction in this array? The relevant transaction in this case would be the one that triggered the event (e.g. CANCEL). I need this transaction in order to update our backend database to reflect the current subscription status. For example, to update the subscription end date to the cancellation_date on a CANCEL event .

I have a similar question regarding the pending_renewal_info array. It's unclear to me from the existing documentation if all customers with an active (or maybe even expired?) subscription will always have an entry in this array.

An array of elements that refers to auto-renewable subscription renewals that are open or failed in the past.

I also need to find the relevant transaction in this field to do things like toggle the subscription status on a DID_CHANGE_RENEWAL_STATUS event or update the billing status on a DID_FAIL_TO_RENEW event. From the docs it doesn't look like there is enough info in the pending_renewal_info alone to compute the current subscription renewal status.

Overall my question really boils down to:

Can I be sure that there will be an entry in both unified_receipt.latest_receipt_info and unified_receipt.pending_renewal_info that matches the top level event auto_renew_product_id? And if so how should I find the relevant object in the respective array? Will there only be a single entry for each auto_renew_product_id or should I search the array and pull out the first match?

1 Answers

I found out that the transactions inside unified_receipt.latest_receipt_info array are ordered by purchased date from the latest to the oldest. And sure that you can found out the the top level event auto_renew_product_id.

However, for updating the subscription status or billing status, I utilize the return value from /verifyRecipt, which you can get by requesting to the Apple verifyReceipt server with receipt-data and password(https://developer.apple.com/documentation/appstorereceipts/verifyreceipt). Noted that the input receipt-data is unified_receipt.latest_receipt, and the responses share the same structure as unified_receipt.

Related