I am building an iOS app and trying to implement an in app purchase (non-consumable).
All the bundle IDs etc. are set up and working, and I can see my product as valid when I fetch the Apple Store servers. However, while testing, I am getting failed transactions at the paymentQueue callback.
Here is what happens in the iOS simulator step by step:
- A message box asks “would you like to buy .. for $0.99?” which is correct
- I click Yes.
- After about a second it says that I’ve already bought it (correct, I test-bought it initially while debugging). I click OK.
- It complains about a login requirement (it says something like MZFinance_LoginRequired, I think its a missing string identifier.) I click OK.
- App Store login box pops up and I enter my test account credentials.
- My breakpoint in Xcode is hit, with the transaction state SKPaymentTransactionStateFailed.
Here is the relevant part of my code:
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
NSArray* arr = response.products;
for (int i = 0; i < arr.count; i++) {
SKProduct* product = [arr objectAtIndex:i];
if([product.productIdentifier isEqualToString:@"<<my in app purchase id which is correct and working>>"]){
SKPayment *payment = [SKPayment paymentWithProduct:product];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
}
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
for (SKPaymentTransaction* ta in transactions) {
switch (ta.transactionState) {
case SKPaymentTransactionStatePurchased:
case SKPaymentTransactionStateRestored:
receipt = [ta transactionReceipt];
[self performSelectorInBackground:@selector(validateFromServer) withObject:nil];
break;
case SKPaymentTransactionStateFailed:
[self purchaseFailed];
break;
}
if(!ta.transactionState == SKPaymentTransactionStatePurchasing){
[[SKPaymentQueue defaultQueue] finishTransaction:ta];
}
}
}
}
[self purchaseFailed] always gets hit, which just notifies the user. What can be wrong here? (I am new to iOS and -obviously- iOS in app purchases).
Thanks.
UPDATE: My test account credentials are correct, as I am getting a different (invalid login) message if I type it wrong.
After some time struggling with it, I’ve noticed that I’m not encountering any problems in production. It was probably a problem with the sandbox servers.