コード例 #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
        }