Home > Net >  How to fix in app purchase for android app?
How to fix in app purchase for android app?

Time:08-24

I have an application live in google play store and have some problems when add billing 3V to handle subscriptions. Any new subscribers can’t access in my application after payment and the payment done and appear in google console .

I hope to help me to handle in app purchase in my application and this is the code :

public static void isUserHasSubscription(Context context, onCheck onCheck) { BillingClient billingClient = BillingClient.newBuilder(context).enablePendingPurchases().setListener(new PurchasesUpdatedListener() { @Override public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List list) {

        }
    }).build();

    billingClient.startConnection(new BillingClientStateListener() {
        @Override
        public void onBillingSetupFinished(BillingResult billingResult) {
            Purchase.PurchasesResult purchasesResult=billingClient.queryPurchases(BillingClient.SkuType.SUBS);


            billingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.SUBS,(billingResult1, list) -> {

                Log.d("billingprocess","purchasesResult.getPurchasesList():" purchasesResult.getPurchasesList());

                //                        //here you can pass the user to use the app because he has an active subscription
                //                        Intent myIntent=new Intent(context,MainActivity.class);
                //                        startActivity(myIntent);
                boolean isPrshees = billingResult1.getResponseCode() == BillingClient.BillingResponseCode.OK && !Objects.requireNonNull(purchasesResult.getPurchasesList()).isEmpty();

                onCheck.onCheck(isPrshees,isPrshees?getOrderId(purchasesResult.getPurchasesList().get(0).getOriginalJson()):"");

            });
        }
        @Override
        public void onBillingServiceDisconnected() {
            onCheck.onCheck(false,"") ;
            // Try to restart the connection on the next request to
            // Google Play by calling the startConnection() method.
            Log.d("billingprocess","onBillingServiceDisconnected");
        }
    });
}

CodePudding user response:

I used the below the library and it's working fine. Please try it, hope its helps you. https://github.com/anjlab/android-inapp-billing-v3 Thank you.

CodePudding user response:

A simple implementation of the Android In-App Billing API.

dependencies {
    implementation 'com.github.moisoni97:google-inapp-billing:1.0.5'
}

More Info. on Github :- https://github.com/Mahadev-code/Android-inApp-Billing

  • Related