Reputation: 197
I'm following this docs to implement google pay:
https://developer.android.com/google/play/billing/billing_library_overview
After running this function and purchage a product:
fun buy() {
val skuList = listOf("vip_small")
if (billingClient.isReady) {
val params = SkuDetailsParams
.newBuilder()
.setSkusList(skuList)
.setType(BillingClient.SkuType.INAPP)
.build()
billingClient.querySkuDetailsAsync(params) { responseCode, skuDetailsList ->
if (responseCode == BillingClient.BillingResponse.OK) {
Log.d("lets", "querySkuDetailsAsync, responseCode: $responseCode")
val flowParams = BillingFlowParams.newBuilder()
.setSku("vip_small")
.setType(BillingClient.SkuType.INAPP) // SkuType.SUB for subscription
.build()
val responseCodee = billingClient.launchBillingFlow(this, flowParams)
Log.d("lets", "launchBillingFlow responseCode: $responseCodee")
} else {
Log.d("lets", "Can't querySkuDetailsAsync, responseCode: $responseCode")
}
}
} else {
Log.d("lets", "Billing Client not ready")
}
}
which works fine I want to know if the purchage has been made so I add this code from the cods:
override fun onPurchasesUpdated(@BillingResponse responseCode: Int, purchases: List<Purchase>?) {
if (responseCode == BillingResponse.OK && purchases != null) {
for (purchase in purchases) {
handlePurchase(purchase)
}
} else if (responseCode == BillingResponse.USER_CANCELED) {
// Handle an error caused by a user cancelling the purchase flow.
} else {
// Handle any other error codes.
}
}
But I get the error 'onPurchasesUpdated' overrides nothing
So I remove override
and get this "error"
Function "onPurchasesUpdated" is never used
What the hell?? How to call this damn function after the purchage has been made?
Upvotes: 2
Views: 1407
Reputation: 197
I got the solution.
You need to make the activity/fragment use the PurchasesUpdatedListener
like:
class VIP : AppCompatActivity(), PurchasesUpdatedListener {
}
Then override will work
Upvotes: 6