public void RestoreTransaction(SKPaymentTransaction transaction) { // Restored Transactions always have an 'original transaction' attached var productId = transaction.OriginalTransaction.Payment.ProductIdentifier; // Record the restore var newPurchase = new InAppPurchase { OrderId = transaction.OriginalTransaction.TransactionIdentifier, ProductId = transaction.OriginalTransaction.Payment.ProductIdentifier, PurchaseTime = NSDateToDateTime(transaction.OriginalTransaction.TransactionDate) }; App.ViewModel.Purchases.Add(newPurchase); // Remove the transaction from the payment queue. // IMPORTANT: Let's ios know we're done SKPaymentQueue.DefaultQueue.FinishTransaction(transaction); // Send out a notification that we’ve finished the transaction using (var pool = new NSAutoreleasePool()) { NSDictionary userInfo = NSDictionary.FromObjectsAndKeys(new NSObject[] { transaction }, new NSObject[] { new NSString("transaction") }); NSNotificationCenter.DefaultCenter.PostNotificationName(InAppRestoreProductsNotification, this, userInfo); } }
public void UpdatePayment(PaymentResponse paymentResponse) { var simsipProductId = this.FortumoToSimsipProductId(paymentResponse.ServiceId); var newPurchase = new InAppPurchase { OrderId = paymentResponse.PaymentCode, ProductId = simsipProductId, PurchaseTime = DateTime.Now }; App.ViewModel.Purchases.Add(newPurchase); }
public void Initialize() { // A Licensing and In-App Billing public key is required before an app can communicate with // Google Play, however you DON'T want to store the key in plain text with the application. // The Unify command provides a simply way to obfuscate the key by breaking it into two or // or more parts, specifying the order to reassemlbe those parts and optionally providing // a set of key/value pairs to replace in the final string. string value = Security.Unify( new string[] { "Insert part 0", "Insert part 3", "Insert part 2", "Insert part 1" }, new int[] { 0, 3, 2, 1 }); // Create a new connection to the Google Play Service _serviceConnection = new InAppBillingServiceConnection(MainActivity.Instance, value); _serviceConnection.OnConnected += () => { this._serviceConnection.BillingHandler.OnProductPurchased += (int response, Purchase purchase, string purchaseData, string purchaseSignature) => { // Record what we purchased var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var purchaseTime = epoch.AddMilliseconds(purchase.PurchaseTime); var newPurchase = new InAppPurchase { OrderId = purchase.OrderId, ProductId = purchase.ProductId, PurchaseTime = purchaseTime }; App.ViewModel.Purchases.Add(newPurchase); // Let anyone know who is interested that purchase has completed if (this.OnPurchaseProduct != null) { this.OnPurchaseProduct(); } }; this._serviceConnection.BillingHandler.QueryInventoryError += (int responseCode, Bundle skuDetails) => { if (this.OnQueryInventoryError != null) { this.OnQueryInventoryError(responseCode, null); } }; this._serviceConnection.BillingHandler.BuyProductError += (int responseCode, string sku) => { // Note, BillingResult.ItemAlreadyOwned, etc. can be used to determine error if (this.OnPurchaseProductError != null) { this.OnPurchaseProductError(responseCode, sku); } }; this._serviceConnection.BillingHandler.InAppBillingProcesingError += (string message) => { if (this.OnInAppBillingProcesingError != null) { this.OnInAppBillingProcesingError(message); } }; this._serviceConnection.BillingHandler.OnInvalidOwnedItemsBundleReturned += (Bundle ownedItems) => { if (this.OnInvalidOwnedItemsBundleReturned != null) { this.OnInvalidOwnedItemsBundleReturned(null); } }; this._serviceConnection.BillingHandler.OnProductPurchasedError += (int responseCode, string sku) => { if (this.OnPurchaseProductError != null) { this.OnPurchaseProductError(responseCode, sku); } }; this._serviceConnection.BillingHandler.OnPurchaseFailedValidation += (Purchase purchase, string purchaseData, string purchaseSignature) => { if (this.OnPurchaseFailedValidation != null) { this.OnPurchaseFailedValidation(null, purchaseData, purchaseSignature); } }; this._serviceConnection.BillingHandler.OnUserCanceled += () => { if (this.OnUserCanceled != null) { this.OnUserCanceled(); } }; this._connected = true; // Load inventory or available products this.QueryInventory(); }; /* Uncomment these if you want to be notified for these events _serviceConnection.OnDisconnected += () => { System.Diagnostics.Debug.WriteLine("Remove"); }; _serviceConnection.OnInAppBillingError += (error, message) => { System.Diagnostics.Debug.WriteLine("Remove"); }; */ // Are we connected to a network? ConnectivityManager connectivityManager = (ConnectivityManager)MainActivity.Instance.GetSystemService(MainActivity.ConnectivityService); NetworkInfo activeConnection = connectivityManager.ActiveNetworkInfo; if ((activeConnection != null) && activeConnection.IsConnected) { // Ok, carefully attempt to connect to the in-app service try { _serviceConnection.Connect(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception trying to connect to in app service: " + ex); } } }
public void FireOnPurchaseProduct(int response, InAppPurchase purchase, string purchaseData, string purchaseSignature) { if (this.OnPurchaseProduct != null) { this.OnPurchaseProduct(); } }
public void RestoreProducts() { var purchases = this._serviceConnection.BillingHandler.GetPurchases(ItemType.Product); // Record what we restored foreach (var purchase in purchases) { var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var purchaseTime = epoch.AddMilliseconds(purchase.PurchaseTime); var newPurchase = new InAppPurchase { OrderId = purchase.OrderId, ProductId = purchase.ProductId, PurchaseTime = purchaseTime }; App.ViewModel.Purchases.Add(newPurchase); } // Notifiy anyone who needs to know products were restored if (this.OnRestoreProducts != null) { this.OnRestoreProducts(); } }