I am implementing an auto-renewable subscription in my app.
Currently, to check if the user have an active subscription, I examine all the records in latest_receipt_info
array from the response JSON returned from the Apple's /verifyReceipt
service, find the one with the max expires_date_ms
and check if this date is in the future. Before checking the dates I also check if the status
field is 0 (receipt is valid).
I was thinking that it is enough, but I recently found out that there is another field - cancellation_date_ms
. As I understand from the docs, this filed is present if user has canceled his subscription through the Apple support.
From (Apple docs)
You can use this value to:
Determine whether to stop providing the content associated with the purchase.
Check for any latest renewal transactions, which may indicate the user re-started or upgraded their subscription, for an auto-renewable subscription purchase.
So I am wondering, if a user cancels his subscription through the Apple support, will this affect the expires_date_ms
for the current subscription period? So the next time I check expires_date_ms
, I know the subscription is not active.
Or does expires_date_ms
stays the same as it was before the user canceled the subscription, and so I need to check the cancellation_date_ms
as well?
You should check for cancellation_date_ms
as well. Expires_date
field doesn't change when customer cancels subscription through Apple Support.
Here is production JSON example with refund:
"latest_receipt_info": [
{
"quantity": "1",
"product_id": "XXX",
"transaction_id": "150000567873035",
"original_transaction_id": "150000567873035",
"purchase_date": "2019-11-10 17:37:05 Etc/GMT",
"purchase_date_ms": "1573407425000",
"purchase_date_pst": "2019-11-10 09:37:05 America/Los_Angeles",
"original_purchase_date": "2019-11-10 17:37:06 Etc/GMT",
"original_purchase_date_ms": "1573407426000",
"original_purchase_date_pst": "2019-11-10 09:37:06 America/Los_Angeles",
"expires_date": "2019-12-10 17:37:05 Etc/GMT",
"expires_date_ms": "1575999425000",
"expires_date_pst": "2019-12-10 09:37:05 America/Los_Angeles",
"cancellation_date": "2019-12-05 19:14:48 Etc/GMT",
"cancellation_date_ms": "1575573288000",
"cancellation_date_pst": "2019-12-05 11:14:48 America/Los_Angeles",
"web_order_line_item_id": "150000194283402",
"is_trial_period": "false",
"is_in_intro_offer_period": "false",
"cancellation_reason": "0",
"subscription_group_identifier": "20502261"
}
],
"pending_renewal_info": [
{
"auto_renew_product_id": "XXX",
"original_transaction_id": "150000567873035",
"product_id": "XXX",
"auto_renew_status": "0"
}
]}