Skip to content

Commit

Permalink
adding wallet transacts
Browse files Browse the repository at this point in the history
  • Loading branch information
adonese committed Dec 4, 2023
1 parent ab05e76 commit d2777bc
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=23.11.3
version=23.12.3
6 changes: 0 additions & 6 deletions lib/src/main/java/com/tuti/Library.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,13 @@ object Library {
PAN = tuti_card_pan,
expiryDate = tuti_card_exp_date
)

client.SignIn(SignInRequest(
mobile = tuti_username,
password = tuti_password
),
onResponse = { signInResponse: SignInResponse ->



val token = signInResponse.authorizationJWT
client.authToken = token

client.sendPaymentRequest(
paymentRequest = PaymentRequest(
mobile = tuti_username,
Expand All @@ -47,7 +42,6 @@ object Library {
onResponse = {tutiResponse -> println(tutiResponse.uuid) },
onError = {tutiResponse, exception -> }
)

},
onError = { tutiResponse, exception -> })
}
Expand Down
14 changes: 14 additions & 0 deletions lib/src/main/java/com/tuti/api/TutiApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.tuti.api.authentication.SignUpResponse
import com.tuti.api.data.*
import com.tuti.api.ebs.EBSRequest
import com.tuti.api.ebs.EBSResponse
import com.tuti.api.ebs.NoebsTransfer
import com.tuti.model.*
import com.tuti.util.IPINBlockGenerator
import kotlinx.serialization.*
Expand Down Expand Up @@ -954,6 +955,19 @@ class TutiApiClient {
)
}

fun noebsTransfer(
transaction: NoebsTransfer,
onResponse: (TutiResponse) -> Unit,
onError: (TutiResponse?, Exception?) -> Unit
) {
sendRequest(
RequestMethods.POST,
dapiServer + Operations.NOEBS_CARD_TRANSFER,
transaction,
onResponse, onError
)
}


/**
* Performs a noebs payment via QR or a payment link. The api is still in beta and
Expand Down
1 change: 1 addition & 0 deletions lib/src/main/java/com/tuti/api/data/TutiResponse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ data class TutiResponse(

@SerialName("ebs_response")
val ebsResponse: EBSResponse = EBSResponse()
//TODO(adonese): some of dapi / noebs fields are not exposed here, transaction_id from noebs wallet
) {

fun getRawPaymentToken(): String {
Expand Down
11 changes: 10 additions & 1 deletion lib/src/main/java/com/tuti/api/ebs/EBSRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,13 @@ class EBSRequest {
}
return ipin
}
}
}


@kotlinx.serialization.Serializable
data class NoebsTransfer(
@SerialName("from_account") val fromAccount: String,
@SerialName("to_account") val toAccount: String,
@SerialName("amount") val amount: Double,
@SerialName("signature") val signature: String
)
1 change: 1 addition & 0 deletions lib/src/main/java/com/tuti/model/Operations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ object Operations {
// https://blue-violet-2528.fly.dev/transactions
const val DAPI_GET_TRANSACTIONS = "transactions"
const val NOEBS_WALLET_BALANCE = "noebs-balance"
const val NOEBS_CARD_TRANSFER = "transfer"
}
36 changes: 33 additions & 3 deletions lib/src/test/java/com/tuti/api/TutiApiClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ package com.tuti.api


import com.tuti.api.authentication.SignInRequest
import com.tuti.api.data.BalanceResponse
import com.tuti.api.data.TutiResponse
import com.tuti.api.ebs.EBSRequest
import com.tuti.api.ebs.NoebsTransfer
import com.tuti.model.NotificationFilters
import com.tuti.model.User
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.fail
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.fail
import java.util.*
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -142,6 +140,38 @@ internal class TutiApiClientTest {
fail("The call to inquireNoebsWallet did not complete within the expected time.")
}
}

@Test
fun noebsTransfer() {
val tutiApiClient = TutiApiClient()
tutiApiClient.authToken = "yourTestAuthToken"
val expectedResponse = 121342212

val latch = CountDownLatch(1) // Initialize CountDownLatch with count 1

var responseReceived: TutiResponse? = null
var errorOccurred: Exception? = null

// Call the method
tutiApiClient.noebsTransfer(NoebsTransfer("249_ACCT_1", toAccount = "12", amount = 32.32, signature = ""), { response ->
responseReceived = response
latch.countDown() // Decrease the count of the latch, releasing the wait in test
}, { _, error ->
errorOccurred = error
latch.countDown() // Ensure to count down in case of error too
})

// Wait for the operation to complete or timeout
val callCompleted = latch.await(10, TimeUnit.SECONDS)

// Assertions
if (callCompleted) {
assertEquals("ok", responseReceived!!.status)
assertNull(errorOccurred)
} else {
fail("The call to inquireNoebsWallet did not complete within the expected time.")
}
}
}


0 comments on commit d2777bc

Please sign in to comment.