using Plugin.InAppBilling; using Plugin.InAppBilling.Abstractions; using System; using Penguloon.Controls; namespace Penguloon.Scenes { public static class BillingManager { public static bool MapPackPurchased { get; set; } = false; public static async System.Threading.Tasks.Task PurchaseMapPackAsync(SceneBase sceneBase) { try { var productId = "map_pack"; //CrossInAppBilling.Current.InTestingMode = true; var connected = await CrossInAppBilling.Current.ConnectAsync(); if (!connected) { Alert.Show("Not connected", 3000, sceneBase); return; } //try to purchase item var purchase = await CrossInAppBilling.Current.PurchaseAsync(productId, ItemType.InAppPurchase, "apppayload"); if (purchase == null) { Alert.Show("Purchase failed", 3000, sceneBase); } else { Alert.Show("Maps unlocked", 4000, sceneBase); //Purchased, save this information var id = purchase.Id; var token = purchase.PurchaseToken; var state = purchase.State; MapPackPurchased = true; } } catch (Exception ex) { //Something bad has occurred, alert user Alert.Show("An error occured", 3000, sceneBase); } //Disconnect, it is okay if we never connected await CrossInAppBilling.Current.DisconnectAsync(); } public static async System.Threading.Tasks.Task CheckPurchasesAsync() { try { var connected = await CrossInAppBilling.Current.ConnectAsync(); if (!connected) { return; } //try to purchase item var purchase = await CrossInAppBilling.Current.GetPurchasesAsync(ItemType.InAppPurchase); if (purchase == null) { return; } else { foreach(InAppBillingPurchase item in purchase) { if (item.ProductId == "map_pack") MapPackPurchased = true; //if (item.ProductId == "android.test.purchased") // MapPackPurchased = true; } } } catch (Exception ex) { //Something bad has occurred } //Disconnect, it is okay if we never connected await CrossInAppBilling.Current.DisconnectAsync(); } } }