Search code examples
androidin-app-purchaseandroid-billing

Getting order ID when querying for purchased items


I'm looking at querying owned items, and it doesn't include getting Checkout order IDs that are available when user actually makes a purchase. Is there no way to query the order ID for a purchase that have already been made?


Solution

  • Try this:

    Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);
    
    int response = ownedItems.getInt("RESPONSE_CODE");
    if (response == 0) {
       ArrayList ownedSkus = 
          ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
       ArrayList purchaseDataList = 
          ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
       ArrayList signatureList = 
          ownedItems.getStringArrayList("INAPP_DATA_SIGNATURE");
       String continuationToken = 
          ownedItems.getString("INAPP_CONTINUATION_TOKEN");
    
       for (int i = 0; i < purchaseDataList.size(); ++i) {
           String purchaseData = purchaseDataList.get(i);
           JSONObject jpurchase = new JSONObject(purchaseData);
           String orderid = jpurchase.getString("orderId");
           Log.v(TAG,"ORDER ID :"+orderid ); 
       }
    }
    

    Thanks.