2
votes

I am integrating Android In-App purchase with Android Native application. I used following code to start In-App purchase intent!

Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(),”product_sku”, "inapp",”Some Developer Payload”);

PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");

startIntentSenderForResult(pendingIntent.getIntentSender(),REQUEST_CODE, new Intent(),Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));

Above code is working with and open Google Play for In-app purchase. I overridden the onActivityResult for getting the result of In-App Purchase (following is code)

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1001) {

        if (resultCode == RESULT_OK) {
            try {
                final JSONObject jo = new JSONObject(purchaseData);
                String orderId = jo.getString("orderId");
                String productId = jo.getString("productId");
                String state = String.valueOf(jo.getInt("purchaseState"));

                //POST purchase result to my server for my record!

                //Finally Consume the product 
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } 

    } 
}

Following is response we received from InApp purchase

'{ 
   "orderId":"12999763169054705758.1371079406387615", 
   "packageName":"com.example.app",
   "productId":"exampleSku",
   "purchaseTime":1345678900000,
   "purchaseState":0,
   "developerPayload":"bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ",
   "purchaseToken":"rojeslcdyyiapnqcynkjyyjh"
 }'

My questions is that how to identify that the in-app purchase transaction is in “Pending” status because "purchaseState" (Integer value in JSON) having only three values “purchased”,” canceled” and “refunded”.

I am from india and google wallet is accepting any transaction immediately after inapp purchase completed.

It is always in Pending status first and then takes upto 48 hours to accept or reject the transaction!

I want only allow my customer to use In app purchased product only after successfully payment in Google waltet.

I faced that My one customer purchased inapp product from my application but somehow their data is not posted on server. Customer told me that that purchase transaction was in pending status initially and completed after two days, even I got that payment in my Merchant account so I concluded that Android is not responding resultCode == RESULT_OK in onActivityResult is purchased is in pending.

So If anyone faced same problem then please explain me the solution or flow to handle the pending status! Should I have to use APN for pending status? But I need that pending status order details to store on my server! Thanks in Advance!

1

1 Answers

1
votes

I know this question was asked a long time ago. But I am facing the very same issue (with an App for the Brazilian market).

I noticed that purchases which got processed right away, everything works fine.

But, some purchases get into the 'pending payment' status and it can take up to 48 hours to change status. But, my server never gets called - as OP stated, I suspect Google play server returns a different status (other than RESULT_OK) and my app doesn't capture that. Then, my user gets charged, but has no access to the PREMIUM features - since my server never got notified.

So, as of 2018, I read that we might have an alternative. The following link has some information on how to deal with subscriptions

https://developer.android.com/google/play/billing/billing_subscriptions

.. and points to the following:

https://developer.android.com/google/play/billing/realtime_developer_notifications

"Realtime Developer Notifications"

this allows Google play to send your server a notification, every time a user subscription status changes. So, if your user's payment took 48h to complete, your server would receive a notification and you could make the user PREMIUM or whatever logic you need.

Hope it helps.