Skip to content

Commit

Permalink
Add customUrlScheme Property to DropInRequest (#439)
Browse files Browse the repository at this point in the history
* Add customUrlScheme property to DropInRequest.

* Add example for spike. Revert this PR before merging.

* Reference updated version of Braintree Core.

* Revert AndroidManifest.xml.

* Add custom return url scheme docs to DropInRequest.

* Revert MainActivity.

* Add unit tests for custom url scheme.

* Update CHANGELOG.

* Update Drop-In/src/main/java/com/braintreepayments/api/DropInRequest.java

Co-authored-by: Sarah Koop <[email protected]>

* Update CHANGELOG.md

Co-authored-by: Jax DesMarais-Leder <[email protected]>

---------

Co-authored-by: Sarah Koop <[email protected]>
Co-authored-by: Jax DesMarais-Leder <[email protected]>
  • Loading branch information
3 people authored Sep 19, 2023
1 parent 3816b5b commit 611d842
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

## unreleased

* Bump braintree_android module dependency versions to `4.38.1`
* Bump braintree_android module dependency versions to `4.38.2`
* Android 14 Support
* Upgrade `compileSdkVersion` and `targetSdkVersion` to API 34
* Add `customUrlScheme` property to `DropInRequest` to allow for custom URL schemes to be set for browser-based flow deep links

## 6.12.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ public class DropInClient {

private static DropInClientParams createDefaultParams(Context context, String authorization, ClientTokenProvider clientTokenProvider, DropInRequest dropInRequest, FragmentActivity activity, Lifecycle lifecycle) {

BraintreeClient braintreeClient;
if (clientTokenProvider != null) {
braintreeClient = new BraintreeClient(context, clientTokenProvider, null, IntegrationType.DROP_IN);
} else {
braintreeClient = new BraintreeClient(context, authorization, null, IntegrationType.DROP_IN);
String customUrlScheme = null;
if (dropInRequest != null) {
customUrlScheme = dropInRequest.getCustomUrlScheme();
}

BraintreeOptions braintreeOptions =
new BraintreeOptions(context, null, customUrlScheme, authorization, clientTokenProvider, IntegrationType.DROP_IN);

BraintreeClient braintreeClient = new BraintreeClient(braintreeOptions);
return new DropInClientParams()
.activity(activity)
.lifecycle(lifecycle)
Expand Down Expand Up @@ -359,7 +361,7 @@ void onDropInResult(DropInResult dropInResult) {
/**
* For clients using a {@link ClientTokenProvider}, call this method to invalidate the existing,
* cached client token. A new client token will be fetched by the SDK when it is needed.
*
* <p>
* For clients not using a {@link ClientTokenProvider}, this method does nothing.
*/
public void invalidateClientToken() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ class DropInInternalClient {

private static DropInInternalClientParams createDefaultParams(Context context, String authorization, DropInRequest dropInRequest, String sessionId) {

BraintreeClient braintreeClient =
new BraintreeClient(context, authorization, sessionId, IntegrationType.DROP_IN);
String customUrlScheme = dropInRequest.getCustomUrlScheme();
BraintreeOptions braintreeOptions =
new BraintreeOptions(context, sessionId, customUrlScheme, authorization, null, IntegrationType.DROP_IN);

BraintreeClient braintreeClient = new BraintreeClient(braintreeOptions);

return new DropInInternalClientParams()
.dropInRequest(dropInRequest)
Expand Down
23 changes: 23 additions & 0 deletions Drop-In/src/main/java/com/braintreepayments/api/DropInRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class DropInRequest implements Parcelable {
private boolean vaultCardDefaultValue = true;
private boolean allowVaultCardOverride = false;

private String customUrlScheme = null;

private int cardholderNameStatus = CardForm.FIELD_DISABLED;

public DropInRequest() {}
Expand Down Expand Up @@ -290,6 +292,25 @@ public boolean getAllowVaultCardOverride() {
return allowVaultCardOverride;
}

/**
* Use this property to customize the return url scheme used to construct deep link return urls
* for browser-based flows. You must also override the intent-filter entry for
* {@link DropInActivity} in your app's AndroidManifest.xml.
*
* @param customUrlScheme A custom return url scheme to use for browser-based flows.
*/
public void setCustomUrlScheme(@Nullable String customUrlScheme) {
this.customUrlScheme = customUrlScheme;
}

/**
* @return If set, the custom return url scheme used for browser-based flows.
*/
@Nullable
public String getCustomUrlScheme() {
return customUrlScheme;
}

@Override
public int describeContents() {
return 0;
Expand All @@ -312,6 +333,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(cardholderNameStatus);
dest.writeByte(vaultCardDefaultValue ? (byte) 1 : (byte) 0);
dest.writeByte(allowVaultCardOverride ? (byte) 1 : (byte) 0);
dest.writeString(customUrlScheme);
}

protected DropInRequest(Parcel in) {
Expand All @@ -330,6 +352,7 @@ protected DropInRequest(Parcel in) {
cardholderNameStatus = in.readInt();
vaultCardDefaultValue = in.readByte() != 0;
allowVaultCardOverride = in.readByte() != 0;
customUrlScheme = in.readString();
}

public static final Creator<DropInRequest> CREATOR = new Creator<DropInRequest>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ public void internalConstructor_setsBraintreeClientWithSessionId() {
assertEquals("session-id", sut.braintreeClient.getSessionId());
}

@Test
public void internalConstructor_usesDefaultBraintreeCustomUrlScheme() {
DropInInternalClient sut =
new DropInInternalClient(activity, Fixtures.TOKENIZATION_KEY, "session-id", new DropInRequest());
assertEquals("com.braintreepayments.api.dropin.test.braintree", sut.braintreeClient.getReturnUrlScheme());
}

@Test
public void internalConstructor_overridesBraintreeCustomUrlSchemeIfSet() {
DropInRequest request = new DropInRequest();
request.setCustomUrlScheme("sample-custom-url-scheme");
DropInInternalClient sut =
new DropInInternalClient(activity, Fixtures.TOKENIZATION_KEY, "session-id", request);
assertEquals("sample-custom-url-scheme", sut.braintreeClient.getReturnUrlScheme());
}

@Test
public void getConfiguration_forwardsInvocationToBraintreeClient() {
BraintreeClient braintreeClient = new MockBraintreeClientBuilder().build();
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
}
}

ext.brainTreeVersion = "4.38.1"
ext.brainTreeVersion = "4.38.2"

ext.deps = [
"braintreeCore" : "com.braintreepayments.api:braintree-core:$brainTreeVersion",
Expand Down

0 comments on commit 611d842

Please sign in to comment.