0

我已经在我的 Android 游戏中实现了应用内结算 v3,但是当我尝试消费购买时遇到了问题。

游戏发布,产品可以成功购买,但是因为消费失败,只能购买一次。当第二次尝试购买时,将5 - developer error返回响应。

谁能给我任何建议?

这是我的代码:

        public boolean orderBoostersV3(String packId, int alreadyAfterConsume) {
            Bundle bundle = null;
            try {
    // for tetsing               packId = "android.test.purchased";
                if (mService == null) {
                    Log.e(TAG, "mService is null");
                    return false;
                }
                // Bundle ownedItems = mService.getPurchases(3, "eu.acgame", "inapp", null);


                bundle = mService.getBuyIntent(3, "eu.acgame", packId, ITEM_TYPE_INAPP, "AC game");

                PendingIntent pendingIntent = bundle.getParcelable(RESPONSE_BUY_INTENT);
                if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_OK) {
                    // Start purchase flow (this brings up the Google Play UI).
                    // Result will be delivered through onActivityResult().
                    try {
                        a.startIntentSenderForResult(pendingIntent.getIntentSender(), RC_BUY, new Intent(),
                                Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
                        // consume(packId); // consuming right after prdering does not work
                        return true;
                    } catch (IntentSender.SendIntentException e) {
                        Log.e(TAG, "Billing unavailable. Error:" + e.getMessage());
                        e.printStackTrace();
                    }
                } else if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE) {
                    Log.d(TAG, "Boostering not available");
                    return false;
                } else if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED && alreadyAfterConsume > 10) {
                    Log.e(TAG, "Consume did not work " + alreadyAfterConsume + " Panic!");
                    return false;
                } else if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
                    Log.d(TAG, "Product " + packId + " already purchased. Calling consume");
                    int result = consume(packId);   // if result not 0, probably all consumed
                    if (result == 0 || result == 5)   // consumed properly, try once more
                        return orderBoostersV3(packId, alreadyAfterConsume + 1);
                    else
                        return orderBoostersV3(packId, 99);  // finish consuming

                } else
                    Log.d(TAG, "Billing unexpected code:" + bundle.getInt(RESPONSE_CODE));

            } catch (RemoteException e) {
                Log.e(TAG, "Billing error");
                e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
            }
            return false;
        }

private int consume(String packId) throws RemoteException {
    Bundle purchases = mService.getPurchases(3, "eu.acgame", "inapp", null);
    Log.d(TAG, "Purchases:" + purchases);
    int response = mService.consumePurchase(3, "eu.acgame", "inapp:eu.acgame:" + packId); // android.test.purchased");
    Log.d(TAG, "Consume response:" + response);
    return response;
}
4

1 回答 1

0

我已经设法解决了我自己的问题。我必须将原始购买令牌传递给consumePurchase,这是从购买项目集合的查询中获得的。

于 2013-06-02T09:18:05.673 回答