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

[v7 Beta] Create DropInLauncher #468

Open
wants to merge 20 commits into
base: v7_beta
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7118268
Rename DropInIntentData to DropInLaunchIntent.
sshropshire Mar 27, 2024
257d30e
Remove deprecated DropInClient methods.
sshropshire Mar 27, 2024
e6a98ac
Rename DropInLifecycleObserver to DropInLauncher.
sshropshire Mar 27, 2024
7a70517
Extract DropInLauncher success and error handling logic from DropInCl…
sshropshire Mar 27, 2024
7ca4634
Remove invalidateClientToken() method.
sshropshire Mar 27, 2024
7ad19eb
Remove DropInClient#getAuthorization() internal call.
sshropshire Mar 27, 2024
3247387
Fix DropInLauncherUnitTest.
sshropshire Mar 27, 2024
7978016
Migrate DropInClient to using context.
sshropshire Mar 27, 2024
4ae9532
Migrate fetch method to a RecentPaymentMethodsClient.
sshropshire Mar 27, 2024
4f85b19
Remove DropInClient and fix broken imports.
sshropshire Mar 27, 2024
9d00464
Fix unit tests.
sshropshire Mar 27, 2024
6457aa5
Remove DropInClientParams class.
sshropshire Mar 27, 2024
6810ac7
Add class and constructor documentation to RecentPaymentMethodsClient.
sshropshire Mar 27, 2024
1a842ce
Provide documentation for DropInLauncherCallback.
sshropshire Mar 27, 2024
8220458
Rename DropInLaunchIntent to DropInLaunchInput and make it package pr…
sshropshire Mar 27, 2024
e0658c3
Add place authorization string in DropInRequest.
sshropshire Apr 3, 2024
7bdd2ac
Revert "Add place authorization string in DropInRequest."
sshropshire Apr 3, 2024
618d3f8
Add TODO.
sshropshire Apr 3, 2024
821b249
Update CHANGELOG.
sshropshire Apr 3, 2024
1977a95
Rename launchDropIn to start on DropInLauncher.
sshropshire Apr 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add place authorization string in DropInRequest.
sshropshire committed Apr 3, 2024
commit e0658c346193a2432422e61d78628807e799fd94
Original file line number Diff line number Diff line change
@@ -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);
@@ -187,7 +187,7 @@ public void launchDropIn(View v) {
dropInRequest.setThreeDSecureRequest(demoThreeDSecureRequest());
}

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

private ThreeDSecureRequest demoThreeDSecureRequest() {
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;
@@ -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();
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;
@@ -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
Original file line number Diff line number Diff line change
@@ -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);

@@ -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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
@@ -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;
@@ -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.
@@ -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.
*/
@@ -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) {
@@ -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>() {
Original file line number Diff line number Diff line change
@@ -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());
}

@@ -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());
}

Original file line number Diff line number Diff line change
@@ -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)) }