mirror of
https://github.com/ProtonMail/protoncore_android.git
synced 2026-06-14 09:54:49 +00:00
fix(plan): Fix subscription plan amount.
This commit is contained in:
+9
@@ -41,6 +41,12 @@ internal data class SubscriptionItemResponse(
|
||||
val currency: String,
|
||||
@SerialName("Amount")
|
||||
val amount: Long,
|
||||
@SerialName("Discount")
|
||||
val discount: Long,
|
||||
@SerialName("RenewDiscount")
|
||||
val renewDiscount: Long,
|
||||
@SerialName("RenewAmount")
|
||||
val renewAmount: Long,
|
||||
@SerialName("External")
|
||||
val external: Int? = null,
|
||||
@SerialName("Plans")
|
||||
@@ -57,6 +63,9 @@ internal data class SubscriptionItemResponse(
|
||||
couponCode = couponCode,
|
||||
currency = currency,
|
||||
amount = amount,
|
||||
discount = discount,
|
||||
renewDiscount = renewDiscount,
|
||||
renewAmount = renewAmount,
|
||||
external = SubscriptionManagement.map[external],
|
||||
plans = plans.map { it.toPlan() },
|
||||
customerId = customerId
|
||||
|
||||
+4
-1
@@ -392,7 +392,10 @@ class PaymentsRepositoryImplTest {
|
||||
periodEnd = 2L,
|
||||
couponCode = null,
|
||||
currency = "EUR",
|
||||
amount = 5L,
|
||||
amount = 5,
|
||||
discount = 0,
|
||||
renewDiscount = 0,
|
||||
renewAmount = 5,
|
||||
plans = listOf(mockk()),
|
||||
external = SubscriptionManagement.PROTON_MANAGED,
|
||||
customerId = null
|
||||
|
||||
+4
-1
@@ -62,7 +62,10 @@ class PerformSubscribeTest {
|
||||
periodEnd = 2L,
|
||||
couponCode = null,
|
||||
currency = "EUR",
|
||||
amount = 5L,
|
||||
amount = 5,
|
||||
discount = 0,
|
||||
renewDiscount = 0,
|
||||
renewAmount = 5,
|
||||
plans = listOf(mockk()),
|
||||
external = SubscriptionManagement.PROTON_MANAGED,
|
||||
customerId = null
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
"CouponCode": null,
|
||||
"Currency": "EUR",
|
||||
"Amount": 4788,
|
||||
"Discount":0,
|
||||
"RenewDiscount":0,
|
||||
"RenewAmount":4788,
|
||||
"Plans": [
|
||||
{
|
||||
"ID": "Wb4NAqmiuqoA7kCHE28y92bBFfN8jaYQCLxHRAB96yGj-bh9SxguXC48_WSU-fRUjdAr-lx95c6rFLplgXyXYA==",
|
||||
|
||||
@@ -29,6 +29,9 @@ public data class Subscription constructor(
|
||||
val couponCode: String?,
|
||||
val currency: String,
|
||||
val amount: Long,
|
||||
val discount: Long,
|
||||
val renewDiscount: Long,
|
||||
val renewAmount: Long,
|
||||
val external: SubscriptionManagement?,
|
||||
val plans: List<Plan>,
|
||||
val customerId: String?
|
||||
|
||||
+3
@@ -51,6 +51,9 @@ class GetCurrentSubscriptionTest {
|
||||
couponCode = null,
|
||||
currency = "EUR",
|
||||
amount = 5,
|
||||
discount = 0,
|
||||
renewDiscount = 0,
|
||||
renewAmount = 5,
|
||||
plans = listOf(mockk()),
|
||||
external = SubscriptionManagement.PROTON_MANAGED,
|
||||
customerId = null
|
||||
|
||||
+1
-1
@@ -131,7 +131,7 @@ class UpgradePlansFragment : BasePlansFragment(R.layout.fragment_plans_upgrade)
|
||||
currentPlan.apply {
|
||||
setBackgroundResource(R.drawable.background_current_plan)
|
||||
visibility = if (input.showSubscription) VISIBLE else GONE
|
||||
setData(plan = plan, currency = currency, collapsible = false)
|
||||
setData(plan = plan, renewAmount = it.renewAmount, currency = currency, collapsible = false)
|
||||
}
|
||||
|
||||
if (it.unredeemedGooglePurchase != null) {
|
||||
|
||||
+5
-3
@@ -32,6 +32,7 @@ import me.proton.core.plan.presentation.entity.PlanCurrency
|
||||
import me.proton.core.plan.presentation.entity.PlanCycle
|
||||
import me.proton.core.plan.presentation.entity.PlanDetailsItem
|
||||
import me.proton.core.presentation.utils.PRICE_ZERO
|
||||
import me.proton.core.presentation.utils.Price
|
||||
import me.proton.core.presentation.utils.formatCentsPriceDefaultLocale
|
||||
import me.proton.core.presentation.utils.onClick
|
||||
import me.proton.core.util.kotlin.exhaustive
|
||||
@@ -55,6 +56,7 @@ class PlanItemView @JvmOverloads constructor(
|
||||
|
||||
fun setData(
|
||||
plan: PlanDetailsItem,
|
||||
renewAmount: Long?,
|
||||
cycle: PlanCycle = PlanCycle.YEARLY,
|
||||
currency: PlanCurrency?,
|
||||
collapsible: Boolean = true
|
||||
@@ -68,7 +70,7 @@ class PlanItemView @JvmOverloads constructor(
|
||||
when (plan) {
|
||||
is PlanDetailsItem.FreePlanDetailsItem -> bindFreePlan(plan)
|
||||
is PlanDetailsItem.PaidPlanDetailsItem -> bindPaidPlan(plan)
|
||||
is PlanDetailsItem.CurrentPlanDetailsItem -> bindCurrentPlan(plan)
|
||||
is PlanDetailsItem.CurrentPlanDetailsItem -> bindCurrentPlan(renewAmount?.toDouble(), plan)
|
||||
}.exhaustive
|
||||
}
|
||||
|
||||
@@ -84,7 +86,7 @@ class PlanItemView @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindCurrentPlan(plan: PlanDetailsItem.CurrentPlanDetailsItem) = with(binding) {
|
||||
private fun bindCurrentPlan(renewAmount: Price?, plan: PlanDetailsItem.CurrentPlanDetailsItem) = with(binding) {
|
||||
currentPlanGroup.visibility = VISIBLE
|
||||
storageProgress.apply {
|
||||
val usedPercentage = plan.usedSpace.toDouble() / plan.maxSpace
|
||||
@@ -151,7 +153,7 @@ class PlanItemView @JvmOverloads constructor(
|
||||
separator.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
val amount = plan.price?.let { price -> plan.cycle?.getPrice(price) } ?: PRICE_ZERO
|
||||
val amount = renewAmount ?: plan.price?.let { price -> plan.cycle?.getPrice(price) } ?: PRICE_ZERO
|
||||
billableAmount = amount
|
||||
planPriceText.text = amount.formatCentsPriceDefaultLocale(currency.name)
|
||||
}
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ internal class PlansListView @JvmOverloads constructor(
|
||||
getView = { parent, inflater -> PlanListViewItemBinding.inflate(inflater, parent, false) },
|
||||
onBind = { plan ->
|
||||
planDetails.apply {
|
||||
setData(plan = plan, currency = selectedCurrency, collapsible = plansSize != 1)
|
||||
setData(plan = plan, renewAmount = null, currency = selectedCurrency, collapsible = plansSize != 1)
|
||||
|
||||
planSelectionListener = { planId, planName, amount, services, type ->
|
||||
selectPlanListener(
|
||||
|
||||
+6
-4
@@ -73,6 +73,7 @@ internal class UpgradePlansViewModel @Inject @Suppress("LongParameterList") cons
|
||||
sealed class Success : SubscribedPlansState() {
|
||||
data class SubscribedPlans(
|
||||
val subscribedPlans: List<PlanDetailsItem>,
|
||||
val renewAmount: Long?,
|
||||
val userCurrency: PlanCurrency?,
|
||||
val subscriptionManagement: SubscriptionManagement? = null,
|
||||
val unredeemedGooglePurchase: UnredeemedGooglePurchase? = null
|
||||
@@ -124,10 +125,11 @@ internal class UpgradePlansViewModel @Inject @Suppress("LongParameterList") cons
|
||||
} else null
|
||||
emit(
|
||||
SubscribedPlansState.Success.SubscribedPlans(
|
||||
subscribedPlans,
|
||||
PlanCurrency.map[user.currency],
|
||||
external,
|
||||
unredeemed
|
||||
subscribedPlans = subscribedPlans,
|
||||
renewAmount = currentSubscription?.renewAmount,
|
||||
userCurrency = PlanCurrency.map[user.currency],
|
||||
subscriptionManagement = external,
|
||||
unredeemedGooglePurchase = unredeemed
|
||||
)
|
||||
)
|
||||
}.catch { error ->
|
||||
|
||||
+3
@@ -197,6 +197,9 @@ class UpgradePlansViewModelTest : ArchTest, CoroutinesTest {
|
||||
couponCode = null,
|
||||
currency = "EUR",
|
||||
amount = 5,
|
||||
discount = 0,
|
||||
renewDiscount = 0,
|
||||
renewAmount = 5,
|
||||
plans = listOf(
|
||||
testSubscribedPlan
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user