Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to know purchase made by which iTunes account? - iOS

My app provides an in-app-purchase non-consumable type. The app has log in facility. Is it possible to make purchase based on logged in user to my app?

I know it sounds awkward. Let me specify the problem.

The device has a already logged in user at iTunes store. At that time, when my app gets install to device for first time, any user can login with credentials to my app. Consider, he made some purchase and log out from the app. Now, another user logged in to the app and can't use facilities available for previous user after in app purchase. But as you know non-consumable product purchase based on iTunes store account (only one non-consumable product can be purchased for each account). I have tried by following way..

  1. Store user id to iCloud, but I don't know by which iTunes account that purchase was made. So, I couldn't display proper message "You should log in with different iTunes account to make purchase".

  2. In android, with the In-app Billing v3, a developer payload string can be sent along with the purchase request. This string is also returned when a query is made for that purchase. So, this can be used to identify the user who made the purchase. Is there anything similar available in iOS?

like image 727
Milan Kamilya Avatar asked Mar 25 '15 12:03

Milan Kamilya


1 Answers

As of iOS 7, SKMutablePayment has an applicationUsername property that can be set when a payment is made. And, SKPaymentQueue has the restoreCompletedTransactionsWithApplicationUsername: method (link).

Apple's guidance is to hash your server-side user ID and pass that up on purchase and restore. So, in your case, if iTunes User A purchases the product it will be bound to your server-side user ID for that purchaser. Then, if iTunes User B attempts to restore, restoration will fail, because they would still be passing up the same server-side user ID.

You'll also have to track (on the server) that your server-side user ID has purchased the product. Otherwise, if iTunes User B attempts to restore you'll need to know the difference between they having logged into the device with a different iTunes account and they having never purchased. And of course, you'll also want to prevent the same server-side user from purchasing the product twice, under different iTunes accounts.

Caveats:

  • If you already have purchases made in production, this most likely won't work.
  • iOS 7+
  • The "already purchased" scenario I mentioned above.
like image 111
DeepFriedTwinkie Avatar answered Sep 28 '22 13:09

DeepFriedTwinkie