diff --git a/Runtime/GuruIAP/Runtime/Code/IAPServiceBase.cs b/Runtime/GuruIAP/Runtime/Code/IAPServiceBase.cs index 92ff0d0..270055b 100644 --- a/Runtime/GuruIAP/Runtime/Code/IAPServiceBase.cs +++ b/Runtime/GuruIAP/Runtime/Code/IAPServiceBase.cs @@ -547,38 +547,38 @@ namespace Guru string productId = purchaseEvent.purchasedProduct.definition.id; ProductInfo info = GetInfoById(productId); bool success = false; - + string productName = ""; if (null != info) { - 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); success = true; + productName = info.Name; + PurchaseCount++; // 记录支付次数 + Debug.Log($"############ ProcessPurchase: PurchaseCount:{PurchaseCount}"); + if (_curPurchasingProduct != null) + { + _curPurchasingProduct = null; // 只有实际发生购买后才会有订单上报. 启动时的 Restore 操作自动调用支付成功. 这里做一个判定, 过滤掉订单的物品 + + 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); + ReportPurchaseResult(purchaseEvent); // 支付结果上报 + } + + var pp = purchaseEvent.purchasedProduct; + if ( pp == null || string.IsNullOrEmpty(pp.receipt)) + { + string msg = $"{Tag} --- Purchased product is null or has no receipt!!"; + Debug.LogError(msg); + Crashlytics.LogException(new Exception(msg)); + } + else + { + OnGetProductReceipt?.Invoke(pp.definition.id, pp.receipt, pp.appleProductIsRestored); + } SetIsIAPUser(success); // 设置用户属性标记 } - PurchaseCount++; // 记录支付次数 - Debug.Log($"############ ProcessPurchase: PurchaseCount:{PurchaseCount}"); - if (_curPurchasingProduct != null) - { - _curPurchasingProduct = null; // 只有实际发生购买后才会有订单上报. 启动时的 Restore 操作自动调用支付成功. 这里做一个判定, 过滤掉订单的物品 - ReportPurchaseResult(purchaseEvent); // 支付结果上报 - } - - var pp = purchaseEvent.purchasedProduct; - if ( pp == null || string.IsNullOrEmpty(pp.receipt)) - { - string msg = $"{Tag} --- Purchased product is null or has no receipt!!"; - Debug.LogError(msg); - Crashlytics.LogException(new Exception(msg)); - } - else - { - OnGetProductReceipt?.Invoke(pp.definition.id, pp.receipt, pp.appleProductIsRestored); - } - - string productName = info?.Name ?? "NULL"; LogI($"{Tag} --- OnPurchaseSuccess :: purchase count: {PurchaseCount} productName: {productName}"); OnPurchaseOver(success, productName); // 支付成功处理逻辑