using System; using System.Collections.Generic; using Unity.Services.Analytics.Internal; using UnityEngine; namespace Unity.Services.Analytics { public class TransactionRealCurrency { /// /// (Required) The ISO 4217 three-letter currency code for the real currency. For example, GBP or USD. /// public string RealCurrencyType; /// /// (Required) The amount of real currency, in the smallest unit applicable to that currency. /// The AnalyticsService.Instance.ConvertCurrencyToMinorUnits method is available to convert a decimal currency value into minor units if required. /// public long RealCurrencyAmount; internal void Serialize(IBuffer buffer) { buffer.PushString("realCurrencyType", RealCurrencyType); buffer.PushInt64("realCurrencyAmount", RealCurrencyAmount); } } public class TransactionItem { /// /// (Required) The name of the item. /// public string ItemName; /// /// (Required) The type of the item, e.g. "weapon" or "spell". /// public string ItemType; /// /// (Required) The amount of the item. /// public long ItemAmount; internal void Serialize(IBuffer buffer) { buffer.PushString("itemName", ItemName); buffer.PushString("itemType", ItemType); buffer.PushInt64("itemAmount", ItemAmount); } } public class TransactionVirtualCurrency { private readonly static string[] k_VirtualCurrencyTypeValues = Event.BakeEnum2String(); /// /// (Required) The name of the virtual currency. /// public string VirtualCurrencyName; /// /// (Required) The type of the virtual currency. /// public VirtualCurrencyType VirtualCurrencyType; /// /// (Required) The amount of the virtual currency. /// public long VirtualCurrencyAmount; internal void Serialize(IBuffer buffer) { buffer.PushString("virtualCurrencyName", VirtualCurrencyName); buffer.PushString("virtualCurrencyType", k_VirtualCurrencyTypeValues[(int)VirtualCurrencyType]); buffer.PushInt64("virtualCurrencyAmount", VirtualCurrencyAmount); } } /// /// Use this class to record transaction events. /// /// For more information about the transaction event, see the documentation page: /// https://docs.unity.com/ugs/en-us/manual/analytics/manual/record-transaction-events /// public class TransactionEvent : Event { private static readonly string[] k_TransactionTypeValues = Event.BakeEnum2String(); private static readonly string[] k_TransactionServerValues = Event.BakeEnum2String(); public TransactionEvent() : this("transaction") { } protected internal TransactionEvent(string name) : base(name, true, 1) { SpentVirtualCurrencies = new List(); SpentItems = new List(); ReceivedVirtualCurrencies = new List(); ReceivedItems = new List(); } /// /// (Required) A name that describes the transaction, for example "BUY GEMS" or "BUY ITEMS". /// public string TransactionName { set { SetParameter("transactionName", value); } } /// /// (Optional) A unique identifier for this specific transaction. /// public string TransactionId { set { SetParameter("transactionID", value); } } /// /// (Required) The type of the transaction. /// public TransactionType TransactionType { set { SetParameter("transactionType", k_TransactionTypeValues[(int)value]); } } /// /// (Optional) The country where this transaction is taking place. /// public string PaymentCountry { set { SetParameter("paymentCountry", value); } } /// /// (Optional) The product identifier (known as a SKU) found in the store. /// public string ProductId { set { SetParameter("productID", value); } } /// /// (Optional) A unique identifier for the SKU, linked to the store SKU identifier. /// public string StoreItemSkuId { set { SetParameter("storeItemSkuID", value); } } /// /// (Optional) A unique identifier for the purchased item. /// public string StoreItemId { set { SetParameter("storeItemID", value); } } /// /// (Optional) The store where the transaction is taking place. /// public string StoreId { set { SetParameter("storeID", value); } } /// /// (Optional) Identifies the source of the transaction, e.g. "3rd party". /// public string StoreSourceId { set { SetParameter("storeSourceID", value); } } /// /// (Optional) Transaction receipt data as provided by the store, to be used for validation. /// public string TransactionReceipt { set { SetParameter("transactionReceipt", value); } } /// /// (Optional) The receipt signature from a Google Play purchase, to be used by the Google Play transaction validation process. /// public string TransactionReceiptSignature { set { SetParameter("transactionReceiptSignature", value); } } /// /// (Optional) The server to use for receipt verification, if applicable. /// public TransactionServer TransactionServer { set { SetParameter("transactionServer", k_TransactionServerValues[(int)value]); } } /// /// (Optional) An identifier for the person or entity with whom the transaction the occuring. /// For example, if this is a trade, this would be the other player's unique identifier. /// public string TransactorID { set { SetParameter("transactorID", value); } } /// /// (Optional) The real currency spent in this transaction. /// public TransactionRealCurrency SpentRealCurrency { get; set; } /// /// (Optional) The virtual currencies spent in this transaction. /// public List SpentVirtualCurrencies { get; private set; } /// /// (Optional) The items spent in this transaction. /// public List SpentItems { get; private set; } /// /// (Optional) The real currency received from this transaction. /// public TransactionRealCurrency ReceivedRealCurrency { get; set; } /// /// (Optional) The virtual currencies received from this transaction. /// public List ReceivedVirtualCurrencies { get; private set; } /// /// (Optional) The items received from this transaction. /// public List ReceivedItems { get; private set; } internal override void Serialize(IBuffer buffer) { buffer.PushString("sdkVersion", SdkVersion.SDK_VERSION); base.Serialize(buffer); buffer.PushProduct("productsReceived", ReceivedRealCurrency, ReceivedVirtualCurrencies, ReceivedItems); buffer.PushProduct("productsSpent", SpentRealCurrency, SpentVirtualCurrencies, SpentItems); } public override void Validate() { base.Validate(); if (!ParameterHasBeenSet("transactionName")) { Debug.LogWarning("A value for the TransactionName parameter is required for a Transaction event."); } if (!ParameterHasBeenSet("transactionType")) { Debug.LogWarning("A value for the TransactionType parameter is required for a Transaction event."); } } public override void Reset() { base.Reset(); SpentRealCurrency = null; SpentItems.Clear(); SpentVirtualCurrencies.Clear(); ReceivedRealCurrency = null; ReceivedItems.Clear(); ReceivedVirtualCurrencies.Clear(); } } }