Product.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. namespace UnityEngine.Purchasing
  2. {
  3. /// <summary>
  4. /// May be purchased as an In App Purchase.
  5. /// </summary>
  6. public class Product
  7. {
  8. /// <summary>
  9. /// Products must have a definition as minimum.
  10. ///
  11. /// Further metadata may be populated following retrieval from the
  12. /// store system.
  13. /// </summary>
  14. internal Product(ProductDefinition definition, ProductMetadata metadata, string receipt)
  15. {
  16. this.definition = definition;
  17. this.metadata = metadata;
  18. this.receipt = receipt;
  19. }
  20. internal Product(ProductDefinition definition, ProductMetadata metadata) : this(definition, metadata, null)
  21. {
  22. }
  23. /// <summary>
  24. /// Basic immutable product properties.
  25. /// </summary>
  26. public ProductDefinition definition { get; private set; }
  27. /// <summary>
  28. /// Localized metadata provided by the store system.
  29. /// </summary>
  30. /// <value>The metadata.</value>
  31. public ProductMetadata metadata { get; internal set; }
  32. /// <summary>
  33. /// Determine if this product is available to purchase according to
  34. /// the store subsystem.
  35. ///
  36. /// This will be false if the product's identifier is unknown,
  37. /// incorrect or otherwise disabled with the store provider
  38. /// (ie Apple, Google et al).
  39. ///
  40. /// If this is false, purchase attempts will immediately fail.
  41. /// </summary>
  42. public bool availableToPurchase { get; internal set; }
  43. /// <summary>
  44. /// A unique identifier for this product's transaction.
  45. ///
  46. /// This will only be set when the product was purchased during this session.
  47. /// </summary>
  48. public string transactionID { get; internal set; }
  49. /// <summary>
  50. /// Owned Non Consumables and Subscriptions should always have receipts.
  51. /// Consumable's receipts are not persisted between App restarts.
  52. /// </summary>
  53. public bool hasReceipt
  54. {
  55. get { return !string.IsNullOrEmpty(receipt); }
  56. }
  57. /// <summary>
  58. /// The purchase receipt for this product, if owned.
  59. /// For consumable purchases, this will be the most recent purchase receipt.
  60. /// Consumable receipts are not saved between app restarts.
  61. /// Receipts is in JSON format.
  62. /// </summary>
  63. public string receipt { get; internal set; }
  64. /// <summary>
  65. /// Check if this product is equal to another.
  66. /// </summary>
  67. /// <param name="obj"> The product to compare with this object. </param>
  68. /// <returns> True if the products are equal </returns>
  69. public override bool Equals(object obj)
  70. {
  71. if (obj == null)
  72. return false;
  73. Product p = obj as Product;
  74. if (p == null)
  75. return false;
  76. return (definition.Equals(p.definition));
  77. }
  78. /// <summary>
  79. /// Get the unique Hash representing the product.
  80. /// </summary>
  81. /// <returns> The hash code as integer </returns>
  82. public override int GetHashCode()
  83. {
  84. return definition.GetHashCode();
  85. }
  86. }
  87. }