This library is Google Play Billing Library wrapper with Coroutine.
- Add it in your settings.gradle at the end of repositories.
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add the dependency
dependencies {
implementation("com.github.TatsukiIshijima.google-billing:core:$version")
implementation("com.github.TatsukiIshijima.google-billing:feature:$version")
// option
// testImplementation("com.github.TatsukiIshijima.google-billing:fake:$version")
}
val googleBillingService = GoogleBillingServiceImpl(
GoogleBillingClientFactoryImpl(
context,
PurchasesListener
)
)
coroutineScope.launch {
try {
val connectionState = googleBillingService.connect()
} catch (e: GoogleBillingServiceException) {
}
}
googleBillingService.disconnect()
coroutineScope.launch {
try {
googleBillingService.purchaseSubscription(
productDetails,
offerToken,
activity,
)
} catch (e: GoogleBillingServiceException) {
}
}
coroutineScope.launch {
try {
googleBillingService.acknowledgePurchase(purchaseToken)
} catch (e: GoogleBillingServiceException) {
}
}
coroutineScope.launch {
try {
googleBillingService.purchaseConsumableProduct(
productDetails,
activity
)
} catch (e: GoogleBillingServiceException) {
}
}
coroutineScope.launch {
try {
googleBillingService.consumePurchase(purchaseTOken)
} catch (e: GoogleBillingServiceException) {
}
}
To build in a local environment, execute the following command in project directory. If successful, an artifact for each module will be created in $HOME/.m2/google-billing.
./gradlew :core:publishToMavenLocal
./gradlew :feature:publishToMavenLocal
./gradlew :fake:publishToMavenLocal