Ejemplo n.º 1
0
        public void ConsumePurchaseWithToken(string token)
        {
            if (iapAvailable != true)
            {
                OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE);
                return;
            }

            ConsumeOwnedPurchaseReq consumeOwnedPurchaseReq = new ConsumeOwnedPurchaseReq
            {
                PurchaseToken = token
            };

            ITask <ConsumeOwnedPurchaseResult> task = iapClient.ConsumeOwnedPurchase(consumeOwnedPurchaseReq);

            task.AddOnSuccessListener((result) =>
            {
                Debug.Log("HMSP: consumePurchase");
                OnConsumePurchaseSuccess?.Invoke();
            }).AddOnFailureListener((exception) =>
            {
                Debug.Log("HMSP: Error on consumePurchase");
                OnConsumePurchaseFailure?.Invoke(exception);
            });
        }
Ejemplo n.º 2
0
        public void ObtainOwnedPurchases()
        {
            if (iapAvailable != true)
            {
                OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE);
                return;
            }

            Debug.Log("HMSP: ObtainOwnedPurchaseRequest");
            OwnedPurchasesReq ownedPurchasesReq = new OwnedPurchasesReq
            {
                PriceType = 1
            };

            ITask <OwnedPurchasesResult> task = iapClient.ObtainOwnedPurchases(ownedPurchasesReq);

            task.AddOnSuccessListener((result) =>
            {
                Debug.Log("HMSP: ObtainOwnedPurchases");
                OnObtainOwnedPurchasesSuccess?.Invoke(result);
            }).AddOnFailureListener((exception) =>
            {
                Debug.Log("HMSP: Error on ObtainOwnedPurchases");
                OnObtainProductInfoFailure?.Invoke(exception);
            });
        }
Ejemplo n.º 3
0
        public void ConsumeOwnedPurchases()
        {
            if (iapAvailable != true)
            {
                OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE);
                return;
            }

            OwnedPurchasesReq ownedPurchasesReq = new OwnedPurchasesReq();

            ITask <OwnedPurchasesResult> task = iapClient.ObtainOwnedPurchases(ownedPurchasesReq);

            task.AddOnSuccessListener((result) =>
            {
                Debug.Log("[HMSIAPManager] recoverPurchases");
                foreach (var inAppPurchaseData in result.InAppPurchaseDataList)
                {
                    ConsumePurchaseWithPurchaseData(inAppPurchaseData);
                    Debug.Log("[HMSIAPManager] recoverPurchases result> " + result.ReturnCode);
                }

                OnRecoverPurchasesSuccess?.Invoke();
            }).AddOnFailureListener((exception) =>
            {
                Debug.LogError("[HMSIAPManager] ConsumeOwnedPurchases failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage);
                OnRecoverPurchasesFailure?.Invoke(exception);
            });
        }
Ejemplo n.º 4
0
        public void ConsumeOwnedPurchases()
        {
            if (iapAvailable != true)
            {
                OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE);
                return;
            }

            OwnedPurchasesReq ownedPurchasesReq = new OwnedPurchasesReq();

            ITask <OwnedPurchasesResult> task = iapClient.ObtainOwnedPurchases(ownedPurchasesReq);

            task.AddOnSuccessListener((result) =>
            {
                Debug.Log("HMSP: recoverPurchases");
                foreach (string inAppPurchaseData in result.InAppPurchaseDataList)
                {
                    ConsumePurchaseWithPurchaseData(inAppPurchaseData);
                    Debug.Log("HMSP: recoverPurchases result> " + result.ReturnCode);
                }

                OnRecoverPurchasesSuccess?.Invoke();
            }).AddOnFailureListener((exception) =>
            {
                Debug.Log($"HMSP: Error on recoverPurchases {exception.StackTrace}");
                OnRecoverPurchasesFailure?.Invoke(exception);
            });
        }
Ejemplo n.º 5
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);
            });
        }
Ejemplo n.º 6
0
        public void ConsumePurchaseWithToken(string token)
        {
            if (iapAvailable != true)
            {
                OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE);
                return;
            }

            ConsumeOwnedPurchaseReq consumeOwnedPurchaseReq = new ConsumeOwnedPurchaseReq
            {
                PurchaseToken = token
            };

            ITask <ConsumeOwnedPurchaseResult> task = iapClient.ConsumeOwnedPurchase(consumeOwnedPurchaseReq);

            task.AddOnSuccessListener((result) =>
            {
                Debug.Log("[HMSIAPManager] consumePurchase");
                OnConsumePurchaseSuccess?.Invoke();
            }).AddOnFailureListener((exception) =>
            {
                Debug.LogError("[HMSIAPManager] ConsumePurchaseWithToken failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage);
                OnConsumePurchaseFailure?.Invoke(exception);
            });
        }
Ejemplo n.º 7
0
        public void ObtainProductSubscriptionInfo(IList <string> productIdSubscriptionList)
        {
            if (iapAvailable != true)
            {
                OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE);
                return;
            }

            ProductInfoReq 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 + "consumable products");
                OnObtainProductInfoSuccess?.Invoke(new List <ProductInfoResult> {
                    type2
                });
            }).AddOnFailureListener((exception) =>
            {
                Debug.Log("[HMSPlugin]: ERROR Consumable ObtainInfo" + exception.Message);
                OnObtainProductInfoFailure?.Invoke(exception);
            });
        }
Ejemplo n.º 8
0
    public void BuyProduct(ProductInfo productInfo)
    {
        if (iapAvailable != true)
        {
            OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE);
            return;
        }

        PurchaseIntentReq purchaseIntentReq = new PurchaseIntentReq
        {
            PriceType = productInfo.PriceType,
            ProductId = productInfo.ProductId,
            // ToDo : developer payload???
            DeveloperPayload = "test"
        };

        ITask <PurchaseIntentResult> task = iapClient.CreatePurchaseIntent(purchaseIntentReq);

        task.AddOnSuccessListener((result) =>
        {
            if (result != null)
            {
                Debug.Log("[HMSPlugin]:" + result.ErrMsg + result.ReturnCode.ToString());
                Debug.Log("[HMSPlugin]: Bought " + purchaseIntentReq.ProductId);
                Status status = result.Status;
                status.StartResolutionForResult((androidIntent) =>
                {
                    PurchaseResultInfo purchaseResultInfo = iapClient.ParsePurchaseResultInfoFromIntent(androidIntent);

                    Debug.Log("HMSPluginResult: " + purchaseResultInfo.ReturnCode);
                    Debug.Log("HMErrorMssg: " + purchaseResultInfo.ErrMsg);
                    Debug.Log("HMS: HMSInAppPurchaseData" + purchaseResultInfo.InAppPurchaseData);
                    Debug.Log("HMS: HMSInAppDataSignature" + purchaseResultInfo.InAppDataSignature);

                    switch (purchaseResultInfo.ReturnCode)
                    {
                    case OrderStatusCode.ORDER_STATE_SUCCESS:
                        OnBuyProductSuccess.Invoke(purchaseResultInfo);
                        break;

                    default:
                        OnBuyProductFailure.Invoke(purchaseResultInfo.ReturnCode);
                        break;
                    }
                }, (exception) =>
                {
                    Debug.Log("[HMSPlugin]:startIntent ERROR");
                });
            }
        }).AddOnFailureListener((exception) =>
        {
            Debug.Log("[HMSPlugin]: ERROR BuyProduct!!" + exception.Message);
        });
    }
Ejemplo n.º 9
0
    // 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);
        });
    }
Ejemplo n.º 10
0
        private void ObtainOwnedPurchases(OwnedPurchasesReq ownedPurchasesReq)
        {
            ITask <OwnedPurchasesResult> task = iapClient.ObtainOwnedPurchases(ownedPurchasesReq);

            task.AddOnSuccessListener((result) =>
            {
                Debug.Log("[HMSIAPManager] ObtainOwnedPurchases");
                foreach (var item in result.InAppPurchaseDataList)
                {
                    Debug.Log("[HMSIAPManager] ProductId: " + item.ProductId + ", ProductName: " + item.ProductName + ", Price: " + item.Price);
                }
                OnObtainOwnedPurchasesSuccess?.Invoke(result);
            }).AddOnFailureListener((exception) =>
            {
                Debug.LogError("[HMSIAPManager]: ObtainOwnedPurchases failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage);
                OnObtainProductInfoFailure?.Invoke(exception);
            });
        }
Ejemplo n.º 11
0
        // TODO Obtain non-consumables too!
        public void ObtainProductInfo(List <string> productIdConsumablesList, List <string> productIdNonConsumablesList, List <string> productIdSubscriptionList)
        {
            if (iapAvailable != true)
            {
                OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE);
                return;
            }

            if (!IsNullOrEmpty(productIdConsumablesList))
            {
                ObtainProductInfo(new List <string>(productIdConsumablesList), 0);
            }
            if (!IsNullOrEmpty(productIdNonConsumablesList))
            {
                ObtainProductInfo(new List <string>(productIdNonConsumablesList), 1);
            }
            if (!IsNullOrEmpty(productIdSubscriptionList))
            {
                ObtainProductInfo(new List <string>(productIdSubscriptionList), 2);
            }
        }
Ejemplo n.º 12
0
        public void ObtainProductInfo(List <string> productIdConsumablesList, List <string> productIdNonConsumablesList, List <string> productIdSubscriptionList)
        {
            if (iapAvailable != true)
            {
                OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE);
                return;
            }

            if (!IsNullOrEmpty(productIdConsumablesList))
            {
                ObtainProductInfo(new List <string>(productIdConsumablesList), PriceType.IN_APP_CONSUMABLE);
            }
            if (!IsNullOrEmpty(productIdNonConsumablesList))
            {
                ObtainProductInfo(new List <string>(productIdNonConsumablesList), PriceType.IN_APP_NONCONSUMABLE);
            }
            if (!IsNullOrEmpty(productIdSubscriptionList))
            {
                ObtainProductInfo(new List <string>(productIdSubscriptionList), PriceType.IN_APP_SUBSCRIPTION);
            }
        }
Ejemplo n.º 13
0
        public void ObtainOwnedPurchases()
        {
            if (iapAvailable != true)
            {
                OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE);
                return;
            }


            Debug.Log("[HMSIAPManager] ObtainOwnedPurchaseRequest");
            ObtainOwnedPurchases(new OwnedPurchasesReq()
            {
                PriceType = PriceType.IN_APP_CONSUMABLE
            });
            ObtainOwnedPurchases(new OwnedPurchasesReq()
            {
                PriceType = PriceType.IN_APP_NONCONSUMABLE
            });
            ObtainOwnedPurchases(new OwnedPurchasesReq()
            {
                PriceType = PriceType.IN_APP_SUBSCRIPTION
            });
        }
Ejemplo n.º 14
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);
            });
        }
Ejemplo n.º 15
0
        public void InternalBuyProduct(ProductInfo productInfo, bool consumeAfter = true, string payload = "")
        {
            if (iapAvailable != true)
            {
                OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE);
                return;
            }

            PurchaseIntentReq purchaseIntentReq = new PurchaseIntentReq
            {
                PriceType        = productInfo.PriceType,
                ProductId        = productInfo.ProductId,
                DeveloperPayload = payload
            };

            ITask <PurchaseIntentResult> task = iapClient.CreatePurchaseIntent(purchaseIntentReq);

            task.AddOnSuccessListener((result) =>
            {
                if (result != null)
                {
                    Debug.Log("[HMSIAPManager]:" + result.ErrMsg + result.ReturnCode.ToString());
                    Debug.Log("[HMSIAPManager]: Buying " + purchaseIntentReq.ProductId);
                    Status status = result.Status;
                    status.StartResolutionForResult((androidIntent) =>
                    {
                        PurchaseResultInfo purchaseResultInfo = iapClient.ParsePurchaseResultInfoFromIntent(androidIntent);

                        if (purchaseResultInfo.ReturnCode == OrderStatusCode.ORDER_STATE_SUCCESS)
                        {
                            Debug.Log("[HMSIAPManager] HMSInAppPurchaseData" + purchaseResultInfo.InAppPurchaseData);
                            Debug.Log("[HMSIAPManager] HMSInAppDataSignature" + purchaseResultInfo.InAppDataSignature);
                            OnBuyProductSuccess.Invoke(purchaseResultInfo);
                            if (consumeAfter)
                            {
                                ConsumePurchase(purchaseResultInfo);
                            }
                        }
                        else
                        {
                            switch (purchaseResultInfo.ReturnCode)
                            {
                            case OrderStatusCode.ORDER_STATE_CANCEL:
                                Debug.LogError("[HMSIAPManager] User cancel payment");
                                break;

                            case OrderStatusCode.ORDER_STATE_FAILED:
                                Debug.LogError("[HMSIAPManager] order payment failed");
                                break;

                            case OrderStatusCode.ORDER_PRODUCT_OWNED:
                                Debug.LogError("[HMSIAPManager] Product owned");
                                break;

                            default:
                                Debug.LogError("[HMSIAPManager] BuyProduct failed. ReturnCode: " + purchaseResultInfo.ReturnCode + ", ErrorMsg: " + purchaseResultInfo.ErrMsg);
                                break;
                            }
                            OnBuyProductFailure?.Invoke(purchaseResultInfo.ReturnCode);
                        }
                    }, (exception) =>
                    {
                        Debug.LogError("[HMSIAPManager] startIntent ERROR");
                    });
                }
            }).AddOnFailureListener((exception) =>
            {
                Debug.LogError("[HMSIAPManager]: BuyProduct failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage);
            });
        }