// TODO Obtain non-consumables too!
    public void ObtainProductInfo(IList <string> productIdConsumablesList = null)
    {
        if (iapAvailable != true)
        {
            OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE);
            return;
        }

        ProductInfoReq productInfoReq = new ProductInfoReq
        {
            PriceType  = 0,
            ProductIds = productIdConsumablesList
        };

        iapClient.ObtainProductInfo(productInfoReq).AddOnSuccessListener((type0) =>
        {
            Debug.Log("[HMSPlugin]:" + type0.ErrMsg + type0.ReturnCode.ToString());
            Debug.Log("[HMSPlugin]: Found " + type0.ProductInfoList.Count + "consumable products");

            productInfoReq = new ProductInfoReq
            {
                PriceType  = 1,
                ProductIds = productIdConsumablesList
            };

            iapClient.ObtainProductInfo(productInfoReq).AddOnSuccessListener((type1) =>
            {
                Debug.Log("[HMSPlugin]:" + type1.ErrMsg + type1.ReturnCode.ToString());
                Debug.Log("[HMSPlugin]: Found " + type1.ProductInfoList.Count + "consumable products");

                productInfoReq = new ProductInfoReq
                {
                    PriceType  = 0,
                    ProductIds = productIdConsumablesList
                };

                OnObtainProductInfoSuccess?.Invoke(new List <ProductInfoResult> {
                    type0, type1
                });
            }).AddOnFailureListener((exception) =>
            {
                Debug.Log("[HMSPlugin]: ERROR Houston!!" + exception.Message);
                OnObtainProductInfoFailure?.Invoke(exception);
            });
        }).AddOnFailureListener((exception) =>
        {
            Debug.Log("[HMSPlugin]: ERROR Houston!!" + exception.Message);
            OnObtainProductInfoFailure?.Invoke(exception);
        });
    }
示例#2
0
    protected void InitIAP()
    {
        foreach (Product product in products)
        {
            if (product.isConsumable)
            {
                productIdConsumablesList.Add(product.productID);
            }
        }

        ProductInfoReq productInfoReq = new ProductInfoReq();



        // CONSUMABLE REQUEST
        productInfoReq.PriceType = 0;

        productInfoReq.ProductIds = productIdConsumablesList;

        ITask <ProductInfoResult> task = iapClient.ObtainProductInfo(productInfoReq);

        Debug.Log(task.Result);

        task.AddOnSuccessListener((result) =>
        {
            if (result != null)
            {
                if (result.ProductInfoList.Count != 0)
                {
                    Debug.Log("[HMSPlugin]:" + result.ErrMsg + result.ReturnCode.ToString());
                    Debug.Log("[HMSPlugin]: Found " + result.ProductInfoList.Count + "consumable products");
                    foreach (ProductInfo productInfo in result.ProductInfoList)
                    {
                        Debug.Log("[HMSPlugin]: " + productInfo.ProductName + "," + productInfo.Price);
                        productInfoList.Add(productInfo);
                    }
                }
            }
            loadedEvent.Invoke();
        }).AddOnFailureListener((exception) =>
        {
            Debug.Log("[HMSPlugin]: ERROR Houston!!" + exception.Message);
        });



        RestorePurchases();
        ObtainOwnedPurchases();
    }
示例#3
0
        private void ObtainProductInfo(IList <string> productIdNonConsumablesList, int priceType)
        {
            if (iapAvailable != true)
            {
                OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE);
                return;
            }

            ProductInfoReq productInfoReq = new ProductInfoReq
            {
                PriceType  = priceType,
                ProductIds = productIdNonConsumablesList
            };

            iapClient.ObtainProductInfo(productInfoReq).AddOnSuccessListener((type) =>
            {
                Debug.Log("[HMSPlugin]:" + type.ErrMsg + type.ReturnCode.ToString());
                Debug.Log("[HMSPlugin]: {0=Consumable}  {1=Non-Consumable}  {2=Subscription}");
                Debug.Log("[HMSPlugin]: Found " + type.ProductInfoList.Count + " type of " + priceType + " products");
                OnObtainProductInfoSuccess?.Invoke(new List <ProductInfoResult> {
                    type
                });
            }).AddOnFailureListener((exception) =>
            {
                Debug.Log("[HMSPlugin]: ERROR non  Consumable ObtainInfo" + exception.Message);
                OnObtainProductInfoFailure?.Invoke(exception);
            });
        }
        private void CreateProductRequest(List <string> consumablesIDs, HuaweiConstants.IAP.IapType type, System.Action onSuccess)
        {
            var productsDataRequest = new ProductInfoReq();

            productsDataRequest.PriceType  = (int)type;
            productsDataRequest.ProductIds = consumablesIDs;

            var task = iapClient.ObtainProductInfo(productsDataRequest);

            task.AddOnFailureListener(GetProductsFailure);
            task.AddOnSuccessListener((result) => { ParseProducts(result, type.ToString()); onSuccess(); });
        }
示例#5
0
        private void ObtainProductInfo(IList <string> productIdNonConsumablesList, PriceType priceType)
        {
            if (iapAvailable != true)
            {
                OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE);
                return;
            }

            ProductInfoReq productInfoReq = new ProductInfoReq
            {
                PriceType  = priceType,
                ProductIds = productIdNonConsumablesList
            };

            iapClient.ObtainProductInfo(productInfoReq).AddOnSuccessListener((type) =>
            {
                Debug.Log("[HMSIAPManager]:" + type.ErrMsg + type.ReturnCode.ToString());
                Debug.Log("[HMSIAPManager]: {0=Consumable}  {1=Non-Consumable}  {2=Subscription}");
                Debug.Log("[HMSIAPManager]: Found " + type.ProductInfoList.Count + " type of " + priceType.Value + " products");
                foreach (var productInfo in type.ProductInfoList)
                {
                    if (!productInfoList.Exists(c => c.ProductId == productInfo.ProductId))
                    {
                        productInfoList.Add(productInfo);
                    }
                    Debug.Log("[HMSIAPManager]: ProductId: " + productInfo.ProductId + ", ProductName: " + productInfo.ProductName + ", Price: " + productInfo.Price);
                }

                OnObtainProductInfoSuccess?.Invoke(new List <ProductInfoResult> {
                    type
                });
            }).AddOnFailureListener((exception) =>
            {
                Debug.LogError("[HMSIAPManager]: ObtainProductInfo failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage);
                OnObtainProductInfoFailure?.Invoke(exception);
            });
        }
        // TODO Obtain non-consumables too!
        public void ObtainProductInfo(IList <string> productIdConsumablesList, IList <string> productIdNonConsumablesList, IList <string> productIdSubscriptionList)
        {
            if (iapAvailable != true)
            {
                OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE);
                return;
            }

            ProductInfoReq productInfoReq = new ProductInfoReq
            {
                PriceType  = 0,
                ProductIds = productIdConsumablesList
            };

            iapClient.ObtainProductInfo(productInfoReq).AddOnSuccessListener((type0) =>
            {
                Debug.Log("[HMSPlugin]:" + type0.ErrMsg + type0.ReturnCode.ToString());
                Debug.Log("[HMSPlugin]: Found " + type0.ProductInfoList.Count + "consumable products");

                productInfoReq = new ProductInfoReq
                {
                    PriceType  = 1,
                    ProductIds = productIdNonConsumablesList
                };

                iapClient.ObtainProductInfo(productInfoReq).AddOnSuccessListener((type1) =>
                {
                    Debug.Log("[HMSPlugin]:" + type1.ErrMsg + type1.ReturnCode.ToString());
                    Debug.Log("[HMSPlugin]: Found " + type1.ProductInfoList.Count + " non consumable products");

                    productInfoReq = new ProductInfoReq
                    {
                        PriceType  = 2,
                        ProductIds = productIdSubscriptionList
                    };

                    iapClient.ObtainProductInfo(productInfoReq).AddOnSuccessListener((type2) =>
                    {
                        Debug.Log("[HMSPlugin]:" + type2.ErrMsg + type2.ReturnCode.ToString());
                        Debug.Log("[HMSPlugin]: Found " + type2.ProductInfoList.Count + " subscription products");


                        OnObtainProductInfoSuccess?.Invoke(new List <ProductInfoResult> {
                            type0, type1, type2
                        });
                    }).AddOnFailureListener((exception) =>
                    {
                        Debug.Log("[HMSPlugin]: ERROR Subscriptions ObtainInfo " + exception.GetBaseException().Message);
                        OnObtainProductInfoFailure?.Invoke(exception);
                    });
                }).AddOnFailureListener((exception) =>
                {
                    Debug.Log("[HMSPlugin]: ERROR Non Consumable ObtainInfo" + exception.Message);
                    OnObtainProductInfoFailure?.Invoke(exception);
                });
            }).AddOnFailureListener((exception) =>
            {
                Debug.Log("[HMSPlugin]: ERROR Consumable ObtainInfo" + exception.Message);
                OnObtainProductInfoFailure?.Invoke(exception);
            });
        }