Skip to content
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

Merged
merged 30 commits into from
Apr 25, 2024

Conversation

warmkesselj
Copy link
Collaborator

@warmkesselj warmkesselj commented Apr 15, 2024

Summary of changes

  • This PR fixes an issue with allowing follow up transactions to occur.
    • Provide a removeObservers method to clear out the observers on completion of a transaction.

Checklist

  • Added a changelog entry

Authors

@warmkesselj
@sshropshire
@saperi22

Copy link
Contributor

@jaxdesmarais jaxdesmarais left a 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?

@@ -117,7 +118,9 @@ fun StatefulActionButtonPreview() {
modifier = Modifier
.fillMaxWidth()
.padding(UIConstants.paddingMedium)
)
) { state ->
Text(text = "Sample Text", modifier = Modifier.padding(64.dp))
Copy link
Contributor

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?

Copy link
Contributor

@saperi22 saperi22 Apr 24, 2024

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

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". 😄

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
saperi22 and others added 4 commits April 24, 2024 10:50
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,
Copy link
Contributor

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?

Copy link
Contributor

@saperi22 saperi22 Apr 24, 2024

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.

Copy link
Collaborator Author

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.

* 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) }
Copy link
Contributor

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?

Copy link
Contributor

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;
    }

Copy link
Collaborator Author

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

@sarahkoop
Copy link
Contributor

Looks like the latest google play compliance changes on main aren't updated here - can we update this branch to the latest main?

@@ -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 ->
Copy link
Contributor

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

Copy link
Contributor

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.

@sarahkoop
Copy link
Contributor

+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))
Copy link
Contributor

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)
}
Copy link
Contributor

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)

@warmkesselj warmkesselj merged commit ece573b into main Apr 25, 2024
7 checks passed
@warmkesselj warmkesselj deleted the fix_unableToStartWebCheckoutSubsequently branch April 25, 2024 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants