Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am integrating Android In-App purchase with Android Native application. I used following code to start In-App purchase intent!

Java
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)

Java
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

JavaScript
'{ 
   "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!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900