Beispiel #1
0
 public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
 {
     // Purchasing has succeeded initializing. Collect our Purchasing references.
     Debug.Log("OnInitialized: PASS");
     Debug.Log("Available items:");
     foreach (var item in controller.products.all)
     {
         if (item.availableToPurchase)
         {
             Debug.Log(string.Join(" - ",
                                   new[]
             {
                 item.transactionID,
                 item.metadata.localizedTitle,
                 item.metadata.localizedDescription,
                 item.metadata.isoCurrencyCode,
                 item.metadata.localizedPrice.ToString(),
                 item.metadata.localizedPriceString,
                 item.transactionID,
                 item.receipt
             }));
         }
     }
     m_StoreController              = controller;
     m_StoreExtensionProvider       = extensions;
     m_TransactionHistoryExtensions = extensions.GetExtension <ITransactionHistoryExtensions>();
 }
Beispiel #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_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();
    }