1

I've implemented the In-App payments like described in the Apple Documents about IAP, but when I try them in Sandbox mode, the 'transactionState' will never get changed to SKPaymentTransactionStatePurchased. (It stays on SKPaymentTransactionStatePurchasing forever.)

Does anybody know what went wrong?

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction *transaction in transactions)
    {
        NSLog(@"%ld", transaction.transactionState);
        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:
                [self completeTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:
                [self failedTransaction:transaction];
                break;
            case SKPaymentTransactionStateRestored:
                [self restoreTransaction:transaction];
            default:
                break;
        }
    }
}

- (void)completeTransaction:(SKPaymentTransaction *)transaction
{
    [self recordTransaction:transaction];
    [self provideContent:transaction.payment.productIdentifier];
    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}

- (void)failedTransaction:(SKPaymentTransaction *)transaction
{
    if (transaction.error.code != SKErrorPaymentCancelled) {
        [NSAlert alertWithError:transaction.error];
    }
    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}

- (void)restoreTransaction:(SKPaymentTransaction *)transaction
{
    [self recordTransaction:transaction];
    [self provideContent:transaction.originalTransaction.payment.productIdentifier];
    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}

- (void)recordTransaction:(SKPaymentTransaction *)transaction
{
    NSLog(@"Record Transaction...");
    // ToDo: Implement 'recordTransaction'.
}

- (void)provideContent:(NSString *)productIdentifier
{
    NSLog(@"Provide Content");
    // ToDo: Implement 'provideContent'.
}
miho
  • 11,765
  • 7
  • 42
  • 85
  • Your problem is not with the code you posted, so it's impossible to tell what's wrong without more information. – rdelmar Apr 20 '12 at 14:50
  • Since the SKPayment is already handled by the AppStore there shouldn't be any other code influence. – miho Apr 20 '12 at 16:35

1 Answers1

0

Tested the same code on different machines. It works every expect on my development machine. Seems not the be my code.

miho
  • 11,765
  • 7
  • 42
  • 85
  • Is you development machine a computer and are you running in the Simulator? In-App purchases do not work in the Simulator and must be tested on an actual device. – SAHM Jul 22 '12 at 00:22
  • 1
    I have run into the same issue. App was working fine on my iphone, then one day it gets stuck on the SKPaymentTransactionStatePurchased step and never moves forward. tested on my iPad and it works fine, tested on a friends phone and it works fine. Seams only to be this phone. Very curious. – Beleg Dec 21 '14 at 23:02
  • 1
    I also encounter this and it drives me nuts. Did you find a solution for this? – Chris8447 Mar 29 '19 at 18:16
  • It seems like you have some pending transaction that you must finish before, please check this: https://stackoverflow.com/a/36091267/488019 – Daniel García Baena May 12 '20 at 11:32