In rare cases, it seems that some of my users are unable to make a purchase without cost. When they try to purchase it, it does not activate the "premium", and when they are restored either from the current installation or from a new installation, paymentQueue: updatedTransactions:it is not called.
I have added many protocols to try to determine why the recovery does not match the expected thread. During a failed restore, none of the events in the RECOVERY category are triggered.
For reference, it [self success];simply displays a view of the content, and [self fail:]displays an error message to the user.
Also [[SKPaymentQueue defaultQueue] addTransactionObserver:self];called in viewDidLoadand [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];called when the button is pressed.
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
[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 {
[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 {
[MBProgressHUD hideHUDForView:self.view animated:TRUE];
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
break;
case SKPaymentTransactionStateDeferred:
break;
case SKPaymentTransactionStateFailed:
[self.tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"PURCHASE"
action:@"failure_hard"
label:transaction.error.localizedDescription
value:nil] build]];
if (transaction.error.code != SKErrorPaymentCancelled) {
[self fail:transaction.error.localizedDescription];
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStatePurchased:
if ([transaction.payment.productIdentifier isEqualToString:(NSString*)productID]) {
[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]) {
[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:
[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.
source
share