107 lines
4.8 KiB
C#
107 lines
4.8 KiB
C#
|
#if UNITY_PURCHASE
|
||
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.Purchasing;
|
||
|
|
||
|
namespace WZ
|
||
|
{
|
||
|
public class IAPSubscribeManager : D_MonoSingleton<IAPSubscribeManager>
|
||
|
{
|
||
|
public Dictionary<string, Dictionary<string, object>> _productArgs = new Dictionary<string, Dictionary<string, object>>();
|
||
|
|
||
|
public void CheckSubscribeDataByProductId(string productId)
|
||
|
{
|
||
|
if (_productArgs.ContainsKey(productId))
|
||
|
{
|
||
|
CheckOrderFromServer(_productArgs[productId],productId);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
RushSDKManager.Instance.OnSubscriptionQueriedByProductId?.Invoke(productId,new SubscribeInfo(-1, "", "", "", -1, -1, -1, -1, -1, "", "", "", ""));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void CheckOrderFromServer(Dictionary<string, object> args,string productId)
|
||
|
{
|
||
|
if (args.Count > 0)
|
||
|
{
|
||
|
ServerMgr.Instance.CheckOrder(args, (code, msg, data) =>
|
||
|
{
|
||
|
LoggerUtils.Debug("[iap] ===>CheckOrderFromServer code:"+code+ " illegal_order:"+data.illegal_order + " illegal_msg:" + data.illegal_msg+ " environment:"+data.environment+
|
||
|
" purchase_time"+data.purchase_time+ " is_subscribed"+ data.is_subscribed+ " is_expired"+data.is_expired+ " is_cancelled:"+ data.is_cancelled+ " is_free_trial:"+
|
||
|
data.is_free_trial+ " is_auto_renewing:"+data.is_auto_renewing+ " remaining_time:"+data.remaining_time+ " expire_time:"+data.expiry_time+ " latest_order_id:"+data.latest_order_id+ " productId:"+ args["product_id"].ToString());
|
||
|
|
||
|
SubscribeInfo resultData = new SubscribeInfo(
|
||
|
data.illegal_order,
|
||
|
data.illegal_msg,
|
||
|
data.environment,
|
||
|
data.purchase_time,
|
||
|
data.is_subscribed,
|
||
|
data.is_expired,
|
||
|
data.is_cancelled,
|
||
|
data.is_free_trial,
|
||
|
data.is_auto_renewing,
|
||
|
data.remaining_time,
|
||
|
data.expiry_time,
|
||
|
data.latest_order_id,
|
||
|
args["product_id"].ToString()
|
||
|
);
|
||
|
|
||
|
RushSDKManager.Instance.OnSubscriptionQueriedByProductId?.Invoke(args["product_id"].ToString(), resultData);
|
||
|
});
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
RushSDKManager.Instance.OnSubscriptionQueriedByProductId?.Invoke(productId,new SubscribeInfo(-1, "", "", "", -1, -1, -1, -1, -1, "", "", "", ""));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void CheckSubscribeReceipt()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
foreach (var product in IAPPurchaseManager.Instance._storeController.products.all)
|
||
|
{
|
||
|
if (product.availableToPurchase)
|
||
|
{
|
||
|
if (product.receipt != null)
|
||
|
{
|
||
|
if (product.definition.type == ProductType.Subscription)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
IAPGoogleJsonInfo.GooglePurchaseData data = new IAPGoogleJsonInfo.GooglePurchaseData(product.receipt);
|
||
|
var args = new Dictionary<string, object>
|
||
|
{
|
||
|
{ "product_type", "Subscription" },
|
||
|
{ "product_id", data.json.productId },
|
||
|
{ "order_id", data.json.orderId },
|
||
|
{ "currency", product.metadata.isoCurrencyCode },
|
||
|
{ "price", product.metadata.localizedPrice.ToString() },
|
||
|
{ "purchase_token", data.json.purchaseToken },
|
||
|
{ "payment_method", "googleplay" }
|
||
|
};
|
||
|
if (!_productArgs.ContainsKey(data.json.productId))
|
||
|
{
|
||
|
_productArgs.Add(data.json.productId, args);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
_productArgs[data.json.productId] = args;
|
||
|
}
|
||
|
}
|
||
|
catch (Exception e) { }
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
catch (Exception exp) { }
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|