How to get email id or order id to database when user purchases my app from play store

前端 未结 2 960
你的背包
你的背包 2021-01-02 00:48

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

相关标签:
2条回答
  • 2021-01-02 01:08

    It cannot be done.

    You cannot get the order IDs of customer purchases.

    0 讨论(0)
  • 2021-01-02 01:33

    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;
                    }
                }
            };
    }
    
    0 讨论(0)
提交回复
热议问题