diff options
| author | aldrikboy <aldrikboy@gmail.com> | 2018-01-26 14:22:18 +0100 |
|---|---|---|
| committer | aldrikboy <aldrikboy@gmail.com> | 2018-01-26 14:22:18 +0100 |
| commit | fae272bc77b1c523a8af7a52bb220b684a2a6c1b (patch) | |
| tree | 3b99c6740f4100f704c82042808731f1ff826b24 /Penguloon/BillingManager.cs | |
| parent | 60f1bddda04ec5fa22778abf176171a547dde949 (diff) | |
Diffstat (limited to 'Penguloon/BillingManager.cs')
| -rw-r--r-- | Penguloon/BillingManager.cs | 94 |
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 |
