6

I'm developing an app with auto-renewing receipts, and saving them in the server, which is all working great, until the user restores their purchases - this causes duplicates.

The transaction_id field is different for the same receipt with every restore, and the original_transaction_id is obviously the same across every run of renewals, so I can't use that. The unique_identifier field is also the same (I don't understand how it's unique). I had been using the web_order_line_item_id field and it seemed fine, but I just tested this with a completely new account, and ended up with a duplicate, so that's useless too.

I am missing something really obviously here? There must be a field that is unique to every receipt, but doesn't change each time it is restored?

Serg
  • 2,346
  • 3
  • 29
  • 38
Malcolm Christie
  • 727
  • 1
  • 6
  • 20
  • Since you save the receipt to your server, why don't you just retrieve the receipt from the server as well? – rocky Jul 11 '13 at 20:54
  • I do for most use scenarios, but I need to allow users to restore purchases on a new or restored device. – Malcolm Christie Jul 11 '13 at 20:56
  • I'm assuming you have some sort of login associated with your auto-renewing subscription. And I'm also assuming you associate the login with the receipt you save on your server. With that in mind, it doesn't matter if a device is new or restored. Whenever the user logs in, you can query your server for the receipt and return it. Are my assumptions wrong? – rocky Jul 11 '13 at 23:03
  • No, the users don't need to login to my app; it should be possible for them to just restore the receipts and identify them through those without them needing to sign up and remember their password etc. It think possibly using both the original_transaction_id and the purchase date would do it, but that seems a bit messy :/ – Malcolm Christie Jul 12 '13 at 08:29
  • Any luck finding the answer? – Kirill Zaitsev Jun 04 '14 at 14:06
  • What kind of duplicates do you have?, wich fields cause you the duplicate? the transaction_id is different for every receipt, so you can't have duplicates if you use that as the primary key. – gabuh Jun 06 '14 at 12:53
  • 1
    `the transaction_id is different for every receipt, so you can't have duplicates if you use that as the primary key` Well actually that means that if you use transaction_id as PK you'll possibly get two records in your database corresponding to one purchase. It's not clear — how one can avoid this situation. – Kirill Zaitsev Jun 08 '14 at 04:42

1 Answers1

3

Apparently original_transaction_id and purchase_date are the only two unique values that will not change after restoring purchases. You can also rely on latest_receipt_info -> web_order_line_item_id as it doesn’t change between restores (unlike latest_receipt_info -> transaction_id). By inspecting latest_receipt_info you can find out expiration_date of the subscription, which apparently apple believes should be enough for you.

avdyushin
  • 1,906
  • 17
  • 21