in-app purchase validation - validate purchase as per user

五迷三道 提交于 2020-01-17 12:24:04

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/29788204/in-app-purchase-validation-validate-purchase-as-per-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!