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

74 lines
1.9 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 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)
{
_helper.ConsumableGoods = consumableGoods;
_helper.NonConsumableGoods = nonConsumableGoods;
_helper.OnRestorePurchase = onRestorePurchase;
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);
}
}