Local receipt validation not working with auto-renewable subscription

I am working an a project where I need to implement local receipt validation for auto-renewable subscription.


The local receipt validation already works for non-consumable purchases.


When I sent the receipt to the App Store for testing, to see how the receipt looks like, I got

the following JSON response back:


This is a short version of the JSON response.


["status": 0, 
"receipt": {
    "in_app" =     (
                {
            "is_trial_period" = false;
            "original_purchase_date" = "2019-11-22 18:25:10 Etc/GMT";
            "product_id" = "NonConsumable";
  …
        },
                {
            "expires_date" = "2019-12-11 23:48:35 Etc/GMT";
            "original_purchase_date" = "2019-12-11 23:43:37 Etc/GMT";
            "product_id" = "MonthlySubscription“;
  …
        }
    );

  …    
}, 
"pending_renewal_info": <__NSArrayM 0x283d7f3f0>(
{
    "auto_renew_product_id" = "com.MonthlySubscription";
    "auto_renew_status" = 0;
    "expiration_intent" = 1;
    "product_id" = "MonthlySubscription";
  …
}
), 
"environment": Sandbox, 
"latest_receipt_info": <__NSArrayM 0x283d7f2d0>(
{
    "is_trial_period" = false;
    "original_purchase_date" = "2019-11-22 18:25:10 Etc/GMT";
    "product_id" = "NonConsumable";
  …
},
{
    "expires_date" = "2019-12-11 23:48:35 Etc/GMT";
    "original_purchase_date" = "2019-12-11 23:43:37 Etc/GMT";
    "product_id" = "MonthlySubscription";
  …
},
{
    "expires_date" = "2019-12-11 23:53:35 Etc/GMT";
    "original_purchase_date" = "2019-12-11 23:43:37 Etc/GMT";
    "product_id" = "com.MonthlySubscription";
  …
},
{
    "expires_date" = "2019-12-11 23:58:35 Etc/GMT";
    "original_purchase_date" = "2019-12-11 23:43:37 Etc/GMT";
    "product_id" = "MonthlySubscription";
  …
},
{
    "expires_date" = "2019-12-12 00:03:35 Etc/GMT";
    "original_purchase_date" = "2019-12-11 23:43:37 Etc/GMT";
    "product_id" = "MonthlySubscription";
  …
},
{
    "expires_date" = "2019-12-12 00:08:35 Etc/GMT";
    "original_purchase_date" = "2019-12-11 23:43:37 Etc/GMT";
    "product_id" = "MonthlySubscription";
  …
},
{
    "expires_date" = "2019-12-12 00:13:35 Etc/GMT";
    "original_purchase_date" = "2019-12-11 23:43:37 Etc/GMT";
    "product_id" = "MonthlySubscription";
  …
}
)
, "latest_receipt": MIIePwYJKoZIhvcNAQcCoIIeMDCCHiwCAQExCzAJBgUrDgMCGgUAMII…]


The JSON field "in_app" has only 2 receipts. One non-consumable and the first purchase of the auto-renewable subscription.

The complete list of the receipts are in the JSON field "latest_receipt_info“.


When I use local receipt validation and I look at ASN.1 Field Type 17 I only get the receipts that match the JSON field "in_app“.


Which means, looking at ASN.1 Field Type 17, I only get the non-consumable and the first purchase of the auto-renewable receipt.

All other subsequent receipts are missing.


How do I get to the other receipts so that I can find out when an auto-renewable subscription has expired?

Is there another Field Type not mentioned in the documentation or does it mean I can't use local receipt validation for auto-renewable subscription?

Replies

You may be handling an old receipt that was sent to your device after the first subscription purchase.

You need to refresh the receipt (SKReceiptRefreshRequest) or have the device receive a new subscription and call updatedTransactions. That will place a new receipt here:

NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];

NSData *receiptData=[NSData dataWithContentsOfURL:receiptURL];

Grab that receipt and it will contain the current purchases.

Sounds like the same issues in this previous thread: https://forums.developer.apple.com/thread/115828


Suggest you speak to support via the contact us link below, and use the feedback assistant to file a bug and see what comes back.


Good luck.

Quoting the docs:


"Receipts for auto-renewable subscriptions can grow over time since the renewal transactions stay in the receipt forever. To optimize performance, the App Store may truncate sandbox receipts to remove old transactions. When validating receipts for transactions made in the sandbox environment, consider creating new test accounts instead of reusing old accounts to test subscription purchases."


In other words, what you're seeing shouldn't be an issue in production, I think.

Thank you all for your replies.


It seems like it is working again.

All purchases are in the receipt.