protected override void CompleteTransaction(string productId) { if (productId == ConsumableViewController.Buy5ProductId) { CreditManager.Add(5); // 5 * qty } else if (productId == ConsumableViewController.Buy10ProductId) { CreditManager.Add(10); // 10 * qty } else { Console.WriteLine("Shouldn't happen, there are only two products"); } }
public void CompleteTransaction(SKPaymentTransaction transaction) { Console.WriteLine("CompleteTransaction " + transaction.TransactionIdentifier); var productId = transaction.Payment.ProductIdentifier; //var qty = transaction.Payment.Quantity; if (productId == ConsumableViewController.Buy5ProductId) { CreditManager.Add(5); // 5 * qty } else if (productId == ConsumableViewController.Buy10ProductId) { CreditManager.Add(10); // 10 * qty } else { Console.WriteLine("Shouldn't happen, there are only two products"); } FinishTransaction(transaction, true); }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); // setup the observer to wait for prices to come back from StoreKit <- AppStore priceObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppPurchaseManager.InAppPurchaseManagerProductsFetchedNotification, (notification) => { var info = notification.UserInfo; if (info == null) { return; } var NSBuy5ProductId = new NSString(Buy5ProductId); var NSBuy10ProductId = new NSString(Buy10ProductId); if (info.ContainsKey(NSBuy5ProductId)) { pricesLoaded = true; var product = (SKProduct)info.ObjectForKey(NSBuy5ProductId); Console.WriteLine("Product id: " + product.ProductIdentifier); Console.WriteLine("Product title: " + product.LocalizedTitle); Console.WriteLine("Product description: " + product.LocalizedDescription); Console.WriteLine("Product price: " + product.Price); Console.WriteLine("Product l10n price: " + product.LocalizedPrice()); buy5Button.Enabled = true; buy5Title.Text = product.LocalizedTitle; buy5Description.Text = product.LocalizedDescription; buy5Button.SetTitle(String.Format(Buy, product.LocalizedPrice()), UIControlState.Normal); } if (info.ContainsKey(NSBuy10ProductId)) { pricesLoaded = true; var product = (SKProduct)info.ObjectForKey(NSBuy10ProductId); Console.WriteLine("Product id: " + product.ProductIdentifier); Console.WriteLine("Product title: " + product.LocalizedTitle); Console.WriteLine("Product description: " + product.LocalizedDescription); Console.WriteLine("Product price: " + product.Price); Console.WriteLine("Product l10n price: " + product.LocalizedPrice()); buy10Button.Enabled = true; buy10Title.Text = product.LocalizedTitle; buy10Description.Text = product.LocalizedDescription; buy10Button.SetTitle(String.Format(Buy, product.LocalizedPrice()), UIControlState.Normal); } }); // only if we can make payments, request the prices if (iap.CanMakePayments()) { // now go get prices, if we don't have them already if (!pricesLoaded) { iap.RequestProductData(products); // async request via StoreKit -> App Store } } else { // can't make payments (purchases turned off in Settings?) buy5Button.SetTitle("AppStore disabled", UIControlState.Disabled); buy10Button.SetTitle("AppStore disabled", UIControlState.Disabled); } balanceLabel.Text = String.Format(Balance, CreditManager.Balance()); // + " monkey credits"; succeededObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppPurchaseManager.InAppPurchaseManagerTransactionSucceededNotification, (notification) => { balanceLabel.Text = String.Format(Balance, CreditManager.Balance()); // + " monkey credits"; }); failedObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppPurchaseManager.InAppPurchaseManagerTransactionFailedNotification, (notification) => { // TODO: Console.WriteLine("Transaction Failed"); }); requestObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppPurchaseManager.InAppPurchaseManagerRequestFailedNotification, (notification) => { // TODO: Console.WriteLine("Request Failed"); buy5Button.SetTitle("Network down?", UIControlState.Disabled); buy10Button.SetTitle("Network down?", UIControlState.Disabled); }); }