Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android billing how to enable enablePendingPurchases()

I've moved from an old gradle of billing api, to the most recent to date, and now I've tried adding

  BillingClient.Builder enablePendingPurchases = BillingClient.newBuilder(this).setListener(this);

but I can not get it to work, here's the error

   Caused by: java.lang.IllegalArgumentException: Support for pending purchases must be enabled. Enable this by calling 'enablePendingPurchases()' on BillingClientBuilder.
        at com.android.billingclient.api.BillingClient$Builder.build(BillingClient.java:309)
        at com.aplicacion.vivaluganoapp.ar.ponerDineroActivity.setupBillingClient(ponerDineroActivity.java:144)
        at com.aplicacion.vivaluganoapp.ar.ponerDineroActivity.onCreate(ponerDineroActivity.java:125)

complete code:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_poner_dinero);

        recyclerProduct.setHasFixedSize(true);
        recyclerProduct.setLayoutManager(new LinearLayoutManager(this));
        BillingClient.Builder enablePendingPurchases = BillingClient.newBuilder(this).setListener(this);

 enablePendingPurchases.build();
setupBillingClient();
    }




    private void setupBillingClient() {


        billingClient = BillingClient.newBuilder (this).setListener(this).build();

        billingClient.startConnection(new BillingClientStateListener() {
            @Override
            public void onBillingSetupFinished(BillingResult responseCode) {
                int maca = BillingClient.BillingResponseCode.OK;
                String maca2 = String.valueOf(maca);

                String maca3 = String.valueOf(responseCode);
                if (maca3 == maca2)
                {
                    Toast.makeText(ponerDineroActivity.this, "WORKS", Toast.LENGTH_SHORT).show();
                }
                else
                {
                    Toast.makeText(ponerDineroActivity.this, "ERROR", Toast.LENGTH_SHORT).show();
                }

            }

            @Override
            public void onBillingServiceDisconnected() {
                Toast.makeText(ponerDineroActivity.this, "Disconnected from Billing", Toast.LENGTH_SHORT).show();
            }
        });

    }

if I place only:

BillingClient.Builder enablePendingPurchases = BillingClient.newBuilder(this);

the error is:

Caused by: java.lang.IllegalArgumentException: Please provide a valid listener for purchases updates.

any help? i'm tired of trying

like image 830
Vampi Avatar asked Jun 07 '19 23:06

Vampi


People also ask

What is billing API version?

The In-app Billing Version 3 API makes it easier for you to integrate In-app Billing into your applications. The features in this version include improved synchronous purchase flow, APIs to let you easily track ownership of consumable goods, and local caching of in-app purchase data.


2 Answers

From the first stacktrace in your question

Enable this by calling 'enablePendingPurchases()'

we can find documentation for method enablePendingPurchases()

This method is required to be called to acknowledge your application has been updated to support purchases that are pending. Pending purchases are not automatically enabled since your application will require updates to ensure entitlement is not granted before payment has been secured. For more information on how to handle pending transactions see https://developer.android.com/google/play/billing/billing_library_overview

If this method is not called, BillingClient instance creation fails.

Your line of code should be:-

enablePendingPurchases = BillingClient.newBuilder(this)
   .enablePendingPurchases()
   .setListener(this);

Instead of :-

enablePendingPurchases = BillingClient.newBuilder(this).setListener(this);
like image 197
Hardy Avatar answered Oct 18 '22 06:10

Hardy


This worked for me.

Just add enablePendingPurchases() like below:

billingClient = BillingClient.newBuilder(this)
                             .setListener(this)
                             .enablePendingPurchases()
                             .build();
like image 10
Donaldo Azemaj Avatar answered Oct 18 '22 06:10

Donaldo Azemaj