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

add missing 3ds button props #234

Merged
merged 3 commits into from
May 20, 2021
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
106 changes: 92 additions & 14 deletions android/src/main/java/com/reactnativestripesdk/Mappers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,21 @@ fun mapToUICustomization(params: ReadableMap): PaymentAuthConfig.Stripe3ds2UiCus
val labelCustomization = getMapOrNull(params, "label")
val navigationBarCustomization = params.getMap("navigationBar")
val textBoxCustomization = getMapOrNull(params, "textField")
val buttonCustomization = getMapOrNull(params, "submitButton")
val submitButtonCustomization = getMapOrNull(params, "submitButton")
val cancelButtonCustomization = getMapOrNull(params, "cancelButton")
val nextButtonCustomization = getMapOrNull(params, "nextButton")
val continueButtonCustomization = getMapOrNull(params, "continueButton")
val resendButtonCustomization = getMapOrNull(params, "resendButton")

val labelCustomizationBuilder = PaymentAuthConfig.Stripe3ds2LabelCustomization.Builder()
val toolbarCustomizationBuilder = PaymentAuthConfig.Stripe3ds2ToolbarCustomization.Builder()
val textBoxCustomizationBuilder = PaymentAuthConfig.Stripe3ds2TextBoxCustomization.Builder()
val buttonCustomizationBuilder = PaymentAuthConfig.Stripe3ds2ButtonCustomization.Builder()

val submitButtonCustomizationBuilder = PaymentAuthConfig.Stripe3ds2ButtonCustomization.Builder()
val cancelButtonCustomizationBuilder = PaymentAuthConfig.Stripe3ds2ButtonCustomization.Builder()
val nextButtonCustomizationBuilder = PaymentAuthConfig.Stripe3ds2ButtonCustomization.Builder()
val continueButtonCustomizationBuilder = PaymentAuthConfig.Stripe3ds2ButtonCustomization.Builder()
val resendButtonCustomizationBuilder = PaymentAuthConfig.Stripe3ds2ButtonCustomization.Builder()

getStringOrNull(labelCustomization,"headingTextColor")?.let {
labelCustomizationBuilder.setHeadingTextColor(it)
Expand Down Expand Up @@ -390,19 +399,77 @@ fun mapToUICustomization(params: ReadableMap): PaymentAuthConfig.Stripe3ds2UiCus
textBoxCustomizationBuilder.setTextFontSize(it)
}

getStringOrNull(buttonCustomization, "backgroundColor")?.let {
buttonCustomizationBuilder.setBackgroundColor(it)
// Submit button
getStringOrNull(submitButtonCustomization, "backgroundColor")?.let {
submitButtonCustomizationBuilder.setBackgroundColor(it)
}
getIntOrNull(submitButtonCustomization, "borderRadius")?.let {
submitButtonCustomizationBuilder.setCornerRadius(it)
}
getStringOrNull(submitButtonCustomization, "textColor")?.let {
submitButtonCustomizationBuilder.setTextColor(it)
}
getIntOrNull(submitButtonCustomization, "textFontSize")?.let {
submitButtonCustomizationBuilder.setTextFontSize(it)
}

// Cancel button
getStringOrNull(cancelButtonCustomization, "backgroundColor")?.let {
cancelButtonCustomizationBuilder.setBackgroundColor(it)
}
getIntOrNull(buttonCustomization, "borderRadius")?.let {
buttonCustomizationBuilder.setCornerRadius(it)
getIntOrNull(cancelButtonCustomization, "borderRadius")?.let {
cancelButtonCustomizationBuilder.setCornerRadius(it)
}
getStringOrNull(buttonCustomization, "textColor")?.let {
buttonCustomizationBuilder.setTextColor(it)
getStringOrNull(cancelButtonCustomization, "textColor")?.let {
cancelButtonCustomizationBuilder.setTextColor(it)
}
getIntOrNull(buttonCustomization, "textFontSize")?.let {
buttonCustomizationBuilder.setTextFontSize(it)
getIntOrNull(cancelButtonCustomization, "textFontSize")?.let {
cancelButtonCustomizationBuilder.setTextFontSize(it)
}

// Continue button
getStringOrNull(continueButtonCustomization, "backgroundColor")?.let {
continueButtonCustomizationBuilder.setBackgroundColor(it)
}
getIntOrNull(continueButtonCustomization, "borderRadius")?.let {
continueButtonCustomizationBuilder.setCornerRadius(it)
}
getStringOrNull(continueButtonCustomization, "textColor")?.let {
continueButtonCustomizationBuilder.setTextColor(it)
}
getIntOrNull(continueButtonCustomization, "textFontSize")?.let {
continueButtonCustomizationBuilder.setTextFontSize(it)
}

// Next button
getStringOrNull(nextButtonCustomization, "backgroundColor")?.let {
nextButtonCustomizationBuilder.setBackgroundColor(it)
}
getIntOrNull(nextButtonCustomization, "borderRadius")?.let {
nextButtonCustomizationBuilder.setCornerRadius(it)
}
getStringOrNull(nextButtonCustomization, "textColor")?.let {
nextButtonCustomizationBuilder.setTextColor(it)
}
getIntOrNull(nextButtonCustomization, "textFontSize")?.let {
nextButtonCustomizationBuilder.setTextFontSize(it)
}

// Resend button
getStringOrNull(resendButtonCustomization, "backgroundColor")?.let {
resendButtonCustomizationBuilder.setBackgroundColor(it)
}
getIntOrNull(resendButtonCustomization, "borderRadius")?.let {
resendButtonCustomizationBuilder.setCornerRadius(it)
}
getStringOrNull(resendButtonCustomization, "textColor")?.let {
resendButtonCustomizationBuilder.setTextColor(it)
}
getIntOrNull(resendButtonCustomization, "textFontSize")?.let {
resendButtonCustomizationBuilder.setTextFontSize(it)
}



val uiCustomization = PaymentAuthConfig.Stripe3ds2UiCustomization.Builder()
.setLabelCustomization(
Expand All @@ -412,16 +479,27 @@ fun mapToUICustomization(params: ReadableMap): PaymentAuthConfig.Stripe3ds2UiCus
toolbarCustomizationBuilder.build()
)
.setButtonCustomization(
buttonCustomizationBuilder.build(),
submitButtonCustomizationBuilder.build(),
PaymentAuthConfig.Stripe3ds2UiCustomization.ButtonType.SUBMIT
)

.setButtonCustomization(
buttonCustomizationBuilder.build(),
continueButtonCustomizationBuilder.build(),
PaymentAuthConfig.Stripe3ds2UiCustomization.ButtonType.CONTINUE
)
.setButtonCustomization(
nextButtonCustomizationBuilder.build(),
PaymentAuthConfig.Stripe3ds2UiCustomization.ButtonType.SELECT
)
.setButtonCustomization(
cancelButtonCustomizationBuilder.build(),
PaymentAuthConfig.Stripe3ds2UiCustomization.ButtonType.CANCEL
)
.setButtonCustomization(
resendButtonCustomizationBuilder.build(),
PaymentAuthConfig.Stripe3ds2UiCustomization.ButtonType.RESEND
)

getStringOrNull(params, "backgroundColor")?.let {
getStringOrNull(params, "accentColor")?.let {
uiCustomization.setAccentColor(it)
}

Expand Down
79 changes: 79 additions & 0 deletions ios/Mappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,91 @@ class Mappers {
if let textColor = submitButtonSettings["textColor"] as? String {
buttonCustomization.textColor = UIColor(hexString: textColor)
}

uiCustomization.setButtonCustomization(buttonCustomization, for: STPThreeDSCustomizationButtonType.submit)
}

if let submitButtonSettings = params["cancelButton"] as? Dictionary<String, Any?> {
let buttonCustomization = uiCustomization.buttonCustomization(for: STPThreeDSCustomizationButtonType.cancel)

if let backgroundColor = submitButtonSettings["backgroundColor"] as? String {
buttonCustomization.backgroundColor = UIColor(hexString: backgroundColor)
}
if let borderRadius = submitButtonSettings["borderRadius"] as? Int {
buttonCustomization.cornerRadius = CGFloat(borderRadius)
}
if let textFontSize = submitButtonSettings["textFontSize"] as? Int {
buttonCustomization.font = UIFont.systemFont(ofSize: CGFloat(textFontSize))
}
if let textColor = submitButtonSettings["textColor"] as? String {
buttonCustomization.textColor = UIColor(hexString: textColor)
}

uiCustomization.setButtonCustomization(buttonCustomization, for: STPThreeDSCustomizationButtonType.cancel)
}

if let submitButtonSettings = params["continueButton"] as? Dictionary<String, Any?> {
let buttonCustomization = uiCustomization.buttonCustomization(for: STPThreeDSCustomizationButtonType.continue)

if let backgroundColor = submitButtonSettings["backgroundColor"] as? String {
buttonCustomization.backgroundColor = UIColor(hexString: backgroundColor)
}
if let borderRadius = submitButtonSettings["borderRadius"] as? Int {
buttonCustomization.cornerRadius = CGFloat(borderRadius)
}
if let textFontSize = submitButtonSettings["textFontSize"] as? Int {
buttonCustomization.font = UIFont.systemFont(ofSize: CGFloat(textFontSize))
}
if let textColor = submitButtonSettings["textColor"] as? String {
buttonCustomization.textColor = UIColor(hexString: textColor)
}

uiCustomization.setButtonCustomization(buttonCustomization, for: STPThreeDSCustomizationButtonType.continue)
}

if let submitButtonSettings = params["nextButton"] as? Dictionary<String, Any?> {
let buttonCustomization = uiCustomization.buttonCustomization(for: STPThreeDSCustomizationButtonType.next)

if let backgroundColor = submitButtonSettings["backgroundColor"] as? String {
buttonCustomization.backgroundColor = UIColor(hexString: backgroundColor)
}
if let borderRadius = submitButtonSettings["borderRadius"] as? Int {
buttonCustomization.cornerRadius = CGFloat(borderRadius)
}
if let textFontSize = submitButtonSettings["textFontSize"] as? Int {
buttonCustomization.font = UIFont.systemFont(ofSize: CGFloat(textFontSize))
}
if let textColor = submitButtonSettings["textColor"] as? String {
buttonCustomization.textColor = UIColor(hexString: textColor)
}

uiCustomization.setButtonCustomization(buttonCustomization, for: STPThreeDSCustomizationButtonType.next)
}

if let submitButtonSettings = params["resendButton"] as? Dictionary<String, Any?> {
let buttonCustomization = uiCustomization.buttonCustomization(for: STPThreeDSCustomizationButtonType.resend)

if let backgroundColor = submitButtonSettings["backgroundColor"] as? String {
buttonCustomization.backgroundColor = UIColor(hexString: backgroundColor)
}
if let borderRadius = submitButtonSettings["borderRadius"] as? Int {
buttonCustomization.cornerRadius = CGFloat(borderRadius)
}
if let textFontSize = submitButtonSettings["textFontSize"] as? Int {
buttonCustomization.font = UIFont.systemFont(ofSize: CGFloat(textFontSize))
}
if let textColor = submitButtonSettings["textColor"] as? String {
buttonCustomization.textColor = UIColor(hexString: textColor)
}

uiCustomization.setButtonCustomization(buttonCustomization, for: STPThreeDSCustomizationButtonType.resend)
}

if let backgroundColor = params["backgroundColor"] as? String {
uiCustomization.backgroundColor = UIColor(hexString: backgroundColor)
}


return uiCustomization
}

Expand Down
8 changes: 6 additions & 2 deletions src/types/ThreeDSecure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ export interface ThreeDSecureConfigurationParams extends ThreeDSecure.Props {
label?: ThreeDSecure.LabelProps;
navigationBar?: ThreeDSecure.NavigationBarProps;
textField?: ThreeDSecure.TextFieldProps;
submitButton?: ThreeDSecure.SubmitButtonProps;
submitButton?: ThreeDSecure.ButtonProps;
cancelButton?: ThreeDSecure.ButtonProps;
continueButton?: ThreeDSecure.ButtonProps;
nextButton?: ThreeDSecure.ButtonProps;
resendButton?: ThreeDSecure.ButtonProps;
}

export namespace ThreeDSecure {
Expand Down Expand Up @@ -68,7 +72,7 @@ export namespace ThreeDSecure {
textFontSize?: number;
}

export interface SubmitButtonProps {
export interface ButtonProps {
backgroundColor?: string;
borderRadius?: number;
textColor?: string;
Expand Down