Project_WL/Assets/Scripts/Purchase/GaaIapCallManager.cs

198 lines
10 KiB
C#
Raw Normal View History

2024-12-15 01:39:39 +00:00
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Gaa
{
public class GaaIapCallManager
{
private static string TAG = "GaaIapCallManager";
private static AndroidJavaObject iapRequestAdapter = null;
private static AndroidJavaClass jc = null;
private static bool isServiceCreated = false;
static void ServiceAvailableEvent(bool value)
{
isServiceCreated = value;
}
public static bool IsServiceAvailable()
{
return isServiceCreated;
}
/*
*
*/
public static void CheckServiceAvailable()
{
if (isServiceCreated == false) {
AndroidNative.ShowMessage("Warning!!", "Press Init Helper to Create Service", "ok");
throw new System.Exception ("No Service Created");
}
}
/*
* GameObject GaaCallbackManager registerCallbackGameObject .
*/
static GaaIapCallManager()
{
GaaIapCallbackManager.ServiceAvailableEvent += ServiceAvailableEvent; //example의 GaaCallbackManager 콜백 등록
jc = new AndroidJavaClass("com.gaa.iap.sdk.unity.IapPlugin");
iapRequestAdapter = jc.CallStatic<AndroidJavaObject>("initialize", "GaaIapCallbackManager");
}
~GaaIapCallManager()
{
GaaIapCallbackManager.ServiceAvailableEvent -= ServiceAvailableEvent; //example의 GaaCallbackManager 콜백 해지
}
/*
* IapPlugin , .
* public key는 .
*/
public static void StartConnection(string publicKey)
{
iapRequestAdapter.Call("startConnection", publicKey);
}
/*
* API를 (inapp) (auto) .
*
* , .
* (getPurchases) (consume) .
*
* (inapp) .
* (inapp) , life cycle (consume) .
*
* (auto) recurringState . -> recurringState 0( ), 1( )
* manageRecurringProduct API를 recurringState는 0 -> 1 . recurringState는 1 -> 0 .
*/
public static void QueryPurchases(string type)
{
CheckServiceAvailable();
iapRequestAdapter.Call("queryPurchases", type);
}
/*
* . ID를 String .
*/
public static void QueryProductDetails (string[] products, string productType)
{
string productStr = String.Join(", ", new List<string>(products).ConvertAll(i => i.ToString()).ToArray());
CheckServiceAvailable();
iapRequestAdapter.Call("queryProductDetails", new object[]{ products, productType });
}
/*
* .
*
* payload:
* Payload .
* Developer Payload .
* Payload Freedom , Payload .
* Developer Payload는 100byte까지 .
* payload를 .
*
* gameUserId, promotionApplicable는 default ("" , false) .
* 1. gameUserId:
* . key value로 .
* 2. promotionApplicable:
* . true : gameUserId로 1 . false : gameUserId로 .
* 3. productName:
* . ("") . .
*
* (inapp) consume을 .
* (auto) manageRecurringAuto를 .
*/
public static void LaunchPurchaseFlow(PurchaseFlowParams param)
{
CheckServiceAvailable();
string json = JsonUtility.ToJson(param);
iapRequestAdapter.Call("launchPurchaseFlow", json);
}
/*
* (inapp) .
* (consume) .
*/
public static void Consume(PurchaseData purchaseData, string devPayload)
{
CheckServiceAvailable();
string purchaseJson = JsonUtility.ToJson(purchaseData);
iapRequestAdapter.Call("consume", purchaseJson, devPayload);
}
/*
* (inapp)
* (consume) (acknowledge) .
*
* (auto)
* (acknowledge) .
*/
public static void Acknowledge(PurchaseData purchaseData, string devPayload)
{
CheckServiceAvailable();
string purchaseJson = JsonUtility.ToJson(purchaseData);
iapRequestAdapter.Call("acknowledge", purchaseJson, devPayload);
}
/*
* (auto) ( / ) .
* - purchaseData : PurchaseData json data
* (auto) recurringState . -> recurringState 0( ), 1( )
*
* (auto) 11 10 recurringState는 0( ) .
* (12 10) 11 10 ~ 12 9 .
* 11 15 API를 (cancel) , 12 9 (recurringState) 1( ) .
* 12 9 API를 (reactivate) , (recurringState) 0( ) .
*/
public static void ManageRecurringProduct(PurchaseData purchaseData, string recurringAction)
{
CheckServiceAvailable();
string purchaseJson = JsonUtility.ToJson(purchaseData);
iapRequestAdapter.Call("manageRecurringProduct", purchaseJson, recurringAction);
}
/*
* (Purchase Service) .
* . .
*/
public static void LaunchUpdateOrInstallFlow()
{
iapRequestAdapter.Call("launchUpdateOrInstallFlow");
}
/*
* launchLoginFlow API를 .
* launchLoginFlow API를 UI적으로 PurchaseService .
* flow를 .
*/
public static void LaunchLoginFlow()
{
iapRequestAdapter.Call("launchLoginFlow");
}
/*
* .
*/
public static void GetStoreInfo()
{
iapRequestAdapter.Call("getStoreInfo");
}
/*
* IapPlugin을 Destroy하며, .
*/
public static void Destroy()
{
iapRequestAdapter.Call("endConnection");
isServiceCreated = false;
}
}
}