Skip to content

TatsukiIshijima/google-billing

Repository files navigation

google-billing

License: MIT

What's this?

This library is Google Play Billing Library wrapper with Coroutine.

Add dependencies

  1. 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' }
    }
}
  1. 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")
}

How to Use

instance

val googleBillingService = GoogleBillingServiceImpl(
 GoogleBillingClientFactoryImpl(
   context,
   PurchasesListener
 )
)

connect

coroutineScope.launch {
  try {
    val connectionState = googleBillingService.connect()
  } catch (e: GoogleBillingServiceException) {
    
  }
}

disconnect

googleBillingService.disconnect()

purchaseSubscription

coroutineScope.launch {
  try {
    googleBillingService.purchaseSubscription(
      productDetails,
      offerToken,
      activity,
    )
  } catch (e: GoogleBillingServiceException) {

  }
}

acknowledgePurchase

coroutineScope.launch {
  try {
    googleBillingService.acknowledgePurchase(purchaseToken)
  } catch (e: GoogleBillingServiceException) {

  }
}

purchaseConsumableProduct

coroutineScope.launch {
  try {
    googleBillingService.purchaseConsumableProduct(
      productDetails,
      activity
    )
  } catch (e: GoogleBillingServiceException) {

  }
}

consumePurchase

coroutineScope.launch {
  try {
    googleBillingService.consumePurchase(purchaseTOken)
  } catch (e: GoogleBillingServiceException) {

  }
}

Local build

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.

core

./gradlew :core:publishToMavenLocal

feature

./gradlew :feature:publishToMavenLocal

fake

./gradlew :fake:publishToMavenLocal