update: 为 IAP Service 添加 Category 值
							parent
							
								
									fdf1dd7c0e
								
							
						
					
					
						commit
						ed41a44758
					
				|  | @ -37,6 +37,7 @@ namespace Guru | |||
|         public bool IsInitialized => _storeController != null && _storeExtensionProvider != null; | ||||
| 
 | ||||
|         private Product _curPurchasingProduct = null; | ||||
|         private string _curProductCategory = ""; | ||||
| 
 | ||||
|         private IAPModel _model; | ||||
|         /// <summary> | ||||
|  | @ -498,7 +499,7 @@ namespace Guru | |||
|         /// 购买商品 | ||||
|         /// </summary> | ||||
|         /// <param name="productName"></param> | ||||
|         public virtual T Buy(string productName) | ||||
|         public virtual T Buy(string productName, string category = "") | ||||
|         { | ||||
|             if (!IsInitialized) | ||||
|             { | ||||
|  | @ -522,12 +523,14 @@ namespace Guru | |||
|                     .Configure<IGooglePlayConfiguration>() | ||||
|                     .SetObfuscatedAccountId(IPMConfig.IPM_UID); | ||||
| #endif | ||||
|                 if (string.IsNullOrEmpty(category)) category = info.Category; | ||||
|                 _storeController.InitiatePurchase(product); | ||||
| 
 | ||||
|                 Analytics.IAPClick(info?.Category??"none", product.definition.id); | ||||
|                 Analytics.IAPImp(DefaultCategory, product.definition.id); | ||||
| 
 | ||||
|                 _curPurchasingProduct = product; | ||||
|                 _curProductCategory = category; | ||||
|                  | ||||
|                 Analytics.IAPClick(_curProductCategory, product.definition.id); | ||||
|                 Analytics.IAPImp(_curProductCategory, product.definition.id); | ||||
| 
 | ||||
| 
 | ||||
|                 OnBuyStart?.Invoke(productName); | ||||
|                 return (T)this; | ||||
|  | @ -557,17 +560,17 @@ namespace Guru | |||
|             { | ||||
|                 if (IsFirstIAP) Analytics.FirstIAP(info.Id, info.Price, info.CurrencyCode); // 上报首次支付打点 | ||||
|                 Analytics.ProductIAP(info.Id,info.Id, info.Price, info.CurrencyCode); | ||||
|                 Analytics.IAPRetTrue(info.Category, info.Id, info.Price, info.CurrencyCode, info.Type, info.IsFree); | ||||
|                 Analytics.IAPRetTrue(_curProductCategory, info.Id, info.Price, info.CurrencyCode, info.Type, info.IsFree); | ||||
|                 success = true; | ||||
|                  | ||||
|                 SetIsIAPUser(success); // 设置用户属性标记 | ||||
|             } | ||||
|              | ||||
|             PurchaseCount++; // 记录支付次数 | ||||
|             Debug.Log($"############ ProcessPurchase: PurchaseCount:{PurchaseCount}"); | ||||
|             // Debug.Log($"############ ProcessPurchase: PurchaseCount:{PurchaseCount}"); | ||||
|             if (_curPurchasingProduct != null) | ||||
|             { | ||||
|                 _curPurchasingProduct = null; // 只有实际发生购买后才会有订单上报.  启动时的 Restore 操作自动调用支付成功. 这里做一个判定, 过滤掉订单的物品 | ||||
|                 // 只有实际发生购买后才会有订单上报.  启动时的 Restore 操作自动调用支付成功. 这里做一个判定, 过滤掉订单的物品 | ||||
|                 ReportPurchaseResult(purchaseEvent); // 支付结果上报 | ||||
|             } | ||||
|              | ||||
|  | @ -589,6 +592,8 @@ namespace Guru | |||
|             OnPurchaseOver(success, productName); // 支付成功处理逻辑 | ||||
|             OnBuyEnd?.Invoke(productName, success); | ||||
|              | ||||
|             ClearCurPurchasingProduct(); // 清除购买缓存 | ||||
|              | ||||
|             return PurchaseProcessingResult.Complete; // 直接Consume 掉当前的商品 | ||||
|         } | ||||
| 
 | ||||
|  | @ -606,11 +611,11 @@ namespace Guru | |||
|             //上报点位,用户购买失败的原因 | ||||
|             if (failureReason == PurchaseFailureReason.UserCancelled) | ||||
|             { | ||||
|                 Analytics.IAPClose(info.Category, product.definition.id); | ||||
|                 Analytics.IAPClose(_curProductCategory, product.definition.id); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 Analytics.IAPRetFalse(info.Category, product.definition.id, failureReason.ToString()); | ||||
|                 Analytics.IAPRetFalse(_curProductCategory, product.definition.id, failureReason.ToString()); | ||||
|             } | ||||
| 
 | ||||
|             LogI($"{Tag} --- OnPurchaseFailed :: failureReason = {failureReason}"); | ||||
|  | @ -619,6 +624,13 @@ namespace Guru | |||
|             OnBuyEnd?.Invoke(info.Name, false); | ||||
|             // 失败原因 | ||||
|             OnBuyFailed?.Invoke(info.Name, failureReason.ToString()); | ||||
|             ClearCurPurchasingProduct(); // 清除购买缓存 | ||||
|         } | ||||
|          | ||||
|         private void ClearCurPurchasingProduct() | ||||
|         { | ||||
|             _curPurchasingProduct = null; | ||||
|             _curProductCategory = ""; | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue