Skip to content

Commit

Permalink
Merge pull request #128 from Tinkoff/MC-7189-mir-3ds
Browse files Browse the repository at this point in the history
MC-7189 3dsv2 для привязки карт мир
  • Loading branch information
jQwout authored Nov 8, 2022
2 parents ec2d993 + 0a0539a commit 4519710
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ internal class NetworkClient {
builder.header("User-Agent", System.getProperty("http.agent"))
builder.header("Accept", JSON)
}

getHeaders().forEach { (key, value) ->
builder.header(key, value)
}

}.build()

private fun <R : AcquiringResponse> checkResult(result: R, onChecked: (isSuccess: Boolean) -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package ru.tinkoff.acquiring.sdk.requests
import com.google.gson.Gson
import ru.tinkoff.acquiring.sdk.AcquiringSdk
import ru.tinkoff.acquiring.sdk.network.AcquiringApi
import ru.tinkoff.acquiring.sdk.network.AcquiringApi.JSON
import ru.tinkoff.acquiring.sdk.network.NetworkClient
import ru.tinkoff.acquiring.sdk.responses.AcquiringResponse
import ru.tinkoff.acquiring.sdk.utils.Request
Expand All @@ -43,6 +44,7 @@ abstract class AcquiringRequest<R : AcquiringResponse>(internal val apiMethod: S
@Volatile
private var disposed = false
private val ignoredFieldsSet: HashSet<String> = hashSetOf(DATA, RECEIPT, RECEIPTS, SHOPS)
private val headersMap: HashMap<String, String> = hashMapOf()

internal open val tokenIgnoreFields: HashSet<String>
get() = ignoredFieldsSet
Expand All @@ -66,10 +68,12 @@ abstract class AcquiringRequest<R : AcquiringResponse>(internal val apiMethod: S
return map
}

protected fun <R : AcquiringResponse> performRequest(request: AcquiringRequest<R>,
responseClass: Class<R>,
onSuccess: (R) -> Unit,
onFailure: (Exception) -> Unit) {
protected fun <R : AcquiringResponse> performRequest(
request: AcquiringRequest<R>,
responseClass: Class<R>,
onSuccess: (R) -> Unit,
onFailure: (Exception) -> Unit
) {
request.validate()
val client = NetworkClient()
client.call(request, responseClass, onSuccess, onFailure)
Expand Down Expand Up @@ -104,9 +108,19 @@ abstract class AcquiringRequest<R : AcquiringResponse>(internal val apiMethod: S
}
}

fun addUserAgentHeader(userAgent: String = System.getProperty("http.agent")) {
headersMap.put("User-Agent", userAgent)
}

fun addContentHeader(content: String = JSON) {
headersMap.put("Accept", content)
}

protected open fun getToken(): String? =
AcquiringSdk.tokenGenerator?.generateToken(this, paramsForToken())

internal fun getHeaders() = headersMap

private fun paramsForToken(): MutableMap<String, Any> {
val tokenParams = asMap()
tokenIgnoreFields.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ class Check3dsVersionResponse(
@SerializedName("PaymentSystem")
val paymentSystem: String? = null

) : AcquiringResponse()
) : AcquiringResponse() {

fun is3DsVersionV2() = version?.startsWith("2") ?: false
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,13 @@ internal class AttachCardViewModel(
coroutine.call(
check3DsRequest,
onSuccess = {
val check3dsMap = ThreeDsHelper.CollectData.invoke(context, it)
ThreeDsHelper.CollectData.addExtraData(check3dsMap, it)
attachCard(requestKey, check3dsMap + (data ?: mapOf()) , it)
if (it.is3DsVersionV2()) {
val check3dsMap = ThreeDsHelper.CollectData.invoke(context, it)
ThreeDsHelper.CollectData.addExtraData(check3dsMap, it)
attachCard(requestKey, check3dsMap + (data ?: mapOf()) , it)
} else {
attachCard(requestKey, data, it)
}
}
)
}
Expand All @@ -114,6 +118,11 @@ internal class AttachCardViewModel(
this.requestKey = requestKey
this.data = data
this.cardData = this@AttachCardViewModel.cardData

if (check3dsVersionResponse?.is3DsVersionV2() == true) {
this.addContentHeader()
this.addUserAgentHeader()
}
}
coroutine.call(attachCardRequest,
onSuccess = { handleAttachSuccess(it, check3dsVersionResponse) },
Expand Down

0 comments on commit 4519710

Please sign in to comment.