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

Property to Hide Card Logos #426

Merged
merged 7 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -188,4 +190,41 @@ class AddCardFragmentUITest {

onView(withId(R.id.bt_button)).check(matches(isDisplayed()))
}

@Test
fun whenStateIsRESUMED_andCardLogosDisabled_supportedCardTypesViewIsGONE() {
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);
}
}

@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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public class AddCardFragment extends DropInFragment implements OnCardFormSubmitL
@VisibleForTesting
CardForm cardForm;

private AccessibleSupportedCardTypesView supportedCardTypesView;
@VisibleForTesting
AccessibleSupportedCardTypesView supportedCardTypesView;

private AnimatedButtonView animatedButtonView;

@VisibleForTesting
Expand All @@ -52,6 +54,14 @@ 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);

Bundle args = getArguments();
DropInRequest dropInRequest = (DropInRequest) args.getParcelable("EXTRA_DROP_IN_REQUEST");

if (dropInRequest.areCardLogosDisabled()) {
supportedCardTypesView.setVisibility(View.GONE);
}

animatedButtonView = view.findViewById(R.id.bt_animated_button_view);

TextView textView = view.findViewById(R.id.bt_privacy_policy);
Expand Down
19 changes: 19 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 @@ -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;

Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down
Loading