Android userChoiceBillingListenerAndroid
Fired when a user selects alternative billing in the User Choice Billing dialog on Android.
originalExternalTransactionId and productDetailsAndroid are available in OpenIAP Spec 2.3.0 / openiap-google 2.3.1 (requires Play Billing 9.1+). Legacy payloads may omit structured product details; use products as the product-ID fallback.
Listener Setup
// Android only - not available on iOSRegisters a listener for User Choice Billing events. This listener is only triggered when the user selects alternative billing instead of Google Play billing.
import dev.hyo.openiap.listener.OpenIapUserChoiceBillingListener
val userChoiceListener = OpenIapUserChoiceBillingListener { details ->
lifecycleScope.launch {
println("User chose alternative billing")
println("Products: ${details.products}")
println("External transaction token received; send it to your backend without logging it.")
// Process payment with your backend
val paymentResult = processPaymentWithBackend(
products = details.products,
token = details.externalTransactionToken
)
if (paymentResult.success) {
// Backend should report token to Google Play within 24 hours
grantUserAccess(details.products)
}
}
}
openIapStore.addUserChoiceBillingListener(userChoiceListener)
// Cleanup when done
openIapStore.removeUserChoiceBillingListener(userChoiceListener)Event Payload
// Android only - not available on iOSexternalTransactionToken - Token that must be reported to Google Play within 24 hours
originalExternalTransactionId - Originating external subscription transaction ID for developer-billed replacements (Play Billing 9.1+)
productDetailsAndroid - Selected product IDs, product types, and offer tokens as optional structured Play Billing 9.1+ data; use products when it is absent
products - List of product IDs selected by the user
Handling User Choice Billing
- Receive
UserChoiceBillingDetailsvia listener - Process payment with your backend payment system
- Send the external transaction token to your backend
- Backend reports token to Google Play within 24 hours (required for compliance)
- Grant user access to purchased content
⚠️ Important: The external transaction token MUST be reported to Google Play within 24 hours. Failure to report tokens may result in account suspension. It is strongly recommended to handle token reporting on your backend server for reliability and security.
Flow Comparison
When using User Choice Billing mode, there are two possible flows depending on user selection:
- Google Play selected - Standard
PurchaseUpdatedevent fires (handle normally) - Alternative billing selected -
UserChoiceBillingAndroidevent fires (handle with your payment system)
See External Purchase documentation for complete implementation examples.