1

Is there a way to find out when a user buys a non-consumable, if he buys it for the first time or has bought it already and gets it again for free?

I checked transactionState, transactionDate of the transaction, but in both cases the data is the same:

  • transactionState: SKPaymentTransactionStatePurchased (and not SKPaymentTransactionStateRestored in case the user bought it already)
  • transactionDate: the date at which the transaction was added to the AppStore's payment queue.
Linus Caldwell
  • 10,908
  • 12
  • 46
  • 58
Alpár
  • 727
  • 10
  • 22
  • Alpár, please take at look at this [thread](http://stackoverflow.com/questions/5623652/differentiating-between-initial-buy-and-free-re-buy-in-storekit-in-app-purchase). Hope it helps. Markus –  May 29 '11 at 04:58
  • Thank you for your help! Unfortunately we can't use it, our case is somewhat complicated... – Alpár Aug 30 '11 at 14:43

2 Answers2

1

You can check Array of transactions which will fill after restoreTransaction method and if Array of transactions is empty it means that user download this upgrade for the first time. In another case you'll check all transactions in Array and compare transaction.payment.productIdentifier with needful product identifire. If it doesn't exist add payment in transaction Array.

For Non-Consumable In-App Purchase I used following code:

#define kInAppPurchaseProUpgradeProductId @"upgradeProductId"

//...
//your payment code for all SKPaymentTransactionStates
//...

//method called when BUY button press
-(void)purchaseProUpgrade{
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
//when restore completed delegate method calls 
-(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue{

    if([[[SKPaymentQueue defaultQueue] transactions] count]==0)            
        [self addNewPaymentForProductId:kInAppPurchaseProUpgradeProductId];
    else            
        for (SKPaymentTransaction *transaction in [[SKPaymentQueue defaultQueue] transactions]){

            if (![transaction.payment.productIdentifier isEqualToString:kInAppPurchaseProUpgradeProductId]){
                [self addNewPaymentForProductId:kInAppPurchaseProUpgradeProductId];
                break;
            }
        }    
}

-(void)addNewPaymentForProductId:(NSString *)productId{
    if([SKPaymentQueue canMakePayments]){
        SKPayment *payment = [SKPayment paymentWithProductIdentifier:productId];
        [[SKPaymentQueue defaultQueue] addPayment:payment];
    }
}

the only disadvantage is that every time you call restoreCompletedTransactions, window will pop up asking you to enter the password of the current user. This solution ensures that the buy window does not appear more than 1 time for each upgrade but all the upgrades will restore every time when you'll try to buy one of them.

Stan
  • 122
  • 4
0

Not sure but maybe you can check if transaction.originalTransacion exists or if is different.

Ecarrion
  • 4,940
  • 1
  • 33
  • 44