///初始化 ///註冊回調地址 public void InitKit(string prefabName) { Debug.Log("IAPKit:Init"); if (isAvailable) { IAPKit.Init(prefabName); } }
public void FinishTransactionByID(string transactionID) { Debug.Log("IAPKit:FinishTransactionByID " + transactionID); if (isAvailable) { IAPKit.FinishTransaction(transactionID); } }
///開始一個購買行為 public void StartPayment(string productId, int num, string username) { if (isAvailable) { String str = String.Format("{0}\t{1}\t{2}", productId, num, username); Debug.Log("IAPKit:StartPayment " + str); IAPKit.BuyProduct(str); } }
///是否可以有購買行為 public bool IsProductsAvailable() { bool ret = false; if (isAvailable) { ret = IAPKit.CanMakePayment(); } Debug.LogFormat("IAPKit:IsProductsAvailable {0}", ret); return(ret); }
///請求商品信息 public void StartProductsRequest(List <string> productIDs) { if (isAvailable) { string str = ""; for (int i = 0, n = productIDs.Count; i < n; i++) { str += productIDs[i] + "\t"; } Debug.Log("IAPKit:StartProductsRequest " + str); IAPKit.RequstProductInfo(str); } }
void Start() { iapKit = GetComponent <IAPKit>(); iapKit.OnPaymentComplete += (string transactionID, string username, string receipt) => { Debug.Log("OnPaymentComplete: " + transactionID); iapKit.FinishTransactionByID(transactionID); }; iapKit.OnPaymentFail += (string transactionID, string username) => { Debug.Log("OnPaymentFail: " + transactionID); iapKit.FinishTransactionByID(transactionID); }; iapKit.OnPaymentRestore += (string transactionID, string username) => { iapKit.FinishTransactionByID(transactionID); }; iapKit.OnProductsReqResponse += (string json) => { Debug.Log("OnProductsReqResponse: " + json); }; iapKit.InitKit("Main"); }