summaryrefslogtreecommitdiff
path: root/Penguloon/BillingManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Penguloon/BillingManager.cs')
-rw-r--r--Penguloon/BillingManager.cs94
1 files changed, 94 insertions, 0 deletions
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