-
Notifications
You must be signed in to change notification settings - Fork 241
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
Instantiate BraintreeClient Within Clients #830
Changes from 8 commits
d8ed6a6
39f6559
f3409c0
e335e03
9bb9dfe
72c6f29
3254786
edc0aee
17367a7
10660d2
20479e8
0970691
78c3c94
d5670aa
d997cec
e6e5a34
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.braintreepayments.api | ||
|
||
import android.content.Context | ||
|
||
data class ClientParams(val context: Context, | ||
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. IMO it would be more clear to require the 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. Yeah 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. On second thought, the parameter object pattern here can be useful. We created too many convenience initializers in 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. Agreed that just plain auth and context as direct constructor parameters is definitely the cleanest - but yeah in v4 we ended up with too many overloads I wanted to avoid that with ClientParams. Return URL isn't a required param for any clients, it's optional for some. But hopefully we won't add a bunch of params to client constructors in this version, so maybe we are safe to just go with auth and context as the main constructor and one overload for the clients that can accept return URL. What do you all think? 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. Yeah there's definitely a middle ground. Thinking on it more, our request objects can also be considered parameter objects. It may make sense to move properties like 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. Good idea I think that's a good compromise here - I'll go with that |
||
val authorization: String, | ||
val returnUrlScheme: String?) { | ||
|
||
constructor(context: Context, authorization: String) : this(context, authorization, null) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.braintreepayments.demo; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.braintreepayments.api.Authorization; | ||
import com.braintreepayments.api.BraintreeClient; | ||
|
||
public interface BraintreeAuthorizationCallback { | ||
void onResult(@NonNull String authString); | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import android.view.Window; | ||
import android.widget.ArrayAdapter; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.appcompat.app.ActionBar; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
|
@@ -30,13 +31,16 @@ public class DemoActivity extends AppCompatActivity implements ActivityCompat.On | |
private BraintreeClient braintreeClient; | ||
private AppBarConfiguration appBarConfiguration; | ||
|
||
private DemoClientTokenProvider clientTokenProvider; | ||
|
||
private SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); | ||
setContentView(R.layout.activity_demo); | ||
clientTokenProvider = new DemoClientTokenProvider(this); | ||
|
||
setupActionBar(); | ||
setProgressBarIndeterminateVisibility(true); | ||
|
@@ -46,16 +50,11 @@ protected void onCreate(Bundle savedInstanceState) { | |
|
||
public BraintreeClient getBraintreeClient() { | ||
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. We should be able to remove the 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. Good call - removed |
||
// lazily instantiate braintree client in case the demo has been reset | ||
if (braintreeClient == null) { | ||
if (Settings.useTokenizationKey(this)) { | ||
String tokenizationKey = Settings.getTokenizationKey(this); | ||
braintreeClient = new BraintreeClient(this, tokenizationKey); | ||
} else { | ||
braintreeClient = | ||
BraintreeClientFactory.createBraintreeClientWithAuthorizationProvider(this); | ||
} | ||
} | ||
return braintreeClient; | ||
return null; | ||
} | ||
|
||
public void fetchAuthorization(BraintreeAuthorizationCallback callback) { | ||
clientTokenProvider.getClientToken(callback); | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
import androidx.navigation.fragment.NavHostFragment; | ||
|
||
import com.braintreepayments.api.BraintreeClient; | ||
import com.braintreepayments.api.ClientParams; | ||
import com.braintreepayments.api.GooglePayCapabilities; | ||
import com.braintreepayments.api.GooglePayClient; | ||
import com.braintreepayments.api.GooglePayLauncher; | ||
|
@@ -22,10 +23,11 @@ | |
import com.google.android.gms.wallet.TransactionInfo; | ||
import com.google.android.gms.wallet.WalletConstants; | ||
|
||
import java.util.Objects; | ||
|
||
public class GooglePayFragment extends BaseFragment { | ||
|
||
private ImageButton googlePayButton; | ||
private BraintreeClient braintreeClient; | ||
private GooglePayClient googlePayClient; | ||
private GooglePayLauncher googlePayLauncher; | ||
|
||
|
@@ -38,8 +40,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, | |
googlePayButton = view.findViewById(R.id.google_pay_button); | ||
googlePayButton.setOnClickListener(this::launchGooglePay); | ||
|
||
braintreeClient = getBraintreeClient(); | ||
googlePayClient = new GooglePayClient(braintreeClient); | ||
googlePayClient = new GooglePayClient(new ClientParams(requireContext(), super.getAuthStringArg())); | ||
googlePayLauncher = new GooglePayLauncher(this, | ||
paymentAuthResult -> googlePayClient.tokenize(paymentAuthResult, | ||
(paymentMethodNonce, error) -> { | ||
|
@@ -57,27 +58,13 @@ public View onCreateView(@NonNull LayoutInflater inflater, | |
public void onResume() { | ||
super.onResume(); | ||
|
||
braintreeClient.getConfiguration((configuration, error) -> { | ||
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. Curious - why were we doing config fetches in the demo app? 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. Yeah we probably could've deleted this a while back. This has roots in v3. I remember removing it from the Core SDK since it would require a runtime dependency on the Google Pay SDK, but we probably kept it in when we went to GA because we needed to get a release out quickly. |
||
if (configuration == null) { | ||
return; | ||
} | ||
|
||
if (GooglePayCapabilities.isGooglePayEnabled(requireActivity(), configuration)) { | ||
|
||
googlePayClient.isReadyToPay(requireActivity(), (isReadyToPay, e) -> { | ||
if (isReadyToPay) { | ||
googlePayButton.setVisibility(View.VISIBLE); | ||
} else { | ||
showDialog( | ||
"Google Payments are not available. The following issues could be the cause:\n\n" + | ||
"No user is logged in to the device.\n\n" + | ||
"Google Play Services is missing or out of date."); | ||
} | ||
}); | ||
googlePayClient.isReadyToPay(requireActivity(), (isReadyToPay, e) -> { | ||
if (isReadyToPay) { | ||
googlePayButton.setVisibility(View.VISIBLE); | ||
} else { | ||
showDialog( | ||
"Google Payments are not available. The following issues could be the cause:\n\n" + | ||
"Google Payments are not enabled for the current merchant.\n\n" + | ||
"No user is logged in to the device.\n\n" + | ||
"Google Play Services is missing or out of date."); | ||
} | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this change impact DropIn at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't - drop-in uses the
BraintreeClient
constructor withBraintreeOptions
param, and has the same "com.braintreepayments.api" group ID as the core libraries, so they all can share these "package-private"/library group methods.