First you should really go back and review the In App purchase documentation that Apple provides - they outline this in detail and it's useful to understand what is being done on their side.
What you are missing is the SKPaymentTransactionObserver - it's your responsibility to implement this observer which you add as an observer of the SKPaymentTransactionQueue. Apple recommends that you add the observer at app launch to the default queue so that it will be able to observe all transactions that take place while your app is running.
Essentially you need to write your own class that implements the SKPaymentTransactionObserver protocol. What this class does is observe catch the callbacks from the payment queue when the iTunes store processes the payment and let's you catch the success and failure events.
Here is the skeleton for the Payment Observer:
PaymentObserver.h
#import <StoreKit/StoreKit.h>
@interface PaymentObserver : NSObject <SKPaymentTransactionObserver> {
}
- (void) completeTransaction: (SKPaymentTransaction *)transaction;
- (void) restoreTransaction: (SKPaymentTransaction *)transaction;
- (void) failedTransaction: (SKPaymentTransaction *)transaction;
@end
PaymentObserver.m
#import "PaymentObserver.h"
@implementation PaymentObserver
- (void)paymentQueue:(SKPaymentQueue *)queue removedTransactions:(NSArray *)transactions
{
// handle payment cancellation
}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
// handle the payment transaction actions for each state
for (SKPaymentTransaction *transaction in transactions)
{
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;
{
// Record the transaction
//...
// Do whatever you need to do to provide the service/subscription purchased
//...
// Remove the transaction from the payment queue.
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
- (void) restoreTransaction: (SKPaymentTransaction *)transaction
{
// Record the transaction
//...
// Do whatever you need to do to provide the service/subscription purchased
//...
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
- (void) failedTransaction: (SKPaymentTransaction *)transaction
{
if (transaction.error.code != SKErrorPaymentCancelled)
{
// Optionally, display an error here.
}
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
@end
Once you have implemented the PaymentObserver you need to add an instance off it to the default payment queue as a transaction observer.
// Done at app launch...
PaymentObserver *paymentObserver = [[PaymentObserver alloc] init];
[[SKPaymentQueue defaultQueue] addTransactionObserver:paymentObserver];