Skip to content

Commit

Permalink
Add place authorization string in DropInRequest.
Browse files Browse the repository at this point in the history
  • Loading branch information
sshropshire committed Apr 3, 2024
1 parent 8220458 commit e0658c3
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void onFailure(@NonNull Exception e) {
}

public void launchDropIn(View v) {
DropInRequest dropInRequest = new DropInRequest();
DropInRequest dropInRequest = new DropInRequest(authString);
dropInRequest.setGooglePayRequest(getGooglePayRequest());
dropInRequest.setVenmoRequest(new VenmoRequest(VenmoPaymentMethodUsage.SINGLE_USE));
dropInRequest.setMaskCardNumber(true);
Expand All @@ -187,7 +187,7 @@ public void launchDropIn(View v) {
dropInRequest.setThreeDSecureRequest(demoThreeDSecureRequest());
}

dropInLauncher.launchDropIn(authString, dropInRequest);
dropInLauncher.launchDropIn(dropInRequest);
}

private ThreeDSecureRequest demoThreeDSecureRequest() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.braintreepayments.api;

import static com.braintreepayments.api.DropInLauncher.EXTRA_AUTHORIZATION;
import static com.braintreepayments.api.DropInLauncher.EXTRA_AUTHORIZATION_ERROR;
import static com.braintreepayments.api.DropInLauncher.EXTRA_CHECKOUT_REQUEST;
import static com.braintreepayments.api.DropInLauncher.EXTRA_CHECKOUT_REQUEST_BUNDLE;
Expand Down Expand Up @@ -78,9 +77,8 @@ protected void onCreate(Bundle savedInstanceState) {
}

if (dropInInternalClient == null) {
String authorization = intent.getStringExtra(EXTRA_AUTHORIZATION);
DropInRequest dropInRequest = getDropInRequest(intent);
dropInInternalClient = new DropInInternalClient(this, authorization, dropInRequest);
dropInInternalClient = new DropInInternalClient(this, dropInRequest);
}

alertPresenter = new AlertPresenter();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.braintreepayments.api;

import static com.braintreepayments.api.DropInLauncher.EXTRA_AUTHORIZATION;
import static com.braintreepayments.api.DropInLauncher.EXTRA_CHECKOUT_REQUEST;
import static com.braintreepayments.api.DropInLauncher.EXTRA_CHECKOUT_REQUEST_BUNDLE;
import static com.braintreepayments.api.DropInResult.EXTRA_ERROR;
Expand All @@ -14,16 +13,15 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

class DropInActivityResultContract extends ActivityResultContract<DropInLaunchInput, DropInResult> {
class DropInActivityResultContract extends ActivityResultContract<DropInRequest, DropInResult> {

@NonNull
@Override
public Intent createIntent(@NonNull Context context, DropInLaunchInput input) {
public Intent createIntent(@NonNull Context context, DropInRequest dropInRequest) {
Bundle dropInRequestBundle = new Bundle();
dropInRequestBundle.putParcelable(EXTRA_CHECKOUT_REQUEST, input.getDropInRequest());
dropInRequestBundle.putParcelable(EXTRA_CHECKOUT_REQUEST, dropInRequest);
return new Intent(context, DropInActivity.class)
.putExtra(EXTRA_CHECKOUT_REQUEST_BUNDLE, dropInRequestBundle)
.putExtra(EXTRA_AUTHORIZATION, input.getAuthorization().toString());
.putExtra(EXTRA_CHECKOUT_REQUEST_BUNDLE, dropInRequestBundle);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ class DropInInternalClient {

private final PaymentMethodInspector paymentMethodInspector = new PaymentMethodInspector();

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

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

Expand All @@ -59,8 +60,8 @@ private static DropInInternalClientParams createDefaultParams(Context context, S
.dropInSharedPreferences(DropInSharedPreferences.getInstance(context.getApplicationContext()));
}

DropInInternalClient(FragmentActivity activity, String authorization, DropInRequest dropInRequest) {
this(createDefaultParams(activity, authorization, dropInRequest));
DropInInternalClient(FragmentActivity activity, DropInRequest dropInRequest) {
this(createDefaultParams(activity, dropInRequest));
}

@VisibleForTesting
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,19 @@ public class DropInLauncher implements DefaultLifecycleObserver {

static final String EXTRA_CHECKOUT_REQUEST = "com.braintreepayments.api.EXTRA_CHECKOUT_REQUEST";
static final String EXTRA_CHECKOUT_REQUEST_BUNDLE = "com.braintreepayments.api.EXTRA_CHECKOUT_REQUEST_BUNDLE";
static final String EXTRA_AUTHORIZATION = "com.braintreepayments.api.EXTRA_AUTHORIZATION";
static final String EXTRA_AUTHORIZATION_ERROR = "com.braintreepayments.api.EXTRA_AUTHORIZATION_ERROR";


@VisibleForTesting
private ActivityResultLauncher<DropInLaunchInput> activityLauncher;
private ActivityResultLauncher<DropInRequest> activityLauncher;

public DropInLauncher(ComponentActivity activity, DropInLauncherCallback callback) {
ActivityResultRegistry registry = activity.getActivityResultRegistry();
activityLauncher = registry.register(
DROP_IN_RESULT, activity, new DropInActivityResultContract(), callback);
}

public void launchDropIn(String authString, DropInRequest dropInRequest) {
Authorization authorization = Authorization.fromString(authString);
DropInLaunchInput launchIntent =
new DropInLaunchInput(dropInRequest, authorization);
activityLauncher.launch(launchIntent);
public void launchDropIn(DropInRequest dropInRequest) {
activityLauncher.launch(dropInRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.braintreepayments.cardform.view.CardForm;
Expand Down Expand Up @@ -30,9 +31,13 @@ public class DropInRequest implements Parcelable {

private String customUrlScheme = null;

private String authorization;

private int cardholderNameStatus = CardForm.FIELD_DISABLED;

public DropInRequest() {}
public DropInRequest(@NonNull String authorization) {
this.authorization = authorization;
}

/**
* This method is optional.
Expand Down Expand Up @@ -303,6 +308,11 @@ public void setCustomUrlScheme(@Nullable String customUrlScheme) {
this.customUrlScheme = customUrlScheme;
}

@NonNull
public String getAuthorization() {
return authorization;
}

/**
* @return If set, the custom return url scheme used for browser-based flows.
*/
Expand Down Expand Up @@ -334,6 +344,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeByte(vaultCardDefaultValue ? (byte) 1 : (byte) 0);
dest.writeByte(allowVaultCardOverride ? (byte) 1 : (byte) 0);
dest.writeString(customUrlScheme);
dest.writeString(authorization);
}

protected DropInRequest(Parcel in) {
Expand All @@ -353,6 +364,7 @@ protected DropInRequest(Parcel in) {
vaultCardDefaultValue = in.readByte() != 0;
allowVaultCardOverride = in.readByte() != 0;
customUrlScheme = in.readString();
authorization = 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 @@ -63,14 +63,14 @@ public void beforeEach() {
@Test
public void constructor_setsIntegrationTypeDropIn() {
DropInInternalClient sut =
new DropInInternalClient(activity, Fixtures.TOKENIZATION_KEY, new DropInRequest());
new DropInInternalClient(activity, new DropInRequest());
assertEquals(IntegrationType.DROP_IN, sut.braintreeClient.getIntegrationType());
}

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

Expand All @@ -79,7 +79,7 @@ public void internalConstructor_overridesBraintreeCustomUrlSchemeIfSet() {
DropInRequest request = new DropInRequest();
request.setCustomUrlScheme("sample-custom-url-scheme");
DropInInternalClient sut =
new DropInInternalClient(activity, Fixtures.TOKENIZATION_KEY, request);
new DropInInternalClient(activity, request);
assertEquals("sample-custom-url-scheme", sut.braintreeClient.getReturnUrlScheme());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class DropInLauncherUnitTest : TestCase() {
val sut = DropInLauncher(activity, callback)

val dropInRequest = DropInRequest()
sut.launchDropIn(Fixtures.BASE64_CLIENT_TOKEN, dropInRequest)
sut.launchDropIn(dropInRequest)

val slot = slot<DropInLaunchInput>()
verify { activityLauncher.launch(capture(slot)) }
Expand Down

0 comments on commit e0658c3

Please sign in to comment.