package com.jeremybarbet.reactnativepurchasekit import com.android.billingclient.api.ProductDetails data class PurchaseKitPrice( val value: Double, val currency: String?, val localized: String?, ) fun parsePrice(product: ProductDetails, type: String?): PurchaseKitPrice { val isSubscriptionType = type == "subscription" val hasSubscription = product.subscriptionOfferDetails?.isNotEmpty() ?: false return if (isSubscriptionType && hasSubscription) { /** * At the moment, we only have one active offer for a subscription at a time * We make the implementation as straight forward as possible to start with */ val details = product.subscriptionOfferDetails!![0].pricingPhases.pricingPhaseList[0] PurchaseKitPrice( details.priceAmountMicros.div(1000000.0), details.priceCurrencyCode, details.formattedPrice, ) } else { val details = product.oneTimePurchaseOfferDetails PurchaseKitPrice( details?.priceAmountMicros?.div(1000000.0) ?: 0.0, details?.priceCurrencyCode, details?.formattedPrice, ) } }