NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/IAP/IAPManager.cs

97 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using PhxhSDK;
using Framework;
using Gameplay.Net;
using cfg.ChargeCfg;
using System.Collections.Generic;
public class IAPManager : Singlenton<IAPManager>
{
private IAPHandle _helper;
private const uint RepeatableCode = 40007;
private CurrencyShopCfg _cfg;
public Dictionary<string, int> ProductDic;
public void Init()
{
_helper = new IAPHandle();
ProductDic = new Dictionary<string, int>();
_cfg = TableManager.Instance.Tables.CurrencyShopCfg;
ShopManager.Instance.InitIAP();
}
public void Release()
{
ProductDic = null;
}
public bool OwnedNonConsumableGood(string productID)
{
if (ProductDic.TryGetValue(productID, out var id))
{
return Actor.Instance.Purchase.GetPurchaseCount((uint)id) > 0;
}
return false;
}
/// <summary>
/// 添加商品并初始化IAP
/// </summary>
public void AddGoods(List<string> consumableGoods, List<string> nonConsumableGoods,
Action<string> onBreakPurchase = null)
{
_helper.ConsumableGoods = consumableGoods;
_helper.NonConsumableGoods = nonConsumableGoods;
_helper.OnBreakPurchase = onBreakPurchase;
try
{
_helper.InitIap();
}
catch (Exception e)
{
DebugUtil.LogError("Add Goods Failed, Error: {0}", e.Message);
}
}
/// <summary>
/// 购买商品
/// </summary>
public void BuyGoods(string goodsName, string actorId, Action<string> onPurchaseSuccess, Action onPurchaseFail)
{
_helper.BuyGoods(goodsName, actorId, onPurchaseSuccess, onPurchaseFail);
}
/// <summary>
/// 设为客户端验证凭证
/// </summary>
public void SetClientVerify(bool clientVerify = false)
{
_helper.ClientVerify = clientVerify;
}
/// <summary>
/// 恢复购买 TODO待测试
/// </summary>
public void RestorePurchase(Action<List<string>> restorePurchase)
{
_helper.RestorePurchase(restorePurchase);
}
/// <summary>
/// 购买成功回掉函数
/// </summary>
public void OnReceiveReceipt(Action<string> onResult)
{
_helper.SendReceiptAction = onResult;
}
/// <summary>
/// 服务器验证成功后操作
/// </summary>
public void ReceiveServerReceipt(string receipt)
{
_helper.RemovePendingOrder(receipt);
}
}