Google In App Billing differentiate user accounts

旧巷老猫 提交于 2021-01-29 06:12:13

问题


I'm developing an app that contains In App Billing non consumable product (Life time Subscription).
User has one email associated with Play Store on his device.

Scenario:
User A create new account using user1@test.com and purchase Lifetime Subscription and logout.
User B create new account using user2@test.com and trying to purchase.
but he get response BillingClient.BillingResponse.ITEM_ALREADY_OWNED.

How do i differ each user to buy item?
I'm using 'com.android.billingclient:billing:2.2.1'


回答1:


If you are using Firebase authentication then you can get user's unique id using String uid = FirebaseAuth.getInstance().getCurrentUser().getUid() and you can use this Id at the time of purchase like -

BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
                .setSkuDetails(skuDetails).setObfuscatedAccountId(uid)
                .build();
        BillingResult billingResult = billingClient.launchBillingFlow(activity, billingFlowParams);

Also in your database use this as unique identifier to check whether user has the subscriotion or not.



来源:https://stackoverflow.com/questions/63130255/google-in-app-billing-differentiate-user-accounts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!