From c3413747485ffce57b5fdfd5bb0b1a3948f2bfc3 Mon Sep 17 00:00:00 2001 From: huyufei Date: Mon, 18 Mar 2024 11:04:24 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E4=BF=AE=E5=A4=8D=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E8=B4=AD=E4=B9=B0=E5=90=8E,=20=E7=94=B1=E4=BA=8E=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E4=BA=86ProcessPurchase=20=E5=9B=9E=E8=B0=83=E8=80=8C?= =?UTF-8?q?=E4=B8=8A=E6=8A=A5=E4=BA=86=E9=A2=84=E6=9C=9F=E5=A4=96=E7=9A=84?= =?UTF-8?q?=20iap=5Fret=5Ftrue=20=E5=92=8C=20first=5Fiap=20=E7=AD=89?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GuruIAP/Runtime/Code/IAPServiceBase.cs | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/Runtime/GuruIAP/Runtime/Code/IAPServiceBase.cs b/Runtime/GuruIAP/Runtime/Code/IAPServiceBase.cs index c23475d..5edcf53 100644 --- a/Runtime/GuruIAP/Runtime/Code/IAPServiceBase.cs +++ b/Runtime/GuruIAP/Runtime/Code/IAPServiceBase.cs @@ -530,8 +530,7 @@ namespace Guru Analytics.IAPClick(_curProductCategory, product.definition.id); Analytics.IAPImp(_curProductCategory, product.definition.id); - - + OnBuyStart?.Invoke(productName); return (T)this; } @@ -555,43 +554,48 @@ 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(_curProductCategory, info.Id, info.Price, info.CurrencyCode, info.Type, info.IsFree); success = true; - + productName = info.Name; SetIsIAPUser(success); // 设置用户属性标记 - } - - PurchaseCount++; // 记录支付次数 - // Debug.Log($"############ ProcessPurchase: PurchaseCount:{PurchaseCount}"); - if (_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); - Analytics.LogCrashlytics(new Exception(msg)); + if (_curPurchasingProduct != null) + { + ReportPurchaseResult(purchaseEvent); // 订单上报 + + // 真实购买后上报对应的事件 + if (IsFirstIAP) Analytics.FirstIAP(info.Id, info.Price, info.CurrencyCode); // 上报首次支付打点 + Analytics.ProductIAP(info.Id,info.Id, info.Price, info.CurrencyCode); + Analytics.IAPRetTrue(_curProductCategory, info.Id, info.Price, info.CurrencyCode, info.Type, info.IsFree); + } + + 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); + Analytics.LogCrashlytics(new Exception(msg)); + } + else + { + OnGetProductReceipt?.Invoke(pp.definition.id, pp.receipt, pp.appleProductIsRestored); + } + + LogI($"{Tag} --- OnPurchaseSuccess :: purchase count: {PurchaseCount} productName: {productName}"); + PurchaseCount++; // 记录支付次数 } else { - OnGetProductReceipt?.Invoke(pp.definition.id, pp.receipt, pp.appleProductIsRestored); + string msg = $"{Tag} --- Purchased end, but can't find ProductInfo with ID: {productId}"; + Debug.LogError(msg); + Analytics.LogCrashlytics(new Exception(msg)); } - string productName = info?.Name ?? "NULL"; - LogI($"{Tag} --- OnPurchaseSuccess :: purchase count: {PurchaseCount} productName: {productName}"); - - OnPurchaseOver(success, productName); // 支付成功处理逻辑 OnBuyEnd?.Invoke(productName, success); - + OnPurchaseOver(success, productName); // 支付成功处理逻辑 ClearCurPurchasingProduct(); // 清除购买缓存 return PurchaseProcessingResult.Complete; // 直接Consume 掉当前的商品