Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS renewable subscription expires_date field

UPDATE:

I'm posting @vitro 's comment here:

Year 2021 - and it is there: https://developer.apple.com/documentation/appstorereceipts/expires_date_ms This field is returned in the JSON response, in the responseBody.Latest_receipt_info and responseBody.Receipt.In_app arrays.
The time a subscription expires or when it will renew, in UNIX epoch time format, in milliseconds. Use this time format for processing dates.

thx @vitro


ORIGINAL POST:

While verifying a renewable subscription receipt I am attempting to get the expiration date of the latest receipt.

According to the apple documentation on receipt fields the "expires_date" field should contain a number which is the number of milliseconds since January 1, 1970, 00:00:00 GMT.(https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html#//apple_ref/doc/uid/TP40010573-CH106-SW1)

When I fetch the field however i am receiving a string with a formatted date from the "expires_date" field. There is another field called "expires_date_ms" that seems to provide the correct data. Apple states "Keys not documented below are reserved for use by Apple and must be ignored by your app."

here is an example of my receipt:

{"quantity":"1", 
 "product_id":"com.testapp.test",
 "transaction_id":"1000000135676121", 
 "original_transaction_id":"1000000135134855", 
 "purchase_date":"2014-12-15 06:53:54 Etc/GMT",  
 "purchase_date_ms":"1418626434059", 
 "purchase_date_pst":"2014-12-14 22:53:54 America/Los_Angeles",  
 "original_purchase_date":"2014-12-15 06:51:12 Etc/GMT",  
 "original_purchase_date_ms":"1418626272000",  
 "original_purchase_date_pst":"2014-12-14 22:51:12 America/Los_Angeles",  
 "expires_date":"2014-12-15 06:56:10 Etc/GMT",  
 "expires_date_ms":"1418626570000",  
 "expires_date_pst":"2014-12-14 22:56:10 America/Los_Angeles",  
 "web_order_line_item_id":"1000000028947356",  
 "is_trial_period":"false"
}]

Which field should i use to obtain the expired date with best practices?

like image 419
Lvergos Avatar asked Dec 15 '14 07:12

Lvergos


People also ask

What is renewable subscription?

Overview. Auto-renewable subscriptions provide access to content, services, or premium features in your app on an ongoing basis. They automatically renew at the end of their duration until the user chooses to cancel.

What time does Apple renew subscriptions?

The subscription renewal process begins in the 10 days before the expiration date. During those 10 days, the App Store checks for any billing issues that might delay or prevent the subscription from being automatically renewed, for example, whether: The customer's payment method is active.

What is Apple StoreKit?

StoreKit provides a simple and secure way to purchase digital goods or services in your apps across all Apple platforms, so people can start playing, gaming, reading, and more, right away.


1 Answers

As you found, the documentation for "expires_date" at this link...

https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html#//apple_ref/doc/uid/TP40010573-CH106-SW1

...states Keys not documented below are reserved for use by Apple and must be ignored by your app. However it does now say that "expires_date" is an ASN.1 Field Value IA5STRING, interpreted as an RFC 3339 date.

It appears that as of today (2015-12-04), a year after your question, Apple has yet to clarify and make official the "expires_date_ms" field which clearly has the milliseconds representing the "expires_date".

As you will also find, a receipt contains a _ms version and _pst version of dates. The _pst is clearly for "PST" or America/Los_Angeles timezone.

receipt":{"receipt_type":"ProductionSandbox", "adam_id":0, "app_item_id":0, "bundle_id":"com.my.cool.app", "application_version":"1.0.3", "download_id":0, "version_external_identifier":0, "receipt_creation_date":"2015-12-04 03:48:00 Etc/GMT", "receipt_creation_date_ms":"1449200880000", "receipt_creation_date_pst":"2015-12-03 19:48:00 America/Los_Angeles", "request_date":"2015-12-04 03:53:45 Etc/GMT", "request_date_ms":"1449201225187", "request_date_pst":"2015-12-03 19:53:45 America/Los_Angeles", "original_purchase_date":"2013-08-01 07:00:00 Etc/GMT", "original_purchase_date_ms":"1375340400000", "original_purchase_date_pst":"2013-08-01 00:00:00 America/Los_Angeles", "original_application_version":"1.0",
"in_app":[
{"quantity":"1", "product_id":"com.my.cool.app.inapppurchase1", "transaction_id":"1000000000000589", "original_transaction_id":"1000000000000589", "purchase_date":"2015-12-03 08:09:32 Etc/GMT", "purchase_date_ms":"1449130172000", "purchase_date_pst":"2015-12-03 00:09:32 America/Los_Angeles", "original_purchase_date":"2015-12-03 08:09:34 Etc/GMT", "original_purchase_date_ms":"1449130174000", "original_purchase_date_pst":"2015-12-03 00:09:34 America/Los_Angeles", "expires_date":"2015-12-03 08:14:32 Etc/GMT", "expires_date_ms":"1449130472000", "expires_date_pst":"2015-12-03 00:14:32 America/Los_Angeles", "web_order_line_item_id":"1000000031087708", "is_trial_period":"false"},
"latest_receipt_info":[
{"quantity":"1", "product_id":"com.my.cool.app.inapppurchase1", "transaction_id":"1000000000000589", "original_transaction_id":"1000000000000589", "purchase_date":"2015-12-03 08:09:32 Etc/GMT", "purchase_date_ms":"1449130172000", "purchase_date_pst":"2015-12-03 00:09:32 America/Los_Angeles", "original_purchase_date":"2015-12-03 08:09:34 Etc/GMT", "original_purchase_date_ms":"1449130174000", "original_purchase_date_pst":"2015-12-03 00:09:34 America/Los_Angeles", "expires_date":"2015-12-03 08:14:32 Etc/GMT", "expires_date_ms":"1449130472000", "expires_date_pst":"2015-12-03 00:14:32 America/Los_Angeles", "web_order_line_item_id":"1000000031087708", "is_trial_period":"false"},
"latest_receipt":"MIItbAYJKoZIhvcNAQcCoIItXTCCLV...truncated...nA=="}

Nevertheless, until the ios releasenotes changes its wording or list of fields, it is, however ignominious, not recommended to use the _ms and _pst fields.

like image 178
WEBjuju Avatar answered Sep 21 '22 04:09

WEBjuju