コード例 #1
0
        void ConfigureStoreKitManager()
        {
            //queue of transactions needing to be verified
            mTransactionsInVerification = new Dictionary <string, object> ();

      #if UNITY_IPHONE
            //don't autoconfirm transactions until we have verified the receipt
            StoreKitBinding.enableHighDetailLogs(true);
            StoreKitManager.autoConfirmTransactions = false;
            StoreKitBinding.setShouldSendTransactionUpdateEvents(true);

            StoreKitManager.productListReceivedEvent += allProducts => {
                Debug.Log("KongStoreKitDemo:: received total products: " + allProducts.Count);
                mPurchaseReady = true;
            };

            // the following handles receipt verification
            StoreKitManager.productPurchaseAwaitingConfirmationEvent += transaction => {
                Debug.Log("KongStoreKitDemo: productPurchaseAwaitingConfirmationEvent: " + transaction.transactionState);
                mTransactionsInVerification[transaction.transactionIdentifier] = transaction; //add this transaction to the queue
                if (KongregateAPI.GetAPI() != null && KongregateAPI.GetAPI().IsReady())
                {
                    Debug.Log("KongStoreKitDemo: verifiying: " + transaction);
                    KongregateAPI.GetAPI().Mtx.VerifyTransactionId(transaction.transactionIdentifier);
                }
                else
                {
                    Debug.Log("KongStoreKitDemo: delay verify until READY event: " + transaction);
                }
            };

            StoreKitManager.restoreTransactionsFailedEvent += errorMsg => {
                Debug.Log("KongStoreKitDemo: restoreTransactionsFailedEvent: " + errorMsg);
            };

            StoreKitManager.restoreTransactionsFinishedEvent += () => {
                Debug.Log("KongStoreKitDemo: restoreTransactionsFinishedEvent");
            };

            StoreKitManager.purchaseSuccessfulEvent += transaction => {
                Debug.Log("KongStoreKitDemo: purchaseSuccessfulEvent: " + transaction.transactionIdentifier);
            };

            StoreKitManager.purchaseFailedEvent += errorMsg => {
                Debug.Log("KongStoreKitDemo: purchase failed: " + errorMsg);
                // pass null, if you do not have the transaction id.
                KongregateAPI.GetAPI().Analytics.FinishPurchase(KongregateAPI.PURCHASE_FAIL, null,
                                                                getPurchaseFields());
                mPurchaseReady = true;
            };

            StoreKitManager.purchaseCancelledEvent += errorMsg => {
                Debug.Log("KongStoreKitDemo: purchase cancelled: " + errorMsg);
                // pass null, if you do not have the transaction id.
                KongregateAPI.GetAPI().Analytics.FinishPurchase(KongregateAPI.PURCHASE_FAIL, null,
                                                                getPurchaseFields());
                mPurchaseReady = true;
            };

            StoreKitManager.transactionUpdatedEvent += transaction => {
                Debug.Log("KongStoreKitDemo: transactionUpdated: " + transaction.transactionState);
            };

            Debug.Log("KongStoreKitDemo: listeners configured");
      #endif
        }
コード例 #2
0
    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();
        }


        if (GUILayout.Button("Enable High Detail Logs"))
        {
            StoreKitBinding.enableHighDetailLogs(true);
        }


        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("Finish All Pending Transactions"))
        {
            // this is only necessary in the case where you turned off confirmation of transactions (see above)
            StoreKitBinding.finishPendingTransactions();
        }


        if (GUILayout.Button("Cancel Downloads"))
        {
            StoreKitBinding.cancelDownloads();
        }


        if (GUILayout.Button("Display App Store"))
        {
            StoreKitBinding.displayStoreWithProductId("656176278");
        }

        endColumn();
    }