Пример #1
0
        //Проверка покупки подписки.
        //Subscription purchase verification.
        public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
        {
            m_GooglePlayStoreExtensions = extensions.GetExtension <IGooglePlayStoreExtensions>();
            m_StoreController           = controller;
            m_StoreExtensionProvider    = extensions;
            Dictionary <string, string> Dict = m_GooglePlayStoreExtensions.GetProductJSONDictionary();

            foreach (Product item in controller.products.all)
            {
                if (item.receipt != null)
                {
                    if (item.definition.type == ProductType.Subscription)
                    {
                        string json = (Dict == null || !Dict.ContainsKey(item.definition.storeSpecificId))
                            ? null
                            : Dict[item.definition.storeSpecificId];
                        SubscriptionManager s    = new SubscriptionManager(item, json);
                        SubscriptionInfo    info = s.getSubscriptionInfo();
                        if (info.getProductId() == "pay_noads")
                        {
                            if (info.isSubscribed() == Result.True)
                            {
                                PlayerPrefsSafe.SetInt("ADS", 1);
                            }
                            else
                            {
                                PlayerPrefsSafe.SetInt("ADS", 0);
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Processes the purchase.
        /// </summary>
        /// <returns>The purchase.</returns>
        /// <param name="args">Arguments.</param>
        public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
        {
            if (args != null && args.purchasedProduct != null)
            {
                IAPProduct product = ConvertFromProduct(args.purchasedProduct);

#if RECEIPT_VALIDATION
                if (Application.platform == RuntimePlatform.Android ||
                    Application.platform == RuntimePlatform.IPhonePlayer ||
                    Application.platform == RuntimePlatform.OSXPlayer)
                {
                    try {
                        //var result =
                        _ReceiptValidator.Validate(args.purchasedProduct.receipt);
                        //Debug.Log("Receipt is valid. Contents:");
                        //foreach (IPurchaseReceipt productReceipt in result) {
                        //	Debug.Log(productReceipt.productID);
                        //	Debug.Log(productReceipt.purchaseDate);
                        //	Debug.Log(productReceipt.transactionID);

                        //	GooglePlayReceipt google = productReceipt as GooglePlayReceipt;
                        //	if (null != google) {
                        //		Debug.Log(google.purchaseState);
                        //		Debug.Log(google.purchaseToken);
                        //	}

                        //	AppleInAppPurchaseReceipt apple = productReceipt as AppleInAppPurchaseReceipt;
                        //	if (null != apple) {
                        //		Debug.Log(apple.originalTransactionIdentifier);
                        //		Debug.Log(apple.subscriptionExpirationDate);
                        //		Debug.Log(apple.cancellationDate);
                        //		Debug.Log(apple.quantity);
                        //	}
                        //}
                    } catch (IAPSecurityException) {
                        Debug.Log("Invalid receipt, not unlocking content");
                        if (OnIAPProcessPurchase != null)
                        {
                            OnIAPProcessPurchase(null, null, null);
                        }
                        return(PurchaseProcessingResult.Complete);
                    }
                }

                // update subscription info
#if UNITY_IOS
                Dictionary <string, string> introductory_info_dict = _AppleExtensions.GetIntroductoryPriceDictionary();
                _UpdateReceipt(args.purchasedProduct, ref product, introductory_info_dict);
#endif
#if UNITY_ANDROID
                Dictionary <string, string> introductory_info_dict = _GooglePlayStoreExtensions.GetProductJSONDictionary();
                _UpdateReceipt(args.purchasedProduct, ref product, introductory_info_dict);
#endif
#endif

                // CloudMoolah purchase completion / finishing currently requires using the API
                // extension IMoolahExtension.RequestPayout to finish a transaction.
                if (_isCloudMoolahStore)
                {
                    // Finish transaction with CloudMoolah server
                    _MoolahExtensions.ValidateReceipt(args.purchasedProduct.transactionID,
                                                      args.purchasedProduct.receipt,
                                                      (string transactionID, ValidateReceiptState state, string message) =>
                    {
                        if (state == ValidateReceiptState.ValidateSucceed)
                        {
                            // Finally, finish transaction with Unity IAP's local
                            // transaction log, recording the transaction id there
                            _StoreController.ConfirmPendingPurchase(args.purchasedProduct);

                            // Unlock content here.
                        }
                        else
                        {
                            Debug.Log("RequestPayOut: failed. transactionID: " + transactionID +
                                      ", state: " + state + ", message: " + message);
                            // Finishing failed. Retry later.
                        }
                    });
                }

                if (OnIAPProcessPurchase != null)
                {
                    OnIAPProcessPurchase(
                        product,
                        args.purchasedProduct.transactionID,
                        args.purchasedProduct.receipt);
                }
                return(PurchaseProcessingResult.Complete);
            }
            else
            {
                if (OnIAPProcessPurchase != null)
                {
                    OnIAPProcessPurchase(null, null, null);
                }
            }

            // still pending
            return(PurchaseProcessingResult.Pending);
        }
Пример #3
0
        //
        // --- IStoreListener
        //


        public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
        {
            // Purchasing has succeeded initializing. Collect our Purchasing references.
            Debug.Log("[IAPManager] OnInitialized.");

            // Overall Purchasing system, configured with products for this application.
            _StoreController = controller;
            // Store specific subsystem, for accessing device-specific store features.
            _StoreExtensionProvider = extensions;

            _AppleExtensions   = extensions.GetExtension <IAppleExtensions>();
            _SamsungExtensions = extensions.GetExtension <ISamsungAppsExtensions>();
            _MoolahExtensions  = extensions.GetExtension <IMoolahExtension>();

            // On Apple platforms we need to handle deferred purchases caused by Apple's Ask to Buy feature.
            // On non-Apple platforms this will have no effect; OnDeferred will never be called.
#if UNITY_IOS
            _AppleExtensions.RegisterPurchaseDeferredListener(OnDeferred);
#endif
#if UNITY_ANDROID
            _GooglePlayStoreExtensions = extensions.GetExtension <IGooglePlayStoreExtensions>();
#endif

#if RECEIPT_VALIDATION
    #if UNITY_EDITOR
    #else
        #if UNITY_IOS
            Dictionary <string, string> introductory_info_dict = _AppleExtensions.GetIntroductoryPriceDictionary();
        #endif
        #if UNITY_ANDROID
            Dictionary <string, string> introductory_info_dict = _GooglePlayStoreExtensions.GetProductJSONDictionary();
        #endif
    #endif
#endif
            // Store products
            for (int i = 0; i < controller.products.all.Length; i++)
            {
                Product    pp = controller.products.all[i];
                IAPProduct p  = null;
                if (products.ContainsKey(pp.definition.id))
                {
                    p                     = products[pp.definition.id];
                    p.priceString         = pp.metadata.localizedPriceString;
                    p.price               = pp.metadata.localizedPrice;
                    p.title               = pp.metadata.localizedTitle;
                    p.description         = pp.metadata.localizedDescription;
                    p.isoCurrencyCode     = pp.metadata.isoCurrencyCode;
                    p.hasReceipt          = pp.hasReceipt;
                    p.availableToPurchase = pp.availableToPurchase;
                    p.receipt             = pp.receipt;
                    p.transactionID       = pp.transactionID;
                    p.rawProduct          = pp;
                    p.hasReceipt          = pp.hasReceipt;

#if RECEIPT_VALIDATION
#if UNITY_EDITOR
#else
                    _UpdateReceipt(pp, ref p, introductory_info_dict);
#endif
#endif
                }
            }
            // callback
            if (OnIAPInitialized != null)
            {
                OnIAPInitialized(products);
            }
        }