Ejemplo n.º 1
0
    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
    {
        //CrossPlatformValidator crossPlatformValidator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.identifier);
        string receipt         = e.purchasedProduct.receipt;
        string isoCurrencyCode = e.purchasedProduct.metadata.isoCurrencyCode;
        int    amount          = decimal.ToInt32(e.purchasedProduct.metadata.localizedPrice * 100m);
        bool   num             = e.purchasedProduct.definition.id.Contains("coins");
        string itemType        = num ? "coins" : "tank";
        string cartType        = num ? "shop" : "garage";
        string storeSpecificId = e.purchasedProduct.definition.storeSpecificId;

        try
        {
            //crossPlatformValidator.Validate(receipt);
            ProcessPurchase(storeSpecificId);
        }
        catch (Exception)
        {
            TankAnalytics.InvalidPurchase();
        }
        PayloadAndroid payloadAndroid = JsonUtility.FromJson <PayloadAndroid>(JsonUtility.FromJson <Receipt>(receipt).Payload);

        //GameAnalytics.NewBusinessEventGooglePlay(isoCurrencyCode, amount, itemType, storeSpecificId, cartType, payloadAndroid.json, payloadAndroid.signature);
        AppsFlyer.validateReceipt("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArDKTBCIaRoT2n1QI1wS/JRep9iSS3AcqQ4Z0Udr5bCxcf0594aY3P39rpfnbRdJUCFjo150j9c1ZKuL0V8rnWOzwRNqdSvPtwiyQNztsQrMG5LkirW61VLCt8kIhpLd0osBeH585s4VV7FBe1m7u6+S98bM1TVm+Ows2/OoXXydyDpcaRaMsNAcM0bt4hWFcRTndwLalmyWHUYJ1tj9N/agtsX6nbBG2uF1Lc7iEH2UoY0VtaXGZdo5tCEHdx+58abxfcuVwHauH7ZzX8jlURDXPy1K0Fi9Ag6IKzrWFEmAjqAjYnmrD3tgHMJEIsKx/OoVI6+AaEfF4nRmejdt6KQIDAQAB", payloadAndroid.json, payloadAndroid.signature, e.purchasedProduct.metadata.localizedPrice.ToString(), e.purchasedProduct.metadata.isoCurrencyCode, null);
        return(PurchaseProcessingResult.Complete);
    }
Ejemplo n.º 2
0
    private void ProcessPurchaseReceipt(string currency, string productID, int amount, Receipt receiptClass)
    {
#if UNITY_ANDROID
        PayloadAndroid receiptPayload = JsonUtility.FromJson <PayloadAndroid>(receiptClass.Payload);
#if GA
        GameAnalyticsSDK.GameAnalytics.NewBusinessEventGooglePlay(currency, amount, "my_item_type", productID, "my_cart_type", receiptPayload.json, receiptPayload.signature);
#endif
#endif
#if UNITY_IOS
        string receiptPayload = receiptClass.Payload;
#if GA
        GameAnalyticsSDK.GameAnalytics.NewBusinessEventIOS(currency, amount, "my_item_type", productID, "my_cart_type", receiptPayload);
#endif
#endif
    }
Ejemplo n.º 3
0
        public SavePayload(string album = null, Action completionHandler = null)
        {
            switch (Application.platform)
            {
            case RuntimePlatform.Android: {
                var nativePayload = new AndroidJavaObject(@"api.natsuite.natshare.SavePayload", album, PayloadAndroid.GetCallbackID(completionHandler));
                this.payload = new PayloadAndroid(nativePayload);
                break;
            }

            case RuntimePlatform.IPhonePlayer: {
                var callback      = completionHandler != null ? (IntPtr)GCHandle.Alloc(completionHandler, GCHandleType.Normal) : IntPtr.Zero;
                var nativePayload = PayloadBridge.CreateSavePayload(album, PayloadiOS.OnCompletion, callback);
                this.payload = new PayloadiOS(nativePayload);
                break;
            }

            default:
                Debug.LogError("NatShare Error: SavePayload is not supported on this platform");
                this.payload = null;     // Self-destruct >:D
                break;
            }
        }
Ejemplo n.º 4
0
    /// <summary>
    /// 内购完成
    /// </summary>
    /// <param name="e"></param>
    /// <returns></returns>
    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    {
        Debug.Log(Name + "=======内购完成的函数执行Start");
        if (buyItemDic.ContainsKey(args.purchasedProduct.definition.storeSpecificId))//如果商品id匹配则执行其恢复购买
        {
            buyItemDic[args.purchasedProduct.definition.storeSpecificId].OnReStore();
            Debug.Log(Name + "price:" + args.purchasedProduct.metadata.localizedPriceString);
            Debug.Log(Name + args.purchasedProduct.metadata.localizedTitle + args.purchasedProduct.metadata.localizedDescription);

            //交易号
            Debug.Log(Name + "storeSpecificId:" + args.purchasedProduct.definition.storeSpecificId);

            //回执单
            Debug.Log(Name + "receipt:" + args.purchasedProduct.receipt);

            //商品的id号
            Debug.Log(Name + "transactionID:" + args.purchasedProduct.transactionID);

            Debug.Log(Name + "成功了!!!!");
        }
        if (String.Equals(args.purchasedProduct.definition.id, buy_adRemove, StringComparison.Ordinal))
        {
            AllSDKManager.GetSDK <AdSdk>().IsEnable = false;
            //移除广告
            Config.RemovedAD();
            AllSDKManager.GetSDK <AllAnalyticsSdk>().Event_IAP_End();
            Debug.Log("去除广告");
            var    product  = controller.products.WithID(buy_adRemove);
            string receipt  = product.receipt;
            string currency = product.metadata.isoCurrencyCode;
            int    amount   = decimal.ToInt32(product.metadata.localizedPrice * 100);
#if UNITY_ANDROID
            Receipt        receiptAndroid = JsonUtility.FromJson <Receipt>(receipt);
            PayloadAndroid receiptPayload = JsonUtility.FromJson <PayloadAndroid>(receiptAndroid.Payload);
            //AllSDKManager.GetSDK<AppsFlyerManager>().Event_BusinessGooglePlay(currency, amount, "Ad");
#endif
#if UNITY_IOS
            Receipt receiptiOS     = JsonUtility.FromJson <Receipt>(receipt);
            string  receiptPayload = receiptiOS.Payload;
            //AppsFlyerManager.Instance.Event_BusinessAppStore(currency, amount, "Ad");
#endif
        }
        else if (String.Equals(args.purchasedProduct.definition.id, buy_goldBrick, StringComparison.Ordinal))
        {
            var    product  = controller.products.WithID(buy_goldBrick);
            string receipt  = product.receipt;
            string currency = product.metadata.isoCurrencyCode;
            int    amount   = decimal.ToInt32(product.metadata.localizedPrice * 100);
#if UNITY_ANDROID
            Receipt        receiptAndroid = JsonUtility.FromJson <Receipt>(receipt);
            PayloadAndroid receiptPayload = JsonUtility.FromJson <PayloadAndroid>(receiptAndroid.Payload);
            //AllSDKManager.GetSDK<AppsFlyerManager>().Event_BusinessGooglePlay(currency, amount, "Ad");
#endif
#if UNITY_IOS
            Receipt receiptiOS     = JsonUtility.FromJson <Receipt>(receipt);
            string  receiptPayload = receiptiOS.Payload;
            //AppsFlyerManager.Instance.Event_BusinessAppStore(currency, amount, "Ad");
#endif
            Debug.Log("购买金币");
            if (PlayerPrefs.HasKey("goldBrick"))
            {
                Globle.goldBrickNum = PlayerPrefs.GetInt("goldBrick");
                PlayerPrefs.DeleteKey("goldBrick");
            }
            Globle.goldBrickNum += 200;
            PlayerPrefs.SetInt("goldBrick", Globle.goldBrickNum);
        }
        return(PurchaseProcessingResult.Complete);
    }
Ejemplo n.º 5
0
        /// <summary>
        /// Покупка
        /// </summary>
        /// <param name="id"></param>
        /// <param name="complete">удачно или нет</param>
        public void Report_PurchaseComplete(string id, bool complete, double price = 0, string currency = "", string transactionId = "", string receipt = "", string errmes = "")
        {
            if (!use_anilytics)
            {
                return;
            }
            string report = e_Purchase;

            if (complete)
            {
                var par3 = new Dictionary <string, object>(5)
                {
                    { e_DevId, deviceId }, { e_Purchase_TransactionId, transactionId }, { e_Purchase_Price, price }, { e_Purchase_Currency, currency }, { e_Purchase_Error, "" }
                };
                var par2 = new Dictionary <string, object>(1)
                {
                    { id, par3 }
                };
                var par1 = new Dictionary <string, object>(1)
                {
                    { e_Purchase_Complete, par2 }
                };
                Instance.ReportEvent(report, par1);
            }
            else
            {
                var par3 = new Dictionary <string, object>(5)
                {
                    { e_DevId, deviceId }, { e_Purchase_TransactionId, transactionId }, { e_Purchase_Price, price }, { e_Purchase_Currency, currency }, { e_Purchase_Error, errmes }
                };
                var par2 = new Dictionary <string, object>(1)
                {
                    { id, par3 }
                };
                var par1 = new Dictionary <string, object>(1)
                {
                    { e_Purchase_Failed, par2 }
                };
                Instance.ReportEvent(report, par1);
            }

            //string report = e_PurchaseComplete + "_" + id;
            //var parameters = new Dictionary<string, object>(4) { { "devId", deviceId }, { "completed", complete.ToString() }, { "price", price }, { "currency", currency } };

            if (complete)
            {
                var revenue = new YandexAppMetricaRevenue(price, currency);
                revenue.ProductID = id;

                if (!string.IsNullOrEmpty(receipt))
                {
                    YandexAppMetricaReceipt yaReceipt = new YandexAppMetricaReceipt();
                    Receipt r_receipt = JsonUtility.FromJson <Receipt>(receipt);
                    r_receipt.TransactionID = transactionId;
#if UNITY_ANDROID
                    PayloadAndroid payloadAndroid = JsonUtility.FromJson <PayloadAndroid>(r_receipt.Payload);
                    yaReceipt.Signature = payloadAndroid.Signature;
                    yaReceipt.Data      = payloadAndroid.Json;

                    yaReceipt.TransactionID = transactionId;
#elif UNITY_IPHONE
                    yaReceipt.TransactionID = receipt.TransactionID;
                    yaReceipt.Data          = receipt.Payload;
#endif
                    revenue.Receipt = yaReceipt;
                }

                Instance.ReportRevenue(revenue);
            }
            Instance.SendEventsBuffer();
        }