【问题标题】:Titanium Android : in-app billing Product not foundTitanium Android:未找到应用内计费产品
【发布时间】:2014-09-17 13:04:01
【问题描述】:

我使用 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
            });

        }

错误

【问题讨论】:

  • 您发布了应用程序吗? (alpha 或 beta)。
  • @user2713030:我已经上传了测试版的apk..但还没有发布
  • 我们只需要上传测试版的 apk 还是需要发布。??
  • 是的,将 apk 上传为 alpha 或 beta,然后将右上角的下拉菜单从草稿更改为已发布。

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


【解决方案1】:

应发布应用程序(Alpha 版或 Beta 版),以便购买商品。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-14
    • 2011-08-10
    • 2017-08-15
    • 1970-01-01
    • 1970-01-01
    • 2014-07-18
    • 1970-01-01
    相关资源
    最近更新 更多