← Back to notebook index

Notebook Topic

In‑App Purchases

English topic guide inspired by the original iOS Developer Notebook, expanded for both iOS and Android teams.

What this topic covers

Execution checklist

iOS implementation notes

Android implementation notes

Code examples

Swift

import StoreKit

@MainActor
func purchase(_ product: Product) async throws -> Transaction {
    let result = try await product.purchase()
    switch result {
    case .success(let verification):
        let transaction = try verification.payloadValue
        await transaction.finish()
        return transaction
    default:
        throw NSError(domain: "IAP", code: 1)
    }
}

Kotlin

fun acknowledgePurchase(purchase: Purchase) {
    if (!purchase.isAcknowledged) {
        val params = AcknowledgePurchaseParams
            .newBuilder()
            .setPurchaseToken(purchase.purchaseToken)
            .build()
        billingClient.acknowledgePurchase(params) { result ->
            check(result.responseCode == BillingClient.BillingResponseCode.OK)
        }
    }
}

Reference links

Related topics