Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PWN-8895, PWN-8776 - striga. payment api #1878

Merged
merged 13 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/src/main/java/org/p2p/wallet/striga/StrigaModule.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package org.p2p.wallet.striga

import org.koin.core.module.dsl.factoryOf
import org.koin.dsl.module
import org.p2p.wallet.common.di.InjectionModule
import org.p2p.wallet.infrastructure.network.interceptor.StrigaHeaderSignatureGenerator
import org.p2p.wallet.kyc.StrigaFragmentFactory
import org.p2p.wallet.striga.di.StrigaSignupModule
import org.p2p.wallet.striga.di.StrigaWalletModule
import org.p2p.wallet.striga.kyc.StrigaKycModule

object StrigaModule : InjectionModule {

override fun create() = module {
includes(
StrigaSignupModule.create(),
StrigaKycModule.create()
StrigaKycModule.create(),
StrigaWalletModule.create()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

such a good name, man! thanks

)

factoryOf(::StrigaUserIdProvider)
factoryOf(::StrigaHeaderSignatureGenerator)
factoryOf(::StrigaFragmentFactory)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ import retrofit2.create
import org.p2p.wallet.R
import org.p2p.wallet.common.di.InjectionModule
import org.p2p.wallet.infrastructure.network.NetworkModule.getRetrofit
import org.p2p.wallet.infrastructure.network.interceptor.StrigaHeaderSignatureGenerator
import org.p2p.wallet.infrastructure.network.interceptor.StrigaProxyApiInterceptor
import org.p2p.wallet.kyc.StrigaFragmentFactory
import org.p2p.wallet.smsinput.SmsInputContract
import org.p2p.wallet.smsinput.SmsInputFactory
import org.p2p.wallet.smsinput.striga.StrigaSmsInputInteractor
import org.p2p.wallet.smsinput.striga.StrigaSmsInputPresenter
import org.p2p.wallet.striga.StrigaUserIdProvider
import org.p2p.wallet.striga.finish.StrigaSignupFinishContract
import org.p2p.wallet.striga.finish.StrigaSignupFinishPresenter
import org.p2p.wallet.striga.onboarding.StrigaOnboardingContract
Expand Down Expand Up @@ -97,10 +94,7 @@ object StrigaSignupModule : InjectionModule {
factoryOf(::StrigaSignupDataDatabaseRepository) bind StrigaSignupDataLocalRepository::class
factoryOf(::StrigaSignupDataMapper)

factoryOf(::StrigaUserIdProvider)
factoryOf(::StrigaItemCellMapper)
factoryOf(::StrigaHeaderSignatureGenerator)
factoryOf(::StrigaFragmentFactory)
singleOf(::StrigaUserStatusRepository)
factoryOf(::StrigaUserStatusDestinationMapper)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.p2p.wallet.striga.di

import org.koin.android.ext.koin.androidContext
import org.koin.core.module.Module
import org.koin.core.module.dsl.factoryOf
import org.koin.core.module.dsl.new
import org.koin.dsl.bind
import org.koin.dsl.module
import retrofit2.create
import org.p2p.wallet.R
import org.p2p.wallet.common.di.InjectionModule
import org.p2p.wallet.infrastructure.network.NetworkModule.getRetrofit
import org.p2p.wallet.infrastructure.network.interceptor.StrigaProxyApiInterceptor
import org.p2p.wallet.striga.wallet.api.StrigaWalletApi
import org.p2p.wallet.striga.wallet.interactor.StrigaWalletInteractor
import org.p2p.wallet.striga.wallet.repository.StrigaWalletRemoteRepository
import org.p2p.wallet.striga.wallet.repository.StrigaWalletRepository
import org.p2p.wallet.striga.wallet.repository.StrigaWalletRepositoryMapper

object StrigaWalletModule : InjectionModule {

override fun create(): Module = module {
initDataLayer()

factoryOf(::StrigaWalletInteractor)
}

private fun Module.initDataLayer() {
single<StrigaWalletApi> {
val url = androidContext().getString(R.string.strigaProxyServiceBaseUrl)
getRetrofit(
baseUrl = url,
tag = "StrigaProxyApi",
interceptor = new(::StrigaProxyApiInterceptor)
).create()
}

factoryOf(::StrigaWalletRepositoryMapper)
factoryOf(::StrigaWalletRemoteRepository) bind StrigaWalletRepository::class
}
}
19 changes: 19 additions & 0 deletions app/src/main/java/org/p2p/wallet/striga/model/StrigaApiError.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,24 @@ enum class StrigaApiErrorCode(val code: String) {
@SerializedName("31008")
EXCEEDED_DAILY_RESEND_SMS_LIMIT("31008"),

// Wallet errors
@SerializedName("00013")
ADDRESS_ALREADY_WHITELISTED("00013"),

@SerializedName("41004")
ADDRESS_NOT_WHITELISTED("41004"),

@SerializedName("60001")
USER_LIMIT_EXCEEDED("60001"),

@SerializedName("41008")
BELOW_MINIMUM_AMOUNT("41008"),

@SerializedName("31004")
INSUFFICIENT_BALANCE("31004"),

@SerializedName("41005")
INVALID_DESTINATION("41005"),

UNKNOWN("-1")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.p2p.wallet.striga.wallet.api

import retrofit2.http.Body
import retrofit2.http.POST
import org.p2p.wallet.striga.wallet.api.request.StrigaAddWhitelistedAddressRequest
import org.p2p.wallet.striga.wallet.api.request.StrigaEnrichAccountRequest
import org.p2p.wallet.striga.wallet.api.request.StrigaGetWhitelistedAddressesRequest
import org.p2p.wallet.striga.wallet.api.request.StrigaInitiateOnchainWithdrawalRequest
import org.p2p.wallet.striga.wallet.api.response.StrigaEnrichFiatAccountResponse
import org.p2p.wallet.striga.wallet.api.response.StrigaInitiateOnchainWithdrawalResponse
import org.p2p.wallet.striga.wallet.api.response.StrigaWhitelistedAddressItemResponse
import org.p2p.wallet.striga.wallet.api.response.StrigaWhitelistedAddressesResponse

interface StrigaWalletApi {

@POST("v1/wallets/send/initiate/onchain")
suspend fun initiateOnchainWithdrawal(
@Body body: StrigaInitiateOnchainWithdrawalRequest
): StrigaInitiateOnchainWithdrawalResponse

@POST("v1/wallets/get/whitelisted-addresses")
suspend fun getWhitelistedAddresses(
@Body body: StrigaGetWhitelistedAddressesRequest
): StrigaWhitelistedAddressesResponse

@POST("v1/wallets/whitelist-address")
suspend fun addWhitelistedAddress(
@Body body: StrigaAddWhitelistedAddressRequest
): StrigaWhitelistedAddressItemResponse

/**
* This method returns absolutely different responses for crypto and fiat accounts
* So use it for fiat accounts only
*/
@POST("v1/wallets/account/enrich")
suspend fun enrichFiatAccount(@Body body: StrigaEnrichAccountRequest): StrigaEnrichFiatAccountResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.p2p.wallet.striga.wallet.api.request

import com.google.gson.annotations.SerializedName

class StrigaAddWhitelistedAddressRequest(
@SerializedName("userId")
val userId: String,
@SerializedName("address")
val address: String,
eduardmaximovich marked this conversation as resolved.
Show resolved Hide resolved
@SerializedName("currency")
val currency: String,
@SerializedName("network")
val network: String,
@SerializedName("label")
val label: String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.p2p.wallet.striga.wallet.api.request

import com.google.gson.annotations.SerializedName

class StrigaEnrichAccountRequest(
@SerializedName("userId")
val userId: String,
@SerializedName("accountId")
val accountId: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.p2p.wallet.striga.wallet.api.request

import com.google.gson.annotations.SerializedName

class StrigaGetWhitelistedAddressesRequest(
@SerializedName("userId")
val userId: String,
@SerializedName("label")
val label: String? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.p2p.wallet.striga.wallet.api.request

import com.google.gson.annotations.SerializedName

/**
* @param userId The Id of the user who is sending this transaction
* @param sourceAccountId The Id of the account to debit
* @param whitelistedAddressId The Id of the whitelisted destination
* @param amount The amount denominated in the smallest divisible unit of the sending currency.
* For example: cents or satoshis
*/
class StrigaInitiateOnchainWithdrawalRequest(
@SerializedName("userId")
val userId: String,
@SerializedName("sourceAccountId")
val sourceAccountId: String,
@SerializedName("whitelistedAddressId")
val whitelistedAddressId: String,
@SerializedName("amount")
val amount: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.p2p.wallet.striga.wallet.api.response

import com.google.gson.annotations.SerializedName

class StrigaBlockchainNetworkResponse(
@SerializedName("name")
val name: String,
@SerializedName("contractAddress")
val contractAddress: String?,
@SerializedName("type")
val type: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.p2p.wallet.striga.wallet.api.response

import com.google.gson.annotations.SerializedName

class StrigaEnrichFiatAccountResponse(
@SerializedName("currency")
val currency: String,
@SerializedName("status")
val status: String,
@SerializedName("internalAccountId")
val internalAccountId: String,
@SerializedName("bankCountry")
val bankCountry: String,
@SerializedName("bankAddress")
val bankAddress: String,
@SerializedName("iban")
val iban: String,
@SerializedName("bic")
val bic: String,
@SerializedName("accountNumber")
val accountNumber: String,
@SerializedName("bankName")
val bankName: String,
@SerializedName("bankAccountHolderName")
val bankAccountHolderName: String,
@SerializedName("provider")
val provider: String,
@SerializedName("paymentType")
val paymentType: String?,
@SerializedName("domestic")
val domestic: Boolean,
eduardmaximovich marked this conversation as resolved.
Show resolved Hide resolved
@SerializedName("routingCodeEntries")
val routingCodeEntries: List<String>,
@SerializedName("payInReference")
val payInReference: String?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.p2p.wallet.striga.wallet.api.response

import com.google.gson.annotations.SerializedName

class StrigaInitiateOnchainWithdrawalResponse(
@SerializedName("challengeId")
val challengeId: String,
@SerializedName("dateExpires")
val dateExpires: String,
@SerializedName("transaction")
val transaction: Transaction,
@SerializedName("feeEstimate")
val feeEstimate: FeeEstimate,
) {

class Transaction(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TransactionRequest
StrigaTransactionRequest

just Transaction can be too ambiguous imho

Copy link
Collaborator Author

@eduardmaximovich eduardmaximovich Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change it to TransactionResponse, because it's hard to get confused as it's a subclass. You can't just use the type TransactionResponse, you need to first specify the parent class as StrigaInitOnchainWithdrawalResponse.TransactionResponse

@SerializedName("syncedOwnerId")
val syncedOwnerId: String,
@SerializedName("sourceAccountId")
val sourceAccountId: String,
@SerializedName("parentWalletId")
val parentWalletId: String,
@SerializedName("currency")
val currency: String,
@SerializedName("amount")
val amount: String,
@SerializedName("status")
val status: String,
@SerializedName("txType")
val txType: String,
@SerializedName("blockchainDestinationAddress")
val blockchainDestinationAddress: String,
@SerializedName("blockchainNetwork")
val blockchainNetwork: StrigaBlockchainNetworkResponse,
@SerializedName("transactionCurrency")
val transactionCurrency: String,
)

class FeeEstimate(
@SerializedName("totalFee")
val totalFee: String,
@SerializedName("networkFee")
val networkFee: String,
@SerializedName("ourFee")
val ourFee: String,
@SerializedName("theirFee")
val theirFee: String,
@SerializedName("feeCurrency")
val feeCurrency: String,
@SerializedName("gasLimit")
val gasLimit: String,
@SerializedName("gasPrice")
val gasPrice: String,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.p2p.wallet.striga.wallet.api.response

import com.google.gson.annotations.SerializedName

class StrigaWhitelistedAddressItemResponse(
@SerializedName("id")
val id: String,
@SerializedName("status")
val status: String,
@SerializedName("address")
val address: String,
@SerializedName("currency")
val currency: String,
@SerializedName("network")
val network: StrigaBlockchainNetworkResponse
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.p2p.wallet.striga.wallet.api.response

import com.google.gson.annotations.SerializedName

class StrigaWhitelistedAddressesResponse(
@SerializedName("addresses")
val addresses: List<StrigaWhitelistedAddressItemResponse>,
@SerializedName("count")
val count: Int,
@SerializedName("total")
val total: Int
)
Loading