Skip to content

Commit

Permalink
Revert 3DS URL Parsing for CardResult (#266)
Browse files Browse the repository at this point in the history
* Add didAttemptThreeDSecureAuthentication and status properties to CardResult.

* Update CardResultView.

* Update CardResult view to use new properties.

* Remove deepLinkUri parameter.

* Fix padding bug.

* Revert deepLinkUrl property removal.

* Update CHANGELOG.md

Co-authored-by: Sarah Koop <[email protected]>

* Make CardResult status property immutable.

---------

Co-authored-by: Sarah Koop <[email protected]>
  • Loading branch information
sshropshire and sarahkoop authored Jul 16, 2024
1 parent 44e3a73 commit 7285f90
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 46 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# PayPal Android SDK Release Notes

## unreleased

* CardPayments
* Deprecate `CardResult.liabilityShift` property
* Deprecate `CardResult.deepLinkUrl` property
* Add `CardResult.status` property
* Add `CardResult.didAttemptThreeDSecureAuthentication` property

## 1.5.0 (2024-07-10)
* PayPalWebPayments
* Deprecate `PayPalWebVaultRequest(setupTokenId, approveVaultHref)`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ internal class CardAuthLauncher(
CardStatus.ApproveOrderError(CardError.malformedDeepLinkError, orderId)
} else {
val liabilityShift = deepLinkUrl.getQueryParameter("liability_shift")
val result = CardResult(orderId, deepLinkUrl, liabilityShift)
val result = CardResult(
orderId = orderId,
liabilityShift = liabilityShift,
didAttemptThreeDSecureAuthentication = true
)
CardStatus.ApproveOrderSuccess(result)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ class CardClient internal constructor(
)

if (response.payerActionHref == null) {
val result = CardResult(response.orderId)
val result = CardResult(
orderId = response.orderId,
status = response.status?.name,
didAttemptThreeDSecureAuthentication = false
)
notifyApproveOrderSuccess(result)
} else {
analyticsService.sendAnalyticsEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ import android.net.Uri
*
* @property [orderId] associated order ID.
* @property [liabilityShift] Liability shift value returned from 3DS verification
* @property [status] status of the order
* @property [didAttemptThreeDSecureAuthentication] 3DS verification was attempted.
* Use v2/checkout/orders/{orderId} in your server to get verification results.
*/
data class CardResult(
val orderId: String,

/**
* @suppress
*/
@Deprecated("Use status instead.")
val deepLinkUrl: Uri? = null,
val liabilityShift: String? = null

@Deprecated("Use didAttemptThreeDSecureAuthentication instead.")
val liabilityShift: String? = null,

val status: String? = null,

val didAttemptThreeDSecureAuthentication: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import io.mockk.slot
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -124,6 +125,8 @@ class CardAuthLauncherUnitTest {
val cardResult = status.result
assertEquals("fake-order-id", cardResult.orderId)
assertEquals("NO", cardResult.liabilityShift)
assertTrue(cardResult.didAttemptThreeDSecureAuthentication)
assertNull(cardResult.status)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.setMain
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertSame
import org.junit.Before
Expand Down Expand Up @@ -98,6 +99,8 @@ class CardClientUnitTest {

val actual = resultSlot.captured
assertEquals("sample-order-id", actual.orderId)
assertEquals(OrderStatus.APPROVED.name, actual.status)
assertFalse(actual.didAttemptThreeDSecureAuthentication)
}

@Test
Expand Down Expand Up @@ -183,7 +186,11 @@ class CardClientUnitTest {
val sut = createCardClient(testScheduler)
sut.approveOrderListener = approveOrderListener

val successResult = CardResult("fake-order-id")
val successResult = CardResult(
orderId = "fake-order-id",
status = OrderStatus.APPROVED.name,
didAttemptThreeDSecureAuthentication = false
)
every {
cardAuthLauncher.deliverBrowserSwitchResult(activity)
} returns CardStatus.ApproveOrderSuccess(successResult)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.paypal.android.uishared.components

import android.net.Uri
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -18,64 +14,44 @@ import com.paypal.android.utils.UIConstants
@Composable
fun CardResultView(result: CardResult) {
Column(
verticalArrangement = UIConstants.spacingMedium,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = UIConstants.paddingMedium)
.padding(UIConstants.paddingMedium)
) {
Text(
text = "Order ID",
style = MaterialTheme.typography.titleMedium,
modifier = Modifier
.padding(top = UIConstants.paddingMedium)
)
Text(
text = result.orderId,
modifier = Modifier
.padding(top = UIConstants.paddingExtraSmall)
)
Text(
text = "Deep Link URL",
style = MaterialTheme.typography.titleMedium,
modifier = Modifier
.padding(top = UIConstants.paddingMedium)
)
val deepLinkUrl = result.deepLinkUrl
if (deepLinkUrl == null) {
Text(
text = "NOT SET",
modifier = Modifier
.padding(top = UIConstants.paddingExtraSmall)
)
} else {
UriView(uri = deepLinkUrl)
}
Spacer(modifier = Modifier.size(UIConstants.paddingLarge))
PropertyView(name = "Order ID", value = result.orderId)
PropertyView(name = "Order Status", value = result.status)
val didAttemptText = if (result.didAttemptThreeDSecureAuthentication) "YES" else "NO"
PropertyView(name = "Did Attempt 3DS Authentication", value = didAttemptText)
}
}

@Preview
@Composable
fun CardResultViewWithDeepLinkPreview() {
fun CardResultViewWith3DSAuth() {
MaterialTheme {
Surface(modifier = Modifier.fillMaxWidth()) {
CardResultView(
CardResult(
"fake-order-id",
Uri.parse("fake-scheme://fake-host/fake-path?fakeParam1=value1&fakeParam2=value2")
)
val result = CardResult(
orderId = "fake-order-id",
status = "fake-status",
didAttemptThreeDSecureAuthentication = true
)
CardResultView(result)
}
}
}

@Preview
@Composable
fun CardResultViewWithoutDeepLinkPreview() {
fun CardResultViewWithout3DSAuth() {
MaterialTheme {
Surface(modifier = Modifier.fillMaxWidth()) {
CardResultView(
CardResult("fake-order-id")
val result = CardResult(
orderId = "fake-order-id",
status = "fake-status",
didAttemptThreeDSecureAuthentication = false
)
CardResultView(result)
}
}
}

0 comments on commit 7285f90

Please sign in to comment.