Esempio n. 1
0
    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs evt)
    {
        try
        {
            bool flag = false;
            // CrossPlatformValidator crossPlatformValidator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.identifier);
            CrossPlatformValidator crossPlatformValidator = new CrossPlatformValidator(null, null, Application.identifier);
            IPurchaseReceipt[]     array = crossPlatformValidator.Validate(evt.purchasedProduct.receipt);
            for (int i = 0; i < array.Count(); i++)
            {
                IPurchaseReceipt productReceipt = array[i];
                if (productReceipt.productID == evt.purchasedProduct.definition.storeSpecificId && PersistentSingleton <Economies> .Instance.IAPs.Find((IAPConfig iap) => iap.ProductID == productReceipt.productID) != null)
                {
                    flag = true;
                }
            }
            IAPConfig iAPConfig = PersistentSingleton <Economies> .Instance.IAPs.Find((IAPConfig iap) => iap.ProductID == evt.purchasedProduct.definition.storeSpecificId);

            if (flag && iAPConfig != null)
            {
                IAPValidated.Value = new IAPTransactionState(iAPConfig, evt.purchasedProduct, evt.purchasedProduct.receipt);
            }
            if (!flag)
            {
                IAPInvalidated.SetValueAndForceNotify(value: true);
            }
        }
        catch (Exception ex)
        {
            UnityEngine.Debug.LogWarning("Invalid receipt - " + ex.Message);
        }
        PurchaseInProgress.SetValueAndForceNotify(value: false);
        GiveIAPToUser(evt.purchasedProduct);
        return(PurchaseProcessingResult.Complete);
    }
        //removing static references on manager destroy -> cause when app resets
        protected override void RefreshStaticOnDestroy()
        {
            StoreController        = null;
            StoreExtensionProvider = null;
            OnPurchaseSuccess      = null;

            OnInitSuccess     = null;
            OnInitFailure     = null;
            OnPurchaseFailure = null;

            PremiumProduct        = null;
            PremiumProductReceipt = null;
        }
Esempio n. 3
0
        static void LogReceipt(IPurchaseReceipt receipt)
        {
            Debug.Log($"Product ID: {receipt.productID}\n" +
                      $"Purchase Date: {receipt.purchaseDate}\n" +
                      $"Transaction ID: {receipt.transactionID}");

            if (receipt is GooglePlayReceipt googleReceipt)
            {
                Debug.Log($"Purchase State: {googleReceipt.purchaseState}\n" +
                          $"Purchase Token: {googleReceipt.purchaseToken}");
            }

            if (receipt is AppleInAppPurchaseReceipt appleReceipt)
            {
                Debug.Log($"Original Transaction ID: {appleReceipt.originalTransactionIdentifier}\n" +
                          $"Subscription Expiration Date: {appleReceipt.subscriptionExpirationDate}\n" +
                          $"Cancellation Date: {appleReceipt.cancellationDate}\n" +
                          $"Quantity: {appleReceipt.quantity}");
            }
        }
Esempio n. 4
0
    void ApplyIAPPackage(string _productId, IPurchaseReceipt _productReceipt = null)
    {
        Debug.Log(">>> ApplyIAPPackage " + _productId);
        if (_productReceipt == null)
        {
            Debug.LogError(">>> _productReceipt is null");
            return;
        }
        string            _tokenPurchase = string.Empty;
        GooglePlayReceipt _google        = _productReceipt as GooglePlayReceipt;

        if (_google != null)
        {
            _tokenPurchase = _google.purchaseToken;
            // Debug.Log(google.purchaseState);
            // Debug.Log(google.purchaseToken);
        }
        AppleInAppPurchaseReceipt _apple = _productReceipt as AppleInAppPurchaseReceipt;

        if (_apple != null)
        {
            // Debug.Log(_apple.originalTransactionIdentifier);
            // Debug.Log(_apple.subscriptionExpirationDate);
            // Debug.Log(_apple.cancellationDate);
            // Debug.Log(_apple.quantity);
            _tokenPurchase = _google.purchaseToken;
        }

        if (!string.IsNullOrEmpty(_tokenPurchase))
        {
            byte _screenPurchase = (byte)IMySceneManager.Type.Home;
            if (CoreGameManager.instance.currentSceneManager != null)
            {
                _screenPurchase = (byte)CoreGameManager.instance.currentSceneManager.mySceneType;
            }

            PurchaseReceiptDetail _purchaseReceiptDetail = new PurchaseReceiptDetail(_screenPurchase, _productReceipt.transactionID, _productId, _tokenPurchase, _productReceipt.purchaseDate);
            DataManager.instance.purchaseReceiptData.AddNewPurchaseReceiptDetail(_purchaseReceiptDetail);

            SubServerDetail _serverDetail = GetGoldScreenController.instance.GetServerDetail();
            LoadingCanvasController.instance.Show(-1f, true);
            _purchaseReceiptDetail.SendMessageToServer(_serverDetail,
                                                       (_listRewarDetails) => {
                PopupManager.Instance.CreatePopupReward(_listRewarDetails);
                GetGoldScreenController.instance.RefreshMyGoldInfo(false);
                // StartCoroutine(CreatePopUpRewards(_listRewarDetails, null));
                if (GetGoldScreenController.instance.currentState == UIHomeScreenController.State.Show &&
                    GetGoldScreenController.instance.currentTab == GetGoldScreenController.Tab.BuyGold)
                {
                    ((GetGoldScreen_PanelBuyGold_Controller)GetGoldScreenController.instance.currentPanel).SetActiveIconWarningHasNewPurchase(true);
                }

                if (HomeManager.instance != null && HomeManager.instance.myCallbackManager != null &&
                    HomeManager.instance.myCallbackManager.onLoadDataGoldGemFinished != null)
                {
                    HomeManager.instance.myCallbackManager.onLoadDataGoldGemFinished();
                }
            },
                                                       () => {
                LoadingCanvasController.instance.Hide();
            });
        }
        else
        {
            Debug.LogError(">>> _tokenPurchase is null");
        }
    }
Esempio n. 5
0
        /// <summary>
        /// Validates the receipt. Works with receipts from Apple stores and Google Play store only.
        /// Always returns true for other stores.
        /// </summary>
        /// <returns><c>true</c>, if the receipt is valid, <c>false</c> otherwise.</returns>
        /// <param name="receipt">Receipt.</param>
        /// <param name="logReceiptContent">If set to <c>true</c> log receipt content.</param>
        private static bool ValidateReceipt(string receipt, out IPurchaseReceipt[] purchaseReceipts, bool logReceiptContent = false)
        {
            purchaseReceipts = new IPurchaseReceipt[0];   // default the out parameter to an empty array

            // Does the receipt has some content?
            if (string.IsNullOrEmpty(receipt))
            {
                Debug.Log("Receipt Validation: receipt is null or empty.");
                return(false);
            }

            bool isValidReceipt = true; // presume validity for platforms with no receipt validation.

            // Unity IAP's receipt validation is only available for Apple app stores and Google Play store.
#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX || UNITY_TVOS
            byte[] googlePlayTangleData = null;
            byte[] appleTangleData      = null;

            // Here we populate the secret keys for each platform.
            // Note that the code is disabled in the editor for it to not stop the EM editor code (due to ClassNotFound error)
            // from recreating the dummy AppleTangle and GoogleTangle classes if they were inadvertently removed.

#if UNITY_ANDROID && !UNITY_EDITOR
            googlePlayTangleData = GooglePlayTangle.Data();
#endif

#if (UNITY_IOS || UNITY_STANDALONE_OSX || UNITY_TVOS) && !UNITY_EDITOR
            appleTangleData = AppleTangle.Data();
#endif

            // Prepare the validator with the secrets we prepared in the Editor obfuscation window.
#if UNITY_5_6_OR_NEWER
            var validator = new CrossPlatformValidator(googlePlayTangleData, appleTangleData, Application.identifier);
#else
            var validator = new CrossPlatformValidator(googlePlayTangleData, appleTangleData, Application.bundleIdentifier);
#endif

            try
            {
                // On Google Play, result has a single product ID.
                // On Apple stores, receipts contain multiple products.
                var result = validator.Validate(receipt);

                // If the validation is successful, the result won't be null.
                if (result == null)
                {
                    isValidReceipt = false;
                }
                else
                {
                    purchaseReceipts = result;

                    // For informational purposes, we list the receipt(s)
                    if (logReceiptContent)
                    {
                        Debug.Log("Receipt contents:");
                        foreach (IPurchaseReceipt productReceipt in result)
                        {
                            if (productReceipt != null)
                            {
                                Debug.Log(productReceipt.productID);
                                Debug.Log(productReceipt.purchaseDate);
                                Debug.Log(productReceipt.transactionID);
                            }
                        }
                    }
                }
            }
            catch (IAPSecurityException)
            {
                isValidReceipt = false;
            }
#endif

            return(isValidReceipt);
        }