Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS In-App Purchase (Consumable) - Server Timeout

I have a question about a particular situation with In-App Purchases.

We have a consumable for buying coins in our app:

  • Use buys a $.99 coin pack with IAP
  • We send a request to our server to record the purchase and add the coins to their account (these coins are shared between multiple devices, our server does the work here)
  • Complete transaction for IAP

Problem is, what we supposed to do if the request to our server times out or fails? The user spent the money, but will never get the coins. And if they try to purchase again at that point, it will give them an error saying the purchase hasn't downloaded.

I have seen a "Restore Transactions" option, but not sure how to apply it here. I'd rather not have a button for it somewhere in the app.

Don't worry this app isn't released yet, and this app is written in C# with MonoTouch, but Objective-C answers are welcome.

like image 353
jonathanpeppers Avatar asked May 06 '26 04:05

jonathanpeppers


1 Answers

Restore transactions would do it. It simply redownloads the purchase again. Take a look at the fifth post here:

http://monogame.codeplex.com/discussions/359109

Here is the code to implement it:

InAppPurchaseManager > MySKPaymentObserver:

    public override void PaymentQueueRestoreCompletedTransactionsFinished (SKPaymentQueue queue)
        {
            foreach(SKPaymentTransaction transaction in queue.Transactions)
            {

                #if DEBUG
                Console.WriteLine("Restoring Transaction " + transaction.Payment.ProductIdentifier);
                #endif
                theManager.restoreTransaction(transaction);
            }
        }

Here is how to call the code in your game:

 app = new InAppPurchaseManager ();
 app.LoadStore();
 SKPaymentQueue.DefaultQueue.RestoreCompletedTransactions();
like image 182
Joseph Anderson Avatar answered May 08 '26 19:05

Joseph Anderson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!