I had successfully implemented in-app purchase in my application.
My query is :
There is One apple id xyz#apple.com through which i am logged in to itunes in ipad or device.
now in my application there are several users. They will purchase products through in-app purchase. my product is non-consumable.
Now, for example there are two user A and B (they logged in to my application so they are application users).
case : user A purchase product using in-app purchase with apple id xyz#apple.com and get user rights of purchased product member (here on success of completion of payment i call web service to make user database update that he/she had purchased product) and logout from my application. Now User B logged in to my application and going to purchase product as well as User A purchased (here Note that the apple id is same xyz#apple.com). But while he trying to purchase product apple says that “you've already purchased this.Tap OK to download it again for free” so user tap OK and this product will again restore as per user and again on success of that method i call web service which make user database update.
so question is how can i differ both user while purchasing product that from this id (i.e. xyz.apple.com) you had already purchased and now user should be different then you have to login using another apple id (may be abc.apple.com).
finally i solved in app purchase issue with the following solution :
1) i get transaction id and update it with the database as per user if transaction id founds duplicate then it will throw error and don’t make user as a paid member.
Means when A user make purchase then i get it's transaction_id and update it to data base as Username : A and transaction_id : XYZ.
and if B user going to purchase from same iTunes id then i will get same transaction_id that is XYZ. So here it will not allow user to be proceed(i.e. from web service don't let user to be paid member and give error). following is code:
-(void)callinApp : (SKPaymentTransaction*) transaction
{
if (transaction.originalTransaction.transactionIdentifier == nil)
{
// send transection.transactionIdentifire
// means it's first time purchasing
NSLog(#"Transection Id : %#",transaction.transactionIdentifier);
UserId = A123;
TransectionID = transaction.transactionIdentifier;
}
else
{
// send transaction.originaltransection.transectionidentifier
// means already purchased one in past
NSLog(#"Original Transection Id:%#",transaction.originalTransaction.transactionIdentifier);
UserId = A123;
TransectionID = transaction.originalTransaction.transactionIdentifier;
}
// call web service and pass TransectionID & UserId
}
2) The error which was coming while doing transaction from another iTunes id the method (updateTransaction) calling multiple time i solved that by removing that apple(iTunes) id from sandbox tester in iTunes connect.
Non-consumable products are purchased once by users and do not expire or decrease with use.
even thought if you are looking for flow that how to match between login user id and in app purchase id. actually i did in App Purchase long times ago so i don't know what parameter sent from apple once in app purchase succeeded. there may be in-app purchase receipt and some other parameter as well. just need to pickup unique parameter that is same for number of time once product downloaded from same user.
So here i am consider "in-app purchase receipt" as unique parameter return once in App purchase succeeded. and once in App purchase succeeded, you can bind in-app purchase receipt with login user id on your sever. so next time when B user going to download same product with same apple user id, in App purchase request will return same in-app purchase receipt so check that weather this receipt id is bind with another login id, if YES then cancel download and show message to user that "This account is already linkup with some other login id".
Related
I have implemented auto-renewal subscription in app purchase in my app, but I am stuck in 1 case scenario.
User can sign up into app after successfully in-app purchase done. App is offer 2 plans Yearly & Monthly.
Let's suppose abc#apple.com in there as apple ID in device settings.
Scenario:
User A gets the subscription with his app credentials and his Apple ID.
User B uses User A's device and signup with User B app credentials but uses User A's Apple ID to buy a subscription.
Currently, it allows that User B to purchase this item but it says that there is a subscription with this user and asks for a permission to modify this subscription.
My question is how to prevent User B to modify User A's subscription? I could not find any solution before the receipt creation. I do not want to allow User B that modifies User A's subscription. I want to inform User B about using different Apple ID to continue to buy a subscription.
How can I restrict user B before he initiate the purchase?
My Try
I try to compare original transactionID, but it is after the purchase initiated & this will restrict the user B to sign up via backend server. But as it is valid purchase so server is update its plan if User B choose other plan than user A chosen before.
Thank you,
If app user 1 purchases a subscription and later he cancels it after some renewals and now app user 2 want to purchase a subscription from the same itunes account, so is this possible and if, how should we handle this on server side?
one itunes account can be use as one subscription only but if you said user 1 already cancel subscription then obviously if another user come to register with the same itunes account that user is possible to purchase a subscription because previously user1 cancel his subscription once his cancel you can use flag on database side that this user in cancel subscription and now whoever is using this account can re subscription or purchase new subscription service
but if user1 decided to purchase another subscription with an existing subscription of user2 now it impossible since they shared same itune account
Yes, it is possible. And to handle it you have to save the Subscription receipt over the server and every time map the new receipt over the server with other receipts. if it does not exist over the server (for your current user) then it's the in-app purchase from new apple id or it's purchased again.
I am implementing In-App Purchases first time in my application and new to In-app purchases Store Kit.
I have few doubts regarding In-app purchases:
What happens if a user purchased a subscription and logged out from the application and another user logs in and trying to purchase the same?
Does iTunes allow the second user to use the First user's purchased product?
If it allows how can we handle the second user's subscription?
What details we will get post Successful/Failed transactions from itunes to save in my database?
For a non-renewing subscription then it is entirely up to you to track expiration and determine what content a user has access to and when.
For example, say your subscription gave access to "the word of the day". If the subscription was active for the month of January, then the user would receive access to new words each day in January. The user should continue to be able to see January's words even after the subscription expires, but no new words.
If they resubscribe in March then they would now get new words throughout March.
You need to track all of this on your server against the user account.
Non-renewable subscription IAPs act much like consumable IAPs. The "Restore purchases" Store Kit function does not restore non-renewable IAP items.
To answer your specific questions:
If a new user logs in to your account system in the app (but the same iTunes account is still active on the device) then a second purchase will succeed and you need to update the subscription start and end dates for the new active account on your server.
You also need to cater for the following:
- The original account logs back in; In this case the original subscription entitlements need to be available
- The original or second account log in to another device; Again, the accounts subscription entitlements need to be available.
No, since non-renewing subscriptions are not restorable, the second user cannot "use" the first user's subscription.
You handle each account in your system independently.
Information about the mechanics of the purchase process are described in the In App Purchase Programming Guide
In my app I have items to show just for users that are pays for subscription. User can log to app by e-mail and password and can logout and on same device can log different user.
My problem is that Apple Id in phone is still same. So when different user logged in he could restore purchase even that he didn't pay anything.
So my question is how can I fix it? How can I connect Apple account to my custom account? Or at least somehow when trying to restore IAP check that this Apple account already have this subscription but different user was logged in. How other apps do this? Thanks
Edit:
I want to use Auto-renewing subscription in my app and I just don't know how to connect it to my custom account system.
When a user makes an IAP, you will not know the Apple Id used to make the purchase. What you will know, however, is the transaction id for the purchase. What you will want to do store the transaction id of the original purchase with your custom account.
When a user restores, you will determine if the SKPaymentTransaction's originalTransaction's transactionIdentifier matches the custom account. If not, then you can assume this is a different user. You can read more about that here:
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/Restoring.html
Note that the receipt contains a field called the original transaction id. This is what you would use for subscriptions to track the original transaction id. This is because each time you auto renew, a new transaction id will be generated for the auto renew. The receipt will actually contain all the purchases.
On your server, you would want to save the original transaction id and potentially the receipt. Essentially the more metadata your store around this, the better off you will be if you have to do any form of double checking transactions.
I want to send the userId of my application with the inApp Purchase so that the transaction ID that I get after successful inApp purchase, I be able to know the userId of the user who purchased that product from Apple's server using the transaction ID. Is this possible ? or something related to it ?