Repository: Automattic/pocket-casts-android
File: modules/features/account/src/main/java/au/com/shiftyjelly/pocketcasts/account/onboarding/components/SubscriptionPlanRow.kt (Kotlin)

Code before:
                width = 1.dp,
                color = MaterialTheme.theme.colors.primaryIcon02,
                shape = CircleShape,
            ),
        )
    }
}

private val SubscriptionPlan.pricePerMonth: Float
    get() {
        val pricePerMonth = when (billingCycle) {
            BillingCycle.Monthly -> recurringPrice?.amount?.toFloat() ?: 0f
            BillingCycle.Yearly -> (recurringPrice?.amount?.toFloat() ?: 0f) / 12f
        }
        return pricePerMonth
    }

private val SubscriptionPlan.recurringPrice: Price? get() = when (this) {
    is SubscriptionPlan.Base -> pricingPhase.price
    is SubscriptionPlan.WithOffer -> pricingPhases.find { it.schedule.recurrenceMode is PricingSchedule.RecurrenceMode.Infinite }?.price
}

private val SubscriptionPlan.pricePerWeek: Float
    get() {
        val pricePerWeek = when (billingCycle) {
            BillingCycle.Monthly -> (recurringPrice?.amount?.toFloat() ?: 0f) / 4f
            BillingCycle.Yearly -> (recurringPrice?.amount?.toFloat() ?: 0f) / 52f
        }
        return pricePerWeek
    }

@Composable
private fun SubscriptionPlan.pricePerPeriod(config: RowConfig): String? {
    return if (this.billingCycle == BillingCycle.Yearly) {
        when (config.pricePerPeriod) {
            PricePerPeriod.PRICE_PER_MONTH -> {
                val currencyCode = recurringPrice?.currencyCode
                if (currencyCode == "USD") {
                    stringResource(LR.string.price_per_month_usd, pricePerMonth)
                } else {
                    stringResource(LR.string.price_per_month, pricePerMonth, currencyCode.orEmpty())
                }
            }

            PricePerPeriod.PRICE_PER_WEEK -> {
                val currencyCode = recurringPrice?.currencyCode
                if (currencyCode == "USD") {
                    stringResource(LR.string.price_per_week_usd, pricePerWeek)
                } else {
                    stringResource(LR.string.price_per_week, pricePerWeek, currencyCode.orEmpty())
                }

Review comment (suggestion):
🛑 I missed it earlier during the code review but this calculation isn't right for price per week.

20.99 PLN per month / 4 = 5.25 PLN
20.99 PLN per month * 12 / 52 = 4.84 PLN

I made the same mistake [here](https://github.com/Automattic/pocket-casts-android/pull/3908#discussion_r2049756216).

Code after:
                shape = CircleShape,
            ),
        )
    }
}

private val SubscriptionPlan.pricePerMonth: Float
    get() {
        val pricePerMonth = when (billingCycle) {
            BillingCycle.Monthly -> recurringPrice.amount
            BillingCycle.Yearly -> recurringPrice.amount / monthsInYear
        }
        return pricePerMonth.toFloat()
    }

private val SubscriptionPlan.pricePerWeek: Float
    get() {
        val pricePerWeek = when (billingCycle) {
            BillingCycle.Monthly -> recurringPrice.amount * monthsInYear
            BillingCycle.Yearly -> recurringPrice.amount
        } / weeksInYear
        return pricePerWeek.toFloat()
    }

private val monthsInYear = 12.toBigDecimal()
private val weeksInYear = 52.toBigDecimal()

@Composable
private fun SubscriptionPlan.pricePerPeriod(config: RowConfig): String? {
    return if (this.billingCycle == BillingCycle.Yearly) {
        when (config.pricePerPeriod) {
            PricePerPeriod.PRICE_PER_MONTH -> {
                val currencyCode = recurringPrice.currencyCode
                if (currencyCode == "USD") {
                    stringResource(LR.string.price_per_month_usd, pricePerMonth)
                } else {
                    stringResource(LR.string.price_per_month, pricePerMonth, currencyCode)
                }
            }

            PricePerPeriod.PRICE_PER_WEEK -> {
                val currencyCode = recurringPrice.currencyCode
                if (currencyCode == "USD") {
                    stringResource(LR.string.price_per_week_usd, pricePerWeek)
                } else {
                    stringResource(LR.string.price_per_week, pricePerWeek, currencyCode)
                }
            }
        }
    } else {
        null