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

Update GooglePayLauncher Constructor Params #876

Merged
merged 2 commits into from
Jan 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
Loading