Skip to content

Commit

Permalink
Clean up legacy named methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
sshropshire committed Dec 6, 2024
1 parent d8398ce commit 3e543ab
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class CardClient internal constructor(
return result
}

fun legacyCompleteAuthChallenge(intent: Intent, authState: String): CardStatus {
fun completeAuthChallenge(intent: Intent, authState: String): CardStatus {
val status = authChallengeLauncher.completeAuthRequest(intent, authState)
when (status) {
is CardStatus.VaultSuccess -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class CardClientUnitTest {
cardAuthLauncher.completeAuthRequest(intent, "auth state")
} returns CardStatus.VaultSuccess(successResult)

sut.legacyCompleteAuthChallenge(intent, "auth state")
sut.completeAuthChallenge(intent, "auth state")

val slot = slot<CardVaultResult>()
verify(exactly = 1) { cardVaultListener.onVaultSuccess(capture(slot)) }
Expand All @@ -287,7 +287,7 @@ class CardClientUnitTest {
cardAuthLauncher.completeAuthRequest(intent, "auth state")
} returns CardStatus.VaultError(error)

sut.legacyCompleteAuthChallenge(intent, "auth state")
sut.completeAuthChallenge(intent, "auth state")

val slot = slot<PayPalSDKError>()
verify(exactly = 1) { cardVaultListener.onVaultFailure(capture(slot)) }
Expand All @@ -303,7 +303,7 @@ class CardClientUnitTest {
cardAuthLauncher.completeAuthRequest(intent, "auth state")
} returns CardStatus.VaultCanceled("fake-setup-token-id")

sut.legacyCompleteAuthChallenge(intent, "auth state")
sut.completeAuthChallenge(intent, "auth state")
// BREAKING CHANGE CALLOUT: if we introduce an "onVaultCanceled()" listener method, it could
// break existing merchant integrations
verify(exactly = 1) { cardVaultListener.onVaultFailure(any()) }
Expand All @@ -319,7 +319,7 @@ class CardClientUnitTest {
cardAuthLauncher.completeAuthRequest(intent, "auth state")
} returns CardStatus.NoResult

sut.legacyCompleteAuthChallenge(intent, "auth state")
sut.completeAuthChallenge(intent, "auth state")
verify { sut.cardVaultListener?.wasNot(Called) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,6 @@ class ApproveOrderViewModel @Inject constructor(
}
}

private fun presentAuthChallenge(
activity: ComponentActivity,
authChallenge: CardAuthChallenge
) {
cardClient?.presentAuthChallenge(activity, authChallenge)?.let { presentAuthResult ->
when (presentAuthResult) {
is CardPresentAuthChallengeResult.Success -> {
authState = presentAuthResult.authState
}

is CardPresentAuthChallengeResult.Failure -> {
approveOrderState =
ActionState.Failure(presentAuthResult.error)
}
}
}
}

private suspend fun approveOrderWithId(activity: ComponentActivity, orderId: String) {
approveOrderState = ActionState.Loading

Expand Down Expand Up @@ -128,6 +110,23 @@ class ApproveOrderViewModel @Inject constructor(
}
}

private fun presentAuthChallenge(
activity: ComponentActivity,
authChallenge: CardAuthChallenge
) {
cardClient?.presentAuthChallenge(activity, authChallenge)?.let { presentAuthResult ->
when (presentAuthResult) {
is CardPresentAuthChallengeResult.Success -> {
authState = presentAuthResult.authState
}

is CardPresentAuthChallengeResult.Failure -> {
approveOrderState = ActionState.Failure(presentAuthResult.error)
}
}
}
}

fun completeOrder(context: Context) {
val orderId = createdOrder?.id
if (orderId == null) {
Expand Down Expand Up @@ -256,6 +255,6 @@ class ApproveOrderViewModel @Inject constructor(
}
}

authState?.let { cardClient?.legacyCompleteAuthChallenge(intent, it) }
authState?.let { cardClient?.completeAuthChallenge(intent, it) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,6 @@ class VaultCardViewModel @Inject constructor(
}

fun completeAuthChallenge(intent: Intent) {
authState?.let { cardClient?.legacyCompleteAuthChallenge(intent, it) }
authState?.let { cardClient?.completeAuthChallenge(intent, it) }
}
}

0 comments on commit 3e543ab

Please sign in to comment.