예제 #1
0
        protected void SendPurchaseSucceededEvent(string id, string receipt, string transactionID)
        {
#if HIGH_PERMISSION_DATA
            Product thisProduct = unity.products.WithStoreSpecificID(id);
            if ((promoPayload != null) &&
                ((id == (string)promoPayload["productId"]) || (id == (string)promoPayload["storeSpecificId"])))
            {
                promoPayload.Add("purchase", "OK");
                if (thisProduct != null)
                {
                    promoPayload.Add("productType", thisProduct.definition.type.ToString());
                }

                var unifiedData = new Dictionary <string, string>();
                unifiedData.Add("data", FormatUnifiedReceipt(receipt, transactionID));
                promoPayload.Add("receipt", unifiedData);

                var purchaseEvent = new PurchasingEvent(promoPayload);
                var profileDict   = m_profileData.GetProfileDict();
                var eventjson     = purchaseEvent.FlatJSON(profileDict);
                m_EventQueue.SendEvent(eventjson);
                promoPayload.Clear();
                promoPayload = null;
            }
            else
            {
                // enriched "organic" purchases here

                // thisProduct can be null if it was an unexpected product. This can happen if you restore a product
                // that is no longer being requested by the app.
                if (thisProduct != null)
                {
                    var purchaseDict = new Dictionary <string, object>();
                    purchaseDict.Add("type", "iap.purchase");
                    purchaseDict.Add("iap_service", true);
                    purchaseDict.Add("iapPromo", false);
                    purchaseDict.Add("purchase", "OK");
                    purchaseDict.Add("productId", thisProduct.definition.id);
                    purchaseDict.Add("storeSpecificId", thisProduct.definition.storeSpecificId);
                    purchaseDict.Add("amount", thisProduct.metadata.localizedPrice);
                    purchaseDict.Add("currency", thisProduct.metadata.isoCurrencyCode);
                    purchaseDict.Add("productType", thisProduct.definition.type.ToString());

                    var unifiedData = new Dictionary <string, string>();
                    unifiedData.Add("data", FormatUnifiedReceipt(receipt, transactionID));
                    purchaseDict.Add("receipt", unifiedData);

                    var purchaseEvent = new PurchasingEvent(purchaseDict);
                    var profileDict   = m_profileData.GetProfileDict();
                    var eventjson     = purchaseEvent.FlatJSON(profileDict);

                    m_EventQueue.SendEvent(EventDestType.IAP, eventjson, eventBaseUrl + "/v1/organic_purchase");
                }
            }
#endif
        }
예제 #2
0
        protected void SendPurchaseFailedEvent(PurchaseFailureDescription failure, string json)
        {
#if HIGH_PERMISSION_DATA
            if (promoPayload != null)
            {
                promoPayload["type"] = "iap.purchasefailed";
                promoPayload.Add("purchase", "FAILED");
                if (json != null)
                {
                    promoPayload.Add("failureJSON", json);
                }

                var purchaseEvent = new PurchasingEvent(promoPayload);
                var profileDict   = m_profileData.GetProfileDict();
                var eventjson     = purchaseEvent.FlatJSON(profileDict);

                m_EventQueue.SendEvent(EventDestType.IAP, eventjson); // don't use Ads tracking event here

                promoPayload.Clear();
                promoPayload = null;
            }
            else
            {
                // enriched "organic" purchases here

                Product thisProduct = unity.products.WithStoreSpecificID(failure.productId);

                if (thisProduct != null)
                {
                    var purchaseDict = new Dictionary <string, object>();
                    purchaseDict.Add("type", "iap.purchasefailed");
                    purchaseDict.Add("iap_service", true);
                    purchaseDict.Add("iapPromo", false);
                    purchaseDict.Add("purchase", "FAILED");
                    purchaseDict.Add("productId", thisProduct.definition.id);
                    purchaseDict.Add("storeSpecificId", thisProduct.definition.storeSpecificId);
                    purchaseDict.Add("amount", thisProduct.metadata.localizedPrice);
                    purchaseDict.Add("currency", thisProduct.metadata.isoCurrencyCode);
                    if (json != null)
                    {
                        purchaseDict.Add("failureJSON", json);
                    }

                    var purchaseEvent = new PurchasingEvent(purchaseDict);
                    var profileDict   = ProfileData.Instance(m_Module.util).GetProfileDict();
                    var eventjson     = purchaseEvent.FlatJSON(profileDict);

                    m_EventQueue.SendEvent(EventDestType.IAP, eventjson, eventBaseUrl + "/v1/organic_purchase");
                }
            }
#endif
        }