Search code examples
iostestingin-app-purchasesubscriptionsreceipt-validation

is_trial_period stays "on" in Apple's Receipt Sandbox


I'm encountering an issue while debugging Apple's in-app purchase receipt. It seems the field "is_trial_period" stays true although the purchase has already expired. To my understanding Apple defines short periods for debugging subscriptions, as seen here:

Testing In-App Purchase Products

Do those times apply for trail periods as well?


Solution

  • This is because Apple issues a separate transaction for the trial period.

    Here is an example excerpt of a receipt from Apple:

    "latest_receipt_info": [
        {
            "quantity": "1",
            "product_id": "onemonth_freetrial",
            "transaction_id": "1000000328795138",
            "original_transaction_id": "1000000328795138",
            "purchase_date": "2017-08-29 23:13:52 Etc/GMT",
            "purchase_date_ms": "1504048432000",
            "purchase_date_pst": "2017-08-29 16:13:52 America/Los_Angeles",
            "original_purchase_date": "2017-08-29 23:13:53 Etc/GMT",
            "original_purchase_date_ms": "1504048433000",
            "original_purchase_date_pst": "2017-08-29 16:13:53 America/Los_Angeles",
            "expires_date": "2017-08-29 23:16:52 Etc/GMT",
            "expires_date_ms": "1504048612000",
            "expires_date_pst": "2017-08-29 16:16:52 America/Los_Angeles",
            "web_order_line_item_id": "1000000036088032",
            "is_trial_period": "true"
        },
        {
            "quantity": "1",
            "product_id": "onemonth_freetrial",
            "transaction_id": "1000000328796241",
            "original_transaction_id": "1000000328795138",
            "purchase_date": "2017-08-29 23:16:52 Etc/GMT",
            "purchase_date_ms": "1504048612000",
            "purchase_date_pst": "2017-08-29 16:16:52 America/Los_Angeles",
            "original_purchase_date": "2017-08-29 23:13:53 Etc/GMT",
            "original_purchase_date_ms": "1504048433000",
            "original_purchase_date_pst": "2017-08-29 16:13:53 America/Los_Angeles",
            "expires_date": "2017-08-29 23:21:52 Etc/GMT",
            "expires_date_ms": "1504048912000",
            "expires_date_pst": "2017-08-29 16:21:52 America/Los_Angeles",
            "web_order_line_item_id": "1000000036088033",
            "is_trial_period": "false"
        }
    ]
    

    The latest_receipt_info field will contain an array for every 'renewal' or 'transaction'. The way Apple handles free trials is by issuing one transaction that will always have is_trial_period be true, and subsequent non-trial renewal have is_trial_period be false. When you handle the receipt just make sure you are looking at the latest transaction by purchase_date or expiration_date which should represent the latest renewal and the one you should base unlocking content off of.

    And regarding length in sandbox, if your IAP product has a free trial, the sandbox environment will issue one trial period, and 5 renewals, for six renewals total.