Google InAppBilling onPurchaseStateChange is never called

The onPurchaseStateChange callback method is never called. I made my own demo application and also tried using the demo version of Google (Dungeons).

I call requestPurchase(String productId, String payload) from the onClick method.

 @Override public void onClick(View view) { if(view == requestPurchaseButton) { mBillingService.requestPurchase("android.test.purchased", "10"); } } 

The callback method onRequestPurchaseResponse(Request, ResponseCode) called. responseCode here gives the value RESULT_OK . Thus, the request was sent to the server.

 @Override public void onRequestPurchaseResponse(RequestPurchase request, ResponseCode responseCode) { if(responseCode == ResponseCode.RESULT_OK) { Log.d("AJ", "onRequestPurchaseResponse.ResponeCode.RESULT_OK"); textView.append(request.mProductId + "\n"); } else if(responseCode == ResponseCode.RESULT_USER_CANCELED) { //doesn't go here } else { //doesn't go here } } 

The javadoc for this method states

This is called when we get a response code from Market for the RequestPurchase request we made. This is NOT used to change purchase status. All changes to the purchase status are accepted in onPurchaseStateChange (PurchaseState, String, int, long). This is used to report various errors, or if the user refused and did not purchase the goods. Possible response codes: RESULT_OK means that the order was successfully sent to the server. OnPurchaseStateChange () will be called later (subject to a PURCHASE or CANCEL purchase condition) when the order is canceled or canceled. This response code can also occur if an order for a market-driven item has already been sent to the server. RESULT_USER_CANCELED means that the user has not bought the item. RESULT_SERVICE_UNAVAILABLE means that we could not connect to the Android Market server (for example, if the data connection does not work). RESULT_BILLING_UNAVAILABLE means that billing in the application is not yet supported. RESULT_ITEM_UNAVAILABLE means that an item for sale does not exist (or is not published) in a server-side directory. RESULT_ERROR is used for any other errors (for example, server error).

But callback method

 @Override public void onPurchaseStateChange(PurchaseState purchaseState, String itemId, int quantity, long purchaseTime, String developerPayload) { Log.d("AJ", "onPurchaseStateChanged"); } 

never called.

Am I missing something? The same thing is done in Dungeons (a demo version of Google), but onPurchaseStateChange not called.

The Test-InAppBilling document shows that we should be able to reach the state of purchase. But when I try, I only see

android.test.purchased: Submit a purchase request.

+3
source share
1 answer

I had the same problem, but I just solved it for myself. I used my public key to work in the code, but I'm trying to run the application on my personal phone. Since I was signed on my phone with my personal account, I assume that Google correctly assumed that I am not a developer. I would have thought that they would send an error message. As soon as I connected my private key to the code, it worked perfectly on my phone. Therefore, the key may not match you.

+6
source

Source: https://habr.com/ru/post/1346014/


All Articles