使用Inapp购买时是否可以添加额外的数据 [英] Is there a way to add extra data when purchasing using Inapp purchases
问题描述
这是一个场景,我们的应用程序中有多位老师.用户可以从老师那里购买3种不同的物品,价格分别为$ 20,$ 30,$ 40.因此,我在Google Play控制台中创建了3种产品.用户购买时我怎么知道他从哪个老师那里买的东西?购买该商品时,我看不到任何设置额外数据的方法.人们通常如何处理这些案件?
Here is a scenerio , We have multiple teachers on our app . User can purchase 3 different items from teacher which costs $20, $30, $40 . So I created 3 products in google play console . When user purchases some item how can I know from which teacher he purchased the item from ? I don't see any way to set extra data when purchasing the item . How people generally handles these cases ?
这是我用来启动付款屏幕的方法
This is the method I use to launch payment screen
fun buyAnItem(activity:Activity,skuDetails: SkuDetails) {
val flowParams = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetails)
.build()
val responseCode =
billingClient.launchBillingFlow(activity, flowParams)
log(responseCode.toString())
}
我看不到在 SkuDetails
或 BillingFlowParams.newBuilder()
我怎么能看到可以为 BillingFlowParams.newBuilder()
.setObfuscatedAccountId()
和 .setObfuscatedProfileId()设置的这两个参数代码>,我应该使用这些吗?对我来说,这似乎是一种hack.
How ever I saw we can set these 2 parameters we can set for BillingFlowParams.newBuilder()
.setObfuscatedAccountId()
and .setObfuscatedProfileId()
, should I be using these ? It looks like a hack to me .
我想找回购买对象中的额外参数
I want to get back the extra params in Purchase object
override fun onPurchasesUpdated(
billingResult: BillingResult?,
purchases: MutableList<Purchase>?
) {
for (purchase in purchases) {
consumePurchase(purchase)
}
}
}
推荐答案
似乎正确的方法就像使用 setObfuscatedProfileId
和 setObfuscatedAccountId
一样.为不同的用户设置一些唯一的值.每个属性最多允许使用64个字符.
Seems like using setObfuscatedProfileId
and setObfuscatedAccountId
is the right way. Set some unique values for different users . maximum of 64 charecters is allowed per each property .
val flowParams = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetails)
.setObfuscatedProfileId(profileId) //Some data you want to send
.setObfuscatedAccountId(id) //Some data you want to send
.build()
val responseCode =
billingClient?.launchBillingFlow(activity, flowParams)
检索:-,您可以使用 purchase.accountIdentifiers?.obfuscatedAccountId
和 purchase.accountIdentifiers?.obfuscatedProfileId
override fun onPurchasesUpdated(
billingResult: BillingResult?,
purchases: MutableList<Purchase>?
) {
if (billingResult?.responseCode == BillingClient.BillingResponseCode.OK && purchases != null) {
for (purchase in purchases) {
CoroutineScope(Dispatchers.Main).launch {
log(purchase.accountIdentifiers?.obfuscatedAccountId)
log(purchase.accountIdentifiers?.obfuscatedProfileId)
consumePurchase(purchase)
}
}
}
}
官方文档:- https://developer.android.com/google/play/billing/developer-payload#attribute
这篇关于使用Inapp购买时是否可以添加额外的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!