-
Notifications
You must be signed in to change notification settings - Fork 263
fix: remove deprecated GooglePay functionality in favour of TaskResultContracts #1616
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <application> | ||
| <meta-data android:name="com.google.android.gms.wallet.api.enabled" android:value="true"/> | ||
| <activity android:name=".GooglePayActivity" | ||
| android:theme="@style/bt_transparent_activity"/> | ||
| </application> | ||
| </manifest> | ||
| </manifest> |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,50 @@ | ||
| package com.braintreepayments.api.googlepay | ||
|
|
||
| import android.content.Context | ||
| import androidx.activity.ComponentActivity | ||
| import androidx.activity.result.ActivityResultLauncher | ||
| import androidx.activity.result.ActivityResultRegistry | ||
| import androidx.fragment.app.Fragment | ||
| import androidx.lifecycle.LifecycleOwner | ||
| import com.braintreepayments.api.core.UserCanceledException | ||
| import com.google.android.gms.tasks.Task | ||
| import com.google.android.gms.wallet.PaymentData | ||
| import com.google.android.gms.wallet.contract.ApiTaskResult | ||
| import com.google.android.gms.wallet.contract.TaskResultContracts | ||
|
|
||
| /** | ||
| * Responsible for launching the Google Pay payment sheet | ||
| */ | ||
| class GooglePayLauncher internal constructor( | ||
| registry: ActivityResultRegistry, | ||
| lifecycleOwner: LifecycleOwner, | ||
| context: Context, | ||
| private val internalGooglePayClient: GooglePayInternalClient = GooglePayInternalClient(), | ||
| callback: GooglePayLauncherCallback | ||
| ) { | ||
|
|
||
| private val activityLauncher: ActivityResultLauncher<GooglePayPaymentAuthRequestParams> = registry.register( | ||
| private val appContext: Context = context.applicationContext | ||
|
|
||
| private val activityLauncher: ActivityResultLauncher<Task<PaymentData>> = registry.register( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like this is the crux of the change. Are the any implications to older APIs or is this fully backwards compatible?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great question. I tested with older versions of the APIs on emulator and it worked just fine but I'll make sure to test on all supported API versions to make sure we won't run into issues
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok so I couldn't get some of the older emulators to work well enough to test, but we do have confirmation that the new API is backwards compatible back to versions that are so old we don't even support. So I think we should be good |
||
| GOOGLE_PAY_RESULT, lifecycleOwner, | ||
| GooglePayActivityResultContract() | ||
| ) { googlePayPaymentAuthResult: GooglePayPaymentAuthResult -> | ||
| callback.onGooglePayLauncherResult( | ||
| googlePayPaymentAuthResult | ||
| ) | ||
| TaskResultContracts.GetPaymentDataResult() | ||
| ) { apiTaskResult: ApiTaskResult<PaymentData> -> | ||
| val result = when { | ||
| apiTaskResult.status.isSuccess -> | ||
| GooglePayPaymentAuthResult(apiTaskResult.result, null) | ||
| apiTaskResult.status.isCanceled -> | ||
| GooglePayPaymentAuthResult(null, UserCanceledException("User canceled Google Pay.")) | ||
| else -> | ||
| GooglePayPaymentAuthResult( | ||
| null, | ||
| GooglePayException( | ||
| "An error was encountered during the Google Pay " + | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a way we can display the status object in our demo app, so that we can see what caused an error right away?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually already covered in the demo app. This PR doesn't change how results are getting delivered, it only changes what's delivering them. If you take a look at the delete results contract file you can see that the handling of the payment status and sending of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you very much, I can see it now! |
||
| "flow. See the status object in this exception for more details.", | ||
| apiTaskResult.status | ||
| ) | ||
| ) | ||
| } | ||
| callback.onGooglePayLauncherResult(result) | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -36,8 +59,10 @@ class GooglePayLauncher internal constructor( | |
| fragment: Fragment, | ||
| callback: GooglePayLauncherCallback | ||
| ) : this( | ||
| fragment.requireActivity().activityResultRegistry, fragment.viewLifecycleOwner, | ||
| callback | ||
| fragment.requireActivity().activityResultRegistry, | ||
| fragment.viewLifecycleOwner, | ||
| fragment.requireContext(), | ||
| callback = callback | ||
| ) | ||
|
|
||
| /** | ||
|
|
@@ -51,7 +76,7 @@ class GooglePayLauncher internal constructor( | |
| constructor( | ||
| activity: ComponentActivity, | ||
| callback: GooglePayLauncherCallback | ||
| ) : this(activity.activityResultRegistry, activity, callback) | ||
| ) : this(activity.activityResultRegistry, activity, activity, callback = callback) | ||
|
|
||
| /** | ||
| * Launches the Google Pay payment sheet. This method cannot be called until the lifecycle of | ||
|
|
@@ -62,7 +87,10 @@ class GooglePayLauncher internal constructor( | |
| * received from invoking [GooglePayClient.createPaymentAuthRequest] | ||
| */ | ||
| fun launch(paymentAuthRequest: GooglePayPaymentAuthRequest.ReadyToLaunch) { | ||
| activityLauncher.launch(paymentAuthRequest.requestParams) | ||
| internalGooglePayClient.loadPaymentData(appContext, paymentAuthRequest.requestParams) | ||
| .addOnCompleteListener { completedTask -> | ||
| activityLauncher.launch(completedTask) | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
|
|
||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.