Skip to content

Commit

Permalink
Add support for null in sca request parameters
Browse files Browse the repository at this point in the history
- Better error message
- Some name changes
  • Loading branch information
andreasvettefors committed Sep 3, 2024
1 parent 0a226b6 commit 47d3c8e
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class PaymentSession(private var orderInfo: ViewPaymentOrderInfo? = null) {
/**
* Contains the state of the payment process
*/

private var _paymentSessionState: MutableLiveData<PaymentSessionState> =
MutableLiveData(PaymentSessionState.Idle)
val paymentSessionState: LiveData<PaymentSessionState> = _paymentSessionState
Expand Down Expand Up @@ -326,7 +325,7 @@ class PaymentSession(private var orderInfo: ViewPaymentOrderInfo? = null) {
}

is StepInstruction.ScaRedirectStep -> {
launch3DSecure(instruction.task)
show3DSecure(instruction.task)
}

is StepInstruction.LaunchClientAppStep -> {
Expand Down Expand Up @@ -426,6 +425,16 @@ class PaymentSession(private var orderInfo: ViewPaymentOrderInfo? = null) {
.useBrowser(false)
.build()

BeaconService.logEvent(
eventAction = EventAction.SDKMethodInvoked(
method = MethodModel(
name = "createPaymentFragment",
sdk = true,
succeeded = true
)
)
)

_paymentSessionState.value = PaymentSessionState.PaymentFragmentCreated(paymentFragment)
setStateToIdle()

Expand Down Expand Up @@ -456,7 +465,7 @@ class PaymentSession(private var orderInfo: ViewPaymentOrderInfo? = null) {
} ?: onSdkProblemOccurred(PaymentSessionProblem.InternalInconsistencyError)
}

private fun launch3DSecure(task: IntegrationTask) {
private fun show3DSecure(task: IntegrationTask) {

val scaRedirectFragment = ScaRedirectFragment(
task,
Expand All @@ -479,11 +488,10 @@ class PaymentSession(private var orderInfo: ViewPaymentOrderInfo? = null) {
_paymentSessionState.value = PaymentSessionState.Dismiss3dSecureFragment
setStateToIdle()


BeaconService.logEvent(
eventAction = EventAction.SDKCallbackInvoked(
method = MethodModel(
name = "dismiss3DSecure",
name = "dismiss3DSecureFragment",
sdk = true,
succeeded = true
)
Expand All @@ -500,7 +508,7 @@ class PaymentSession(private var orderInfo: ViewPaymentOrderInfo? = null) {
BeaconService.logEvent(
eventAction = EventAction.SDKCallbackInvoked(
method = MethodModel(
name = "show3DSecure",
name = "show3DSecureFragment",
sdk = true,
succeeded = true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ sealed class PaymentSessionState {
PaymentSessionState()

/**
* Called when 3d-secure should be shown
* Called when a 3D secure view needs to be presented.
*
* @param fragment Fragment with 3D secure view.
*/
class Show3dSecureFragment(val fragment: Fragment) : PaymentSessionState()

/**
* Called when 3d-secure can be dismissed
* Called whenever the 3D secure view can be dismissed.
*/
object Dismiss3dSecureFragment : PaymentSessionState()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal object SessionOperationHandler {

private val alreadyUsedProblemUrls: MutableList<String> = mutableListOf()
private val alreadyUsedSwishUrls: MutableList<String> = mutableListOf()
private val scaMethodRequestDataPerformed: MutableMap<String, String> = mutableMapOf()
private val scaMethodRequestDataPerformed: MutableMap<String?, String> = mutableMapOf()
private val scaRedirectDataPerformed: MutableMap<String, String> = mutableMapOf()
private var hasShownAvailableInstruments: Boolean = false

Expand Down Expand Up @@ -150,7 +150,7 @@ internal object SessionOperationHandler {

scaMethodRequestDataPerformed[scaMethodRequest.getExpectValuesFor(
PaymentSessionAPIConstants.THREE_DS_METHOD_DATA
)?.value as String] =
)?.value as String?] =
completionIndicator

instructions.add(0, StepInstruction.OverrideApiCall(paymentOutputModel))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ internal open class PaymentSessionAPIClient {
continuation.resume(
PaymentSessionResponse.Error(
SwedbankPayAPIError.Error(
message = connection.responseMessage,
responseCode = responseCode
)
)
Expand Down Expand Up @@ -283,6 +284,7 @@ internal open class PaymentSessionAPIClient {
continuation.resume(
PaymentSessionResponse.Error(
SwedbankPayAPIError.Error(
message = connection.responseMessage,
responseCode = responseCode
)
)
Expand Down
Loading

0 comments on commit 47d3c8e

Please sign in to comment.