Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if the user has bought a subscription

in my android app i implemented the in App-Billing, where the user can buy a subscription in the app. when the user launch the app, i want to check if he has any subscription at all, to decide which content should i show him. i'm using the latest in-app-billing library implementation 'com.android.billingclient:billing:1.1' thank you in advance for the help

like image 863
korchix Avatar asked Oct 21 '25 05:10

korchix


2 Answers

You have two options

  1. Create a WebAPI as Google suggest having a separate server which tracks users purchases and communicates with the Google APIs. Refer LINK.
  2. Use Google's InApp billing library to get users subscription.

Refer this answer. It will give you some idea of In-app purchase workflow.

I also suggest you go through some articles about InApp purchase.

  • Tutorial: How to Implement In-app Billing in Android LINK
  • Article on implementing InApp purchase LINK.
  • How to verify purchase for android app in server side (google play in app billing v3) LINK.
  • Another SO answer LINK
  • Another SO answer LINK
  • Code Project Sample LINK.
like image 146
Kishan Vaishnav Avatar answered Oct 23 '25 21:10

Kishan Vaishnav


my goal was to find out, if the user has a subscription at all. i have resolved it like this.

    mBillingManager = new BillingManager(this);

    Purchase.PurchasesResult  purchasesResult = mBillingManager.getPurchaseMadeByUser();
    if(purchasesResult.getResponseCode() == BillingClient.BillingResponse.OK && (purchasesResult.getPurchasesList() != null)){
        hasSubscription = true;
    }

and everywhere in the app, i check if hasSubscription == true then don't load the ads.

to set up the In-App Billing in my App, i followed this Tutorial from Google : https://codelabs.developers.google.com/codelabs/play-billing-codelab/#0

like image 29
korchix Avatar answered Oct 23 '25 21:10

korchix