Exemplo n.º 1
0
    /// <summary>
    /// This will be called when Unity IAP has finished initialising.
    /// </summary>
    public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    {
        m_Controller             = controller;
        m_AppleExtensions        = extensions.GetExtension <IAppleExtensions> ();
        m_SamsungExtensions      = extensions.GetExtension <ISamsungAppsExtensions> ();
        m_MoolahExtensions       = extensions.GetExtension <IMoolahExtension> ();
        m_MicrosoftExtensions    = extensions.GetExtension <IMicrosoftExtensions> ();
        m_UnityChannelExtensions = extensions.GetExtension <IUnityChannelExtensions> ();

        InitUI(controller.products.all);

        // 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.
        m_AppleExtensions.RegisterPurchaseDeferredListener(OnDeferred);

        Debug.Log("Available items:");
        foreach (var item in controller.products.all)
        {
            if (item.availableToPurchase)
            {
                Debug.Log(string.Join(" - ",
                                      new[]
                {
                    item.metadata.localizedTitle,
                    item.metadata.localizedDescription,
                    item.metadata.isoCurrencyCode,
                    item.metadata.localizedPrice.ToString(),
                    item.metadata.localizedPriceString,
                    item.transactionID,
                    item.receipt
                }));
            }
        }

        // Prepare model for purchasing
        if (m_Controller.products.all.Length > 0)
        {
            m_SelectedItemIndex = 0;
        }

        // Populate the product menu now that we have Products
        for (int t = 0; t < m_Controller.products.all.Length; t++)
        {
            var item        = m_Controller.products.all[t];
            var description = string.Format("{0} | {1} => {2}", item.metadata.localizedTitle, item.metadata.localizedPriceString, item.metadata.localizedPrice);

            // NOTE: my options list is created in InitUI
            GetDropdown().options[t] = new Dropdown.OptionData(description);
        }

        // Ensure I render the selected list element
        GetDropdown().RefreshShownValue();

        // Now that I have real products, begin showing product purchase history
        UpdateHistoryUI();

        LogProductDefinitions();
    }
Exemplo n.º 2
0
	/// <summary>
	/// This will be called when Unity IAP has finished initialising.
	/// </summary>
	public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
	{
		m_Controller = controller;
		m_AppleExtensions = extensions.GetExtension<IAppleExtensions> ();
		m_SamsungExtensions = extensions.GetExtension<ISamsungAppsExtensions> ();
		m_MoolahExtensions = extensions.GetExtension<IMoolahExtension> ();

		InitUI(controller.products.all);

		// 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.
		m_AppleExtensions.RegisterPurchaseDeferredListener(OnDeferred);

		Debug.Log("Available items:");
		foreach (var item in controller.products.all)
		{
			if (item.availableToPurchase)
			{
				Debug.Log(string.Join(" - ",
					new[]
					{
						item.metadata.localizedTitle,
						item.metadata.localizedDescription,
						item.metadata.isoCurrencyCode,
						item.metadata.localizedPrice.ToString(),
						item.metadata.localizedPriceString,
						item.transactionID,
						item.receipt
					}));
			}
		}

		// Prepare model for purchasing
		if (m_Controller.products.all.Length > 0) 
		{
			m_SelectedItemIndex = 0;
		}

		// Populate the product menu now that we have Products
		for (int t = 0; t < m_Controller.products.all.Length; t++)
		{
			var item = m_Controller.products.all[t];
			var description = string.Format("{0} - {1}", item.metadata.localizedTitle, item.metadata.localizedPriceString);

			// NOTE: my options list is created in InitUI
			GetDropdown().options[t] = new Dropdown.OptionData(description);
		}

		// Ensure I render the selected list element
		GetDropdown().RefreshShownValue();

		// Now that I have real products, begin showing product purchase history
		UpdateHistoryUI();
	}
Exemplo n.º 3
0
    /// <summary>
    /// This will be called when Unity IAP has finished initialising.
    /// </summary>
    public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    {
        m_Controller             = controller;
        m_AppleExtensions        = extensions.GetExtension <IAppleExtensions>();
        m_SamsungExtensions      = extensions.GetExtension <ISamsungAppsExtensions>();
        m_MoolahExtensions       = extensions.GetExtension <IMoolahExtension>();
        m_MicrosoftExtensions    = extensions.GetExtension <IMicrosoftExtensions>();
        m_UnityChannelExtensions = extensions.GetExtension <IUnityChannelExtensions>();

        InitUI(controller.products.all);

        // 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.
        m_AppleExtensions.RegisterPurchaseDeferredListener(OnDeferred);

        Debug.Log("Available items:");
        foreach (var item in controller.products.all)
        {
            if (item.availableToPurchase)
            {
                Debug.Log(string.Join(" - ",
                                      new[]
                {
                    item.metadata.localizedTitle,
                    item.metadata.localizedDescription,
                    item.metadata.isoCurrencyCode,
                    item.metadata.localizedPrice.ToString(),
                    item.metadata.localizedPriceString,
                    item.transactionID,
                    item.receipt
                }));
#if INTERCEPT_PROMOTIONAL_PURCHASES
                // Set all these products to be visible in the user's App Store according to Apple's Promotional IAP feature
                // https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/StoreKitGuide/PromotingIn-AppPurchases/PromotingIn-AppPurchases.html
                m_AppleExtensions.SetStorePromotionVisibility(item, AppleStorePromotionVisibility.Show);
#endif
            }
        }

        // Populate the product menu now that we have Products
        AddProductUIs(m_Controller.products.all);

        LogProductDefinitions();
    }
Exemplo n.º 4
0
    /// <summary>
    /// This will be called when Unity IAP has finished initialising.
    /// 这将在Unity IAP完成初始化时被调用。
    /// </summary>
    public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    {
        m_Controller             = controller;
        m_AppleExtensions        = extensions.GetExtension <IAppleExtensions>();
        m_SamsungExtensions      = extensions.GetExtension <ISamsungAppsExtensions>();
        m_MoolahExtensions       = extensions.GetExtension <IMoolahExtension>();
        m_MicrosoftExtensions    = extensions.GetExtension <IMicrosoftExtensions>();
        m_UnityChannelExtensions = extensions.GetExtension <IUnityChannelExtensions>();

        InitUI(controller.products.all);

        // 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.
        //在苹果平台上,我们需要处理由苹果要求购买功能引起的延期购买。
        //在非苹果平台上,这不会有任何效果;延期将永远不会被调用。
        m_AppleExtensions.RegisterPurchaseDeferredListener(OnDeferred);

        Debug.Log("Available items:");
        foreach (var item in controller.products.all)
        {
            if (item.availableToPurchase)
            {
                Debug.Log(string.Join(" - ",
                                      new[]
                {
                    item.metadata.localizedTitle,
                    item.metadata.localizedDescription,
                    item.metadata.isoCurrencyCode,
                    item.metadata.localizedPrice.ToString(),
                    item.metadata.localizedPriceString,
                    item.transactionID,
                    item.receipt
                }));
            }
        }

        // Populate the product menu now that we have Products
        //填充产品菜单,现在我们有产品
        AddProductUIs(m_Controller.products.all);

        LogProductDefinitions();
    }
Exemplo n.º 5
0
    /// <summary>
    /// This will be called when Unity IAP has finished initialising.
    /// </summary>
    public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    {
        m_Controller                   = controller;
        m_AppleExtensions              = extensions.GetExtension <IAppleExtensions>();
        m_SamsungExtensions            = extensions.GetExtension <ISamsungAppsExtensions>();
        m_MicrosoftExtensions          = extensions.GetExtension <IMicrosoftExtensions>();
        m_TransactionHistoryExtensions = extensions.GetExtension <ITransactionHistoryExtensions>();
        m_GooglePlayStoreExtensions    = extensions.GetExtension <IGooglePlayStoreExtensions>();
        // Sample code for expose product sku details for google play store
        // Key is product Id (Sku), value is the skuDetails json string
        //Dictionary<string, string> google_play_store_product_SKUDetails_json = m_GooglePlayStoreExtensions.GetProductJSONDictionary();
        // Sample code for manually finish a transaction (consume a product on GooglePlay store)
        //m_GooglePlayStoreExtensions.FinishAdditionalTransaction(productId, transactionId);
        m_GooglePlayStoreExtensions.SetLogLevel(0); // 0 == debug, info, warning, error. 1 == warning, error only.

        InitUI(controller.products.all);

        // 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.
        m_AppleExtensions.RegisterPurchaseDeferredListener(OnDeferred);

#if SUBSCRIPTION_MANAGER
        Dictionary <string, string> introductory_info_dict = m_AppleExtensions.GetIntroductoryPriceDictionary();
#endif
        // Sample code for expose product sku details for apple store
        //Dictionary<string, string> product_details = m_AppleExtensions.GetProductDetails();


        Debug.Log("Available items:");
        foreach (Product item in controller.products.all)
        {
            if (item.availableToPurchase)
            {
                Debug.Log(string.Join(" - ", item.metadata.localizedTitle, item.metadata.localizedDescription,
                                      item.metadata.isoCurrencyCode, item.metadata.localizedPrice.ToString(),
                                      item.metadata.localizedPriceString, item.transactionID, item.receipt));
#if INTERCEPT_PROMOTIONAL_PURCHASES
                // Set all these products to be visible in the user's App Store according to Apple's Promotional IAP feature
                // https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/StoreKitGuide/PromotingIn-AppPurchases/PromotingIn-AppPurchases.html
                m_AppleExtensions.SetStorePromotionVisibility(item, AppleStorePromotionVisibility.Show);
#endif

#if SUBSCRIPTION_MANAGER
                // this is the usage of SubscriptionManager class
                if (item.receipt != null)
                {
                    if (item.definition.type == ProductType.Subscription)
                    {
                        if (checkIfProductIsAvailableForSubscriptionManager(item.receipt))
                        {
                            string intro_json =
                                (introductory_info_dict == null || !introductory_info_dict.ContainsKey(item.definition.storeSpecificId)) ? null : introductory_info_dict[item.definition.storeSpecificId];
                            SubscriptionManager p    = new SubscriptionManager(item, intro_json);
                            SubscriptionInfo    info = p.getSubscriptionInfo();
                            Debug.Log("product id is: " + info.getProductId());
                            Debug.Log("purchase date is: " + info.getPurchaseDate());
                            Debug.Log("subscription next billing date is: " + info.getExpireDate());
                            Debug.Log("is subscribed? " + info.isSubscribed().ToString());
                            Debug.Log("is expired? " + info.isExpired().ToString());
                            Debug.Log("is cancelled? " + info.isCancelled());
                            Debug.Log("product is in free trial peroid? " + info.isFreeTrial());
                            Debug.Log("product is auto renewing? " + info.isAutoRenewing());
                            Debug.Log("subscription remaining valid time until next billing date is: " + info.getRemainingTime());
                            Debug.Log("is this product in introductory price period? " + info.isIntroductoryPricePeriod());
                            Debug.Log("the product introductory localized price is: " + info.getIntroductoryPrice());
                            Debug.Log("the product introductory price period is: " + info.getIntroductoryPricePeriod());
                            Debug.Log("the number of product introductory price period cycles is: " + info.getIntroductoryPricePeriodCycles());
                        }
                        else
                        {
                            Debug.Log("This product is not available for SubscriptionManager class, only products that are purchase by 1.19+ SDK can use this class.");
                        }
                    }
                    else
                    {
                        Debug.Log("the product is not a subscription product");
                    }
                }
                else
                {
                    Debug.Log("the product should have a valid receipt");
                }
#endif
            }
        }

        // Populate the product menu now that we have Products
        AddProductUIs(m_Controller.products.all);

        LogProductDefinitions();
    }
Exemplo n.º 6
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);
            }
        }