13

I want to get order id or email id of user when he purchases my app from play store.

I want that when ever user purchases my app, the order id gets stored in my sql database. Next when user signup from my app and enters order id, that order id can be validated with stored order id.

Or if I can get email id used for that purchase then I can store that purchase with that email id.

Thanks

Anku Agarwal
  • 459
  • 1
  • 3
  • 12

2 Answers2

2

It cannot be done.

You cannot get the order IDs of customer purchases.

Tom Alabaster
  • 965
  • 6
  • 12
1

When the application open then in your first activity you can have this method for checking purchase done or not?

This is basic code to understand how to get inapp details, You may need to add security in this by using native or encryption.

public class HomeActivity extends Activity{
private IabHelper mIabHelper;
    private void checkPurchase(){
        String base64EncodedPublickey = "Your BASE 64 key";
        if (mIabHelper == null) {
            mIabHelper = new IabHelper(getActivity(), base64EncodedPublickey);
            mIabHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
                @Override
                public void onIabSetupFinished(IabResult result) {
                    try {
                        if (result.isSuccess()) {
                            mIabHelper.queryInventoryAsync(mQueryFinishedListener);
                        }
                    } catch (IabHelper.IabAsyncInProgressException e) {
                    }
                }
            });
        }
    }

    IabHelper.QueryInventoryFinishedListener
                mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
            public void onQueryInventoryFinished(final IabResult result, final Inventory inventory) {
                Gson gson = new Gson();
                try {
                    if (result.isFailure()) {
                        return;
                    }
                    if (inventory.hasPurchase("Package name")) {
                        Purchase purchase = inventory.getPurchase("Inapp Package name");
                        if (purchase != null) {
                            String puchaseDetails = gson.toJson(purchase);
                              Log.e(TAG, "Purchase Data : "+puchaseDetails);
                        }
                    }
                } catch (Exception e) {
                    localData = null;
                }
            }
        };
}
Amjad Khan
  • 1,309
  • 15
  • 32