iosin-app-purchasereceipt-validation

Need to understand iOS InApp purchase receipt


I'm digging into iOS in-app purchase validation (server side) and I got pretty much confused about the receipt fields returned by apple's validation server. The documentation available here is not really clear (at least for me)

So here is a real (obfuscated) in-app purchase receipt returned by Apple's validation server

{
  "receipt": {
    "receipt_type": "Production",
    "adam_id": XXXXXXX,
    "app_item_id": XXXXXXXXX,
    "bundle_id": "com.XXXXX.XXXXX",
    "application_version": "XXXXXXXXX",
    "download_id": XXXXXXXXXXXX,
    "version_external_identifier": XXXXXXXXXXX,
    "receipt_creation_date": "2019-10-15 14:01:41 Etc/GMT",
    "receipt_creation_date_ms": "1571148101000",
    "receipt_creation_date_pst": "2019-10-15 07:01:41 America/Los_Angeles",
    "request_date": "2019-10-15 14:04:20 Etc/GMT",
    "request_date_ms": "1571148260390",
    "request_date_pst": "2019-10-15 07:04:20 America/Los_Angeles",
    "original_purchase_date": "2018-11-27 18:28:48 Etc/GMT",
    "original_purchase_date_ms": "1543343328000",
    "original_purchase_date_pst": "2018-11-27 10:28:48 America/Los_Angeles",
    "original_application_version": "XXXXXXXXX",
    "in_app": [
      {
        "quantity": "1",
        "product_id": "com.XXXXXXXXXX.XXXXX.XXXXXX",
        "transaction_id": "XXXXXXXXXXX",
        "original_transaction_id": "XXXXXXXXXX",
        "purchase_date": "2019-10-15 14:01:41 Etc/GMT",
        "purchase_date_ms": "1571148101000",
        "purchase_date_pst": "2019-10-15 07:01:41 America/Los_Angeles",
        "original_purchase_date": "2019-10-15 14:01:41 Etc/GMT",
        "original_purchase_date_ms": "1571148101000",
        "original_purchase_date_pst": "2019-10-15 07:01:41 America/Los_Angeles",
        "is_trial_period": "false"
      }
    ]
  },
  "status": 0,
  "environment": "Production"
}

So my questions are:

  1. The fields starting with "original_purchase_date" represent a datetime but why they have a different value in the 2 parts of the receipt ?
  2. In the in_app part of the receipt, can the values of the fields starting with "purchase_date" and the values of the fields starting with "original_purchase_date" be different ? And if yes, in which case ?
  3. Is the "application_version" field contains the value of the current build version published of the app since the "original_application_version" field, according to the documentation, represent the build version of the app the user used to make the purchase ?

Thanks a lot for your help and answers.


Solution

  • R.E.B Hernandez!

    1. original_purchase_date inside in_app is the time when in-app purchase has been made, the one outside this array is the date when the app was installed for the first time.
    2. If you use non-consumable and non-renewing subscriptions, then purchase_date will be the same as original_purchase_date. However, if you use auto-renewable subscriptions, then you should check latest_receipt_info array instead of in_app. And in case of subscriptions, original_purchase_date will represent only the date of the first transaction.
    3. Yes, application_version is the current version of the app on the device. original_application_version is the version of the app that the user originally purchased.

    Here is documentation link