0

I get some product id detail from getProductDetails(). And i successfully purchase the first three testing product. but i can't get purchased product list from getPurchases().

=================================================================================

    public void getThePurchasedItem(ArrayList<String> productQuery){
    final Bundle queryBundle = new Bundle();
    queryBundle.putStringArrayList("ITEM_ID_LIST", productQuery);
    new Thread(new Runnable() {
        @Override
        public void run() {
            // TODO Auto-generated method stub
            String continuationToken = null;
            Bundle ownedItems = null;
            try {
                showToast("getThePurchasedItem 0000000");
                ownedItems = mService.getPurchases(BILLING_API_VERSION, getPackageName(), ITEM_TYPE_INAPP, queryBundle, continuationToken);
                showToast("getThePurchasedItem 1111111");
       //                   ownedItems = mService.getPurchases(BILLING_API_VERSION, getPackageName(), ITEM_TYPE_INAPP, null, null);
            } catch (RemoteException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            int response = ownedItems.getInt("RESPONSE_CODE");

            showToast("response code:"+response);

            if (response == RESULT_OK) {
                ArrayList<String> ownedProducts = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
                ArrayList<String> purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");

                continuationToken = ownedItems.getString("INAPP_CONTINUATION_TOKEN");

                System.out.println("getPurchasedItem data size:"+purchaseDataList.size());
                System.out.println("getPurchasedItem item size:"+ownedItems.size());
                String data = "";

                showToast("purchaseDataList.size():"+purchaseDataList.size());
                showToast("ownedProducts.size():"+ownedProducts.size());

                for (int i = 0; i < purchaseDataList.size(); ++i) {
                    String purchaseData = purchaseDataList.get(i);
                    String product = ownedProducts.get(i);

                    System.out.println("product:"+product);
                    System.out.println("purchaseData:"+purchaseData);
                    /*purchaseData look like this
                    {
                    "productId": "YourProductID",
                    "purchaseToken": "XDd333xk38s",
                    "developerPayload": ""
                    }*/
                    try {
                        JSONObject jsonPurchaseData = new JSONObject(purchaseData);
                        String productId = jsonPurchaseData.getString("productId");
                        String developerPayload = jsonPurchaseData.getString("developerPayload");
                        String purchaseToken = jsonPurchaseData.getString("purchaseToken");
                        lastObtainedPurchaseToken = purchaseToken;

                        System.out.println("productId:"+productId);
                        System.out.println("developerPayload:"+developerPayload);
                        System.out.println("purchaseToken:"+purchaseToken);

                        data += "=============================\n";
                        data +="\nproductId:"+productId + "\n";
                        data +="developerPayload:"+developerPayload + "\n";
                        data +="purchaseToken:"+purchaseToken + "\n\n";

                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    // do something with this purchase information
                    // e.g. display the updated list of products owned by user
                } 
                data += "=============================";

                if(purchaseDataList.size()==0){
                    data="No one product purchased";
                }
                final String finalData = data;
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        textview.setText(finalData);
                    }
                });
            }else{
                System.out.println("getPurchasedItem failed:"+response);
            }
        }
    }).start();
}

1 Answers1

1

Test ID's are not storing the purchase status information on backend, thus you can not get the data with them. thus to get the actualk purchase history working, you should use the real ID's you have reserved for your content in Nokia Store. Also do remember to wait untill the IDs have passed the QA before you attempt to utilize them.

Dr.Jukka
  • 2,346
  • 2
  • 15
  • 20