So I have setup an auto-renewable subscription for my app with a period of 1 month, which equals 5 minutes or so in the sandbox. In the client app I subscribe, send the receipt to my server, it gets verified and I put a record in my database that this user has a subscription.
My question is how do I check if this subscription has been renewed? I have read the docs and can't figure out what should I do.
Here is where I am so far:
0
, great. I also get latest_receipt
, which I replace in my database with the oldest receipt.latest_receipt
, I get status 21006
(expired receipt) and this: { receipt: { original_purchase_date_pst: '2013-08-06 11:58:04 America/Los_Angeles', unique_identifier: '------------', original_transaction_id: '----------', expires_date: '1376129825000', transaction_id: '------------', quantity: '1', product_id: 'subscription', item_id: '--------', bid: 'com.--------', unique_vendor_identifier: '---------', web_order_line_item_id: '---------', bvrs: '2.0', expires_date_formatted: '2013-08-10 10:17:05 Etc/GMT', purchase_date: '2013-08-10 10:12:05 Etc/GMT', purchase_date_ms: '1376129525000', expires_date_formatted_pst: '2013-08-10 03:17:05 America/Los_Angeles', purchase_date_pst: '2013-08-10 03:12:05 America/Los_Angeles', original_purchase_date: '2013-08-06 18:58:04 Etc/GMT', original_purchase_date_ms: '1375815484000' }, latest_expired_receipt_info: { original_purchase_date_pst: '2013-08-06 11:58:04 America/Los_Angeles', unique_identifier: '-------', original_transaction_id: '-', expires_date: '1376129825000', transaction_id: '-', quantity: '1', product_id: 'subscription', item_id: '-', bid: 'com.-', unique_vendor_identifier: '--', web_order_line_item_id: '-', bvrs: '2.0', expires_date_formatted: '2013-08-10 10:17:05 Etc/GMT', purchase_date: '2013-08-10 10:12:05 Etc/GMT', purchase_date_ms: '1376129525000', expires_date_formatted_pst: '2013-08-10 03:17:05 America/Los_Angeles', purchase_date_pst: '2013-08-10 03:12:05 America/Los_Angeles', original_purchase_date: '2013-08-06 18:58:04 Etc/GMT', original_purchase_date_ms: '1375815484000' }, status: 21006 }
The second element in the array used to be latest_receipt_info
, but now it's latest_EXPIRED_receipt_info
. Here is what the docs say:
In addition to the receipt_data field, the response may also include two new fields. If the user’s subscription is active and was renewed by a transaction that took place after the receipt your server sent to the App Store, the
latest_receipt
field includes a base-64 encoded receipt for the last renewal for this subscription. The decoded data for this new receipt is also provided in thelatest_expired_receipt_info
field. Your server can use this new receipt to maintain a record of the most recent renewal.
So if the sub has been renewed since my server last checked, the decoded receipt for the renewal should be in latest_expired_receipt_info
. In that object the expires_date
is the same as the original receipt's expires_date
.
What the hell? I just want to check if the sub is active. Can anyone explain in simple words how do I do that?
Thank you!
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.
Once you have logged into a sandbox account using this method, you can then go to the Settings app, tap “iTunes & App Store”, then scroll to the bottom to the Sandbox Account section. Here you can log in and out of different sandbox accounts for testing.
My experience. Let's assume, we always send initial receipt to Apple's server.
In any case, you'll get JSON with at least two fields: status
(no comments) and receipt
(information about receipt that you've send).
Additionally to that:
1) If the subscription is still active, you'll additionally get latest_receipt
(base64-encoded string) and latest_receipt_info
(information about that receipt).
2) If the subscription is already expired, you'll additionally get latest_expired_receipt_info
(information about last renewing receipt). Yes, you get only information about it, no base64-encoded string.
And yes, AFAIK, that's not documented anywhere. Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With