heisenberg3008
heisenberg3008

Reputation: 65

Buy same item over and over without consuming - In App purchase android

I have kept a donate tab and want to let the users buy the items over and over again. I have implemented a code but it lets the user buy the specific item only once. I have used managed products in play console for products.

 btn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
           if(billingClient.isReady()){
             SkuDetailsParams params=SkuDetailsParams.newBuilder()
             .setSkusList(Arrays.asList("purchase_aaa","purchase_bbb","purchase_ccc","purchase_ddd"))
             .setType(BillingClient.SkuType.INAPP).build();

 billingClient.querySkuDetailsAsync(params, new SkuDetailsResponseListener() {
         @Override
          public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
           if(responseCode==BillingClient.BillingResponse.OK)
        {
              loadProductToRecyclerView(skuDetailsList);
                  }
             else{
               Toast.makeText(Donate.this, "Cannot query product", Toast.LENGTH_SHORT).show();
                  }
                  }
                });
                }
                else
        {
                Toast.makeText(Donate.this, "Not ready", Toast.LENGTH_SHORT).show();
                }
            }
        });

  @Override
    public void onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) {
        if(purchases!=null){
        Toast.makeText(this, "Purchased"+purchases.size(), Toast.LENGTH_SHORT).show();
    }
    }

Upvotes: 0

Views: 394

Answers (1)

from56
from56

Reputation: 4127

That's by design and cannot be changed, in-app managed products can only be purchased once.

If you want the user who has paid more to have more features enabled, you will have to create as many in-app managed products as levels exist.

If it is a game in which, for example, the user is consuming items then when he no longer has any, you consume the in-app product so he can buy it again.

Or you can also consume the product immediately after the purchase and keep track of how many he has purchased through your own means, an own server or perhaps through firebase, but this already means that you will have to implement a user authentication system for your app.

Consume a purchase:

ConsumeResponseListener consumeListener = new ConsumeResponseListener() {
            @Override
            public void onConsumeResponse(BillingResult billingResult, String purchaseToken) {

            }
        };
 String token = purchase.getPurchaseToken();
            ConsumeParams consumeParams = ConsumeParams.newBuilder().setPurchaseToken(token).build();
            billingClient.consumeAsync(consumeParams, consumeListener);

Upvotes: 2

Related Questions