【问题标题】:Google In-App billing V2 testing restore transactionsGoogle In-App billing V2 测试恢复交易
【发布时间】:2013-12-02 11:34:23
【问题描述】:

我正在为 Blackberry 应用内计费开发 Android 运行时,它们支持 Google 应用内计费版本 2,因此我需要使用版本 2 而不是版本 3。

我的项目已管理。

我一直在测试恢复事务部分。

1) 如何测试?

2) 我们可以使用“android.test.purchased”进行测试吗?如果可以,如何?

3) 恢复交易(已购买物品)的流程如何?

4)根据我的理解,onPurchaseStateChange 在我们请求购买和恢复购买的项目时调用一次。我的理解正确吗?

我已经查看了官方开发者网站,但我有点困惑。

这是我卡住的主要代码部分。

 private class DungeonsPurchaseObserver extends PurchaseObserver {
        public DungeonsPurchaseObserver(Handler handler) {
            super(BlackBerryInAppPurchaseActivity.this, handler);
        }

        @Override
        public void onBillingSupported(boolean supported, String type) {
            if (Consts.DEBUG) {
            Log.i(TAG, "supported: " + supported);
            }
            Toast.makeText(getApplicationContext(), " billing supported: " + supported, 2000).show();
            if (type == null || type.equals(Consts.ITEM_TYPE_INAPP)) {
            if (supported) {
                restoreDatabase();
            } else {
                showDialog(DIALOG_BILLING_NOT_SUPPORTED_ID);
            }
            } else {
            showDialog(DIALOG_SUBSCRIPTIONS_NOT_SUPPORTED_ID);
            }
        }

        @Override
        public void onPurchaseStateChange(PurchaseState purchaseState, String itemId, int quantity, long purchaseTime, String developerPayload) {
            if (Consts.DEBUG) {
            Log.i(TAG, "onPurchaseStateChange() itemId: " + itemId + " " + purchaseState);
            }
            Toast.makeText(getApplicationContext(), "onPurchaseStateChange() itemId: " + itemId + " " + purchaseState, 2000).show();
            if (purchaseState == PurchaseState.PURCHASED) {
                    //Update the UI -unlock app 
            updateUI();
            Toast.makeText(getApplicationContext(), "Purchased Update the Ui " + purchaseState, 2000).show();
            mOwnedItems.add(itemId);
            //Toast.makeText(getApplicationContext(), "Hiding the button as the item is purchased " + itemId + " " + purchaseState, 2000).show();
            }
            //mOwnedItemsCursor.requery();
            Toast.makeText(getApplicationContext(), "SKU IS " + mSku, 2000).show();
            if (itemId.equals(mSku)) {
            switch (purchaseState) {

            case PURCHASED:
                Toast.makeText(getApplicationContext(), " Purchased itemId: " + itemId + " " + purchaseState, 2000).show();
                break;

            default:
                Toast.makeText(getApplicationContext(), " Item NOT Purchased itemId: " + itemId + " " + purchaseState, 2000).show();
                break;

            }
            }
        }

        @Override
        public void onRequestPurchaseResponse(RequestPurchase request, ResponseCode responseCode) {
            if (Consts.DEBUG) {
            Log.d(TAG, request.mProductId + ": " + responseCode);
            }
            //  Toast.makeText(getApplicationContext(), "request.mProductId " + responseCode, 2000).show();
            if (responseCode == ResponseCode.RESULT_OK) {
            if (Consts.DEBUG) {
                Log.i(TAG, "purchase was successfully sent to server");
            }

            Toast.makeText(getApplicationContext(), "purchase was successfully sent to server" + responseCode, 2000).show();
            logProductActivity(request.mProductId, "sending purchase request");
            } else if (responseCode == ResponseCode.RESULT_USER_CANCELED) {
            if (Consts.DEBUG) {
                Log.i(TAG, "user canceled purchase");
            }
            logProductActivity(request.mProductId, "dismissed purchase dialog");
            } else {
            if (Consts.DEBUG) {
                Log.i(TAG, "purchase failed");
            }
            Toast.makeText(getApplicationContext(), "purchase failed" + responseCode, 2000).show();
            logProductActivity(request.mProductId, "request purchase returned " + responseCode);
            }
        }

        @Override
        public void onRestoreTransactionsResponse(RestoreTransactions request, ResponseCode responseCode) {
            if (responseCode == ResponseCode.RESULT_OK) {
            if (Consts.DEBUG) {
                Log.d(TAG, "completed RestoreTransactions request");
            }
            Toast.makeText(getApplicationContext(), "completed RestoreTransactions request " + responseCode, 2000).show();
            // Update the shared preferences so that we don't perform
            // a RestoreTransactions again.
            SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
            SharedPreferences.Editor edit = prefs.edit();
            edit.putBoolean(DB_INITIALIZED, true);
            edit.commit();
            } else {
            if (Consts.DEBUG) {
                Log.d(TAG, "RestoreTransactions error: " + responseCode);
            }
            Toast.makeText(getApplicationContext(), "RestoreTransactions error: " + responseCode, 2000).show();
            }
        }
        }

【问题讨论】:

    标签: android in-app-purchase in-app-billing blackberry-android


    【解决方案1】:

    编辑:

    这是来自官方 android 开发者网站:

    /**
    * Request type is RESTORE_TRANSACTIONS
    */
      Bundle request = makeRequestBundle("RESTORE_TRANSACTIONS");
      request.putLong(REQUEST_NONCE, mNonce);
      Bundle response = mService.sendBillingRequest(request);
      // Do something with this response.
    }
    

    您应该阅读标题为“恢复交易信息 (RESTORE_TRANSACTIONS)”下的文档,您可以在此处找到:

    http://developer.android.com/google/play/billing/v2/billing_integrate.html

    【讨论】:

    • 所以你的意思是我需要将此作为 SKU 而不是“android.test.purchased”发送?
    • 是的! ;) 如果您的应用内购买将被退款,这是测试 SKU。
    • 但我不想退款,我想恢复我购买的商品
    • 对不起,我以为你的意思是退款和恢复。我更新了我的代码,我认为这就是你要找的
    • 您提供的代码是版本 3,我正在处理的是版本 2,
    猜你喜欢
    • 2011-12-17
    • 1970-01-01
    • 2014-11-12
    • 2014-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-01
    相关资源
    最近更新 更多