Skip to content
This repository was archived by the owner on Oct 17, 2025. It is now read-only.

Commit 59ba42e

Browse files
authored
IAP module refactor, Kotlin 2, Compose (#2)
## Refactor - Initialize billing via `initBillingClient` - Add `ProductManager` caching - Strengthen `fetchProducts` and `requestPurchase` - Expose: - `getAvailableItems(type)` - `getStorefront` - Move private helpers below public API - Remove `ExpoMapMappers` in favor of model `toJSON` ## Upgrade - Upgrade to Kotlin **2.0.21** - Enable Kotlin Compose plugin in **app** and **library** - Align to **Java 17** - Remove deprecated `targetSdk` in library
1 parent 5683fe2 commit 59ba42e

File tree

10 files changed

+468
-244
lines changed

10 files changed

+468
-244
lines changed

Example/build.gradle.kts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id("com.android.application")
33
id("org.jetbrains.kotlin.android")
4+
id("org.jetbrains.kotlin.plugin.compose")
45
}
56

67
android {
@@ -33,23 +34,18 @@ android {
3334
}
3435

3536
compileOptions {
36-
sourceCompatibility = JavaVersion.VERSION_11
37-
targetCompatibility = JavaVersion.VERSION_11
37+
sourceCompatibility = JavaVersion.VERSION_17
38+
targetCompatibility = JavaVersion.VERSION_17
3839
}
3940

4041
kotlinOptions {
41-
jvmTarget = "11"
42+
jvmTarget = "17"
4243
}
4344

4445
buildFeatures {
4546
compose = true
4647
}
4748

48-
composeOptions {
49-
kotlinCompilerExtensionVersion =
50-
(project.findProperty("COMPOSE_COMPILER_VERSION") as String?) ?: "1.5.14"
51-
}
52-
5349
packaging {
5450
resources {
5551
excludes += "/META-INF/{AL2.0,LGPL2.1}"
@@ -81,4 +77,3 @@ dependencies {
8177
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
8278
androidTestImplementation("androidx.compose.ui:ui-test-junit4:$composeUiVersion")
8379
}
84-

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
plugins {
22
id("com.android.library") version "8.5.0" apply false
33
id("com.android.application") version "8.5.0" apply false
4-
id("org.jetbrains.kotlin.android") version "1.9.24" apply false
4+
id("org.jetbrains.kotlin.android") version "2.0.21" apply false
5+
id("org.jetbrains.kotlin.plugin.compose") version "2.0.21" apply false
56
id("com.vanniktech.maven.publish") version "0.29.0" apply false
67
}
78

openiap/build.gradle.kts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id("com.android.library")
33
id("org.jetbrains.kotlin.android")
4+
id("org.jetbrains.kotlin.plugin.compose")
45
id("com.vanniktech.maven.publish")
56
}
67

@@ -16,7 +17,6 @@ android {
1617

1718
defaultConfig {
1819
minSdk = 21
19-
targetSdk = 34
2020

2121
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2222
consumerProguardFiles("consumer-rules.pro")
@@ -33,31 +33,26 @@ android {
3333
}
3434

3535
compileOptions {
36-
sourceCompatibility = JavaVersion.VERSION_11
37-
targetCompatibility = JavaVersion.VERSION_11
36+
sourceCompatibility = JavaVersion.VERSION_17
37+
targetCompatibility = JavaVersion.VERSION_17
3838
}
3939

4040
kotlinOptions {
41-
jvmTarget = "11"
41+
jvmTarget = "17"
4242
}
4343

4444
// Enable Compose for composables in this library (IapContext)
4545
buildFeatures {
4646
compose = true
4747
}
48-
49-
composeOptions {
50-
kotlinCompilerExtensionVersion =
51-
(project.findProperty("COMPOSE_COMPILER_VERSION") as String?) ?: "1.5.14"
52-
}
5348
}
5449

5550
dependencies {
5651
implementation("androidx.core:core-ktx:1.12.0")
5752
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
5853

59-
// Google Play Billing Library
60-
api("com.android.billingclient:billing-ktx:6.0.1")
54+
// Google Play Billing Library (align with app/lib v8)
55+
api("com.android.billingclient:billing-ktx:8.0.0")
6156

6257
// Kotlin Coroutines
6358
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")

openiap/src/main/java/dev/hyo/openiap/OpenIapError.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ sealed class OpenIapError : Exception() {
99
abstract val code: String
1010
abstract override val message: String
1111

12+
fun toJSON(): Map<String, Any?> = mapOf(
13+
"code" to toCode(this),
14+
"message" to (this.message ?: ""),
15+
"platform" to "android",
16+
)
17+
1218
data class ProductNotFound(val productId: String) : OpenIapError() {
1319
override val code = "PRODUCT_NOT_FOUND"
1420
override val message = "Product not found: $productId"

0 commit comments

Comments
 (0)