diff --git a/payment/data/src/main/kotlin/me/proton/core/payment/data/api/response/SubscriptionItemResponse.kt b/payment/data/src/main/kotlin/me/proton/core/payment/data/api/response/SubscriptionItemResponse.kt index f301f2136..95136efd5 100644 --- a/payment/data/src/main/kotlin/me/proton/core/payment/data/api/response/SubscriptionItemResponse.kt +++ b/payment/data/src/main/kotlin/me/proton/core/payment/data/api/response/SubscriptionItemResponse.kt @@ -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 diff --git a/payment/data/src/test/kotlin/me/proton/core/payment/data/repository/PaymentsRepositoryImplTest.kt b/payment/data/src/test/kotlin/me/proton/core/payment/data/repository/PaymentsRepositoryImplTest.kt index f7a478535..9a8bc729f 100644 --- a/payment/data/src/test/kotlin/me/proton/core/payment/data/repository/PaymentsRepositoryImplTest.kt +++ b/payment/data/src/test/kotlin/me/proton/core/payment/data/repository/PaymentsRepositoryImplTest.kt @@ -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 diff --git a/payment/data/src/test/kotlin/me/proton/core/payment/data/usecase/PerformSubscribeTest.kt b/payment/data/src/test/kotlin/me/proton/core/payment/data/usecase/PerformSubscribeTest.kt index b95378aee..2fa4e6055 100644 --- a/payment/data/src/test/kotlin/me/proton/core/payment/data/usecase/PerformSubscribeTest.kt +++ b/payment/data/src/test/kotlin/me/proton/core/payment/data/usecase/PerformSubscribeTest.kt @@ -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 diff --git a/payment/data/src/test/resources/GET/payments/v4/subscription.json b/payment/data/src/test/resources/GET/payments/v4/subscription.json index e82430299..34275649e 100644 --- a/payment/data/src/test/resources/GET/payments/v4/subscription.json +++ b/payment/data/src/test/resources/GET/payments/v4/subscription.json @@ -9,6 +9,9 @@ "CouponCode": null, "Currency": "EUR", "Amount": 4788, + "Discount":0, + "RenewDiscount":0, + "RenewAmount":4788, "Plans": [ { "ID": "Wb4NAqmiuqoA7kCHE28y92bBFfN8jaYQCLxHRAB96yGj-bh9SxguXC48_WSU-fRUjdAr-lx95c6rFLplgXyXYA==", diff --git a/payment/domain/src/main/kotlin/me/proton/core/payment/domain/entity/Subscription.kt b/payment/domain/src/main/kotlin/me/proton/core/payment/domain/entity/Subscription.kt index 37649bde2..c16d099b3 100644 --- a/payment/domain/src/main/kotlin/me/proton/core/payment/domain/entity/Subscription.kt +++ b/payment/domain/src/main/kotlin/me/proton/core/payment/domain/entity/Subscription.kt @@ -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, val customerId: String? diff --git a/payment/domain/src/test/kotlin/me/proton/core/payment/domain/usecase/GetCurrentSubscriptionTest.kt b/payment/domain/src/test/kotlin/me/proton/core/payment/domain/usecase/GetCurrentSubscriptionTest.kt index 2e368e7ee..39afc1e2e 100644 --- a/payment/domain/src/test/kotlin/me/proton/core/payment/domain/usecase/GetCurrentSubscriptionTest.kt +++ b/payment/domain/src/test/kotlin/me/proton/core/payment/domain/usecase/GetCurrentSubscriptionTest.kt @@ -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 diff --git a/plan/presentation/src/main/kotlin/me/proton/core/plan/presentation/ui/UpgradePlansFragment.kt b/plan/presentation/src/main/kotlin/me/proton/core/plan/presentation/ui/UpgradePlansFragment.kt index 0d19c3ea6..1c1ad2a00 100644 --- a/plan/presentation/src/main/kotlin/me/proton/core/plan/presentation/ui/UpgradePlansFragment.kt +++ b/plan/presentation/src/main/kotlin/me/proton/core/plan/presentation/ui/UpgradePlansFragment.kt @@ -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) { diff --git a/plan/presentation/src/main/kotlin/me/proton/core/plan/presentation/view/PlanItemView.kt b/plan/presentation/src/main/kotlin/me/proton/core/plan/presentation/view/PlanItemView.kt index cf20eaa86..e81e5f052 100644 --- a/plan/presentation/src/main/kotlin/me/proton/core/plan/presentation/view/PlanItemView.kt +++ b/plan/presentation/src/main/kotlin/me/proton/core/plan/presentation/view/PlanItemView.kt @@ -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) } diff --git a/plan/presentation/src/main/kotlin/me/proton/core/plan/presentation/view/PlansListView.kt b/plan/presentation/src/main/kotlin/me/proton/core/plan/presentation/view/PlansListView.kt index 413f4562c..cac5551e8 100644 --- a/plan/presentation/src/main/kotlin/me/proton/core/plan/presentation/view/PlansListView.kt +++ b/plan/presentation/src/main/kotlin/me/proton/core/plan/presentation/view/PlansListView.kt @@ -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( diff --git a/plan/presentation/src/main/kotlin/me/proton/core/plan/presentation/viewmodel/UpgradePlansViewModel.kt b/plan/presentation/src/main/kotlin/me/proton/core/plan/presentation/viewmodel/UpgradePlansViewModel.kt index 23abd91c3..33ffa5916 100644 --- a/plan/presentation/src/main/kotlin/me/proton/core/plan/presentation/viewmodel/UpgradePlansViewModel.kt +++ b/plan/presentation/src/main/kotlin/me/proton/core/plan/presentation/viewmodel/UpgradePlansViewModel.kt @@ -73,6 +73,7 @@ internal class UpgradePlansViewModel @Inject @Suppress("LongParameterList") cons sealed class Success : SubscribedPlansState() { data class SubscribedPlans( val subscribedPlans: List, + 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 -> diff --git a/plan/presentation/src/test/kotlin/me/proton/core/plan/presentation/viewmodel/UpgradePlansViewModelTest.kt b/plan/presentation/src/test/kotlin/me/proton/core/plan/presentation/viewmodel/UpgradePlansViewModelTest.kt index 96545c9a3..47122fb1a 100644 --- a/plan/presentation/src/test/kotlin/me/proton/core/plan/presentation/viewmodel/UpgradePlansViewModelTest.kt +++ b/plan/presentation/src/test/kotlin/me/proton/core/plan/presentation/viewmodel/UpgradePlansViewModelTest.kt @@ -197,6 +197,9 @@ class UpgradePlansViewModelTest : ArchTest, CoroutinesTest { couponCode = null, currency = "EUR", amount = 5, + discount = 0, + renewDiscount = 0, + renewAmount = 5, plans = listOf( testSubscribedPlan ),