Skip to content

Commit

Permalink
Merge pull request #98 from VictorKabata/QoL_improvements
Browse files Browse the repository at this point in the history
Updated dependencies
  • Loading branch information
VictorKabata authored Sep 22, 2023
2 parents df25d23 + 73a4208 commit d3106ee
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 33 deletions.
23 changes: 9 additions & 14 deletions app-iOS/app-iOS/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,15 @@ func initiateMpesaPayment(daraja:Daraja,
transactionDesc: String,
callbackUrl: String,
accountReference: String){
do{
let response=try daraja.initiateMpesaExpressPayment(businessShortCode: businessShortCode, amount: amount, phoneNumber: phoneNumber,transactionType: DarajaTransactionType.customerpaybillonline, transactionDesc: "M-Pesa payment", callbackUrl: "https://mydomain.com/path", accountReference: "Daraja KMP iOS")

response.onSuccess(action: {data in
print(data.self)
})
.onFailure(action: {error in
print(error)
})

print(response)
}catch{
print("An error occured")
}

let response=daraja.initiateMpesaExpressPayment(businessShortCode: businessShortCode, amount: amount, phoneNumber: phoneNumber,transactionType: DarajaTransactionType.customerpaybillonline, transactionDesc: "M-Pesa payment", callbackUrl: "https://mydomain.com/path", accountReference: "Daraja KMP iOS")

response.onSuccess(action: {data in
print(data.self)
})
.onFailure(action: {error in
print(error)
})
}

struct ContentView_Previews: PreviewProvider {
Expand Down
6 changes: 3 additions & 3 deletions daraja/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ val javadocJar = tasks.register<Jar>("javadocJar") {
from(dokkaOutputDir)
}

kover {
koverReport {
verify {
rule {
name = "Minimal line coverage rate in percents"
bound { minValue = 50 }
isEnabled = false
bound { minValue = 20 }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ internal class DarajaApiService constructor(
private val httpClient: HttpClient,
private val consumerKey: String,
private val consumerSecret: String,
private val inMemoryCache: Cache<Long, DarajaToken> = Cache.Builder()
private val inMemoryCache: Cache<Long, DarajaToken> = Cache.Builder<Long, DarajaToken>()
.expireAfterWrite(3600.toDuration(DurationUnit.SECONDS)).build()
) {

/** ToDo: Handle daraja auth errors correctly
* Initiate API call using the [httpClient] provided by Ktor to fetch Daraja API access token
/** Initiate API call using the [httpClient] provided by Ktor to fetch Daraja API access token
* of type [DarajaToken]*/
internal suspend fun fetchAccessToken(): DarajaResult<DarajaToken> = darajaSafeApiCall {
val key = "$consumerKey:$consumerSecret"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ internal suspend fun parseNetworkError(
exception: Exception? = null
): DarajaException {
return errorResponse?.body<DarajaException>()
?: DarajaException(requestId = "0", errorCode = "0", errorMessage = exception?.message)
?: DarajaException(errorMessage = exception?.message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@

package com.vickbt.darajakmp.network

import com.vickbt.darajakmp.network.models.MpesaExpressRequest
import com.vickbt.darajakmp.network.models.MpesaExpressResponse
import com.vickbt.darajakmp.network.models.DarajaToken
import com.vickbt.darajakmp.network.models.DarajaTransactionResponse
import com.vickbt.darajakmp.network.models.DarajaTransactionRequest
import com.vickbt.darajakmp.network.models.DarajaTransactionResponse
import com.vickbt.darajakmp.network.models.MpesaExpressRequest
import com.vickbt.darajakmp.network.models.MpesaExpressResponse
import com.vickbt.darajakmp.utils.DarajaResult
import com.vickbt.darajakmp.utils.DarajaTransactionType
import io.github.reactivecircus.cache4k.Cache
import io.ktor.client.HttpClient
import kotlinx.coroutines.test.runTest
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlinx.coroutines.test.runTest

class DarajaApiServiceTest {

Expand Down Expand Up @@ -72,7 +72,7 @@ class DarajaApiServiceTest {
fun setup() {
mockKtorHttpClient = mockDarajaHttpClient.mockDarajaHttpClient

mockInMemoryCache = Cache.Builder().build()
mockInMemoryCache = Cache.Builder<Long, DarajaToken>().build()

darajaApiService = DarajaApiService(
httpClient = mockKtorHttpClient,
Expand Down
14 changes: 7 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ ktLint = "10.3.0"
detekt = "1.19.0"
spotless = "6.2.2"
nativeCocoapod = "1.9.0"
dokka = "1.8.20"
kover = "0.6.1"
dokka = "1.9.0"
kover = "0.7.3"
mulitplatformSwiftPackage = "2.0.3"
gradleVersionUpdate = "0.45.0"
gradleVersionUpdate = "0.48.0"

# Kotlin Multiplatform Version
kotlinxCoroutines = "1.7.3"
kotlinxSerializationJson = "1.5.1"
kotlinxDateTime = "0.4.0"
kotlinxDateTime = "0.4.1"
napier = "2.6.1"
ktor = "2.3.2"
ktor = "2.3.4"
kotlinxTestResources = "0.2.2"
composeMultiplatform = "1.5.0-beta01"
cache4k = "0.9.0"
mockative = "1.3.1"
cache4k = "0.11.0"
mockative = "2.0.1"

[plugins]
ktLint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktLint" }
Expand Down

0 comments on commit d3106ee

Please sign in to comment.