Skip to content

Commit

Permalink
feat: move to com.android.billingclient:billing:5.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ch4rl3x committed Apr 8, 2023
1 parent 9dba40e commit 13d9577
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 deletions.
15 changes: 7 additions & 8 deletions billing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ apply from: '../_ktlint.gradle'

ext {
PUBLISH_GROUP_ID = 'de.charlex.billing'
PUBLISH_VERSION = '5.0.0.0-rc02'
PUBLISH_VERSION = '5.2.0-rc01'
PUBLISH_ARTIFACT_ID = 'billing-suspend'
}

apply from: '../_publish.gradle'

android {
compileSdkVersion 33
buildToolsVersion "31.0.0"

defaultConfig {
minSdkVersion 26
minSdkVersion 23
targetSdkVersion 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -47,13 +46,13 @@ dependencies {
/**
* Billing
*/
api 'com.android.billingclient:billing:5.0.0'
api 'com.android.billingclient:billing-ktx:5.0.0'
api 'com.android.billingclient:billing:5.2.0'
api 'com.android.billingclient:billing-ktx:5.2.0'

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.core:core-ktx:1.9.0'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
31 changes: 28 additions & 3 deletions billing/src/main/java/de/charlex/billing/BillingHelper.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.charlex.billing

import android.app.Activity
import android.content.Context
import android.util.Log
import com.android.billingclient.api.AcknowledgePurchaseParams
import com.android.billingclient.api.BillingClient
Expand Down Expand Up @@ -35,24 +36,38 @@ import kotlin.coroutines.suspendCoroutine
/**
* Helps to make all necessary functions from billingClient suspendable
*/
class BillingHelper(private val activity: Activity, billingClientBuilder: BillingClient.Builder.() -> Unit) : PurchasesUpdatedListener {
class BillingHelper(context: Context, billingClientBuilder: BillingClient.Builder.() -> Unit) : PurchasesUpdatedListener {

@Deprecated(level = DeprecationLevel.ERROR, message = "Don't use the constructor with activity as param", replaceWith = ReplaceWith("BillingHelper(context, billingClientBuilder)"))
constructor(activity: Activity, billingClientBuilder: BillingClient.Builder.() -> Unit) : this(activity.applicationContext, billingClientBuilder)

private var billingClient: BillingClient

init {
val builder = BillingClient.newBuilder(activity)
val builder = BillingClient.newBuilder(context)
billingClientBuilder.invoke(builder)
builder.setListener(this)
billingClient = builder.build()
}

private var billingContinuation: Continuation<PurchasesResult>? = null

@Deprecated(level = DeprecationLevel.ERROR, message = "Use showInAppMessages with activity as param", replaceWith = ReplaceWith("showInAppMessages(activity, inAppMessageParams, resultHandler)"))
private fun showInAppMessages(
inAppMessageParams: InAppMessageParams = InAppMessageParams.newBuilder()
.addInAppMessageCategoryToShow(InAppMessageParams.InAppMessageCategoryId.TRANSACTIONAL)
.build(),
resultHandler: (InAppMessageResult) -> Unit
) {
error("Use showInAppMessages with activity as param")
}

private fun showInAppMessages(
activity: Activity,
inAppMessageParams: InAppMessageParams = InAppMessageParams.newBuilder()
.addInAppMessageCategoryToShow(InAppMessageParams.InAppMessageCategoryId.TRANSACTIONAL)
.build(),
resultHandler: (InAppMessageResult) -> Unit
) {
billingClient.showInAppMessages(
activity,
Expand Down Expand Up @@ -199,14 +214,24 @@ class BillingHelper(private val activity: Activity, billingClientBuilder: Billin
}
}

@Deprecated(level = DeprecationLevel.ERROR, message = "Use purchase with activity as param", replaceWith = ReplaceWith("purchase(activity, productDetails, offerToken, isOfferPersonalized, validation)"))
suspend fun purchase(
productDetails: ProductDetails,
offerToken: String? = null,
isOfferPersonalized: Boolean = false,
validation: suspend (Purchase) -> Boolean = { true }
): PurchasesResult? {
error("Use purchase with activity as param")
}

/**
* Performs a network query purchase SKUs
*
* @param sku String[] Specifies the SKUs to be purchased.
* @param type String Specifies the [BillingClient.SkuType](https://developer.android.com/reference/com/android/billingclient/api/BillingClient.SkuType) of SKUs to query.
*
*/
suspend fun purchase(productDetails: ProductDetails, offerToken: String? = null, isOfferPersonalized: Boolean = false, validation: suspend (Purchase) -> Boolean = { true }): PurchasesResult? {
suspend fun purchase(activity: Activity, productDetails: ProductDetails, offerToken: String? = null, isOfferPersonalized: Boolean = false, validation: suspend (Purchase) -> Boolean = { true }): PurchasesResult? {
if (billingClient.startConnectionIfNecessary()) {
// val skuDetails: List<ProductDetails>? = queryProductDetails(sku, type)
// skuDetails?.let {
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.7.0"
ext.kotlin_version = "1.8.10"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath "com.android.tools.build:gradle:7.4.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.30.0'

Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
kotlin.code.style=official
android.disableAutomaticComponentCreation=true
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Sep 14 01:58:53 CEST 2021
#Sat Apr 08 09:34:25 CEST 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit 13d9577

Please sign in to comment.