From 3ef3807253256108a5fef00e181cb91f1d9f2064 Mon Sep 17 00:00:00 2001 From: huyufei Date: Mon, 18 Mar 2024 14:51:12 +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 | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) 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); // 支付成功处理逻辑