Is there a way to find out a purchase made using an iTunes account? - iOS

My application provides a non-consumable type in the application. The application has a login. Can I make a purchase based on a registered user in my application?

I know that sounds awkward. Let me point out the problem.

The device has an already registered user in the iTunes store. At the time when my application is first installed on the device, any user can log in with my credentials to my application. Think he made a purchase and left the application. Now another user has registered in the application and cannot use the funds available for the previous user after purchasing the application. But, as you know, the purchase of a non-consumable product based on the iTunes store account (for each account you can purchase only one unused product). I tried as follows.

  • Save the user ID in iCloud, but I don’t know which iTunes account the purchase was made. Therefore, I was not able to display the correct message "You must be logged in with a different iTunes account to complete the purchase."

  • In android, with the In-app Billing v3, the developer payload line can be sent along with the purchase request. This row is also returned when a request is made for this purchase. Thus, this can be used to identify the user who made the purchase. Is there something similar in iOS?

+7
ios objective-c in-app-purchase
source share
2 answers

Starting with iOS 7, SKMutablePayment has an applicationUsername property that can be set when making a payment. And SKPaymentQueue has a restoreCompletedTransactionsWithApplicationUsername: method (link) .

The Apple Guide is to hash your server-side user ID and pass it on when you purchase and restore. So, in your case, if iTunes User A purchases a product, it will be tied to your server-side user ID for this customer. Then, if iTunes User B tries to recover, the restore will fail because they will still transmit the same user ID on the server side.

You will also have to monitor (on the server) that your server-side user ID has purchased the product. Otherwise, if iTunes User B tries to recover, you need to know the difference between the fact that they logged into the device with a different iTunes account and they never bought. And, of course, you also want the same server user to buy the product twice under different iTunes accounts.

Cautions:

  • If you already have purchases made in production, this most likely will not work.
  • iOS 7+
  • The "already acquired" scenario that I mentioned above.
+6
source share

if the recovery purchase is successful than the purchase made by this account.

 [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; [[SKPaymentQueue defaultQueue]restoreCompletedTransactions]; // Then this is called - (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue { NSLog(@"%@",queue ); NSLog(@"Restored Transactions are once again in Queue for purchasing %@",[queue transactions]); NSMutableArray *purchasedItemIDs = [[NSMutableArray alloc] init]; NSLog(@"received restored transactions: %i", queue.transactions.count); for (SKPaymentTransaction *transaction in queue.transactions) { NSString *productID = transaction.payment.productIdentifier; [purchasedItemIDs addObject:productID]; NSLog (@"product id is %@" , productID); // here put an if/then statement to write files based on previously purchased items // example if ([productID isEqualToString: @"youruniqueproductidentifier]){write files} else { nslog sorry} } } 
0
source share

All Articles