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..
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".
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?
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 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