private void HandleIapResult(PurchaseIAPResult iapResult, Promise <BuyItemResult> promise) { BuyItemResultCode resultCode = (iapResult.result == PurchaseIAPResultCode.Success) ? BuyItemResultCode.Success : BuyItemResultCode.InAppPurchaseFailed; var buyItemResult = new BuyItemResult(resultCode, iapResult); promise.Resolve(buyItemResult); }
private BuyItemResult BuyItemWithVC(ItemConfigData itemConfigData) { var result = new BuyItemResult(BuyItemResultCode.Error); if (itemConfigData.costs.Count > 0) { result = BuyItemByCosts(itemConfigData); } else if (itemConfigData.alternativeCosts.Count > 0) { result = BuyItemByAlternativeCosts(itemConfigData); } return(result); }
public IPromise <BuyItemResult> BuyItem(string itemId, CurrencyType currencyType = CurrencyType.AutoDetect) { var promise = new Promise <BuyItemResult>(); ItemConfigData itemData = itemConfigModel.GetItem(itemId); if (currencyType == CurrencyType.HardCurrency) { BuyItemByIAP(itemId, promise); return(promise); } if (currencyType == CurrencyType.VirtualCurrency) { BuyItemResult result = BuyItemWithVC(itemData); promise.Resolve(result); return(promise); } // Auto detect virtual currency or hard currency; if (itemConfigModel.HasAnyCosts(itemData)) { BuyItemResult result = BuyItemWithVC(itemData); promise.Resolve(result); } else if (itemConfigModel.IsInAppItem(itemData)) { BuyItemByIAP(itemId, promise); } else { Debug.LogError("Attempted to purchase an item with no defined costs"); promise.Resolve(new BuyItemResult(BuyItemResultCode.Error)); } return(promise); }