Forest_Client/Forest/Assets/Scripts/Gameplay/IAP/IAPManager.cs

74 lines
1.9 KiB
C#
Raw Normal View History

2024-06-12 15:01:54 +08:00
using System;
using PhxhSDK;
using System.Collections.Generic;
public class IAPManager : Singlenton<IAPManager>
{
private IAPHandle _helper;
public void Init()
{
_helper = new IAPHandle();
}
/// <summary>
/// 添加商品并初始化IAP
/// </summary>
public void AddGoods(List<string> consumableGoods, List<string> nonConsumableGoods,
Action<string> onRestorePurchase = null)
2024-06-12 15:01:54 +08:00
{
_helper.ConsumableGoods = consumableGoods;
_helper.NonConsumableGoods = nonConsumableGoods;
_helper.OnRestorePurchase = onRestorePurchase;
2024-06-12 15:01:54 +08:00
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);
}
}