Skip to content

Commit

Permalink
Update GooglePayLauncher Constructor Params (#876)
Browse files Browse the repository at this point in the history
* Update constructor and doc strings

* Fix wording
  • Loading branch information
sarahkoop authored Jan 5, 2024
1 parent 8ef9c38 commit b2b62d1
Showing 1 changed file with 28 additions and 3 deletions.
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

0 comments on commit b2b62d1

Please sign in to comment.