Skip to content
Snippets Groups Projects
Commit f30304a3 authored by Taras's avatar Taras
Browse files

Create subscription list item and mapping

parent cada7d5f
No related branches found
No related tags found
No related merge requests found
package org.futo.circles.model
import org.futo.circles.core.list.IdEntity
data class SubscriptionListItem(
override val id: String,
val name: String,
val description: String,
val price: String,
val duration: String
) : IdEntity<String>
\ No newline at end of file
package org.futo.circles.subscriptions.google
import android.content.Context
import com.android.billingclient.api.ProductDetails
import org.futo.circles.extensions.Response
import org.futo.circles.model.SubscriptionListItem
import org.futo.circles.subscriptions.formatIsoPeriod
fun ProductDetails.toSubscriptionListItem(context: Context): SubscriptionListItem {
val productOffer =
subscriptionOfferDetails?.last()?.pricingPhases?.pricingPhaseList?.last()
return SubscriptionListItem(
id = productId,
name = name,
description = description,
price = productOffer?.formattedPrice ?: "",
duration = productOffer?.billingPeriod?.formatIsoPeriod(context) ?: ""
)
}
fun Response<List<ProductDetails>>.toSubscriptionListItemsResponse(context: Context): Response<List<SubscriptionListItem>> =
when (val response = this) {
is Response.Success -> Response.Success(response.data.map {
it.toSubscriptionListItem(context)
})
is Response.Error -> response
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment