void OnGUI() { beginColumn(); if (GUILayout.Button("Get Can Make Payments")) { bool canMakePayments = StoreKitBinding.canMakePayments(); Debug.Log("StoreKit canMakePayments: " + canMakePayments); } if (GUILayout.Button("Request Product Data")) { // array of product ID's from iTunesConnect. MUST match exactly what you have there! var productIdentifiers = new string[] { "anotherProduct", "tt", "testProduct", "sevenDays", "oneMonthSubsciber" }; StoreKitBinding.requestProductData(productIdentifiers); } if (GUILayout.Button("Restore Completed Transactions")) { StoreKitBinding.restoreCompletedTransactions(); } endColumn(true); // enforce the fact that we can't purchase products until we retrieve the product data if (_products != null && _products.Count > 0) { if (GUILayout.Button("Purchase Random Product")) { var productIndex = Random.Range(0, _products.Count); var product = _products[productIndex]; Debug.Log("preparing to purchase product: " + product.productIdentifier); StoreKitBinding.purchaseProduct(product.productIdentifier, 1); } } else { GUILayout.Label("Once you successfully request product data a purchase button will appear here for testing"); } if (GUILayout.Button("Get Saved Transactions")) { List <StoreKitTransaction> transactionList = StoreKitBinding.getAllSavedTransactions(); // Print all the transactions to the console Debug.Log("\ntotal transaction received: " + transactionList.Count); foreach (StoreKitTransaction transaction in transactionList) { Debug.Log(transaction.ToString() + "\n"); } } if (GUILayout.Button("Turn Off Auto Confirmation of Transactions")) { // this is used when you want to validate receipts on your own server or when dealing with iTunes hosted content // you must manually call StoreKitBinding.finishPendingTransactions when the download/validation is complete StoreKitManager.autoConfirmTransactions = false; } if (GUILayout.Button("Cancel Downloads")) { StoreKitBinding.cancelDownloads(); } if (GUILayout.Button("Display App Store")) { StoreKitBinding.displayStoreWithProductId("305967442"); } endColumn(); }
void OnGUI() { return; if (GUILayout.Button("Get Can Make Payments")) { canMakePayments = StoreKitBinding.canMakePayments(); Debug.Log("StoreKit canMakePayments: " + canMakePayments); } if (GUILayout.Button("Get Product Data")) { // array of product ID's from iTunesConnect. MUST match exactly what you have there! var productIdentifiers = new string[] { "com.DMDEnterprise.kicktheballfree.100coins", "com.DMDEnterprise.kicktheballfree.200coins" }; StoreKitBinding.requestProductData(productIdentifiers); } if (GUILayout.Button("Restore Completed Transactions")) { StoreKitBinding.restoreCompletedTransactions(); } // enforce the fact that we can't purchase products until we retrieve the product data if (_products != null && _products.Count > 0) { if (GUILayout.Button("Purchase Random Product")) { var productIndex = Random.Range(0, _products.Count); var product = _products[productIndex]; Debug.Log("preparing to purchase product: " + product.productIdentifier); StoreKitBinding.purchaseProduct(product.productIdentifier, 1); } } if (GUILayout.Button("Get Saved Transactions")) { List <StoreKitTransaction> transactionList = StoreKitBinding.getAllSavedTransactions(); // Print all the transactions to the console Debug.Log("\ntotal transaction received: " + transactionList.Count); foreach (StoreKitTransaction transaction in transactionList) { Debug.Log(transaction.ToString() + "\n"); } } if (GUILayout.Button("Turn Off Auto Confirmation of Transactions")) { // this is used when you want to validate receipts on your own server or when dealing with iTunes hosted content // you must manually call StoreKitBinding.finishPendingTransactions when the download/validation is complete StoreKitManager.autoConfirmTransactions = false; } if (GUILayout.Button("Display App Store")) { StoreKitBinding.displayStoreWithProductId("305967442"); } }
void OnGUI() { float yPos = 5.0f; float xPos = 5.0f; float width = (Screen.width >= 960 || Screen.height >= 960) ? 320 : 160; float height = (Screen.width >= 960 || Screen.height >= 960) ? 80 : 40; float heightPlus = height + 10.0f; if (GUI.Button(new Rect(xPos, yPos, width, height), "Get Can Make Payments")) { bool canMakePayments = StoreKitBinding.canMakePayments(); Debug.Log("StoreKit canMakePayments: " + canMakePayments); } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Get Product Data")) { // array of product ID's from iTunesConnect. MUST match exactly what you have there! var productIdentifiers = new string[] { "anotherProduct", "tt", "testProduct", "sevenDays", "oneMonthSubsciber" }; StoreKitBinding.requestProductData(productIdentifiers); } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Restore Completed Transactions")) { StoreKitBinding.restoreCompletedTransactions(); } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Validate Receipt")) { // grab the transactions, then just validate the first one List <StoreKitTransaction> transactionList = StoreKitBinding.getAllSavedTransactions(); if (transactionList.Count > 0) { StoreKitBinding.validateReceipt(transactionList[0].base64EncodedTransactionReceipt, true); } } // Second column xPos = Screen.width - width - 5.0f; yPos = 5.0f; // enforce the fact that we can't purchase products until we retrieve the product data if (_products != null && _products.Count > 0) { if (GUI.Button(new Rect(xPos, yPos, width, height), "Purchase Random Product")) { var productIndex = Random.Range(0, _products.Count); var product = _products[productIndex]; Debug.Log("preparing to purchase product: " + product.productIdentifier); StoreKitBinding.purchaseProduct(product.productIdentifier, 1); } } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Validate Subscription")) { // grab the transactions and if we have a subscription in there validate it List <StoreKitTransaction> transactionList = StoreKitBinding.getAllSavedTransactions(); foreach (var t in transactionList) { if (t.productIdentifier == "sevenDays") { StoreKitBinding.validateAutoRenewableReceipt(t.base64EncodedTransactionReceipt, "YOUR_SECRET_FROM_ITC", true); break; } } } if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Get Saved Transactions")) { List <StoreKitTransaction> transactionList = StoreKitBinding.getAllSavedTransactions(); // Print all the transactions to the console Debug.Log("\ntotal transaction received: " + transactionList.Count); foreach (StoreKitTransaction transaction in transactionList) { Debug.Log(transaction.ToString() + "\n"); } } }
//상품리스트 성공적으로 들어올떄 콜백함수 void productListReceivedEvent(List <StoreKitProduct> productList) { UserEditor.Getsingleton.EditLog("productListReceivedEvent. total products received: " + productList.Count); // print the products to the console //foreach (StoreKitProduct product in productList) // UserEditor.Getsingleton.EditLog(product.ToString() + "\n"); //Loadmanager.instance.LoadingUI(false); //상품정보(가격, 화폐단위) 받아오기 for (int i = 0; i < productList.Count; i++) { Dic_StorkitProductInfo [productList [i].productIdentifier] = productList[i]; //Debug.Log (productList [i].productIdentifier + " / " + productList [i].price + " / " + productList [i].currencyCode + " / " + productList [i].formattedPrice + // " / " + productList [i].currencySymbol); } // 구입 했던 거래 정보 List <StoreKitTransaction> _storeKitTrns = StoreKitBinding.getAllSavedTransactions(); UserEditor.Getsingleton.EditLog("getAllSavedTransactions count : " + _storeKitTrns.Count); // for(int i = 0 ; i < _storeKitTrns.Count ; i++) // { // UserEditor.Getsingleton.EditLog ("getAllSavedTransactions _ Transaction state : " + _storeKitTrns[i].ToString()); // // } // 구매 후 소모 처리 되지 않은 상 품들 List <StoreKitTransaction> _storekitAllCurrent = StoreKitBinding.getAllCurrentTransactions(); UserEditor.Getsingleton.EditLog("getAllCurrentTransactions count : " + _storekitAllCurrent.Count); for (int i = 0; i < _storekitAllCurrent.Count; i++) { isForceConsume = true; UserEditor.Getsingleton.EditLog("getAllCurrentTransactions _ Transaction state : " + _storekitAllCurrent[i].ToString()); if (_storekitAllCurrent [i].transactionState == StoreKitTransactionState.Purchased) //거래 대기열에 있음, 사용자에게 청구 됨. 클라이언트는 트랜잭션을 완료해야함. { // 다시 소모 처리 시된 상품 저장 => 만약 소모처리중 프로토콜 에러 발 생시 강제 소모 하려고 storekitTracs.Add(_storekitAllCurrent [i]); //거래 상품중에 소모를 하지않은 상품들 소모해준다 productPurchaseAwaitingConfirmationEvent(_storekitAllCurrent [i]); //StoreKitBinding.finishPendingTransaction (_storekitAllCurrent [i].transactionIdentifier); } else if (_storekitAllCurrent [i].transactionState == StoreKitTransactionState.Failed) // 거래 실패된 상품 거래 는 그냥 소모 처리 한다 { UserEditor.Getsingleton.EditLog("강제소모 함 : " + _storekitAllCurrent [i].productIdentifier + " / " + _storekitAllCurrent [i].transactionState); StoreKitBinding.finishPendingTransaction(_storekitAllCurrent [i].transactionIdentifier); } } if (_storekitAllCurrent.Count > 0) { isForceConsume = false; } IsGetQueryInventory = true; }
void OnGUI() { float yPos = 10.0f; float xPos = 20.0f; float width = 210.0f; if (GUI.Button(new Rect(xPos, yPos, width, 40), "Get Can Make Payments")) { bool canMakePayments = StoreKitBinding.canMakePayments(); Debug.Log("StoreKit canMakePayments: " + canMakePayments); } if (GUI.Button(new Rect(xPos, yPos += 50, width, 40), "Get Product Data")) { // comma delimited list of product ID's from iTunesConnect. MUST match exactly what you have there! string productIdentifiers = "anotherProduct,tt,testProduct,sevenDays,oneMonthSubsciber"; StoreKitBinding.requestProductData(productIdentifiers); } if (GUI.Button(new Rect(xPos, yPos += 50, width, 40), "Restore Completed Transactions")) { StoreKitBinding.restoreCompletedTransactions(); } if (GUI.Button(new Rect(xPos, yPos += 50, width, 40), "Validate Receipt")) { // grab the transactions, then just validate the first one List <StoreKitTransaction> transactionList = StoreKitBinding.getAllSavedTransactions(); if (transactionList.Count > 0) { StoreKitBinding.validateReceipt(transactionList[0].base64EncodedTransactionReceipt, true); } } // Second column xPos += xPos + width; yPos = 10.0f; if (GUI.Button(new Rect(xPos, yPos, width, 40), "Purchase Product 1")) { StoreKitBinding.purchaseProduct("testProduct", 1); } if (GUI.Button(new Rect(xPos, yPos += 50, width, 40), "Purchase Product 2")) { StoreKitBinding.purchaseProduct("anotherProduct", 1); } if (GUI.Button(new Rect(xPos, yPos += 50, width, 40), "Purchase Subscription")) { StoreKitBinding.purchaseProduct("sevenDays", 1); } if (GUI.Button(new Rect(xPos, yPos += 50, width, 40), "Validate Subscription")) { // grab the transactions and if we have a subscription in there validate it List <StoreKitTransaction> transactionList = StoreKitBinding.getAllSavedTransactions(); foreach (var t in transactionList) { if (t.productIdentifier == "sevenDays") { StoreKitBinding.validateAutoRenewableReceipt(t.base64EncodedTransactionReceipt, "YOUR_SECRET_FROM_ITC", true); break; } } } if (GUI.Button(new Rect(xPos, yPos += 50, width, 40), "Get Saved Transactions")) { List <StoreKitTransaction> transactionList = StoreKitBinding.getAllSavedTransactions(); // Print all the transactions to the console Debug.Log("\ntotal transaction received: " + transactionList.Count); foreach (StoreKitTransaction transaction in transactionList) { Debug.Log(transaction.ToString() + "\n"); } } }
// check for purchases on online servers at billing initialization. // If a purchase is not registered, set local purchase state back to false private void VerifyReceipts() { //get list of old purchases: on iOS the saved and filtered transactions (avoiding duplicates), //on Android we use the old purchases list received from Google #if UNITY_IPHONE List <StoreKitTransaction> prods = FilterTransactions(StoreKitBinding.getAllSavedTransactions()); #endif if (prods == null || prods.Count == 0) { return; } //loop over all IAP items to check if a valid receipt exists for (int i = 0; i < ids.Length; i++) { //cache IAP id, //only verify purchased items string localId = ids[i]; string globalId = GetIAPIdentifier(localId); if (DBManager.isPurchased(globalId)) { //initialize item as faked and loop over receipts bool faked = true; for (int j = 0; j < prods.Count; j++) { //find corresponding transaction class string identifier = ""; #if UNITY_IPHONE StoreKitTransaction purchase = prods[j]; identifier = purchase.productIdentifier; #elif UNITY_ANDROID GooglePurchase purchase = prods[j]; identifier = purchase.productId; #endif if (identifier == localId) { //we found a receipt for this product on the device, //unset fake purchase and let our external //server decide what happens with this transaction faked = false; MakeRequest(purchase); break; } } //we haven't found a receipt for this item, yet it is //set to purchased. This can't be, maybe our external server //response or the database has been hacked with fake data if (faked) { IAPItem item = null; if (ShopManager.GetInstance()) { item = ShopManager.GetIAPItem(globalId); } if (item) { item.Purchased(false); } DBManager.RemovePurchased(globalId); } } } }