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

Remove ClientTokenProvider #831

Merged
merged 25 commits into from
Dec 5, 2023
Merged

Remove ClientTokenProvider #831

merged 25 commits into from
Dec 5, 2023

Conversation

sarahkoop
Copy link
Contributor

@sarahkoop sarahkoop commented Nov 16, 2023

Summary of changes

  • Remove ClientTokenProvider and asynchronous loading of authorization in favor of having merchants instantiate clients with authorization directly (see Instantiate BraintreeClient Within Clients #830).
  • Remove overload BraintreeClient constructor and add authorization parameter
  • Remove internal AuthorizationLoader class
  • The effect of this change for merchants is that if they pass an invalid authentication string to their client constructors, it will be returned as a config error (error fetching configuration, rather than error fetching authorization).
  • Making BraintreeClient internal and removing public constructors also has the side effect of making getConfiguration private. As far as I can tell, getConfiguration is not publicly available in iOS, so I think this is an ok change.

Note: Update base to v5 after #830 is merged.

Checklist

  • Added a changelog entry

Authors

@sarahkoop sarahkoop marked this pull request as ready for review November 17, 2023 16:11
@sarahkoop sarahkoop requested a review from a team as a code owner November 17, 2023 16:11
});
} else {
braintreeClient.getConfiguration((configuration, e) -> {
if (configuration == null) {
callback.onResult(null, null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but this is like the only callback with two success parameters and no error parameter. We should be able to fix that for v5 since we can make breaking changes.

@@ -69,111 +74,26 @@ open class BraintreeClient @VisibleForTesting internal constructor(
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
constructor(clientParams: ClientParams) :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The effect of this change for merchants is that if they pass an invalid authentication string to their client constructors, it will be returned as a config error (error fetching configuration, rather than error fetching authorization).

On iOS, the BTAPIClient (closest to android's BraintreeClient) has a failable init which gets triggered if some of the SDKs manual checks on the clientToken after base64 decoding fail.

We could move up that logic in the Android sequence of events to more closely mirror iOS and return an error sooner if the auth is invalid (I think it lives here). Total take it or leave it comment - curious your thoughts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The concept of a failable init doesn't really exist in Kotlin or Java - there are some hacky ways to achieve that behavior but I don't think it would be an expected integration pattern for merchants. We could always throw an error in the init method, but that means merchants have to handle the error which I think is less ideal than calling back an error further in the flow. To make it more explicit, we could add a check to the four BraintreeClient methods that fail for auth (http calls and getConfiguration) if auth is InvalidAuthorization and callback an authorization error at the top of those methods so that the errors are more clear. Requires some code duplication but I think that's probably the best merchant experience - what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scannillo I decided to go ahead and callback an auth error in the four BraintreeClient methods that would error on config fetch for invalid auth. In v4 we had a helpful auth error message directing merchants to docs so I think that's a good message to keep.

@sarahkoop sarahkoop changed the base branch from instantiate_braintree_client to v5 November 30, 2023 18:26
@sarahkoop sarahkoop merged commit 5b1040a into v5 Dec 5, 2023
2 checks passed
@sarahkoop sarahkoop deleted the remove_ct_provider branch December 5, 2023 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants