Billing in Google Play apps in the wrong order? (static testing)

Android documentation for In-app Billing looks pretty clear on the next question. After REQUEST_PURCHASE

you show a check with a pending intent (great, no problem), then the user interacts with the checkout and clicks the buy button (in this case, I'm using a static product id android.test.purchased

).

Now my broadcast receiver should receive RESPONSE_CODE

and THEN statement a IN_APP_NOTIFY

. Well, that's not happening. Sometimes I get a response first, but often I get it after being notified.

The second highlighted section from the Android Doc section below is the reason this is the problem. If I update the status in my app to expected when I receive an asynchronous buy request response as the docs seem to indicate that I should then if this response comes after notification my application will get stuck in a pending state. Should it say "when you get result_ok from syncronus direct response"?

Is this a bug with Goole Play (Google Play version on my phone is 3.5.15 and Android os version is 2.2)? Am I misunderstanding the Docs? Are the docs just wrong? Is this a problem with static testing products? Perhaps there is something else wrong? Please note that on my side everything runs on the UI thread, so this is not a threading issue.

The log output from a typical non-working run is shown in botton.

Relevant section of Android documentation (emphasis mine):

Broadcast intent handling

The REQUEST_PURCHASE request also triggers two asynchronous responses (broadcast). First, the Google Play app sends a Broadcast Transfer RESPONSE_CODE , which contains the request error information. If the request does not generate an error, RESPONSE_CODE conveys the RESULT_OK intent, indicating that the request was successfully sent. (To be clear, the RESULT_OK response does not indicate that the requested purchase was successful; it indicates that the request was successfully submitted to Google Play.)

Then, when the requested transaction changes state (for example, the purchase is successfully debited from the credit card or the user cancels on the purchase), the Google Play app sends an IN_APP_NOTIFY broadcast. This message contains a notification ID that you can use to retrieve transaction data for a REQUEST_PURCHASE request.

Note. The Google Play app also sends IN_APP_NOTIFY for refunds. For more information, see Handling IN_APP_NOTIFY Messages.

Since the purchase process is not instantaneous and can take several seconds (or more), you should assume that the purchase request is pending from the moment you receive the RESULT_OK message until you receive the IN_APP_NOTIFY message for the transaction . Although the transaction pending on the Google Play checkout UI displays "Authorized Purchase ...", this notification is rejected after 60 seconds and you should not rely on this notification as your primary means of communicating transaction status to users. Instead, we recommend doing the following:

An example from my logs of things not going in the expected order:

MAKING REQUEST: PurchaseRequest
EXECUTING REQUEST: PurchaseRequest
IMEDIATE RESPONSE IN: PurchaseRequest, IS RESULT_OK
REQUEST ID: 1814990809059790249, PurchaseRequest
Receiver: Notify
Notify String in IN_APP_NOTIFY intent: android.test.purchased
PROCESSING NOTIFICATION
MAKING REQUEST: PurchaseInformationRequest
EXECUTING REQUEST: PurchaseInformationRequest
IMEDIATE RESPONSE IN: PurchaseInformationRequest, IS RESULT_OK
REQUEST ID: 602248989635492868, PurchaseInformationRequest
Receiver: purchase state changed
PROCESSING PURCHASE_STATE_CHANGE
newestMarketPurchaseState = PURCHASED
SetState on product 'Enterprise'. Message: PURCHASED
MAKING REQUEST: ConfirmNotificationsRequest
EXECUTING REQUEST: ConfirmNotificationsRequest
IMEDIATE RESPONSE IN: ConfirmNotificationsRequest, IS RESULT_OK
REQUEST ID: 693394902887436727, ConfirmNotificationsRequest
Receiver: Response Code = RESULT_OK
Receiver: Response Code requestId = 602248989635492868
PROCESSING RESPONSE
ASYNCH RESPONSE IN: PurchaseInformationRequest, IS RESULT_OK
Receiver: Response Code = RESULT_OK
Receiver: Response Code requestId = 1814990809059790249
PROCESSING RESPONSE
ASYNCH RESPONSE IN: PurchaseRequest, IS RESULT_OK
SetState on product 'Enterprise'. Message: PURCHASE PENDING
Receiver: Response Code = RESULT_OK
Receiver: Response Code requestId = 693394902887436727
PROCESSING RESPONSE
ASYNCH RESPONSE IN: ConfirmNotificationsRequest, IS RESULT_OK
Confirm Notifications Request returned asynch OK

      

+3


source to share


1 answer


I faced this problem too. According to the answers to the question Are Android signals being broadcast? , there is no absolute guarantee that intents will be received in the order in which they were sent. They usually do, but not necessarily. Therefore, even if Google Play orders them correctly, they may still come in a different order.



In my opinion, the only solution is to assume nothing about the arrival time of the RESPONSE_CODE. In this respect, the documentation on Android really seems to me wrong. Probably the response codes should have been implemented via a callback and not as broadcast. I have to admit that Google gets pretty sloppy at times.

+3


source







All Articles