In rare cases it seems that some of my users are unable to make a non-consumable purchase. When they attempt to purchase it doesn't activate "premium" and when they restore from either their current install or a fresh install paymentQueue: updatedTransactions:
is not called.
I've added a lot of logging specifically to try and determine why the restore is not following an expected flow. During a failed restore none of the "RESTORE" category events are fired.
For reference [self success];
just displays the content view and [self fail:]
displays an error message to the user instead.
Also [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
is called in viewDidLoad
and [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
is called on button press.
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
// COMPLETION POINT - RESTORE COMPLETE***
[MBProgressHUD hideHUDForView:self.view animated:TRUE];
if ([SKPaymentQueue defaultQueue].transactions.count == 0) {
[self.tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"RESTORE"
action:@"failure_hard"
label:@"no_purchases"
value:nil] build]];
[self fail:@"There are no items available to restore at this time."];
} else {
[self success];
}
}
- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error {
// COMPLETION POINT - RESTORE FAILED
[MBProgressHUD hideHUDForView:self.view animated:TRUE];
[self.tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"RESTORE"
action:@"failure_hard"
label:error.localizedDescription
value:nil] build]];
[self fail:error.localizedDescription];
}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
// Make sure completion states call [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
// in order to prevent sign in popup
// http://stackoverflow.com/a/10853107/740474
[MBProgressHUD hideHUDForView:self.view animated:TRUE];
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
break;
case SKPaymentTransactionStateDeferred:
break;
case SKPaymentTransactionStateFailed:
// COMPLETION POINT - PURCHASE FAILED
[self.tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"PURCHASE"
action:@"failure_hard"
label:transaction.error.localizedDescription
value:nil] build]];
if (transaction.error.code != SKErrorPaymentCancelled) {
// only show error if not a cancel
[self fail:transaction.error.localizedDescription];
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStatePurchased:
// COMPLETION POINT - PURCHASE SUCCESS
if ([transaction.payment.productIdentifier isEqualToString:(NSString*)productID]) {
// premium purchase successful
[self.tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"PURCHASE"
action:@"success"
label:nil
value:nil] build]];
[Utils setPremium:YES];
[self success];
} else {
[self.tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"PURCHASE"
action:@"failure_hard"
label:@"no_id"
value:nil] build]];
[self fail:@"The item you purchased was not returned from Apple servers. Please contact us."];
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
if ([transaction.payment.productIdentifier isEqualToString:(NSString*)productID]) {
// premium purchase restored
[self.tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"RESTORE"
action:@"restore_success"
label:nil
value:nil] build]];
[Utils setPremium:YES];
} else {
[self.tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"RESTORE"
action:@"failure_hard"
label:@"no_id"
value:nil] build]];
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
default:
// For debugging
[self.tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"STORE"
action:@"transaction_weird"
label:[NSString stringWithFormat:@"Unexpected transaction state %@", @(transaction.transactionState)]
value:nil] build]];
break;
}
}
}
Any suggestions would be appreciated