Titanium Android:应用内结算产品未找到

时间:2014-09-17 13:04:02

标签: android in-app-purchase titanium titanium-modules

我使用Titanium Appcelerator开发Android应用程序。我在开发者控制台中有非托管产品(非消费品中的产品。当我试图访问和购买..

"找不到您尝试购买的商品。"

mycode的

  

InAppBilling.queryInventory();

var InAppBilling = require('ti.inappbilling');
    var PUBLIC_KEY = 'xxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxx';
    var DEVELOPER_PAYLOAD = 'gk@g.com';
    var toConsume = null;

    ////////////////////////////////////////////////////////
    // Utils
    ////////////////////////////////////////////////////////

    try
    {
        function runSetup() {
            log('Running startSetup...');
            InAppBilling.startSetup({
                publicKey : PUBLIC_KEY
            });
            log('Wait for setup to complete successfully');
        }

        function responseString(responseCode) {
            switch (responseCode) {
            case InAppBilling.RESULT_OK:
                return 'OK';
            case InAppBilling.RESULT_USER_CANCELED:
                return 'USER CANCELED';
            case InAppBilling.RESULT_BILLING_UNAVAILABLE:
                return 'BILLING UNAVAILABLE';
            case InAppBilling.RESULT_ITEM_UNAVAILABLE:
                return 'ITEM UNAVAILABLE';
            case InAppBilling.RESULT_DEVELOPER_ERROR:
                return 'DEVELOPER ERROR';
            case InAppBilling.RESULT_ERROR:
                return 'RESULT ERROR';
            case InAppBilling.RESULT_ITEM_ALREADY_OWNED:
                return 'RESULT ITEM ALREADY OWNED';
            case InAppBilling.RESULT_ITEM_NOT_OWNED:
                return 'RESULT ITEM NOT OWNED';

            case InAppBilling.IAB_RESULT_REMOTE_EXCEPTION:
                return 'IAB RESULT REMOTE EXCEPTION';
            case InAppBilling.IAB_RESULT_BAD_RESPONSE:
                return 'IAB RESULT BAD RESPONSE';
            case InAppBilling.IAB_RESULT_VERIFICATION_FAILED:
                return 'IAB RESULT VERIFICATION FAILED';
            case InAppBilling.IAB_RESULT_SEND_INTENT_FAILED:
                return 'IAB RESULT SEND INTENT FAILED';
            case InAppBilling.IAB_RESULT_UNKNOWN_PURCHASE_RESPONSE:
                return 'IAB RESULT UNKNOWN PURCHASE RESPONSE';
            case InAppBilling.IAB_RESULT_MISSING_TOKEN:
                return 'IAB RESULT MISSING TOKEN';
            case InAppBilling.IAB_RESULT_UNKNOWN_ERROR:
                return 'IAB RESULT UNKNOWN ERROR';
            case InAppBilling.IAB_RESULT_SUBSCRIPTIONS_NOT_AVAILABLE:
                return 'IAB RESULT SUBSCRIPTIONS NOT AVAILABLE';
            case InAppBilling.IAB_RESULT_INVALID_CONSUMPTION:
                return 'IAB RESULT INVALID CONSUMPTION';
            }
            return '';
        }

        function purchaseStateString(state) {
            switch (state) {
            case InAppBilling.PURCHASE_STATE_PURCHASED:
                return 'PURCHASE STATE PURCHASED';
            case InAppBilling.PURCHASE_STATE_CANCELED:
                return 'PURCHASE STATE CANCELED';
            case InAppBilling.PURCHASE_STATE_REFUNDED:
                return 'PURCHASE STATE REFUNDED';
            }
            return '';
        }

        function purchaseTypeString(state) {
            switch (state) {
            case InAppBilling.ITEM_TYPE_INAPP:
                return 'ITEM TYPE INAPP';
            case InAppBilling.ITEM_TYPE_SUBSCRIPTION:
                return 'ITEM TYPE SUBSCRIPTION';
            }
            return '';
        }

        function purchaseProperties(p) {
            var str = 'type: ' + purchaseTypeString(p.type) + '\norderId: ' + p.orderId + '\npackageName: ' + p.packageName + '\nproductId: ' + p.productId + '\npurchaseTime: ' + new Date(p.purchaseTime) + '\npurchaseState: ' + purchaseStateString(p.purchaseState) + '\ndeveloperPayload: ' + p.developerPayload + '\ntoken: ' + p.token;
            p_txid = p.token;
            return str;
        }

        ////////////////////////////////////////////////////////
        // setup                                              //
        ////////////////////////////////////////////////////////

        InAppBilling.addEventListener('setupcomplete', function(e) {
            log('Setup response: ' + responseString(e.responseCode));
            if (e.success) {
                log('Setup completed successfully!');
            } else {
                alert('InAppBilling Setup FAILED.');
            }
        });

        InAppBilling.addEventListener('queryinventorycomplete', function(e) {
            alert('Query Inventory response: ' + responseString(e.responseCode) + '\n -- ' + 'queryinventorycomplete-- ' + e.success);

            var inventory = e.inventory;
            var purchaseIds = ['com.app.et'];
            var purchase, details;
            if (e.success) {
                for (var i = 0, j = purchaseIds.length; i < j; i++) {
                    // Check for details
                    if (inventory.hasDetails(purchaseIds[i])) {
                        log('Check log for Purchase ' + i + ' details');
                        Ti.API.info('Details: ' + JSON.stringify(inventory.getDetails(purchaseIds[i])));
                    }
                    // Check for purchase
                    alert(purchaseIds[i] + '--hasPurchase--' + inventory.hasPurchase(purchaseIds[i]));
                    if (inventory.hasPurchase(purchaseIds[i])) {
                        purchase = inventory.getPurchase(purchaseIds[i]);
                        // Print details for each purchase
                        log('Check log for Purchase ' + i + ' properties');
                        Ti.API.info(purchaseProperties(purchase));

                    }
                }
            }

        });

        InAppBilling.addEventListener('purchasecomplete', function(e) {
            alert('Purchase response: ' + responseString(e.responseCode));
            if (e.success && e.purchase) {
                log(purchaseProperties(e.purchase));
                // Prepare the purchase to be consumed
                if (e.purchase.productId === 'gas') {
                    toConsume = e.purchase;
                    log('gas is queued to be consumed');
                }
                alert('Purchase completed successfully');

            }
        });

        InAppBilling.addEventListener('consumecomplete', function(e) {
            log('Consume response: ' + responseString(e.responseCode));
            if (e.success) {
                alert('Consume completed successfully');
            }
        });

        function make_purchase() {
            InAppBilling.queryInventory();
            //  alert('purchase android com.app.et ');
            InAppBilling.purchase({
                productId : 'com.app.et',
                type : InAppBilling.ITEM_TYPE_INAPP,
                developerPayload : DEVELOPER_PAYLOAD
            });

        }

错误

ERROR

1 个答案:

答案 0 :(得分:0)

应该发布应用程序(alpha或beta),以便可以购买这些项目。