diff --git a/CHANGELOG.md b/CHANGELOG.md index 370fe72000..4750f7237b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,9 @@ * Update `ThreeDSecureRequest.isDataOnlyRequested()` to `ThreeDSecureRequest.getDataOnlyRequested()` * Update `ThreeDSecureRequest.isExemptionRequested()` to `ThreeDSecureRequest.getDataOnlyRequested()` * Update `ThreeDSecureRequest.isCardAddChallengeRequested()` to `ThreeDSecureRequest.getCardAddChallengeRequested()` + * ThreeDSecure + * Split `ThreeDSecureV2UiCustomization.setButtonCustomization()` to `setButtonCustomization()` and `setButtonType()` + * Change `ThreeDSecureV2ButtonType` to an enum ## 5.0.0-beta1 (2024-07-23) diff --git a/Demo/src/main/java/com/braintreepayments/demo/CardFragment.java b/Demo/src/main/java/com/braintreepayments/demo/CardFragment.java index a9dd8faf59..2d91a83f26 100644 --- a/Demo/src/main/java/com/braintreepayments/demo/CardFragment.java +++ b/Demo/src/main/java/com/braintreepayments/demo/CardFragment.java @@ -36,6 +36,7 @@ import com.braintreepayments.api.threedsecure.ThreeDSecureResult; import com.braintreepayments.api.threedsecure.ThreeDSecureUiType; import com.braintreepayments.api.threedsecure.ThreeDSecureV2ButtonCustomization; +import com.braintreepayments.api.threedsecure.ThreeDSecureV2ButtonType; import com.braintreepayments.api.threedsecure.ThreeDSecureV2LabelCustomization; import com.braintreepayments.api.threedsecure.ThreeDSecureV2TextBoxCustomization; import com.braintreepayments.api.threedsecure.ThreeDSecureV2ToolbarCustomization; @@ -200,7 +201,7 @@ public void onPurchase(View v) { card.setExpirationYear(cardForm.getExpirationYear()); card.setCvv(cardForm.getCvv()); // TODO: GQL currently only returns the bin if validate = false - card.setShouldValidate(false); + card.setShouldValidate(false); card.setPostalCode(cardForm.getPostalCode()); cardClient.tokenize(card, (cardResult) -> { @@ -325,8 +326,8 @@ private ThreeDSecureRequest threeDSecureRequest(PaymentMethodNonce paymentMethod v2UiCustomization.setLabelCustomization(labelCustomization); v2UiCustomization.setTextBoxCustomization(textBoxCustomization); v2UiCustomization.setToolbarCustomization(toolbarCustomization); - v2UiCustomization.setButtonCustomization(submitButtonCustomization, - ThreeDSecureV2UiCustomization.BUTTON_TYPE_VERIFY); + v2UiCustomization.setButtonCustomization(submitButtonCustomization); + v2UiCustomization.setButtonType(ThreeDSecureV2ButtonType.BUTTON_TYPE_VERIFY); ThreeDSecureRequest threeDSecureRequest = new ThreeDSecureRequest(); threeDSecureRequest.setAmount("10"); diff --git a/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2ButtonCustomization.java b/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2ButtonCustomization.java deleted file mode 100644 index 1cf24a48f9..0000000000 --- a/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2ButtonCustomization.java +++ /dev/null @@ -1,148 +0,0 @@ -package com.braintreepayments.api.threedsecure; - -import android.os.Parcel; -import android.os.Parcelable; - -import androidx.annotation.Nullable; - -import com.cardinalcommerce.shared.userinterfaces.ButtonCustomization; - -/** - * Button customization options for 3D Secure 2 flows. - */ -public class ThreeDSecureV2ButtonCustomization implements Parcelable { - - private final ButtonCustomization cardinalButtonCustomization = new ButtonCustomization(); - - public ThreeDSecureV2ButtonCustomization() { - } - - /** - * @param textFontName Font type for the UI element. - */ - public void setTextFontName(@Nullable String textFontName) { - cardinalButtonCustomization.setTextFontName(textFontName); - } - - /** - * @param textColor Color code in Hex format. For example, the color code can be “#999999”. - */ - public void setTextColor(@Nullable String textColor) { - cardinalButtonCustomization.setTextColor(textColor); - } - - /** - * @param textFontSize Font size for the UI element. - */ - public void setTextFontSize(int textFontSize) { - cardinalButtonCustomization.setTextFontSize(textFontSize); - } - - /** - * @return Font type for the UI element. - */ - @Nullable - public String getTextFontName() { - return cardinalButtonCustomization.getTextFontName(); - } - - /** - * @return Color code in Hex format. - */ - @Nullable - public String getTextColor() { - return cardinalButtonCustomization.getTextColor(); - } - - /** - * @return Font size for the UI element. - */ - public int getTextFontSize() { - return cardinalButtonCustomization.getTextFontSize(); - } - - /** - * @param backgroundColor Color code in Hex format. For example, the color code can be - * “#999999”. - */ - public void setBackgroundColor(@Nullable String backgroundColor) { - cardinalButtonCustomization.setBackgroundColor(backgroundColor); - } - - /** - * @param cornerRadius Radius (integer value) for the button corners. - */ - public void setCornerRadius(int cornerRadius) { - cardinalButtonCustomization.setCornerRadius(cornerRadius); - } - - /** - * @return Color code in Hex format. - */ - @Nullable - public String getBackgroundColor() { - return cardinalButtonCustomization.getBackgroundColor(); - } - - /** - * @return Radius (integer value) for the button corners. - */ - public int getCornerRadius() { - return cardinalButtonCustomization.getCornerRadius(); - } - - ButtonCustomization getCardinalButtonCustomization() { - return cardinalButtonCustomization; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeString(cardinalButtonCustomization.getTextFontName()); - parcel.writeString(cardinalButtonCustomization.getTextColor()); - parcel.writeInt(cardinalButtonCustomization.getTextFontSize()); - parcel.writeString(cardinalButtonCustomization.getBackgroundColor()); - parcel.writeInt(cardinalButtonCustomization.getCornerRadius()); - } - - protected ThreeDSecureV2ButtonCustomization(Parcel in) { - String textFontName = in.readString(); - String textColor = in.readString(); - int textFontSize = in.readInt(); - String backgroundColor = in.readString(); - int cornerRadius = in.readInt(); - - if (textFontName != null) { - cardinalButtonCustomization.setTextFontName(textFontName); - } - if (textColor != null) { - cardinalButtonCustomization.setTextColor(textColor); - } - if (textFontSize != 0) { - cardinalButtonCustomization.setTextFontSize(textFontSize); - } - if (backgroundColor != null) { - cardinalButtonCustomization.setBackgroundColor(backgroundColor); - } - if (cornerRadius != 0) { - cardinalButtonCustomization.setCornerRadius(cornerRadius); - } - } - - public static final Creator CREATOR = - new Creator() { - @Override - public ThreeDSecureV2ButtonCustomization createFromParcel(Parcel in) { - return new ThreeDSecureV2ButtonCustomization(in); - } - - @Override - public ThreeDSecureV2ButtonCustomization[] newArray(int size) { - return new ThreeDSecureV2ButtonCustomization[size]; - } - }; -} diff --git a/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2ButtonCustomization.kt b/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2ButtonCustomization.kt new file mode 100644 index 0000000000..bac1e95806 --- /dev/null +++ b/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2ButtonCustomization.kt @@ -0,0 +1,36 @@ +package com.braintreepayments.api.threedsecure + +import android.os.Parcelable +import com.cardinalcommerce.shared.userinterfaces.ButtonCustomization +import kotlinx.parcelize.Parcelize + +/** + * Button customization options for 3D Secure 2 flows. + * + * @property textFontName Font type for the UI element. + * @property textColor Color code in Hex format. For example, the color code can be “#999999”. + * @property textFontSize Font size for the UI element. + * @property backgroundColor @param backgroundColor Color code in Hex format. For example, the color + * code can be “#999999”. + * @property cornerRadius Radius (integer value) for the button corners. + */ +@Parcelize +data class ThreeDSecureV2ButtonCustomization( + var textFontName: String? = null, + var textColor: String? = null, + var textFontSize: Int = 0, + var backgroundColor: String? = null, + var cornerRadius: Int = 0 +) : Parcelable { + + val cardinalButtonCustomization: ButtonCustomization + get() { + return ButtonCustomization().also { + textFontName?.let { textFontName -> it.textFontName = textFontName } + textColor?.let { textColor -> it.textColor = textColor } + if (textFontSize != 0) it.textFontSize = textFontSize + backgroundColor?.let { backgroundColor -> it.backgroundColor = backgroundColor } + if (cornerRadius != 0) it.cornerRadius = cornerRadius + } + } +} diff --git a/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2ButtonType.kt b/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2ButtonType.kt new file mode 100644 index 0000000000..07f95177af --- /dev/null +++ b/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2ButtonType.kt @@ -0,0 +1,12 @@ +package com.braintreepayments.api.threedsecure + +/** + * Button types that can be customized in 3D Secure 2 flows. + */ +enum class ThreeDSecureV2ButtonType { + BUTTON_TYPE_VERIFY, + BUTTON_TYPE_CONTINUE, + BUTTON_TYPE_NEXT, + BUTTON_TYPE_CANCEL, + BUTTON_TYPE_RESEND +} diff --git a/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2LabelCustomization.java b/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2LabelCustomization.java deleted file mode 100644 index 47be19c568..0000000000 --- a/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2LabelCustomization.java +++ /dev/null @@ -1,168 +0,0 @@ -package com.braintreepayments.api.threedsecure; - -import android.os.Parcel; -import android.os.Parcelable; - -import androidx.annotation.Nullable; - -import com.cardinalcommerce.shared.userinterfaces.LabelCustomization; - -/** - * Label customization options for 3D Secure 2 flows. - */ -public class ThreeDSecureV2LabelCustomization implements Parcelable { - - private final LabelCustomization cardinalLabelCustomization = new LabelCustomization(); - - public ThreeDSecureV2LabelCustomization() { - } - - /** - * @param textFontName Font type for the UI element. - */ - public void setTextFontName(@Nullable String textFontName) { - cardinalLabelCustomization.setTextFontName(textFontName); - } - - /** - * @param textColor Color code in Hex format. For example, the color code can be “#999999”. - */ - public void setTextColor(@Nullable String textColor) { - cardinalLabelCustomization.setTextColor(textColor); - } - - /** - * @param textFontSize Font size for the UI element. - */ - public void setTextFontSize(int textFontSize) { - cardinalLabelCustomization.setTextFontSize(textFontSize); - } - - /** - * @return Font type for the UI element. - */ - @Nullable - public String getTextFontName() { - return cardinalLabelCustomization.getTextFontName(); - } - - /** - * @return Color code in Hex format. - */ - @Nullable - public String getTextColor() { - return cardinalLabelCustomization.getTextColor(); - } - - /** - * @return Font size for the UI element. - */ - public int getTextFontSize() { - return cardinalLabelCustomization.getTextFontSize(); - } - - /** - * @param headingTextColor Color code in Hex format. For example, the color code can be - * “#999999”. - */ - public void setHeadingTextColor(@Nullable String headingTextColor) { - cardinalLabelCustomization.setHeadingTextColor(headingTextColor); - } - - /** - * @param headingTextFontName Font type for the heading label text. - */ - public void setHeadingTextFontName(@Nullable String headingTextFontName) { - cardinalLabelCustomization.setHeadingTextFontName(headingTextFontName); - } - - /** - * @param headingTextFontSize Font size for the heading label text. - */ - public void setHeadingTextFontSize(int headingTextFontSize) { - cardinalLabelCustomization.setHeadingTextFontSize(headingTextFontSize); - } - - /** - * @return Color code in Hex format. - */ - @Nullable - public String getHeadingTextColor() { - return cardinalLabelCustomization.getHeadingTextColor(); - } - - /** - * @return Font type for the heading label text. - */ - @Nullable - public String getHeadingTextFontName() { - return cardinalLabelCustomization.getHeadingTextFontName(); - } - - /** - * @return Font size for the heading label text. - */ - public int getHeadingTextFontSize() { - return cardinalLabelCustomization.getHeadingTextFontSize(); - } - - LabelCustomization getCardinalLabelCustomization() { - return cardinalLabelCustomization; - } - - @Override - public int describeContents() { - return 0; - } - - private ThreeDSecureV2LabelCustomization(Parcel in) { - String textFontName = in.readString(); - String textColor = in.readString(); - int textFontSize = in.readInt(); - String headingTextColor = in.readString(); - String headingTextFontName = in.readString(); - int headingTextFontSize = in.readInt(); - - if (textFontName != null) { - cardinalLabelCustomization.setTextFontName(textFontName); - } - if (textColor != null) { - cardinalLabelCustomization.setTextColor(textColor); - } - if (textFontSize != 0) { - cardinalLabelCustomization.setTextFontSize(textFontSize); - } - if (headingTextColor != null) { - cardinalLabelCustomization.setHeadingTextColor(headingTextColor); - } - if (headingTextFontName != null) { - cardinalLabelCustomization.setHeadingTextFontName(headingTextFontName); - } - if (headingTextFontSize != 0) { - cardinalLabelCustomization.setHeadingTextFontSize(headingTextFontSize); - } - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeString(cardinalLabelCustomization.getTextFontName()); - parcel.writeString(cardinalLabelCustomization.getTextColor()); - parcel.writeInt(cardinalLabelCustomization.getTextFontSize()); - parcel.writeString(cardinalLabelCustomization.getHeadingTextColor()); - parcel.writeString(cardinalLabelCustomization.getHeadingTextFontName()); - parcel.writeInt(cardinalLabelCustomization.getHeadingTextFontSize()); - } - - public static final Creator CREATOR = - new Creator() { - @Override - public ThreeDSecureV2LabelCustomization createFromParcel(Parcel in) { - return new ThreeDSecureV2LabelCustomization(in); - } - - @Override - public ThreeDSecureV2LabelCustomization[] newArray(int size) { - return new ThreeDSecureV2LabelCustomization[size]; - } - }; -} diff --git a/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2LabelCustomization.kt b/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2LabelCustomization.kt new file mode 100644 index 0000000000..2e12c16f16 --- /dev/null +++ b/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2LabelCustomization.kt @@ -0,0 +1,41 @@ +package com.braintreepayments.api.threedsecure + +import android.os.Parcelable +import com.cardinalcommerce.shared.userinterfaces.LabelCustomization +import kotlinx.parcelize.Parcelize + +/** + * Label customization options for 3D Secure 2 flows. + * + * @property textFontName Font type for the UI element. + * @property textColor Color code in Hex format. For example, the color code can be “#999999”. + * @property textFontSize Font size for the UI element. + * @property headingTextColor Color code in Hex format. For example, the color code can be + * “#999999”. + * @property headingTextFontName Font type for the heading label text. + * @property headingTextFontSize Font size for the heading label text. + */ +@Parcelize +data class ThreeDSecureV2LabelCustomization( + var textFontName: String? = null, + var textColor: String? = null, + var textFontSize: Int = 0, + var headingTextColor: String? = null, + var headingTextFontName: String? = null, + var headingTextFontSize: Int = 0 +) : Parcelable { + + val cardinalLabelCustomization: LabelCustomization + get() { + return LabelCustomization().also { + textFontName?.let { textFontName -> it.textFontName = textFontName } + textColor?.let { textColor -> it.textColor = textColor } + if (textFontSize != 0) it.textFontSize = textFontSize + headingTextColor?.let { headingTextColor -> it.headingTextColor = headingTextColor } + headingTextFontName?.let { headingTextFontName -> + it.headingTextFontName = headingTextFontName + } + if (headingTextFontSize != 0) it.headingTextFontSize = headingTextFontSize + } + } +} diff --git a/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2TextBoxCustomization.java b/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2TextBoxCustomization.java deleted file mode 100644 index fe3f68b398..0000000000 --- a/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2TextBoxCustomization.java +++ /dev/null @@ -1,166 +0,0 @@ -package com.braintreepayments.api.threedsecure; - -import android.os.Parcel; -import android.os.Parcelable; - -import androidx.annotation.Nullable; - -import com.cardinalcommerce.shared.userinterfaces.TextBoxCustomization; - -/** - * Text box customization options for 3D Secure 2 flows. - */ -public class ThreeDSecureV2TextBoxCustomization implements Parcelable { - - private final TextBoxCustomization cardinalTextBoxCustomization = new TextBoxCustomization(); - - public ThreeDSecureV2TextBoxCustomization() { - } - - /** - * @param textFontName Font type for the UI element. - */ - public void setTextFontName(@Nullable String textFontName) { - cardinalTextBoxCustomization.setTextFontName(textFontName); - } - - /** - * @param textColor Color code in Hex format. For example, the color code can be “#999999”. - */ - public void setTextColor(@Nullable String textColor) { - cardinalTextBoxCustomization.setTextColor(textColor); - } - - /** - * @param textFontSize Font size for the UI element. - */ - public void setTextFontSize(int textFontSize) { - cardinalTextBoxCustomization.setTextFontSize(textFontSize); - } - - /** - * @return Font type for the UI element. - */ - @Nullable - public String getTextFontName() { - return cardinalTextBoxCustomization.getTextFontName(); - } - - /** - * @return Color code in Hex format. - */ - @Nullable - public String getTextColor() { - return cardinalTextBoxCustomization.getTextColor(); - } - - /** - * @return Font size for the UI element. - */ - public int getTextFontSize() { - return cardinalTextBoxCustomization.getTextFontSize(); - } - - /** - * @param borderWidth Width (integer value) of the text box border. - */ - public void setBorderWidth(int borderWidth) { - cardinalTextBoxCustomization.setBorderWidth(borderWidth); - } - - /** - * @param borderColor Color code in Hex format. For example, the color code can be “#999999”. - */ - public void setBorderColor(@Nullable String borderColor) { - cardinalTextBoxCustomization.setBorderColor(borderColor); - } - - /** - * @param cornerRadius Radius (integer value) for the text box corners. - */ - public void setCornerRadius(int cornerRadius) { - cardinalTextBoxCustomization.setCornerRadius(cornerRadius); - } - - /** - * @return Width (integer value) of the text box border. - */ - public int getBorderWidth() { - return cardinalTextBoxCustomization.getBorderWidth(); - } - - /** - * @return Color code in Hex format. - */ - @Nullable - public String getBorderColor() { - return cardinalTextBoxCustomization.getBorderColor(); - } - - /** - * @return Radius (integer value) for the text box corners. - */ - public int getCornerRadius() { - return cardinalTextBoxCustomization.getCornerRadius(); - } - - TextBoxCustomization getCardinalTextBoxCustomization() { - return cardinalTextBoxCustomization; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeString(cardinalTextBoxCustomization.getTextFontName()); - parcel.writeString(cardinalTextBoxCustomization.getTextColor()); - parcel.writeInt(cardinalTextBoxCustomization.getTextFontSize()); - parcel.writeInt(cardinalTextBoxCustomization.getBorderWidth()); - parcel.writeString(cardinalTextBoxCustomization.getBorderColor()); - parcel.writeInt(cardinalTextBoxCustomization.getCornerRadius()); - } - - private ThreeDSecureV2TextBoxCustomization(Parcel in) { - String textFontName = in.readString(); - String textColor = in.readString(); - int textFontSize = in.readInt(); - int borderWidth = in.readInt(); - String borderColor = in.readString(); - int cornerRadius = in.readInt(); - - if (textFontName != null) { - cardinalTextBoxCustomization.setTextFontName(textFontName); - } - if (textColor != null) { - cardinalTextBoxCustomization.setTextColor(textColor); - } - if (textFontSize != 0) { - cardinalTextBoxCustomization.setTextFontSize(textFontSize); - } - if (borderWidth != 0) { - cardinalTextBoxCustomization.setBorderWidth(borderWidth); - } - if (borderColor != null) { - cardinalTextBoxCustomization.setBorderColor(borderColor); - } - if (cornerRadius != 0) { - cardinalTextBoxCustomization.setCornerRadius(cornerRadius); - } - } - - public static final Creator CREATOR = - new Creator() { - @Override - public ThreeDSecureV2TextBoxCustomization createFromParcel(Parcel in) { - return new ThreeDSecureV2TextBoxCustomization(in); - } - - @Override - public ThreeDSecureV2TextBoxCustomization[] newArray(int size) { - return new ThreeDSecureV2TextBoxCustomization[size]; - } - }; -} diff --git a/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2TextBoxCustomization.kt b/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2TextBoxCustomization.kt new file mode 100644 index 0000000000..8888664717 --- /dev/null +++ b/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2TextBoxCustomization.kt @@ -0,0 +1,38 @@ +package com.braintreepayments.api.threedsecure + +import android.os.Parcelable +import com.cardinalcommerce.shared.userinterfaces.TextBoxCustomization +import kotlinx.parcelize.Parcelize + +/** + * Text box customization options for 3D Secure 2 flows. + * + * @property textFontName Font type for the UI element. + * @property textColor Color code in Hex format. For example, the color code can be “#999999”. + * @property textFontSize Font size for the UI element. + * @property borderWidth Width (integer value) of the text box border. + * @property borderColor Color code in Hex format. For example, the color code can be “#999999”. + * @property cornerRadius Radius (integer value) for the text box corners. + */ +@Parcelize +data class ThreeDSecureV2TextBoxCustomization( + var textFontName: String? = null, + var textColor: String? = null, + var textFontSize: Int = 0, + var borderWidth: Int = 0, + var borderColor: String? = null, + var cornerRadius: Int = 0 +) : Parcelable { + + val cardinalTextBoxCustomization: TextBoxCustomization + get() { + return TextBoxCustomization().also { + textFontName?.let { textFontName -> it.textFontName = textFontName } + textColor?.let { textColor -> it.textColor = textColor } + if (textFontSize != 0) it.textFontSize = textFontSize + if (borderWidth != 0) it.borderWidth = borderWidth + borderColor?.let { borderColor -> it.borderColor = borderColor } + if (cornerRadius != 0) it.cornerRadius = cornerRadius + } + } +} diff --git a/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2ToolbarCustomization.java b/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2ToolbarCustomization.java deleted file mode 100644 index 56e454c834..0000000000 --- a/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2ToolbarCustomization.java +++ /dev/null @@ -1,169 +0,0 @@ -package com.braintreepayments.api.threedsecure; - -import android.os.Parcel; -import android.os.Parcelable; - -import androidx.annotation.Nullable; - -import com.cardinalcommerce.shared.userinterfaces.ToolbarCustomization; - -/** - * Toolbar customization options for 3D Secure 2 flows. - */ -public class ThreeDSecureV2ToolbarCustomization implements Parcelable { - - private final ToolbarCustomization cardinalToolbarCustomization = new ToolbarCustomization(); - - public ThreeDSecureV2ToolbarCustomization() { - } - - /** - * @param textFontName Font type for the UI element. - */ - public void setTextFontName(@Nullable String textFontName) { - cardinalToolbarCustomization.setTextFontName(textFontName); - } - - /** - * @param textColor Color code in Hex format. For example, the color code can be “#999999”. - */ - public void setTextColor(@Nullable String textColor) { - cardinalToolbarCustomization.setTextColor(textColor); - } - - /** - * @param textFontSize Font size for the UI element. - */ - public void setTextFontSize(int textFontSize) { - cardinalToolbarCustomization.setTextFontSize(textFontSize); - } - - /** - * @return Font type for the UI element. - */ - @Nullable - public String getTextFontName() { - return cardinalToolbarCustomization.getTextFontName(); - } - - /** - * @return Color code in Hex format. - */ - @Nullable - public String getTextColor() { - return cardinalToolbarCustomization.getTextColor(); - } - - /** - * @return Font size for the UI element. - */ - public int getTextFontSize() { - return cardinalToolbarCustomization.getTextFontSize(); - } - - /** - * @param backgroundColor Color code in Hex format. For example, the color code can be - * “#999999”. - */ - public void setBackgroundColor(@Nullable String backgroundColor) { - cardinalToolbarCustomization.setBackgroundColor(backgroundColor); - } - - /** - * @param headerText Text for the header. - */ - public void setHeaderText(@Nullable String headerText) { - cardinalToolbarCustomization.setHeaderText(headerText); - } - - /** - * @param buttonText Text for the button. For example, “Cancel”. - */ - public void setButtonText(@Nullable String buttonText) { - cardinalToolbarCustomization.setButtonText(buttonText); - } - - /** - * @return Color code in Hex format. - */ - @Nullable - public String getBackgroundColor() { - return cardinalToolbarCustomization.getBackgroundColor(); - } - - /** - * @return Text for the header. - */ - @Nullable - public String getHeaderText() { - return cardinalToolbarCustomization.getHeaderText(); - } - - /** - * @return Text for the button. - */ - @Nullable - public String getButtonText() { - return cardinalToolbarCustomization.getButtonText(); - } - - ToolbarCustomization getCardinalToolbarCustomization() { - return cardinalToolbarCustomization; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeString(cardinalToolbarCustomization.getTextFontName()); - parcel.writeString(cardinalToolbarCustomization.getTextColor()); - parcel.writeInt(cardinalToolbarCustomization.getTextFontSize()); - parcel.writeString(cardinalToolbarCustomization.getBackgroundColor()); - parcel.writeString(cardinalToolbarCustomization.getHeaderText()); - parcel.writeString(cardinalToolbarCustomization.getButtonText()); - } - - private ThreeDSecureV2ToolbarCustomization(Parcel in) { - String textFontName = in.readString(); - String textColor = in.readString(); - int textFontSize = in.readInt(); - String backgroundColor = in.readString(); - String headerText = in.readString(); - String buttonText = in.readString(); - - if (textFontName != null) { - cardinalToolbarCustomization.setTextFontName(textFontName); - } - if (textColor != null) { - cardinalToolbarCustomization.setTextColor(textColor); - } - if (textFontSize != 0) { - cardinalToolbarCustomization.setTextFontSize(textFontSize); - } - if (backgroundColor != null) { - cardinalToolbarCustomization.setBackgroundColor(backgroundColor); - } - if (headerText != null) { - cardinalToolbarCustomization.setHeaderText(headerText); - } - if (buttonText != null) { - cardinalToolbarCustomization.setButtonText(buttonText); - } - } - - public static final Creator CREATOR = - new Creator() { - @Override - public ThreeDSecureV2ToolbarCustomization createFromParcel(Parcel in) { - return new ThreeDSecureV2ToolbarCustomization(in); - } - - @Override - public ThreeDSecureV2ToolbarCustomization[] newArray(int size) { - return new ThreeDSecureV2ToolbarCustomization[size]; - } - }; -} diff --git a/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2ToolbarCustomization.kt b/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2ToolbarCustomization.kt new file mode 100644 index 0000000000..2107201382 --- /dev/null +++ b/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2ToolbarCustomization.kt @@ -0,0 +1,38 @@ +package com.braintreepayments.api.threedsecure + +import android.os.Parcelable +import com.cardinalcommerce.shared.userinterfaces.ToolbarCustomization +import kotlinx.parcelize.Parcelize + +/** + * Toolbar customization options for 3D Secure 2 flows. + * + * @property textFontName Font type for the UI element. + * @property textColor Color code in Hex format. For example, the color code can be “#999999”. + * @property textFontSize Font size for the UI element. + * @property backgroundColor Color code in Hex format. For example, the color code can be “#999999”. + * @property headerText Text for the header. + * @property buttonText Text for the button. For example, “Cancel”. + */ +@Parcelize +data class ThreeDSecureV2ToolbarCustomization( + var textFontName: String? = null, + var textColor: String? = null, + var textFontSize: Int = 0, + var backgroundColor: String? = null, + var headerText: String? = null, + var buttonText: String? = null +) : Parcelable { + + val cardinalToolbarCustomization: ToolbarCustomization + get() { + return ToolbarCustomization().also { + textFontName?.let { textFontName -> it.textFontName = textFontName } + textColor?.let { textColor -> it.textColor = textColor } + if (textFontSize != 0) it.textFontSize = textFontSize + backgroundColor?.let { backgroundColor -> it.backgroundColor = backgroundColor } + headerText?.let { headerText -> it.headerText = headerText } + buttonText?.let { buttonText -> it.buttonText = buttonText } + } + } +} diff --git a/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2UiCustomization.java b/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2UiCustomization.java deleted file mode 100644 index 9995f7bdc5..0000000000 --- a/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2UiCustomization.java +++ /dev/null @@ -1,189 +0,0 @@ -package com.braintreepayments.api.threedsecure; - - -import android.os.Parcel; -import android.os.Parcelable; - -import androidx.annotation.IntDef; -import androidx.annotation.Nullable; - -import com.cardinalcommerce.shared.models.enums.ButtonType; -import com.cardinalcommerce.shared.userinterfaces.UiCustomization; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * UI customization options for 3D Secure 2 flows. - */ -public class ThreeDSecureV2UiCustomization implements Parcelable { - - /** - * Button types that can be customized in 3D Secure 2 flows. - */ - @Retention(RetentionPolicy.SOURCE) - @IntDef({BUTTON_TYPE_VERIFY, BUTTON_TYPE_CONTINUE, BUTTON_TYPE_NEXT, BUTTON_TYPE_CANCEL, - BUTTON_TYPE_RESEND}) - @interface ThreeDSecureV2ButtonType { - } - - public static final int BUTTON_TYPE_VERIFY = 0; - public static final int BUTTON_TYPE_CONTINUE = 1; - public static final int BUTTON_TYPE_NEXT = 2; - public static final int BUTTON_TYPE_CANCEL = 3; - public static final int BUTTON_TYPE_RESEND = 4; - - private ThreeDSecureV2ButtonCustomization buttonCustomization; - private ThreeDSecureV2LabelCustomization labelCustomization; - private ThreeDSecureV2TextBoxCustomization textBoxCustomization; - private ThreeDSecureV2ToolbarCustomization toolbarCustomization; - private @ThreeDSecureV2ButtonType int buttonType; - private UiCustomization cardinalValue = new UiCustomization(); - - public ThreeDSecureV2UiCustomization() { - } - - /** - * Set button customization options for 3D Secure 2 flows. - * - * @param buttonCustomization {@link ThreeDSecureV2ButtonCustomization} - * @param buttonType Button type - */ - public void setButtonCustomization( - @Nullable ThreeDSecureV2ButtonCustomization buttonCustomization, - @ThreeDSecureV2ButtonType int buttonType) { - this.buttonCustomization = buttonCustomization; - this.buttonType = buttonType; - cardinalValue.setButtonCustomization(buttonCustomization.getCardinalButtonCustomization(), - getCardinalButtonType(buttonType)); - } - - /** - * Label customization options for 3D Secure 2 flows. - * - * @param labelCustomization {@link ThreeDSecureV2LabelCustomization} - */ - public void setLabelCustomization( - @Nullable ThreeDSecureV2LabelCustomization labelCustomization) { - this.labelCustomization = labelCustomization; - cardinalValue.setLabelCustomization(labelCustomization.getCardinalLabelCustomization()); - } - - /** - * Text box customization options for 3D Secure 2 flows. - * - * @param textBoxCustomization {@link ThreeDSecureV2TextBoxCustomization} - */ - public void setTextBoxCustomization( - @Nullable ThreeDSecureV2TextBoxCustomization textBoxCustomization) { - this.textBoxCustomization = textBoxCustomization; - cardinalValue.setTextBoxCustomization( - textBoxCustomization.getCardinalTextBoxCustomization()); - } - - /** - * Toolbar customization options for 3D Secure 2 flows. - * - * @param toolbarCustomization {@link ThreeDSecureV2ToolbarCustomization} - */ - public void setToolbarCustomization( - @Nullable ThreeDSecureV2ToolbarCustomization toolbarCustomization) { - this.toolbarCustomization = toolbarCustomization; - cardinalValue.setToolbarCustomization( - toolbarCustomization.getCardinalToolbarCustomization()); - } - - /** - * @return {@link ThreeDSecureV2ButtonCustomization} - */ - @Nullable - public ThreeDSecureV2ButtonCustomization getButtonCustomization() { - return buttonCustomization; - } - - /** - * @return {@link ThreeDSecureV2LabelCustomization} - */ - @Nullable - public ThreeDSecureV2LabelCustomization getLabelCustomization() { - return labelCustomization; - } - - /** - * @return {@link ThreeDSecureV2TextBoxCustomization} - */ - @Nullable - public ThreeDSecureV2TextBoxCustomization getTextBoxCustomization() { - return textBoxCustomization; - } - - /** - * @return {@link ThreeDSecureV2ToolbarCustomization} - */ - @Nullable - public ThreeDSecureV2ToolbarCustomization getToolbarCustomization() { - return toolbarCustomization; - } - - UiCustomization getCardinalUiCustomization() { - return cardinalValue; - } - - private ButtonType getCardinalButtonType(@ThreeDSecureV2ButtonType int buttonType) { - switch (buttonType) { - case BUTTON_TYPE_VERIFY: - return ButtonType.VERIFY; - case BUTTON_TYPE_CONTINUE: - return ButtonType.CONTINUE; - case BUTTON_TYPE_NEXT: - return ButtonType.NEXT; - case BUTTON_TYPE_CANCEL: - return ButtonType.CANCEL; - case BUTTON_TYPE_RESEND: - return ButtonType.RESEND; - default: - return null; - } - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeParcelable(buttonCustomization, i); - parcel.writeParcelable(labelCustomization, i); - parcel.writeParcelable(textBoxCustomization, i); - parcel.writeParcelable(toolbarCustomization, i); - parcel.writeInt(buttonType); - parcel.writeSerializable(cardinalValue); - } - - private ThreeDSecureV2UiCustomization(Parcel in) { - buttonCustomization = - in.readParcelable(ThreeDSecureV2ButtonCustomization.class.getClassLoader()); - labelCustomization = - in.readParcelable(ThreeDSecureV2LabelCustomization.class.getClassLoader()); - textBoxCustomization = - in.readParcelable(ThreeDSecureV2TextBoxCustomization.class.getClassLoader()); - toolbarCustomization = - in.readParcelable(ThreeDSecureV2ToolbarCustomization.class.getClassLoader()); - buttonType = in.readInt(); - cardinalValue = (UiCustomization) in.readSerializable(); - } - - public static final Creator CREATOR = - new Creator() { - @Override - public ThreeDSecureV2UiCustomization createFromParcel(Parcel in) { - return new ThreeDSecureV2UiCustomization(in); - } - - @Override - public ThreeDSecureV2UiCustomization[] newArray(int size) { - return new ThreeDSecureV2UiCustomization[size]; - } - }; -} diff --git a/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2UiCustomization.kt b/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2UiCustomization.kt new file mode 100644 index 0000000000..1bdec40980 --- /dev/null +++ b/ThreeDSecure/src/main/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2UiCustomization.kt @@ -0,0 +1,57 @@ +package com.braintreepayments.api.threedsecure + +import android.os.Parcelable +import com.cardinalcommerce.shared.models.enums.ButtonType +import com.cardinalcommerce.shared.userinterfaces.UiCustomization +import kotlinx.parcelize.Parcelize + +/** + * UI customization options for 3D Secure 2 flows. + * + * @property buttonCustomization button customization options for 3D Secure 2 flows + * @property buttonType type of 3D Secure button + * @property labelCustomization label customization options for 3D Secure 2 flows + * @property textBoxCustomization text box customization options for 3D Secure 2 flows + * @property toolbarCustomization toolbar customization options for 3D Secure 2 flows + */ +@Parcelize +data class ThreeDSecureV2UiCustomization( + var buttonCustomization: ThreeDSecureV2ButtonCustomization? = null, + var buttonType: ThreeDSecureV2ButtonType? = null, + var labelCustomization: ThreeDSecureV2LabelCustomization? = null, + var textBoxCustomization: ThreeDSecureV2TextBoxCustomization? = null, + var toolbarCustomization: ThreeDSecureV2ToolbarCustomization? = null, +) : Parcelable { + + val cardinalUiCustomization: UiCustomization + get() { + return UiCustomization().also { + if (buttonCustomization != null && buttonType != null) { + it.setButtonCustomization( + buttonCustomization?.cardinalButtonCustomization, + getCardinalButtonType(buttonType) + ) + } + labelCustomization?.let { labelCustomization -> + it.labelCustomization = labelCustomization.cardinalLabelCustomization + } + textBoxCustomization?.let { textBoxCustomization -> + it.textBoxCustomization = textBoxCustomization.cardinalTextBoxCustomization + } + toolbarCustomization?.let { toolbarCustomization -> + it.toolbarCustomization = toolbarCustomization.cardinalToolbarCustomization + } + } + } + + private fun getCardinalButtonType(buttonType: ThreeDSecureV2ButtonType?): ButtonType? { + return when (buttonType) { + ThreeDSecureV2ButtonType.BUTTON_TYPE_VERIFY -> ButtonType.VERIFY + ThreeDSecureV2ButtonType.BUTTON_TYPE_CONTINUE -> ButtonType.CONTINUE + ThreeDSecureV2ButtonType.BUTTON_TYPE_NEXT -> ButtonType.NEXT + ThreeDSecureV2ButtonType.BUTTON_TYPE_CANCEL -> ButtonType.CANCEL + ThreeDSecureV2ButtonType.BUTTON_TYPE_RESEND -> ButtonType.RESEND + else -> null + } + } +} diff --git a/ThreeDSecure/src/test/java/com/braintreepayments/api/threedsecure/CardinalClientUnitTest.kt b/ThreeDSecure/src/test/java/com/braintreepayments/api/threedsecure/CardinalClientUnitTest.kt index ab683f47d6..2cd0897023 100644 --- a/ThreeDSecure/src/test/java/com/braintreepayments/api/threedsecure/CardinalClientUnitTest.kt +++ b/ThreeDSecure/src/test/java/com/braintreepayments/api/threedsecure/CardinalClientUnitTest.kt @@ -80,8 +80,8 @@ class CardinalClientUnitTest { val parameters = parametersSlot.captured assertEquals( - request.v2UiCustomization!!.cardinalUiCustomization, - parameters.uiCustomization + request.v2UiCustomization!!.cardinalUiCustomization.toolbarCustomization, + parameters.uiCustomization.toolbarCustomization ) } diff --git a/ThreeDSecure/src/test/java/com/braintreepayments/api/threedsecure/ThreeDSecureRequestUnitTest.java b/ThreeDSecure/src/test/java/com/braintreepayments/api/threedsecure/ThreeDSecureRequestUnitTest.java index 03aef64681..967332718c 100644 --- a/ThreeDSecure/src/test/java/com/braintreepayments/api/threedsecure/ThreeDSecureRequestUnitTest.java +++ b/ThreeDSecure/src/test/java/com/braintreepayments/api/threedsecure/ThreeDSecureRequestUnitTest.java @@ -67,8 +67,8 @@ public void writeToParcel() { ThreeDSecureV2UiCustomization v2UiCustomization = new ThreeDSecureV2UiCustomization(); v2UiCustomization.setLabelCustomization(labelCustomization); v2UiCustomization.setTextBoxCustomization(textBoxCustomization); - v2UiCustomization.setButtonCustomization(buttonCustomization, - ThreeDSecureV2UiCustomization.BUTTON_TYPE_VERIFY); + v2UiCustomization.setButtonCustomization(buttonCustomization); + v2UiCustomization.setButtonType(ThreeDSecureV2ButtonType.BUTTON_TYPE_VERIFY); v2UiCustomization.setToolbarCustomization(toolbarCustomization); Map customFields = new HashMap<>(); diff --git a/ThreeDSecure/src/test/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2UiCustomizationUnitTest.java b/ThreeDSecure/src/test/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2UiCustomizationUnitTest.java index b0017ac408..4b32142898 100644 --- a/ThreeDSecure/src/test/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2UiCustomizationUnitTest.java +++ b/ThreeDSecure/src/test/java/com/braintreepayments/api/threedsecure/ThreeDSecureV2UiCustomizationUnitTest.java @@ -24,8 +24,8 @@ public class ThreeDSecureV2UiCustomizationUnitTest { public void setsAllCardinalClassProperties() { ThreeDSecureV2UiCustomization sut = new ThreeDSecureV2UiCustomization(); sut.setLabelCustomization(new ThreeDSecureV2LabelCustomization()); - sut.setButtonCustomization(new ThreeDSecureV2ButtonCustomization(), - ThreeDSecureV2UiCustomization.BUTTON_TYPE_NEXT); + sut.setButtonCustomization(new ThreeDSecureV2ButtonCustomization()); + sut.setButtonType(ThreeDSecureV2ButtonType.BUTTON_TYPE_NEXT); sut.setTextBoxCustomization(new ThreeDSecureV2TextBoxCustomization()); sut.setToolbarCustomization(new ThreeDSecureV2ToolbarCustomization()); @@ -80,8 +80,8 @@ public void writeToParcel() { toolbarCustomization.setTextFontSize(15); ThreeDSecureV2UiCustomization customization = new ThreeDSecureV2UiCustomization(); - customization.setButtonCustomization(buttonCustomization, - ThreeDSecureV2UiCustomization.BUTTON_TYPE_CONTINUE); + customization.setButtonCustomization(buttonCustomization); + customization.setButtonType(ThreeDSecureV2ButtonType.BUTTON_TYPE_CONTINUE); customization.setLabelCustomization(labelCustomization); customization.setTextBoxCustomization(textBoxCustomization); customization.setToolbarCustomization(toolbarCustomization);