Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

ios - How to detect and verify a renewal for an auto-renewable subscription?

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:

  1. The initial receipt that gets sent to my server is verified with a status 0, great. I also get latest_receipt, which I replace in my database with the oldest receipt.
  2. After 6 minutes when I try to verify the 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 the latest_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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...