Skip to content
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.processout.sdk.api.service

import android.net.Uri
import androidx.core.net.toUri
import com.processout.sdk.api.model.request.POAlternativePaymentMethodRequest
import com.processout.sdk.api.model.response.POAlternativePaymentMethodResponse
import com.processout.sdk.api.model.response.POAlternativePaymentMethodResponse.APMReturnType
import com.processout.sdk.core.POFailure.*
import com.processout.sdk.core.POFailure.Code.*
import com.processout.sdk.core.ProcessOutResult
import com.processout.sdk.core.logger.POLogger
import com.processout.sdk.core.util.findBy
import com.processout.sdk.di.ContextGraph

Expand Down Expand Up @@ -39,7 +41,7 @@ internal class DefaultAlternativePaymentMethodsService(
}
arrayList
}
val uriBuilder = Uri.parse(baseUrl).buildUpon()
val uriBuilder = baseUrl.toUri().buildUpon()
pathComponents.forEach { uriBuilder.appendPath(it) }
request.additionalData?.forEach {
uriBuilder.appendQueryParameter("additional_data[${it.key}]", it.value)
Expand All @@ -54,24 +56,33 @@ internal class DefaultAlternativePaymentMethodsService(
message = "Invalid or malformed alternative payment method URI: $uri"
)
}

uri.getQueryParameter("token")?.let { gatewayToken ->
if (gatewayToken.isEmpty()) {
POLogger.debug("Gateway 'token' is empty in the URI: %s", uri)
}
val customerId = uri.getQueryParameter("customer_id")
val tokenId = uri.getQueryParameter("token_id")
val returnType = if (customerId != null && tokenId != null)
APMReturnType.CREATE_TOKEN else APMReturnType.AUTHORIZATION
return ProcessOutResult.Success(
POAlternativePaymentMethodResponse(
gatewayToken = gatewayToken,
customerId = customerId,
tokenId = tokenId,
returnType = returnType
)
)
}
uri.getQueryParameter("error_code")?.let { errorCode ->
return ProcessOutResult.Failure(failureCode(errorCode))
}

val gatewayToken = uri.getQueryParameter("token") ?: String()

val customerId = uri.getQueryParameter("customer_id")
val tokenId = uri.getQueryParameter("token_id")
val returnType = if (customerId != null && tokenId != null)
APMReturnType.CREATE_TOKEN else APMReturnType.AUTHORIZATION

POLogger.warn("Neither the gateway 'token' nor 'error_code' is set in the URI: %s", uri)
return ProcessOutResult.Success(
POAlternativePaymentMethodResponse(
gatewayToken = gatewayToken,
customerId = customerId,
tokenId = tokenId,
returnType = returnType
gatewayToken = String(),
customerId = null,
tokenId = null,
returnType = APMReturnType.AUTHORIZATION
)
)
}
Expand Down