iPR iPR - 3 months ago 21
Objective-C Question

in-app purchase validation - validate purchase as per user

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).

iPR iPR
Answer

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.