diff --git a/GooglePay/src/main/java/com/braintreepayments/api/GooglePayLauncher.java b/GooglePay/src/main/java/com/braintreepayments/api/GooglePayLauncher.java index c31da0d01b..82bec45f16 100644 --- a/GooglePay/src/main/java/com/braintreepayments/api/GooglePayLauncher.java +++ b/GooglePay/src/main/java/com/braintreepayments/api/GooglePayLauncher.java @@ -1,15 +1,15 @@ package com.braintreepayments.api; +import androidx.activity.ComponentActivity; import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.ActivityResultRegistry; import androidx.annotation.NonNull; import androidx.annotation.VisibleForTesting; import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentActivity; import androidx.lifecycle.LifecycleOwner; /** - * Responsible for launching the Google Pay dialog + * Responsible for launching the Google Pay payment sheet */ public class GooglePayLauncher { @@ -18,13 +18,29 @@ public class GooglePayLauncher { private static final String GOOGLE_PAY_RESULT = "com.braintreepayments.api.GooglePay.RESULT"; + /** + * Used to launch the Google Pay payment sheet from within an Android Fragment. This class must be + * instantiated before the Fragment is created. + * + * @param fragment the Android Fragment from which you will launch the Google Pay payment sheet + * @param callback a {@link GooglePayLauncherCallback} to receive the result of the Google Pay + * payment flow + */ public GooglePayLauncher(@NonNull Fragment fragment, @NonNull GooglePayLauncherCallback callback) { this(fragment.getActivity().getActivityResultRegistry(), fragment.getViewLifecycleOwner(), callback); } - public GooglePayLauncher(@NonNull FragmentActivity activity, + /** + * Used to launch the Google Pay payment sheet from within an Android Activity. This class must be + * instantiated before the Activity is created. + * + * @param activity the Android Activity from which you will launch the Google Pay payment sheet + * @param callback a {@link GooglePayLauncherCallback} to receive the result of the Google Pay + * payment flow + */ + public GooglePayLauncher(@NonNull ComponentActivity activity, @NonNull GooglePayLauncherCallback callback) { this(activity.getActivityResultRegistry(), activity, callback); } @@ -36,6 +52,15 @@ public GooglePayLauncher(@NonNull FragmentActivity activity, new GooglePayActivityResultContract(), callback::onResult); } + /** + * Launches the Google Pay payment sheet. This method cannot be called until the lifecycle of + * the Fragment or Activity used to instantiate your {@link GooglePayLauncher} has reached the + * CREATED state. + * + * @param googlePayPaymentAuthRequestParams the {@link GooglePayPaymentAuthRequestParams} + * received from invoking + * {@link GooglePayClient#createPaymentAuthRequest(GooglePayRequest, GooglePayPaymentAuthRequestCallback)} + */ public void launch(GooglePayPaymentAuthRequestParams googlePayPaymentAuthRequestParams) { activityLauncher.launch(googlePayPaymentAuthRequestParams); }