-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix unable to start web checkout in subsequent transactions #251
Conversation
Demo/src/main/java/com/paypal/android/uishared/components/ActionButtonColumn.kt
Outdated
Show resolved
Hide resolved
Demo/src/main/java/com/paypal/android/uishared/components/ErrorView.kt
Outdated
Show resolved
Hide resolved
Demo/src/main/java/com/paypal/android/uishared/components/ErrorView.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there are some Detekt errors that we should resolve. Can we also add some tests around the removeObservers
methods?
CardPayments/src/main/java/com/paypal/android/cardpayments/CardClient.kt
Outdated
Show resolved
Hide resolved
PayPalWebPayments/src/main/java/com/paypal/android/paypalwebpayments/PayPalWebCheckoutClient.kt
Outdated
Show resolved
Hide resolved
…thub.com/paypal/paypal-android into fix_unableToStartWebCheckoutSubsequently
CardPayments/src/main/java/com/paypal/android/cardpayments/CardClient.kt
Outdated
Show resolved
Hide resolved
@@ -117,7 +118,9 @@ fun StatefulActionButtonPreview() { | |||
modifier = Modifier | |||
.fillMaxWidth() | |||
.padding(UIConstants.paddingMedium) | |||
) | |||
) { state -> | |||
Text(text = "Sample Text", modifier = Modifier.padding(64.dp)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious what this is needed for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jaxdesmarais looks like this is part of compose preview (annotated by @Preview) https://github.com/paypal/paypal-android/pull/251/files/cb5d5b7a7818424851e4a2f68406e5e9e233538b#diff-dbdf8e5b958c81bbcff72ecd0e61151a09aae144ce2f9726e2b1616511de536bR107
It is a tool that allows users to view the UI in the IDE while developing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was just for previewing purposes to see the behavior when inflating the action column.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah gotcha, didn't see it was in a preview and was confused by the "Sample Text". 😄
PayPalWebPayments/src/main/java/com/paypal/android/paypalwebpayments/PayPalWebCheckoutClient.kt
Outdated
Show resolved
Hide resolved
Co-authored-by: Jax DesMarais-Leder <[email protected]>
Co-authored-by: Jax DesMarais-Leder <[email protected]>
Co-authored-by: Jax DesMarais-Leder <[email protected]>
@@ -13,7 +14,7 @@ import com.paypal.android.corepayments.analytics.AnalyticsService | |||
*/ | |||
class PayPalWebCheckoutClient internal constructor( | |||
// NEXT MAJOR VERSION: remove hardcoded activity reference | |||
private val activity: FragmentActivity, | |||
activity: FragmentActivity, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be public now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is no longer a class variable - it's a linter optimization.
The scope of activity
is now limited to the constructor and a class level variable, so the activity
object is no longer needed after the constructor is done constructing. It is essentially a local object and needs no private
modifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appears it can remain a private property. Pushing changes now.
…thub.com/paypal/paypal-android into fix_unableToStartWebCheckoutSubsequently
* Call this method at the end of the web checkout flow to clear out all observers and listeners | ||
*/ | ||
fun removeObservers() { | ||
activityReference.get()?.let { it.lifecycle.removeObserver(observer) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is lifecycle always non null here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is non-null all the time.
@NonNull
@Override
public Lifecycle getLifecycle() {
return mLifecycleRegistry;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My guess would be that it's always not null, but I don't know that much about Android. Perhaps I can add some guards around it
Looks like the latest google play compliance changes on main aren't updated here - can we update this branch to the latest main? |
…fix_unableToStartWebCheckoutSubsequently
@@ -138,7 +138,10 @@ class PayPalWebCheckoutClient internal constructor( | |||
* Call this method at the end of the web checkout flow to clear out all observers and listeners | |||
*/ | |||
fun removeObservers() { | |||
activityReference.get()?.let { it.lifecycle.removeObserver(observer) } | |||
activity.lifecycle?.let { lifecycle -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I think we want to revert this change - it should be on the activityReference right? And I think Sai is correct it's always non-null, so disregard my comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 need to revert the change.
+1 to Jax's comment - Is it possible to unit test removeObservers? |
@@ -117,7 +118,9 @@ fun StatefulActionButtonPreview() { | |||
modifier = Modifier | |||
.fillMaxWidth() | |||
.padding(UIConstants.paddingMedium) | |||
) | |||
) { state -> | |||
Text(text = "Sample Text", modifier = Modifier.padding(64.dp)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah gotcha, didn't see it was in a preview and was confused by the "Sample Text". 😄
activityReference.get()?.let { activity -> | ||
payPalWebLauncher.launchPayPalWebCheckout(activity, request)?.let { launchError -> | ||
notifyWebCheckoutFailure(launchError, request.orderId) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should return an error if activity we can't get the activity reference - PayPal won't be launched but merchant wont get any notification (same for vault)
Summary of changes
removeObservers
method to clear out the observers on completion of a transaction.Checklist
Authors
@warmkesselj
@sshropshire
@saperi22