Skip to main content

v1.0.0-rc - Simplified API Design

ยท 3 min read
Hyo

We're excited to announce the release of kmp-iap v1.0.0-rc, which brings significant API improvements that make in-app purchases even easier to implement in your Kotlin Multiplatform projects.

๐ŸŽฏ Key Changesโ€‹

Simplified API Designโ€‹

We've removed unnecessary wrapper classes to make the API more intuitive and reduce boilerplate code. The core methods now accept parameters directly instead of requiring wrapper objects.

๐Ÿ“ API Changesโ€‹

1. requestProducts() - Direct Parametersโ€‹

Before (v1.0.0-beta)โ€‹

val products = kmpIapInstance.requestProducts(
ProductRequest(
skus = listOf("product_id"),
type = ProductType.INAPP
)
)

After (v1.0.0-rc)โ€‹

val products = kmpIapInstance.requestProducts(
skus = listOf("product_id"),
type = ProductType.INAPP
)

2. requestPurchase() - Streamlined Parametersโ€‹

Before (v1.0.0-beta)โ€‹

val purchase = kmpIapInstance.requestPurchase(
RequestPurchaseProps(
ios = RequestPurchaseIosProps(
sku = "product_id",
quantity = 1
),
android = RequestPurchaseAndroidProps(
skus = listOf("product_id")
)
)
)

After (v1.0.0-rc)โ€‹

// Cross-platform purchase with DSL
val purchase = kmpIapInstance.requestPurchase {
ios {
sku = "product_id"
quantity = 1
}
android {
skus = listOf("product_id")
}
}

// Single platform purchase
val iosPurchase = kmpIapInstance.requestPurchase {
ios {
sku = "product_id"
}
}

๐Ÿš€ Migration Guideโ€‹

Update Your Gradle Dependenciesโ€‹

dependencies {
implementation("io.github.hyochan:kmp-iap:1.0.0-rc.2")
}

Code Migrationโ€‹

The migration is straightforward - simply remove the wrapper classes:

  1. For requestProducts(): Remove ProductRequest wrapper
  2. For requestPurchase(): Remove RequestPurchaseProps wrapper and pass parameters directly

Complete Exampleโ€‹

Here's a complete example showing the new simplified API:

import io.github.hyochan.kmpiap.kmpIapInstance
import io.github.hyochan.kmpiap.*

class StoreViewModel {
suspend fun loadProducts() {
// Initialize connection
val connected = kmpIapInstance.initConnection()
if (!connected) return

// Load products - no wrapper needed
val products = kmpIapInstance.requestProducts(
skus = listOf("premium", "coins_100", "coins_500"),
type = ProductType.INAPP
)

// Load subscriptions
val subscriptions = kmpIapInstance.requestProducts(
skus = listOf("monthly_sub", "yearly_sub"),
type = ProductType.SUBS
)
}

suspend fun purchaseProduct(productId: String) {
// Simple purchase - just pass the SKU
val purchase = kmpIapInstance.requestPurchase(sku = productId)

// Handle the purchase
kmpIapInstance.finishTransaction(
purchase = purchase,
isConsumable = true
)
}

suspend fun purchaseWithOptions(productId: String) {
// Purchase with platform-specific options
val purchase = kmpIapInstance.requestPurchase(
sku = productId,
ios = RequestPurchaseIosProps(
sku = productId,
quantity = 1,
appAccountToken = "user_token"
),
android = RequestPurchaseAndroidProps(
skus = listOf(productId),
obfuscatedAccountIdAndroid = "user_123"
)
)
}
}

โœจ Benefitsโ€‹

  1. Cleaner Code: Less boilerplate, more readable code
  2. Easier to Use: Direct parameter passing is more intuitive
  3. Better IDE Support: Better auto-completion and parameter hints
  4. Backward Compatible: Platform-specific options still available when needed

๐Ÿ”„ What's Nextโ€‹

This RC1 release brings us closer to the stable 1.0.0 release. We're focusing on:

  • Final testing and bug fixes
  • Documentation improvements
  • Community feedback integration

๐Ÿ“š Resourcesโ€‹

๐Ÿ™ Feedbackโ€‹

Please try out the new API and let us know your feedback! Report any issues on our GitHub Issues page.

Happy coding! ๐ŸŽ‰