From fae272bc77b1c523a8af7a52bb220b684a2a6c1b Mon Sep 17 00:00:00 2001 From: aldrikboy Date: Fri, 26 Jan 2018 14:22:18 +0100 Subject: map pack --- Penguloon/BillingManager.cs | 94 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 Penguloon/BillingManager.cs (limited to 'Penguloon/BillingManager.cs') diff --git a/Penguloon/BillingManager.cs b/Penguloon/BillingManager.cs new file mode 100644 index 0000000..2611414 --- /dev/null +++ b/Penguloon/BillingManager.cs @@ -0,0 +1,94 @@ +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(); + } + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2