Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle cancelled IAP transactions

I'm using StoreKit for in-app purchases. I'm finding that the API is quirky in its behavior when the user presses the "Cancel" button.

For example, if I push Cancel on the "Confirm Your In App Purchase" screen, I get a SKPaymentTransactionStateFailed transaction with error.code == SKErrorPaymentCancelled as I'd expect.

But if I push Buy and then press Cancel, I get a Failed transaction with error.code == 0. The error.localizedDescription is "Cannot connect to iTunes Store" which is clearly a lie.

It's tempting to treat all Failed transactions as ignorable cancellations, but I can also clearly see that if the device is offline in airplane mode, I get a Failed transaction with no alert popup; I should really notify the user to explain the problem in that case.

I note that MKStoreKit assumes all failures are cancellations. MKStoreManager's failedTransaction method is never called; MKStoreObserver always calls transactionCanceled for all Failed transactions. The MKStoreManager.h comments recommend no error message for transactionCanceled, which makes sense, but then who will notify the user about Failed non-cancelled transactions?

What's the best practice for handling these failures? Should I swallow errors? Always show an error, even if it's redundant?

like image 286
Dan Fabulich Avatar asked Apr 26 '11 09:04

Dan Fabulich


People also ask

How do I restore in app purchases Swift?

To restore your purchases:Open the drawer from the upper left corner of the screen and select Support. Select Purchases and Paid App from the menu. Tap on the menu option, located in the upper right-hand corner of the screen. Tap on Recover Paid App.

Do Apple subscriptions automatically renew?

They automatically renew at the end of their duration until the user chooses to cancel. Subscriptions are available on iOS, iPadOS, macOS, watchOS, and tvOS.


1 Answers

We have a pretty substantial user base buying stuff over mobile connections and only show alerts for

code != SKErrorPaymentCancelled && code != SKErrorPaymentNotAllowed

Apparently, it's the best you can do. I've also seen the weird behavior on cancellation that you mention, which is a framework bug as far as I can tell.

like image 110
Steven Kramer Avatar answered Nov 03 '22 01:11

Steven Kramer