From d2777bcb58a371f47085aafd3c0584359b6ff451 Mon Sep 17 00:00:00 2001 From: Mohamed Yousif Date: Mon, 4 Dec 2023 14:54:29 +0400 Subject: [PATCH] adding wallet transacts --- gradle.properties | 2 +- lib/src/main/java/com/tuti/Library.kt | 6 ---- .../main/java/com/tuti/api/TutiApiClient.kt | 14 ++++++++ .../java/com/tuti/api/data/TutiResponse.kt | 1 + .../main/java/com/tuti/api/ebs/EBSRequest.kt | 11 +++++- .../main/java/com/tuti/model/Operations.kt | 1 + .../java/com/tuti/api/TutiApiClientTest.kt | 36 +++++++++++++++++-- 7 files changed, 60 insertions(+), 11 deletions(-) diff --git a/gradle.properties b/gradle.properties index 1f90590..d210508 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=23.11.3 +version=23.12.3 diff --git a/lib/src/main/java/com/tuti/Library.kt b/lib/src/main/java/com/tuti/Library.kt index e578fc4..ae54ef1 100644 --- a/lib/src/main/java/com/tuti/Library.kt +++ b/lib/src/main/java/com/tuti/Library.kt @@ -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, @@ -47,7 +42,6 @@ object Library { onResponse = {tutiResponse -> println(tutiResponse.uuid) }, onError = {tutiResponse, exception -> } ) - }, onError = { tutiResponse, exception -> }) } diff --git a/lib/src/main/java/com/tuti/api/TutiApiClient.kt b/lib/src/main/java/com/tuti/api/TutiApiClient.kt index e8ef4d7..86e2776 100644 --- a/lib/src/main/java/com/tuti/api/TutiApiClient.kt +++ b/lib/src/main/java/com/tuti/api/TutiApiClient.kt @@ -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.* @@ -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 diff --git a/lib/src/main/java/com/tuti/api/data/TutiResponse.kt b/lib/src/main/java/com/tuti/api/data/TutiResponse.kt index 282f981..1dfabce 100644 --- a/lib/src/main/java/com/tuti/api/data/TutiResponse.kt +++ b/lib/src/main/java/com/tuti/api/data/TutiResponse.kt @@ -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 { diff --git a/lib/src/main/java/com/tuti/api/ebs/EBSRequest.kt b/lib/src/main/java/com/tuti/api/ebs/EBSRequest.kt index 8b72e1b..21030bb 100644 --- a/lib/src/main/java/com/tuti/api/ebs/EBSRequest.kt +++ b/lib/src/main/java/com/tuti/api/ebs/EBSRequest.kt @@ -173,4 +173,13 @@ class EBSRequest { } return ipin } -} \ No newline at end of file +} + + +@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 +) \ No newline at end of file diff --git a/lib/src/main/java/com/tuti/model/Operations.kt b/lib/src/main/java/com/tuti/model/Operations.kt index b00821c..d9f5a29 100644 --- a/lib/src/main/java/com/tuti/model/Operations.kt +++ b/lib/src/main/java/com/tuti/model/Operations.kt @@ -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" } \ No newline at end of file diff --git a/lib/src/test/java/com/tuti/api/TutiApiClientTest.kt b/lib/src/test/java/com/tuti/api/TutiApiClientTest.kt index 7d27236..f48ae2f 100644 --- a/lib/src/test/java/com/tuti/api/TutiApiClientTest.kt +++ b/lib/src/test/java/com/tuti/api/TutiApiClientTest.kt @@ -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 @@ -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.") + } + } }