play-billing-samples
play-billing-samples copied to clipboard
How to get email in users data in google play subscriptions an additional call to the Google Play Developer API. The subscription purchase
hi How to get Email Playstore when use subscription an additional call to the Google Play Developer API. The subscription purchase
i have use get in code
` private suspend fun checkSubscription() {
var subscriptionPurchase = SubscriptionPurchase()
try {
val credential = subscriptionPurchase.getGoogleCredential(requireContext())
val androidPublisher = subscriptionPurchase.getAndroidPublisher(credential)
val subscriptionPurchase = subscriptionPurchase.getSubscriptionPurchase(androidPublisher, PACKAGE_NAME, SUBSCRIPTION_ID, PURCHASE_TOKEN)
Log.d("SubscriptionChecker", "Subscription Status: ${subscriptionPurchase?.emailAddress}")
// Check if email is present
if (subscriptionPurchase?.emailAddress != null) {
Log.d("SubscriptionChecker", "User Email: ${subscriptionPurchase.emailAddress}")
} else {
Log.d("SubscriptionChecker", "Email address not available for this purchase.")
}
} catch (e: Exception) {
e.printStackTrace()
Log.d("SubscriptionChecker Error", e.message.toString())
}
}
public fun getAndroidPublisher(credential: GoogleCredential): AndroidPublisher {
return AndroidPublisher.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
// .setApplicationName(APPLICATION_NAME)
.build()
}
public suspend fun getSubscriptionPurchase(
androidPublisher: AndroidPublisher,
packageName: String,
subscriptionId: String,
token: String
): SubscriptionPurchase? {
return withContext(Dispatchers.IO) {
androidPublisher.purchases().subscriptions().get(packageName, subscriptionId, token).execute()
}
}
public fun getGoogleCredential(context: Context): GoogleCredential {
val assetManager = context.assets
val inputStream: InputStream = assetManager!!.open(SERVICE_ACCOUNT_FILE_PATH)
return GoogleCredential.fromStream(inputStream)
.createScoped(listOf(AndroidPublisherScopes.ANDROIDPUBLISHER))
}`
and i. debug code in show detail. and why. not get email. please help