123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- namespace UnityEngine.Purchasing
- {
- /// <summary>
- /// May be purchased as an In App Purchase.
- /// </summary>
- public class Product
- {
- /// <summary>
- /// Products must have a definition as minimum.
- ///
- /// Further metadata may be populated following retrieval from the
- /// store system.
- /// </summary>
- internal Product(ProductDefinition definition, ProductMetadata metadata, string receipt)
- {
- this.definition = definition;
- this.metadata = metadata;
- this.receipt = receipt;
- }
-
- internal Product(ProductDefinition definition, ProductMetadata metadata) : this(definition, metadata, null)
- {
- }
-
- /// <summary>
- /// Basic immutable product properties.
- /// </summary>
- public ProductDefinition definition { get; private set; }
-
- /// <summary>
- /// Localized metadata provided by the store system.
- /// </summary>
- /// <value>The metadata.</value>
- public ProductMetadata metadata { get; internal set; }
-
- /// <summary>
- /// Determine if this product is available to purchase according to
- /// the store subsystem.
- ///
- /// This will be false if the product's identifier is unknown,
- /// incorrect or otherwise disabled with the store provider
- /// (ie Apple, Google et al).
- ///
- /// If this is false, purchase attempts will immediately fail.
- /// </summary>
- public bool availableToPurchase { get; internal set; }
-
- /// <summary>
- /// A unique identifier for this product's transaction.
- /// This will only be set when the product was purchased during this session.
- /// Consumable's transactionID are not set between app restarts unless it has a pending transaction.
- /// Once a consumable has been acknowledged (ConfirmPendingPurchase) the `transactionID` is removed.
- /// </summary>
- public string transactionID { get; internal set; }
-
- /// <summary>
- /// A unique identifier for this Apple product's original transaction.
- ///
- /// This will only be set when the Apple product was purchased during this session.
- /// </summary>
- public string appleOriginalTransactionID { get; internal set; }
-
- /// <summary>
- /// Indicates if this Apple product is restored.
- /// </summary>
- public bool appleProductIsRestored { get; internal set; }
-
- /// <summary>
- /// Owned Non Consumables and Subscriptions should always have receipts.
- /// Consumable's receipts are not persisted between App restarts unless it has a pending transaction.
- /// Once a consumable has been acknowledged (ConfirmPendingPurchase) the `receipt` is removed.
- /// </summary>
- public bool hasReceipt => !string.IsNullOrEmpty(receipt);
-
- /// <summary>
- /// The purchase receipt for this product, if owned.
- /// For consumable purchases, this will be the most recent purchase receipt.
- /// Consumable's receipts are not set between app restarts unless it has a pending transaction.
- /// Once a consumable has been acknowledged (ConfirmPendingPurchase) the `receipt` is removed.
- /// Receipts is in JSON format.
- /// </summary>
- public string receipt { get; internal set; }
-
- /// <summary>
- /// Check if this product is equal to another.
- /// </summary>
- /// <param name="obj"> The product to compare with this object. </param>
- /// <returns> True if the products are equal </returns>
- public override bool Equals(object obj)
- {
- if (obj == null)
- {
- return false;
- }
-
- var p = obj as Product;
- if (p == null)
- {
- return false;
- }
-
- return definition.Equals(p.definition);
- }
-
- /// <summary>
- /// Get the unique Hash representing the product.
- /// </summary>
- /// <returns> The hash code as integer </returns>
- public override int GetHashCode()
- {
- return definition.GetHashCode();
- }
- }
- }
|