Skip to main content
Samsung Developer Program

Report Consumed Items

How to make consumable in-app items that were 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).

To get all of the purchased consumable items that have not yet been reported as consumed, make a getIsConsumable() call. Each item's purchase ID, which must be specified in the consumePurchasedItems() call, is contained in the onPayment and onGetOwnedProducts callbacks. 

We recommend that you report consumable items as consumed soon after their purchase, whether or not the user has used the items. For optimum processing, we recommend reporting multiple consumed items in one consumePurchasedItems() call. You can specify multiple item purchase IDs using comma delimiters.

If you make aconsumePurchasedItems() call for a non-consumable item or a consumable item that was previously reported as consumed, an error is returned.

For details about the IAP Helper API elements, see:

To report consumable in-app items as consumed

Note: The example 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 item's purchase ID),  and the OnConsumePurchasedItemsListener interface to get consume report results.

    public class MainActivity extends AppCompatActivity
        implements OnPaymentListener, OnConsumePurchasedItemsListener {
    
  2. After the consumable item is purchased, 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 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?