android: Inapp billing: Error response: 7:Item Already Owned

前端 未结 5 1042
面向向阳花
面向向阳花 2021-01-31 09:09

I am learning to implement an in-app billing for my app such that people can for example, donate $ when press the donate button.

The user is allowed to donate more than

5条回答
  •  醉酒成梦
    2021-01-31 09:38

    You purchased "android.test.purchased" but did not consume it. However, if you forgot to consume it immediately, it is not easy to consume it again. We can wait for 14 days. The fake purchase will be cleared automatically. But it is not acceptable.

    I spent a lot of time finding the solution:

    Add this line to get debug info.

    _iabHelper.enableDebugLogging(true, "TAG");
    

    Run the app. In LogCat, you will see a json string like

    {"packageName":"com.example","orderId":"transactionId.android.test.purchased","productId":"android.test.purchased","developerPayload":"123","purchaseTime":0,"purchaseState":0,"purchaseToken":"inapp:com.example:android.test.purchased"}
    

    Consume it manually (Replace THAT_JSON_STRING with your json string)

        Purchase purchase;
        try {
            purchase = new Purchase("inapp", THAT_JSON_STRING, "");
            _iabHelper.consumeAsync(purchase, new OnConsumeFinishedListener() {
    
                @Override
                public void onConsumeFinished(Purchase purchase, IabResult result) {
                    Log.d("TAG", "Result: " + result);
                }
            });
        } catch (JSONException e) {
            e.printStackTrace();
        }
    

    _iabHelper is mHelper.

提交回复
热议问题