Skip to content

Commit

Permalink
Merge pull request #1875 from HedvigInsurance/cleanup/octopus_payment…
Browse files Browse the repository at this point in the history
…_history

Cleanup/octopus payment history
  • Loading branch information
StylianosGakis authored Nov 10, 2023
2 parents e5fec3d + b9dc945 commit 712a8fb
Show file tree
Hide file tree
Showing 22 changed files with 352 additions and 162 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,8 @@ fragment CostFragment on InsuranceCost {
...MonetaryAmountFragment
}
}

fragment MonetaryAmountFragment on MonetaryAmountV2 {
amount
currency
}

This file was deleted.

2 changes: 1 addition & 1 deletion app/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ dependencies {
implementation(projects.dataClaimFlow)
implementation(projects.dataClaimTriaging)
implementation(projects.dataForever)
implementation(projects.dataPayment)
implementation(projects.dataSettingsDatastorePublic)
implementation(projects.dataTravelCertificatePublic)
implementation(projects.datadogCore)
Expand Down Expand Up @@ -243,7 +244,6 @@ dependencies {
implementation(projects.notificationBadgeDataPublic)
implementation(projects.notificationCore)
implementation(projects.notificationFirebase)
implementation(projects.payment)
implementation(projects.theme)

debugImplementation(libs.androidx.compose.uiTestManifest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.hedvig.android.core.datastore.di.dataStoreModule
import com.hedvig.android.core.demomode.DemoManager
import com.hedvig.android.core.demomode.di.demoModule
import com.hedvig.android.data.forever.di.foreverDataModule
import com.hedvig.android.data.payment.di.paymentModule
import com.hedvig.android.data.settings.datastore.di.settingsDatastoreModule
import com.hedvig.android.data.travelcertificate.di.claimFlowDataModule
import com.hedvig.android.data.travelcertificate.di.travelCertificateDataModule
Expand Down Expand Up @@ -75,7 +76,6 @@ import com.hedvig.android.navigation.core.di.deepLinkModule
import com.hedvig.android.notification.badge.data.di.notificationBadgeModule
import com.hedvig.android.notification.core.NotificationSender
import com.hedvig.android.notification.firebase.di.firebaseNotificationModule
import com.hedvig.android.payment.di.paymentModule
import com.hedvig.app.authenticate.LogoutUseCaseImpl
import com.hedvig.app.feature.chat.service.ChatNotificationSender
import com.hedvig.app.feature.chat.service.ReplyWorker
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.hedvig.android.core.designsystem.component.information

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.material.icons.Icons
import androidx.compose.material3.Icon
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.LineBreak
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.hedvig.android.core.designsystem.component.button.HedvigContainedSmallButton
import com.hedvig.android.core.designsystem.material3.infoElement
import com.hedvig.android.core.icons.Hedvig
import com.hedvig.android.core.icons.hedvig.normal.InfoFilled

@Composable
fun HedvigInformationSection(
title: String,
buttonText: String,
onButtonClick: () -> Unit,
modifier: Modifier = Modifier,
subTitle: String? = null,
contentPadding: PaddingValues = WindowInsets.safeDrawing.asPaddingValues(),
withDefaultVerticalSpacing: Boolean = true,
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = modifier
.padding(contentPadding)
.padding(horizontal = 16.dp),
) {
if (withDefaultVerticalSpacing) {
Spacer(Modifier.height(32.dp))
}
Icon(
imageVector = Icons.Hedvig.InfoFilled,
contentDescription = null,
tint = MaterialTheme.colorScheme.infoElement,
)
Spacer(Modifier.height(16.dp))
Text(
text = title,
textAlign = TextAlign.Center,
style = LocalTextStyle.current.copy(
lineBreak = LineBreak.Heading,
),
modifier = Modifier.fillMaxWidth(),
)
Spacer(Modifier.height(2.dp))
if (subTitle != null) {
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.onSurfaceVariant) {
Text(
text = subTitle,
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth(),
)
}
}
Spacer(Modifier.height(24.dp))
HedvigContainedSmallButton(
text = buttonText,
onClick = onButtonClick,
)
if (withDefaultVerticalSpacing) {
Spacer(Modifier.height(32.dp))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
plugins {
id("hedvig.android.ktlint")
id("hedvig.android.library")
alias(libs.plugins.apollo)
alias(libs.plugins.squareSortDependencies)
}

dependencies {
apolloMetadata(projects.apolloOctopusPublic)

implementation(libs.apollo.normalizedCache)
implementation(libs.apollo.runtime)
implementation(libs.arrow.core)
Expand All @@ -14,7 +17,15 @@ dependencies {
implementation(libs.moneta)
implementation(projects.apolloCore)
implementation(projects.apolloGiraffePublic)
implementation(projects.apolloOctopusPublic)
implementation(projects.coreCommonPublic)
implementation(projects.coreDemoMode)
implementation(projects.coreUiData)
implementation(projects.languageCore)
}

apollo {
service("octopus") {
packageName.set("octopus")
}
}
File renamed without changes.
11 changes: 11 additions & 0 deletions app/data/data-payment/src/main/graphql/QueryPaymentHistory.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
query PaymentHistory {
currentMember {
chargeHistory {
status
date
amount {
...MoneyFragment
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.hedvig.android.payment
package com.hedvig.android.data.payment

import arrow.core.Either
import com.hedvig.android.apollo.OperationResult
import com.hedvig.android.core.common.ErrorMessage

interface PaymentRepository {
suspend fun getChargeHistory(): Either<OperationResult.Error, ChargeHistory>
suspend fun getChargeHistory(): Either<ErrorMessage, ChargeHistory>

suspend fun getPaymentData(): Either<OperationResult.Error, PaymentData>
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
package com.hedvig.android.payment
package com.hedvig.android.data.payment

import arrow.core.Either
import arrow.core.raise.either
import com.hedvig.android.apollo.OperationResult
import com.hedvig.android.core.common.ErrorMessage
import com.hedvig.android.core.uidata.UiMoney
import java.math.BigDecimal
import java.time.LocalDate
import kotlin.time.Duration.Companion.days
import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toJavaLocalDate
import kotlinx.datetime.toLocalDateTime
import octopus.type.CurrencyCode
import org.javamoney.moneta.Money

class PaymentRepositoryDemo : PaymentRepository {
override suspend fun getChargeHistory(): Either<OperationResult.Error, ChargeHistory> = either {
override suspend fun getChargeHistory(): Either<ErrorMessage, ChargeHistory> = either {
ChargeHistory(
List(5) { index ->
ChargeHistory.Charge(
amount = Money.of(49 * (index + 1), "SEK"),
date = Clock.System.now().minus(31.days * index).toLocalDateTime(TimeZone.UTC).date.toJavaLocalDate(),
amount = UiMoney(49.0 * (index + 1), CurrencyCode.SEK),
date = Clock.System.now().minus(31.days * index).toLocalDateTime(TimeZone.UTC).date,
paymentStatus = ChargeHistory.Charge.PaymentStatus.SUCCESSFUL,
)
},
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hedvig.android.payment
package com.hedvig.android.data.payment

import arrow.core.Either
import arrow.core.raise.either
Expand All @@ -9,29 +9,40 @@ import com.hedvig.android.apollo.OperationResult
import com.hedvig.android.apollo.safeExecute
import com.hedvig.android.apollo.toEither
import com.hedvig.android.apollo.toMonetaryAmount
import com.hedvig.android.core.common.ErrorMessage
import com.hedvig.android.core.uidata.UiMoney
import com.hedvig.android.language.LanguageService
import giraffe.ChargeHistoryQuery
import giraffe.PaymentQuery
import giraffe.type.PayoutMethodStatus
import giraffe.type.TypeOfContract
import java.time.LocalDate
import javax.money.MonetaryAmount
import kotlinx.datetime.LocalDate
import octopus.PaymentHistoryQuery
import octopus.type.MemberChargeHistoryEntryStatus

internal class PaymentRepositoryImpl(
private val apolloClient: ApolloClient,
private val giraffeApolloClient: ApolloClient,
private val octopusApolloClient: ApolloClient,
private val languageService: LanguageService,
) : PaymentRepository {
override suspend fun getChargeHistory(): Either<OperationResult.Error, ChargeHistory> = either {
apolloClient
.query(ChargeHistoryQuery())
override suspend fun getChargeHistory(): Either<ErrorMessage, ChargeHistory> = either {
octopusApolloClient
.query(PaymentHistoryQuery())
.safeExecute()
.toEither()
.map {
.toEither(::ErrorMessage)
.map { paymentData ->
val chargeHistory = paymentData.currentMember.chargeHistory
ChargeHistory(
charges = it.chargeHistory.map {
charges = chargeHistory.map { chargeHistoryEntry ->
ChargeHistory.Charge(
amount = it.amount.fragments.monetaryAmountFragment.toMonetaryAmount(),
date = it.date,
amount = UiMoney.fromMoneyFragment(chargeHistoryEntry.amount),
date = chargeHistoryEntry.date,
paymentStatus = when (chargeHistoryEntry.status) {
MemberChargeHistoryEntryStatus.PENDING -> ChargeHistory.Charge.PaymentStatus.PENDING
MemberChargeHistoryEntryStatus.FAILED -> ChargeHistory.Charge.PaymentStatus.FAILED
MemberChargeHistoryEntryStatus.SUCCESS -> ChargeHistory.Charge.PaymentStatus.SUCCESSFUL
else -> ChargeHistory.Charge.PaymentStatus.UNKNOWN
},
)
},
)
Expand All @@ -40,7 +51,7 @@ internal class PaymentRepositoryImpl(
}

override suspend fun getPaymentData(): Either<OperationResult.Error, PaymentData> = either {
val data = apolloClient
val data = giraffeApolloClient
.query(PaymentQuery(languageService.getGraphQLLocale()))
.fetchPolicy(FetchPolicy.NetworkOnly)
.safeExecute()
Expand Down Expand Up @@ -105,16 +116,24 @@ data class ChargeHistory(
val charges: List<Charge>,
) {
data class Charge(
val amount: MonetaryAmount,
val amount: UiMoney,
val date: LocalDate,
)
val paymentStatus: PaymentStatus,
) {
enum class PaymentStatus {
PENDING,
SUCCESSFUL,
FAILED,
UNKNOWN,
}
}
}

data class PaymentData(
val nextCharge: MonetaryAmount,
val monthlyCost: MonetaryAmount?,
val totalDiscount: MonetaryAmount?,
val nextChargeDate: LocalDate?,
val nextChargeDate: java.time.LocalDate?,
val redeemedCampagins: List<Campaign>,
val bankName: String?,
val bankDescriptor: String?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package com.hedvig.android.payment.di
package com.hedvig.android.data.payment.di

import com.apollographql.apollo3.ApolloClient
import com.hedvig.android.apollo.giraffe.di.giraffeClient
import com.hedvig.android.apollo.octopus.di.octopusClient
import com.hedvig.android.core.demomode.DemoManager
import com.hedvig.android.payment.PaymentRepositoryDemo
import com.hedvig.android.payment.PaymentRepositoryImpl
import com.hedvig.android.data.payment.PaymentRepositoryDemo
import com.hedvig.android.data.payment.PaymentRepositoryImpl
import org.koin.dsl.module

val paymentModule = module {
single<PaymentRepositoryImpl> { PaymentRepositoryImpl(get<ApolloClient>(giraffeClient), get()) }
single<PaymentRepositoryImpl> {
PaymentRepositoryImpl(
giraffeApolloClient = get<ApolloClient>(giraffeClient),
octopusApolloClient = get<ApolloClient>(octopusClient),
languageService = get(),
)
}
single<PaymentRepositoryDemo> { PaymentRepositoryDemo() }
single {
PaymentRepositoryProvider(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.hedvig.android.payment.di
package com.hedvig.android.data.payment.di

import com.hedvig.android.core.demomode.DemoManager
import com.hedvig.android.core.demomode.ProdOrDemoProvider
import com.hedvig.android.payment.PaymentRepository
import com.hedvig.android.data.payment.PaymentRepository

class PaymentRepositoryProvider(
override val demoManager: DemoManager,
Expand Down
3 changes: 2 additions & 1 deletion app/feature/feature-profile/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ dependencies {
implementation(projects.coreIcons)
implementation(projects.coreResources)
implementation(projects.coreUi)
implementation(projects.coreUiData)
implementation(projects.dataForever)
implementation(projects.dataPayment)
implementation(projects.dataSettingsDatastorePublic)
implementation(projects.hanalyticsCore)
implementation(projects.hanalyticsFeatureFlagsPublic)
Expand All @@ -53,7 +55,6 @@ dependencies {
implementation(projects.navigationComposeTyped)
implementation(projects.navigationCore)
implementation(projects.notificationPermission)
implementation(projects.payment)
implementation(projects.placeholder)
implementation(projects.pullrefresh)
implementation(projects.theme)
Expand Down
Loading

0 comments on commit 712a8fb

Please sign in to comment.