Skip to content

Commit

Permalink
Fix invoice api (#1797)
Browse files Browse the repository at this point in the history
* Redesign requeset screen UI

* fix MissingKoinDefinitionException

* removed comments and fixed share qr code bug

* fix: Invoice APIs
  • Loading branch information
Nagarjuna0033 authored Oct 25, 2024
1 parent fac59da commit 28f9bd5
Show file tree
Hide file tree
Showing 34 changed files with 879 additions and 554 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ package org.mifospay.core.data.domain.usecase.invoice

import android.net.Uri
import android.util.Log
import com.mifospay.core.model.entity.Invoice
import com.mifospay.core.model.entity.invoice.Invoice
import org.mifospay.core.data.base.UseCase
import org.mifospay.core.data.fineract.repository.FineractRepository
import org.mifospay.core.data.util.Constants
Expand All @@ -27,13 +27,12 @@ class FetchInvoice(
class ResponseValue(
val invoices: List<Invoice?>,
) : UseCase.ResponseValue

override fun executeUseCase(requestValues: RequestValues) {
val paymentLink = requestValues.uniquePaymentLink
try {
val params = paymentLink?.pathSegments
val clientId = params?.get(0) // "clientId"
val invoiceId = params?.get(1) // "invoiceId"
val clientId = params?.get(0)?.toLong() // "clientId"
val invoiceId = params?.get(1)?.toLong() // "invoiceId
if (clientId != null && invoiceId != null) {
mFineractRepository.fetchInvoice(clientId, invoiceId)
.observeOn(AndroidSchedulers.mainThread())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
package org.mifospay.core.data.domain.usecase.invoice

import android.util.Log
import com.mifospay.core.model.entity.Invoice
import com.mifospay.core.model.entity.invoice.Invoice
import org.mifospay.core.data.base.UseCase
import org.mifospay.core.data.fineract.repository.FineractRepository
import rx.Subscriber
Expand All @@ -28,7 +28,7 @@ class FetchInvoices(
) : UseCase.ResponseValue

override fun executeUseCase(requestValues: RequestValues) {
mFineractRepository.fetchInvoices(requestValues.clientId)
mFineractRepository.fetchInvoices(requestValues.clientId.toLong())
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(
Expand All @@ -40,6 +40,7 @@ class FetchInvoices(
}

override fun onNext(invoices: List<Invoice>) {
Log.d("invoice@@@", invoices.toString())
useCaseCallback.onSuccess(ResponseValue(invoices))
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import com.mifospay.core.model.domain.twofactor.AccessToken
import com.mifospay.core.model.domain.twofactor.DeliveryMethod
import com.mifospay.core.model.domain.user.NewUser
import com.mifospay.core.model.domain.user.User
import com.mifospay.core.model.entity.Invoice
import com.mifospay.core.model.entity.Page
import com.mifospay.core.model.entity.SearchedEntity
import com.mifospay.core.model.entity.TPTResponse
Expand All @@ -30,6 +29,8 @@ import com.mifospay.core.model.entity.beneficary.BeneficiaryPayload
import com.mifospay.core.model.entity.beneficary.BeneficiaryUpdatePayload
import com.mifospay.core.model.entity.client.Client
import com.mifospay.core.model.entity.client.ClientAccounts
import com.mifospay.core.model.entity.invoice.Invoice
import com.mifospay.core.model.entity.invoice.InvoiceEntity
import com.mifospay.core.model.entity.kyc.KYCLevel1Details
import com.mifospay.core.model.entity.payload.StandingInstructionPayload
import com.mifospay.core.model.entity.payload.TransferPayload
Expand Down Expand Up @@ -206,24 +207,30 @@ class FineractRepository(
)
}

fun addInvoice(clientId: String, invoice: Invoice?): Observable<GenericResponse> {
return fineractApiManager.invoiceApi.addInvoice(clientId, invoice)
fun addInvoice(clientId: Long, invoice: InvoiceEntity?): Observable<Unit> {
return Observable.fromCallable {
fineractApiManager.invoiceApi.addInvoice(clientId, invoice)
}
}

fun fetchInvoices(clientId: String): Observable<List<Invoice>> {
fun fetchInvoices(clientId: Long): Observable<List<Invoice>> {
return fineractApiManager.invoiceApi.getInvoices(clientId)
}

fun fetchInvoice(clientId: String, invoiceId: String): Observable<List<Invoice>> {
fun fetchInvoice(clientId: Long, invoiceId: Long): Observable<List<Invoice>> {
return fineractApiManager.invoiceApi.getInvoice(clientId, invoiceId)
}

fun editInvoice(clientId: String, invoice: Invoice): Observable<GenericResponse> {
return fineractApiManager.invoiceApi.updateInvoice(clientId, invoice.id, invoice)
fun editInvoice(clientId: Long, invoice: Invoice): Observable<Unit> {
return Observable.fromCallable {
fineractApiManager.invoiceApi.updateInvoice(clientId, invoice.id, invoice)
}
}

fun deleteInvoice(clientId: String, invoiceId: Int): Observable<GenericResponse> {
return fineractApiManager.invoiceApi.deleteInvoice(clientId, invoiceId)
fun deleteInvoice(clientId: Long, invoiceId: Long): Observable<Unit> {
return Observable.fromCallable {
fineractApiManager.invoiceApi.deleteInvoice(clientId, invoiceId)
}
}

val users: Observable<List<UserWithRole>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.material3.OutlinedIconButton
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand All @@ -28,17 +29,26 @@ fun IconBox(
icon: ImageVector,
onClick: () -> Unit,
modifier: Modifier = Modifier,
tint: Color? = null,
) {
OutlinedIconButton(
onClick = onClick,
modifier = modifier,
shape = RoundedCornerShape(12.dp),
border = BorderStroke(2.dp, MaterialTheme.colorScheme.onSurface.copy(alpha = 0.1f)),
) {
Icon(
imageVector = icon,
contentDescription = icon.name,
)
if (tint != null) {
Icon(
imageVector = icon,
contentDescription = icon.name,
tint = tint,
)
} else {
Icon(
imageVector = icon,
contentDescription = icon.name,
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ fun MifosScaffold(
backPress: () -> Unit,
modifier: Modifier = Modifier,
topBarTitle: Int? = null,
titleColor: Color? = MaterialTheme.colorScheme.onSurface,
iconTint: Color? = null,
floatingActionButtonContent: FloatingActionButtonContent? = null,
snackbarHost: @Composable () -> Unit = {},
scaffoldContent: @Composable (PaddingValues) -> Unit = {},
Expand All @@ -35,6 +37,8 @@ fun MifosScaffold(
topBarTitle = topBarTitle,
backPress = backPress,
actions = actions,
titleColor = titleColor,
iconTint = iconTint,
)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@ fun MifosTopBar(
backPress: () -> Unit,
modifier: Modifier = Modifier,
actions: @Composable RowScope.() -> Unit = {},
titleColor: Color? = null,
iconTint: Color? = null,
) {
CenterAlignedTopAppBar(
title = {
Text(
text = stringResource(id = topBarTitle),
style = MaterialTheme.typography.titleMedium,
color = titleColor ?: MaterialTheme.colorScheme.onSurface,
)
},
navigationIcon = {
IconBox(
icon = MifosIcons.ArrowBack2,
onClick = backPress,
tint = iconTint,
)
},
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.material.icons.filled.ArrowOutward
import androidx.compose.material.icons.filled.AttachMoney
import androidx.compose.material.icons.filled.Camera
import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.CheckCircleOutline
import androidx.compose.material.icons.filled.ChevronLeft
import androidx.compose.material.icons.filled.ChevronRight
import androidx.compose.material.icons.filled.Close
Expand All @@ -30,6 +31,7 @@ import androidx.compose.material.icons.filled.Photo
import androidx.compose.material.icons.filled.PhotoLibrary
import androidx.compose.material.icons.filled.QrCode
import androidx.compose.material.icons.filled.QrCode2
import androidx.compose.material.icons.filled.RemoveCircleOutline
import androidx.compose.material.icons.filled.Share
import androidx.compose.material.icons.filled.Visibility
import androidx.compose.material.icons.filled.VisibilityOff
Expand Down Expand Up @@ -99,4 +101,6 @@ object MifosIcons {
val QrCode2 = Icons.Filled.QrCode2
val Edit = Icons.Filled.Edit
val Edit2 = Icons.Outlined.Edit
val CheckCircle = Icons.Default.CheckCircleOutline
val CheckCircle2 = Icons.Default.RemoveCircleOutline
}
49 changes: 0 additions & 49 deletions core/model/src/main/java/com/mifospay/core/model/entity/Invoice.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md
*/
package com.mifospay.core.model.entity.invoice

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize

@Parcelize
data class Invoice(
val id: Long,
@SerializedName("client_id")
val clientId: Long,
val consumerId: String,
val consumerName: String,
val amount: Double,
@SerializedName("itemsbought")
val itemsBought: String,
val status: Long,
val transactionId: String,
val invoiceId: Long,
val title: String,
val date: String,
@SerializedName("created_at")
val createdAt: List<Long>,
@SerializedName("updated_at")
val updatedAt: List<Long>,
) : Parcelable
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md
*/
package com.mifospay.core.model.entity.invoice

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class InvoiceEntity(
val id: Long,
val invoiceId: Long,
val consumerId: String,
val consumerName: String,
val amount: Double,
@SerialName("itemsbought")
val itemsBought: String,
val status: Long,
val transactionId: String,
val title: String,
val date: String,
val locale: String,
val dateFormat: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import javax.net.ssl.SSLContext
import javax.net.ssl.TrustManager
import javax.net.ssl.X509TrustManager

class MifosWalletOkHttpClient(private val preferences: PreferencesHelper) {
class MifosWalletOkHttpClient(
private val preferences: PreferencesHelper,
private val username: String? = null,
private val password: String? = null,
private val isTesting: Boolean = false,
) {
// Create a trust manager that does not validate certificate chains
val mifosOkHttpClient: OkHttpClient
// Interceptor :> Full Body Logger and ApiRequest Header
Expand Down Expand Up @@ -78,7 +83,11 @@ class MifosWalletOkHttpClient(private val preferences: PreferencesHelper) {

// Interceptor :> Full Body Logger and ApiRequest Header
builder.addInterceptor(logger)
builder.addInterceptor(org.mifospay.core.network.ApiInterceptor(preferences))
if (isTesting && username != null && password != null) {
builder.addInterceptor(TestingApiInterceptor(username, password))
} else {
builder.addInterceptor(ApiInterceptor(preferences))
}
return builder.build()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md
*/
package org.mifospay.core.network

import okhttp3.Credentials
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException

class TestingApiInterceptor(
private val username: String,
private val password: String,
) : Interceptor {

@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
val chainRequest = chain.request()

val basicAuthCredentials = Credentials.basic(username, password)

val builder = chainRequest.newBuilder()
.header(HEADER_TENANT, DEFAULT)
.header(HEADER_AUTH, basicAuthCredentials)

val request = builder.build()
return chain.proceed(request)
}

companion object {
const val HEADER_TENANT = "Fineract-Platform-TenantId"
const val HEADER_AUTH = "Authorization"
const val DEFAULT = "venus"
}
}
Loading

0 comments on commit 28f9bd5

Please sign in to comment.