From 74dbc471e44ac42f80ebbe0acc49134d91a72c72 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Mon, 7 Aug 2023 11:15:10 -0500 Subject: [PATCH 1/7] add cardLogosDisabled property to DropInRequest --- .../braintreepayments/api/DropInRequest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Drop-In/src/main/java/com/braintreepayments/api/DropInRequest.java b/Drop-In/src/main/java/com/braintreepayments/api/DropInRequest.java index 2f65a7da..9cf45cdf 100644 --- a/Drop-In/src/main/java/com/braintreepayments/api/DropInRequest.java +++ b/Drop-In/src/main/java/com/braintreepayments/api/DropInRequest.java @@ -24,6 +24,7 @@ public class DropInRequest implements Parcelable { private boolean payPalDisabled = false; private boolean venmoDisabled = false; private boolean cardDisabled = false; + private boolean cardLogosDisabled = false; private boolean vaultCardDefaultValue = true; private boolean allowVaultCardOverride = false; @@ -98,6 +99,15 @@ public void setCardDisabled(boolean disableCard) { cardDisabled = disableCard; } + /** + * This method is optional. + * + * @param disableCardLogos If set to true, hides all card logos in Drop-in. Default value is false. + */ + public void setCardLogosDisabled(boolean disableCardLogos) { + cardLogosDisabled = disableCardLogos; + } + /** * This method is optional. * @@ -210,6 +220,13 @@ public boolean isCardDisabled() { return cardDisabled; } + /** + * @return If card logos are disabled in Drop-in + */ + public boolean areCardLogosDisabled() { + return cardLogosDisabled; + } + /** * @return The Google Pay Request {@link GooglePayRequest} for the transaction. */ @@ -287,6 +304,7 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeByte(payPalDisabled ? (byte) 1 : (byte) 0); dest.writeByte(venmoDisabled ? (byte) 1 : (byte) 0); dest.writeByte(cardDisabled ? (byte) 1 : (byte) 0); + dest.writeByte(cardLogosDisabled ? (byte) 1 : (byte) 0); dest.writeParcelable(threeDSecureRequest, 0); dest.writeByte(maskCardNumber ? (byte) 1 : (byte) 0); dest.writeByte(maskSecurityCode ? (byte) 1 : (byte) 0); @@ -304,6 +322,7 @@ protected DropInRequest(Parcel in) { payPalDisabled = in.readByte() != 0; venmoDisabled = in.readByte() != 0; cardDisabled = in.readByte() != 0; + cardLogosDisabled = in.readByte() != 0; threeDSecureRequest = in.readParcelable(ThreeDSecureRequest.class.getClassLoader()); maskCardNumber = in.readByte() != 0; maskSecurityCode = in.readByte() != 0; From 3f41de1e5c63b627db0097572fa5b86aa1daaaa9 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Mon, 7 Aug 2023 13:36:22 -0500 Subject: [PATCH 2/7] add logic to set visibility of card logos --- .../java/com/braintreepayments/api/AddCardFragment.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Drop-In/src/main/java/com/braintreepayments/api/AddCardFragment.java b/Drop-In/src/main/java/com/braintreepayments/api/AddCardFragment.java index 1381b2dd..7c5a5867 100644 --- a/Drop-In/src/main/java/com/braintreepayments/api/AddCardFragment.java +++ b/Drop-In/src/main/java/com/braintreepayments/api/AddCardFragment.java @@ -29,6 +29,8 @@ public class AddCardFragment extends DropInFragment implements OnCardFormSubmitL private AccessibleSupportedCardTypesView supportedCardTypesView; private AnimatedButtonView animatedButtonView; + private static Boolean cardLogosDisabled; + @VisibleForTesting DropInViewModel dropInViewModel; @@ -41,6 +43,8 @@ static AddCardFragment from(DropInRequest dropInRequest, @Nullable String cardNu args.putString("EXTRA_CARD_NUMBER", cardNumber); } + cardLogosDisabled = dropInRequest.areCardLogosDisabled(); + AddCardFragment instance = new AddCardFragment(); instance.setArguments(args); return instance; @@ -52,6 +56,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa cardForm = view.findViewById(R.id.bt_card_form); supportedCardTypesView = view.findViewById(R.id.bt_supported_card_types); + + if (cardLogosDisabled) { + supportedCardTypesView.setVisibility(View.GONE); + } + animatedButtonView = view.findViewById(R.id.bt_animated_button_view); TextView textView = view.findViewById(R.id.bt_privacy_policy); From 3d6e4a5e433006f9a4e79a1bf96f80a4a86f1f0b Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Mon, 7 Aug 2023 13:41:41 -0500 Subject: [PATCH 3/7] add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8df626c0..50fc260e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## unreleased * Add California Privacy Laws notice of collection to credit card form +* Add `DropInRequest.setCardLogosDisabled()` to hide card logos on the credit card form if desired ## 6.10.0 From 93d402f65dc810560a216563871f2488c1cf9558 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Mon, 7 Aug 2023 14:46:37 -0500 Subject: [PATCH 4/7] PR feedback - update to use bundle arguments to determine if card logos are disabled --- .../java/com/braintreepayments/api/AddCardFragment.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Drop-In/src/main/java/com/braintreepayments/api/AddCardFragment.java b/Drop-In/src/main/java/com/braintreepayments/api/AddCardFragment.java index 7c5a5867..c5980d3c 100644 --- a/Drop-In/src/main/java/com/braintreepayments/api/AddCardFragment.java +++ b/Drop-In/src/main/java/com/braintreepayments/api/AddCardFragment.java @@ -29,8 +29,6 @@ public class AddCardFragment extends DropInFragment implements OnCardFormSubmitL private AccessibleSupportedCardTypesView supportedCardTypesView; private AnimatedButtonView animatedButtonView; - private static Boolean cardLogosDisabled; - @VisibleForTesting DropInViewModel dropInViewModel; @@ -43,8 +41,6 @@ static AddCardFragment from(DropInRequest dropInRequest, @Nullable String cardNu args.putString("EXTRA_CARD_NUMBER", cardNumber); } - cardLogosDisabled = dropInRequest.areCardLogosDisabled(); - AddCardFragment instance = new AddCardFragment(); instance.setArguments(args); return instance; @@ -57,7 +53,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa cardForm = view.findViewById(R.id.bt_card_form); supportedCardTypesView = view.findViewById(R.id.bt_supported_card_types); - if (cardLogosDisabled) { + Bundle args = getArguments(); + DropInRequest dropInRequest = (DropInRequest) args.getParcelable("EXTRA_DROP_IN_REQUEST"); + + if (dropInRequest.areCardLogosDisabled()) { supportedCardTypesView.setVisibility(View.GONE); } From 3bcc715d98514bd59f9d949c5134b69c4b9a07dd Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Wed, 9 Aug 2023 09:44:59 -0500 Subject: [PATCH 5/7] PR feedback: add UI and Unit test --- .../api/AddCardFragmentUITest.kt | 21 +++++++++++++++++++ .../api/AddCardFragment.java | 4 +++- .../api/DropInRequestUnitTest.java | 2 ++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Drop-In/src/androidTest/java/com/braintreepayments/api/AddCardFragmentUITest.kt b/Drop-In/src/androidTest/java/com/braintreepayments/api/AddCardFragmentUITest.kt index 4ca2f538..5910b77e 100644 --- a/Drop-In/src/androidTest/java/com/braintreepayments/api/AddCardFragmentUITest.kt +++ b/Drop-In/src/androidTest/java/com/braintreepayments/api/AddCardFragmentUITest.kt @@ -1,5 +1,7 @@ package com.braintreepayments.api +import android.os.Bundle +import android.view.View import androidx.fragment.app.testing.FragmentScenario import androidx.lifecycle.Lifecycle import androidx.test.espresso.Espresso.onView @@ -188,4 +190,23 @@ class AddCardFragmentUITest { onView(withId(R.id.bt_button)).check(matches(isDisplayed())) } + + @Test + fun whenStateIsRESUMED_andCardholderNameDisabled_expirationDateFieldIsFocused() { + val dropInRequest = DropInRequest() + dropInRequest.setCardLogosDisabled(true); + + val args = Bundle() + args.putParcelable("EXTRA_DROP_IN_REQUEST", dropInRequest) + args.putString("EXTRA_CARD_NUMBER", VISA) + + val scenario = FragmentScenario.launchInContainer(AddCardFragment::class.java, args, R.style.bt_drop_in_activity_theme) + scenario.moveToState(Lifecycle.State.RESUMED) + + onView(isRoot()).perform(waitFor(500)) + + scenario.onFragment { fragment -> + assertEquals(View.GONE, fragment.supportedCardTypesView.visibility); + } + } } diff --git a/Drop-In/src/main/java/com/braintreepayments/api/AddCardFragment.java b/Drop-In/src/main/java/com/braintreepayments/api/AddCardFragment.java index c5980d3c..ff8db6ee 100644 --- a/Drop-In/src/main/java/com/braintreepayments/api/AddCardFragment.java +++ b/Drop-In/src/main/java/com/braintreepayments/api/AddCardFragment.java @@ -26,7 +26,9 @@ public class AddCardFragment extends DropInFragment implements OnCardFormSubmitL @VisibleForTesting CardForm cardForm; - private AccessibleSupportedCardTypesView supportedCardTypesView; + @VisibleForTesting + AccessibleSupportedCardTypesView supportedCardTypesView; + private AnimatedButtonView animatedButtonView; @VisibleForTesting diff --git a/Drop-In/src/test/java/com/braintreepayments/api/DropInRequestUnitTest.java b/Drop-In/src/test/java/com/braintreepayments/api/DropInRequestUnitTest.java index 7e2ff5b6..3d31baf5 100644 --- a/Drop-In/src/test/java/com/braintreepayments/api/DropInRequestUnitTest.java +++ b/Drop-In/src/test/java/com/braintreepayments/api/DropInRequestUnitTest.java @@ -73,6 +73,7 @@ public void includesAllOptions() { dropInRequest.setAllowVaultCardOverride(true); dropInRequest.setVaultCardDefaultValue(true); dropInRequest.setCardholderNameStatus(CardForm.FIELD_OPTIONAL); + dropInRequest.setCardLogosDisabled(true); assertNotNull(dropInRequest.getGooglePayRequest()); assertEquals("10", dropInRequest.getGooglePayRequest().getTransactionInfo().getTotalPrice()); @@ -94,6 +95,7 @@ public void includesAllOptions() { assertTrue(dropInRequest.isPayPalDisabled()); assertTrue(dropInRequest.isVenmoDisabled()); assertTrue(dropInRequest.isCardDisabled()); + assertTrue(dropInRequest.areCardLogosDisabled()); assertNotNull(dropInRequest.getThreeDSecureRequest()); assertEquals("abc-123", dropInRequest.getThreeDSecureRequest().getNonce()); assertEquals("2", dropInRequest.getThreeDSecureRequest().getVersionRequested()); From 62f6dadabb594c930f2952353da98948bf6c6b29 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Wed, 9 Aug 2023 10:58:02 -0500 Subject: [PATCH 6/7] Update Drop-In/src/androidTest/java/com/braintreepayments/api/AddCardFragmentUITest.kt Co-authored-by: sshropshire <58225613+sshropshire@users.noreply.github.com> --- .../java/com/braintreepayments/api/AddCardFragmentUITest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Drop-In/src/androidTest/java/com/braintreepayments/api/AddCardFragmentUITest.kt b/Drop-In/src/androidTest/java/com/braintreepayments/api/AddCardFragmentUITest.kt index 5910b77e..3186574b 100644 --- a/Drop-In/src/androidTest/java/com/braintreepayments/api/AddCardFragmentUITest.kt +++ b/Drop-In/src/androidTest/java/com/braintreepayments/api/AddCardFragmentUITest.kt @@ -192,7 +192,7 @@ class AddCardFragmentUITest { } @Test - fun whenStateIsRESUMED_andCardholderNameDisabled_expirationDateFieldIsFocused() { + fun whenStateIsRESUMED_andCardLogosDisabled_supportedCardTypesViewisGONE() { val dropInRequest = DropInRequest() dropInRequest.setCardLogosDisabled(true); From e1a36296713881bf65318f6a26f930ea617e20c3 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Wed, 9 Aug 2023 11:15:17 -0500 Subject: [PATCH 7/7] add whenStateIsRESUMED_andCardLogosEnabled_supportedCardTypesViewIsVISIBLE UITest --- .../api/AddCardFragmentUITest.kt | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Drop-In/src/androidTest/java/com/braintreepayments/api/AddCardFragmentUITest.kt b/Drop-In/src/androidTest/java/com/braintreepayments/api/AddCardFragmentUITest.kt index 3186574b..13f8fdf8 100644 --- a/Drop-In/src/androidTest/java/com/braintreepayments/api/AddCardFragmentUITest.kt +++ b/Drop-In/src/androidTest/java/com/braintreepayments/api/AddCardFragmentUITest.kt @@ -192,7 +192,7 @@ class AddCardFragmentUITest { } @Test - fun whenStateIsRESUMED_andCardLogosDisabled_supportedCardTypesViewisGONE() { + fun whenStateIsRESUMED_andCardLogosDisabled_supportedCardTypesViewIsGONE() { val dropInRequest = DropInRequest() dropInRequest.setCardLogosDisabled(true); @@ -209,4 +209,22 @@ class AddCardFragmentUITest { assertEquals(View.GONE, fragment.supportedCardTypesView.visibility); } } + + @Test + fun whenStateIsRESUMED_andCardLogosEnabled_supportedCardTypesViewIsVISIBLE() { + val dropInRequest = DropInRequest() + + val args = Bundle() + args.putParcelable("EXTRA_DROP_IN_REQUEST", dropInRequest) + args.putString("EXTRA_CARD_NUMBER", VISA) + + val scenario = FragmentScenario.launchInContainer(AddCardFragment::class.java, args, R.style.bt_drop_in_activity_theme) + scenario.moveToState(Lifecycle.State.RESUMED) + + onView(isRoot()).perform(waitFor(500)) + + scenario.onFragment { fragment -> + assertEquals(View.VISIBLE, fragment.supportedCardTypesView.visibility); + } + } }