问题
I am trying to use the new Android Billing Client library(1.0)
Previously, while trying to perform a purchase, there was option to add extra data to the intent.
However, when using the new library, things have been simplified to a great degree. But is there way to add the developer payload(extra string) to the purchase flow ?
回答1:
The new version of the billing library supports the developer payload.
You can set the developer payload when acknowledging the purchase or consuming it.
val client: BillingClient = ...
val listener: AcknowledgePurchaseResponseListener = ...
val acknowledgePurchaseParams =
AcknowledgePurchaseParams.newBuilder()
.setPurchaseToken(/* token */)
.setDeveloperPayload(/* payload */)
.build()
client.acknowledgePurchase(acknowledgePurchaseParams, listener)
Attach a developer payload in Android Billing Library v2.0
回答2:
Found the answer to it, the names have been changed, hence the confusion.
The BillingFlowParams builder, exposes a function named setAccountId(String accountId)
. The definition for this function is :
Specify an optional obfuscated string that is uniquely associated with the user's account in your app. If you pass this value, Google Play can use it to detect irregular activity, such as many devices making purchases on the same account in a short period of time. Do not use the developer ID or the user's Google ID for this field. In addition, this field should not contain the user's ID in cleartext. We recommend that you use a one-way hash to generate a string from the user's ID and store the hashed string in this field.
I think this is the new way to specify developer payload, or any extra string for extra layer of validation. So the code will look something like this :
private fun makePurchaseFromGoogle(developerPayload : String) {
val purchaseParams = BillingFlowParams.newBuilder()
.setSku(product.sku)
.setType(product.type)
.setAccountId(developerPayload) // dev-payload
.build()
googleBillingClient.launchBillingFlow(activity, purchaseParams)
}
来源:https://stackoverflow.com/questions/49521453/android-billing-client-library-how-to-specify-developer-payloadextra-data