Skip to main content
Samsung Developer Program

Report Consumed Items

How to make a consumable in-app item that was previously purchased available for purchase again

 

After a consumable in-app item has been purchased, it cannot be purchase again until it is reported as consumed to Samsung IAP, which then enables the user to purchase the item again. 

Note: Whether or not the user has actually used a consumable in-app item in your Android app (for example, either a dart in-app item has been thrown in a dart game, or the dart has not been thrown), the item can be reported as thrown (for example, so the user can get lots of darts for the next round of dart games in the tournament).

When reporting a consumed item, the call must specify the item's purchase ID, which is contained in the onPayment and onGetOwnedProducts callbacks.

For optimum processing, we recommend reporting multiple consumed items in one consumePurchasedItems() call. You can specify each item's purchase ID with a comma delimiter.

For details about the IAP Helper API elements, see:

To enable your app to report an in-app item as consumed:

The code shows how to set up necessary listeners, determine that one in-app item is consumable and was successfully purchased, get the item's purchase ID, report the item as consumed to Samsung IAP, and after receiving the processing results, display an appropriate message to the user.

  1. After the MainActivity class declaration, implement the OnPaymentListenerinterface to get purchase item and transaction information, including the purchase ID and the OnConsumePurchasedItemsListener interface to get consume report results.
    public class MainActivity extends AppCompatActivity 
        implements OnPaymentListener, OnConsumePurchasedItemsListener {

     
  2. Determine that the in-app item was successfully purchased (no error codes in ErrorVo, andPurchaseVo was returned). If so, determine that the item is consumable, get the purchase ID of the item, and call consumePurchasedItems().
    // If Payment is finished Successfully
    // ================================================================
    if (_errorVO.getErrorCode() == IapHelper.IAP_ERROR_NONE) {
        if (_purchaseVO != null) {
            alert.setTitle(_errorVO.getErrorString());
            alert.setMessage(_purchaseVO.dump());
            
            if (_purchaseVO.getIsConsumable()) {
            String purchaseId = _purchaseVO.getPurchaseId();
            mIapHelper.consumePurchasedItems(purchaseId, this);
            }
        }
    }
    

     

  3. Display a message that is appropriate for the consumePurchasedItems() results received in the OnConsumePurchasedItemsListener interface by addingonConsumePurchasedItems()

    @Override 
    public void onConsumePurchasedItems(ErrorVo _errorVO, ArrayList<ConsumeVo> _consumeList) 
    { 
        if (_errorVO != null) { 
            if (_errorVO.getErrorCode() == IapHelper.IAP_ERROR_NONE) { 
                Toast.makeText(this, "This product has been successfully consumed.", 
                    Toast.LENGTH_SHORT).show(); 
            } 
            else { 
                Toast.makeText(this, _errorVO.getErrorString(), Toast.LENGTH_SHORT).show(); 
            } 
        } 
        else { 
            Toast.makeText(this, "ErrorVo is null.", Toast.LENGTH_SHORT).show();
        }
    }
    

 

To enable users to report all their in-app items as consumed:

The code shows how to set up necessary listeners, get the purchase IDs of all consumable in-app items purchased by the user, report all the items as consumed to Samsung IAP, and after receiving the processing results, display an appropriate message to the user.

  1. After the MainActivity class declaration, implement the OnGetOwnedListListenerinterface to get the purchase IDs of the in-app items and the OnConsumePurchasedItemsListener interface to get consume report results.
    public class MainActivity extends AppCompatActivity 
        implements OnGetOwnedListListener, OnConsumePurchasedItemsListener {


     
  2. Add a UI button that calls doConsumePurchasedItems() to the owned_list_layout.xml layout.
    <!-- Consume Purchased Items Button --> 
    <Button 
        android:id="@+id/btn_consume_purchased_items" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:text="@string/consume_purchased_items" 
        android:onClick="doConsumePurchasedItems"/>


     
  3. Get the purchase IDs of all purchased consumable items (which determines the items were successfully purchased), and report all the items as consumed by adding doConsumePurchasedItemsto OwnedListActivity.
    public void doConsumePurchasedItems(View _view) { 
    
        if (mOwnedList != null && mOwnedList.size() > 0) { 
        String purchasedIds = null; 
        
            for (OwnedProductVo vo : mOwnedList) { 
                if (vo.getType().equals("item") 
                        && vo.getIsConsumable()) { 
        
                    if (purchasedIds == null) { 
                        purchasedIds = vo.getPurchaseId(); 
                    } 
                    else { 
                        purchasedIds += "," + vo.getPurchaseId(); 
                    } 
                } 
            } 
        
            if (purchasedIds != null) { 
                mIapHelper.consumePurchasedItems(purchasedIds, this); 
            }
        }
    }


     
  4. Display a message that is appropriate for the consumePurchasedItems() results received in the OnConsumePurchasedItemsListener interface by addingonConsumePurchasedItems().
    @Override 
    public void onConsumePurchasedItems(ErrorVo _errorVO, ArrayList<ConsumeVo> _consumeList) 
    { 
        if (_errorVO != null) { 
            if (_errorVO.getErrorCode() == IapHelper.IAP_ERROR_NONE) { 
                Toast.makeText(this, "The purchased items have been consumed successfully.", 
                    Toast.LENGTH_SHORT).show(); 
            } 
            else { 
                Toast.makeText(this, _errorVO.getErrorString(), Toast.LENGTH_SHORT).show(); 
            } 
        } 
        else { 
            Toast.makeText(this, "ErrorVo is null.", Toast.LENGTH_SHORT).show();
        }
    }

 

To test your code: 

  • We recommend you run the test in both Developer Test Mode (Success) and Developer Test Mode (Failed).
  • In your Android app code:
    • Set the IAP operating mode to the appropriate test mode.
    • Confirm that all item IDs must match the IDs of registered in-app items. 
  • Your Android app and the in-app items must be registered in Seller Office.
     
  1. When the operating mode is Developer Test Mode (Success):
    1. Purchase a consumable in-app item. 
      For details, see Initiate an In-App Item Purchase.
    2. Try to purchase the same item.
    3. Verify that the purchase request results indicate the request failed (IAP_ERROR_ALREADY_PURCHASED).
    4. Run your consumable item reporting code. 
    5. Try to purchase the same item.
    6. Verify that the purchase request results indicate the request succeeded (IAP_ERROR_NONE).
       
  2. When the operating mode is Developer Test Mode (Failed):
    1. Purchase a consumable in-app item. 
    2. Verify that the purchase request results indicate the request failed.

 

  • Was this article helpful?