提交
This commit is contained in:
@@ -3,23 +3,19 @@ using System;
|
||||
using DG.Tweening;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using UnityEngine.Purchasing;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using ScrewsMaster;
|
||||
|
||||
|
||||
public class PurchasingManager : IStoreListener
|
||||
public class PurchasingManager
|
||||
{
|
||||
public static readonly PurchasingManager Instance = new PurchasingManager();
|
||||
private IStoreController storeController;
|
||||
private static IExtensionProvider extensionProvider;
|
||||
private static IAppleExtensions appleExtension;
|
||||
|
||||
//private static IGooglePlayStoreExtensions googleExtension;
|
||||
|
||||
private Action<string> failedCallback;
|
||||
private Action<Product> successedCallback;
|
||||
|
||||
private ApplePayClass applePayData;
|
||||
|
||||
@@ -34,26 +30,7 @@ public class PurchasingManager : IStoreListener
|
||||
/// </summary>
|
||||
public void InitProduct()
|
||||
{
|
||||
Debug.Log("[barry] InitProduct111;;;;;;;;;;;;;;;;;;;");
|
||||
if (IsInitialized()) return;
|
||||
Debug.Log("[barry] InitProduct222;;;;;;;;;;;;;;;;;;;");
|
||||
var module = StandardPurchasingModule.Instance();
|
||||
ConfigurationBuilder builder = ConfigurationBuilder.Instance(module);
|
||||
builder.AddProduct(buy_one, ProductType.Consumable); //买格子
|
||||
|
||||
builder.AddProduct(buy_gold_1, ProductType.Consumable);//购买金币
|
||||
builder.AddProduct(buy_gold_2, ProductType.Consumable);
|
||||
builder.AddProduct(buy_gold_3, ProductType.Consumable);
|
||||
builder.AddProduct(buy_gold_4, ProductType.Consumable);
|
||||
builder.AddProduct(buy_gold_5, ProductType.Consumable);
|
||||
builder.AddProduct(remove_ad, ProductType.Consumable);//移出广告
|
||||
|
||||
builder.AddProduct(battle_pass, ProductType.Consumable);//战令解锁
|
||||
|
||||
builder.AddProduct(pack_reward, ProductType.Consumable);//奖励礼包
|
||||
builder.AddProduct(fail_pack, ProductType.Consumable);//奖励礼包
|
||||
builder.AddProduct(three_days_gift, ProductType.Consumable);//三天礼包
|
||||
UnityPurchasing.Initialize(this, builder);
|
||||
}
|
||||
|
||||
public const string buy_one = "com.twistturn.space.24.99";
|
||||
@@ -132,39 +109,7 @@ public class PurchasingManager : IStoreListener
|
||||
|
||||
private void ApplePay(ApplePayClass data_)
|
||||
{
|
||||
string _productId = data_.sku;
|
||||
|
||||
if (applePayData != null)
|
||||
{
|
||||
GameHelper.ShowTips("There are payments that are being processed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsInitialized())
|
||||
{
|
||||
OnFailedCallback("Not initialized.");
|
||||
return;
|
||||
}
|
||||
var product = storeController.products.WithID(_productId);
|
||||
if (product == null || !product.availableToPurchase)
|
||||
{
|
||||
OnFailedCallback("Either is not found or is not available for purchase");
|
||||
return;
|
||||
}
|
||||
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PayloadingUI_Open);
|
||||
|
||||
applePayData = data_;
|
||||
|
||||
storeController.InitiatePurchase(product);
|
||||
|
||||
NetworkKit.PostWithHeader<ApplePayClass>("shop/applePayCreate", applePayData, (isSuccess, obj) =>
|
||||
{
|
||||
if (isSuccess)
|
||||
{
|
||||
applePayData.innerOrderId = obj.innerOrderId;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//private List<Product> product_list = new List<Product>();
|
||||
@@ -176,91 +121,13 @@ public class PurchasingManager : IStoreListener
|
||||
/// <param name="restoreCallback">恢复回调</param>
|
||||
public void IosRestore(Action<bool, string> restoreCallback)
|
||||
{
|
||||
if (appleExtension != null)
|
||||
{
|
||||
appleExtension.RestoreTransactions((success, message) =>
|
||||
{
|
||||
restoreCallback(success, message);
|
||||
if (!success)
|
||||
{
|
||||
Debug.LogWarning($"[barry] Restore transactions failed: {message}");
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[barry] IAppleExtensions is null");
|
||||
restoreCallback(false, "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//======================================分割线=========================================
|
||||
|
||||
|
||||
public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
|
||||
{
|
||||
Debug.Log("[barry] OnInitialized-----------w-");
|
||||
storeController = controller;
|
||||
extensionProvider = extensions;
|
||||
appleExtension = extensions.GetExtension<IAppleExtensions>();
|
||||
|
||||
//googleExtension = extensions.GetExtension<IGooglePlayStoreExtensions>();
|
||||
}
|
||||
|
||||
|
||||
public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
|
||||
{
|
||||
Debug.Log("[barry] uuuuuuuuuuuuuuuuuuuu" + product.transactionID);
|
||||
if (applePayData == null) return;
|
||||
|
||||
Debug.Log("[barry] applePayData.sku" + applePayData.sku);
|
||||
|
||||
if (applePayData.sku == buy_one)
|
||||
{
|
||||
NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, BuriedPointEvent.buy_one_open, 1);
|
||||
}
|
||||
else if (applePayData.sku == remove_ad)
|
||||
{
|
||||
NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, BuriedPointEvent.remove_ad_open, 1);
|
||||
}
|
||||
else if (applePayData.sku == pack_reward)
|
||||
{
|
||||
NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, BuriedPointEvent.pack_open, 1);
|
||||
}
|
||||
else if (applePayData.shopName != null && applePayData.shopName.StartsWith("buy_gold"))
|
||||
{
|
||||
int startIndex = "buy_gold".Length;
|
||||
string suffix = applePayData.shopName[startIndex..]; // 截取 "gold" 后的所有字符
|
||||
string eventOpenName = $"gold_open_{suffix}";
|
||||
// string eventSuccessName = $"gold_success_{suffix}";
|
||||
|
||||
NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, eventOpenName, 1);
|
||||
}
|
||||
else if (applePayData.sku == battle_pass)
|
||||
{
|
||||
NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, BuriedPointEvent.pass_open, 1);
|
||||
}
|
||||
else if (applePayData.sku == fail_pack)
|
||||
{
|
||||
NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, BuriedPointEvent.fail_open, 1);
|
||||
}
|
||||
else if (applePayData.sku == three_days_gift)
|
||||
{
|
||||
NetworkKit.BuriedPoint(BuriedPointEvent.Apple_pay_event, BuriedPointEvent.three_days_gift_open, 1);
|
||||
}
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PayloadingUI_Close);
|
||||
Debug.LogWarning("[barry] OnPurchaseFailedproduct:" + product.transactionID + " failureReason:" + failureReason);
|
||||
|
||||
var failData = new checkData();
|
||||
failData.innerOrderId = applePayData.innerOrderId;
|
||||
NetworkKit.PostWithHeader<ApplePayClass>("shop/applePayCancel", failData, (isSuccess, obj) =>
|
||||
{
|
||||
Debug.Log("[barry] applePayCancel:" + isSuccess);
|
||||
|
||||
applePayData = null;
|
||||
});
|
||||
}
|
||||
|
||||
public void SaveApplePayData(Dictionary<string, ApplePayClass> payData)
|
||||
{
|
||||
@@ -269,31 +136,7 @@ public class PurchasingManager : IStoreListener
|
||||
|
||||
}
|
||||
|
||||
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs purchaseEvent)
|
||||
{
|
||||
Debug.Log("[barry] gggggggggggggggggggggggggggggggg" + purchaseEvent.purchasedProduct.transactionID);
|
||||
|
||||
var payDataJson = PlayerPrefs.GetString("apple_pay_data", "{}");
|
||||
Debug.Log($"[barry]1111111 payDataJson ==== {payDataJson}");
|
||||
var statusDictionary = JsonConvert.DeserializeObject<Dictionary<string, ApplePayClass>>(payDataJson);
|
||||
if (!statusDictionary.ContainsKey(purchaseEvent.purchasedProduct.transactionID))
|
||||
{
|
||||
if (applePayData == null)
|
||||
{
|
||||
Debug.Log("[barry] applePayClass is null");
|
||||
return PurchaseProcessingResult.Complete;
|
||||
}
|
||||
statusDictionary.Add(purchaseEvent.purchasedProduct.transactionID, applePayData);
|
||||
SaveApplePayData(statusDictionary);
|
||||
applePayData = null;
|
||||
}
|
||||
Debug.Log($"[barry]2222222 payDataJson ==== {payDataJson}");
|
||||
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PayloadingUI_Open);
|
||||
|
||||
ApplePaySuccess(purchaseEvent.purchasedProduct.transactionID);
|
||||
|
||||
return PurchaseProcessingResult.Complete;
|
||||
}
|
||||
|
||||
public void ApplePaySuccess(string transactionID)
|
||||
{
|
||||
@@ -428,11 +271,7 @@ public class PurchasingManager : IStoreListener
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsInitialized()
|
||||
{
|
||||
Debug.Log("[barry 10]IsInitialized======:");
|
||||
return storeController != null && extensionProvider != null;
|
||||
}
|
||||
|
||||
|
||||
private void OnFailedCallback(string _reason)
|
||||
{
|
||||
@@ -443,17 +282,6 @@ public class PurchasingManager : IStoreListener
|
||||
}
|
||||
}
|
||||
|
||||
public void OnInitializeFailed(InitializationFailureReason error, string message)
|
||||
{
|
||||
Debug.Log("[barry] OnInitializeFailed Reason:" + error);
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void OnInitializeFailed(InitializationFailureReason error)
|
||||
{
|
||||
Debug.Log("[barry] OnInitializeFailed Reason:" + error);
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user