Purchase.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using Godot;
  3. using Godot.Collections;
  4. namespace AndroidInAppPurchasesWithCSharp.GodotGooglePlayBilling
  5. {
  6. // https://developer.android.com/reference/com/android/billingclient/api/Purchase.PurchaseState
  7. public enum PurchaseState
  8. {
  9. UnspecifiedState = 0,
  10. Purchased = 1,
  11. Pending = 2,
  12. }
  13. public partial class Purchase
  14. {
  15. public Purchase() { }
  16. public Purchase(Dictionary purchase)
  17. {
  18. foreach (var key in purchase.Keys)
  19. {
  20. try
  21. {
  22. switch (key)
  23. {
  24. case "order_id":
  25. OrderId = (string)purchase[key];
  26. break;
  27. case "package_name":
  28. PackageName = (string)purchase[key];
  29. break;
  30. case "purchase_state":
  31. PurchaseState = (PurchaseState)purchase[key];
  32. break;
  33. case "purchase_time":
  34. PurchaseTime = Convert.ToInt64(purchase[key]);
  35. break;
  36. case "purchase_token":
  37. PurchaseToken = (string)purchase[key];
  38. break;
  39. case "signature":
  40. Signature = (string)purchase[key];
  41. break;
  42. case "sku":
  43. Sku = (string)purchase[key];
  44. break;
  45. case "is_acknowledged":
  46. IsAcknowledged = (bool)purchase[key];
  47. break;
  48. case "is_auto_renewing":
  49. IsAutoRenewing = (bool)purchase[key];
  50. break;
  51. }
  52. }
  53. catch (System.Exception ex)
  54. {
  55. GD.Print("Error: ", purchase[key], " -> ", ex.ToString());
  56. }
  57. }
  58. }
  59. public string OrderId { get; set; }
  60. public string PackageName { get; set; }
  61. public PurchaseState PurchaseState { get; set; }
  62. public long PurchaseTime { get; set; }
  63. public string PurchaseToken { get; set; }
  64. public string Signature { get; set; }
  65. public string Sku { get; set; }
  66. public bool IsAcknowledged { get; set; }
  67. public bool IsAutoRenewing { get; set; }
  68. }
  69. }