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

Introduced FieldVisibility for kcp and social security number fields #39

Merged
merged 4 commits into from
Oct 2, 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
25 changes: 18 additions & 7 deletions android/src/main/kotlin/com/adyen/adyen_checkout/PlatformApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ enum class DropInResultType(val raw: Int) {
}
}

enum class FieldVisibility(val raw: Int) {
SHOW(0),
HIDE(1);

companion object {
fun ofRaw(raw: Int): FieldVisibility? {
return values().firstOrNull { it.raw == raw }
}
}
}

/** Generated class from Pigeon that represents data sent in messages. */
data class SessionDTO (
val id: String,
Expand Down Expand Up @@ -289,8 +300,8 @@ data class CardsConfigurationDTO (
val showStorePaymentField: Boolean,
val showCvcForStoredCard: Boolean,
val showCvc: Boolean,
val showKcpField: Boolean,
val showSocialSecurityNumberField: Boolean,
val kcpFieldVisibility: FieldVisibility,
val socialSecurityNumberFieldVisibility: FieldVisibility,
val supportedCardTypes: List<String?>

) {
Expand All @@ -302,10 +313,10 @@ data class CardsConfigurationDTO (
val showStorePaymentField = list[2] as Boolean
val showCvcForStoredCard = list[3] as Boolean
val showCvc = list[4] as Boolean
val showKcpField = list[5] as Boolean
val showSocialSecurityNumberField = list[6] as Boolean
val kcpFieldVisibility = FieldVisibility.ofRaw(list[5] as Int)!!
Robert-SD marked this conversation as resolved.
Show resolved Hide resolved
val socialSecurityNumberFieldVisibility = FieldVisibility.ofRaw(list[6] as Int)!!
val supportedCardTypes = list[7] as List<String?>
return CardsConfigurationDTO(holderNameRequired, addressMode, showStorePaymentField, showCvcForStoredCard, showCvc, showKcpField, showSocialSecurityNumberField, supportedCardTypes)
return CardsConfigurationDTO(holderNameRequired, addressMode, showStorePaymentField, showCvcForStoredCard, showCvc, kcpFieldVisibility, socialSecurityNumberFieldVisibility, supportedCardTypes)
}
}
fun toList(): List<Any?> {
Expand All @@ -315,8 +326,8 @@ data class CardsConfigurationDTO (
showStorePaymentField,
showCvcForStoredCard,
showCvc,
showKcpField,
showSocialSecurityNumberField,
kcpFieldVisibility.raw,
socialSecurityNumberFieldVisibility.raw,
supportedCardTypes,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import CashAppPayConfigurationDTO
import CashAppPayEnvironment
import DropInConfigurationDTO
import Environment
import FieldVisibility
import GooglePayConfigurationDTO
import GooglePayEnvironment
import OrderResponseDTO
Expand Down Expand Up @@ -99,9 +100,9 @@ object ConfigurationMapper {
.setShowStorePaymentField(cardsConfigurationDTO.showStorePaymentField)
.setHideCvcStoredCard(!cardsConfigurationDTO.showCvcForStoredCard)
.setHideCvc(!cardsConfigurationDTO.showCvc)
.setKcpAuthVisibility(determineKcpAuthVisibility(cardsConfigurationDTO.showKcpField))
.setKcpAuthVisibility(determineKcpAuthVisibility(cardsConfigurationDTO.kcpFieldVisibility))
.setSocialSecurityNumberVisibility(
determineSocialSecurityNumberVisibility(cardsConfigurationDTO.showSocialSecurityNumberField)
determineSocialSecurityNumberVisibility(cardsConfigurationDTO.socialSecurityNumberFieldVisibility)
)
.setSupportedCardTypes(*mapToSupportedCardTypes(cardsConfigurationDTO.supportedCardTypes))
.setHolderNameRequired(cardsConfigurationDTO.holderNameRequired)
Expand Down Expand Up @@ -142,17 +143,17 @@ object ConfigurationMapper {
}
}

private fun determineKcpAuthVisibility(visible: Boolean?): KCPAuthVisibility {
return when (visible) {
true -> KCPAuthVisibility.SHOW
else -> KCPAuthVisibility.HIDE
private fun determineKcpAuthVisibility(fieldVisibility: FieldVisibility): KCPAuthVisibility {
return when (fieldVisibility) {
FieldVisibility.SHOW -> KCPAuthVisibility.SHOW
FieldVisibility.HIDE -> KCPAuthVisibility.HIDE
}
}

private fun determineSocialSecurityNumberVisibility(visible: Boolean?): SocialSecurityNumberVisibility {
private fun determineSocialSecurityNumberVisibility(visible: FieldVisibility): SocialSecurityNumberVisibility {
return when (visible) {
true -> SocialSecurityNumberVisibility.SHOW
else -> SocialSecurityNumberVisibility.HIDE
FieldVisibility.SHOW -> SocialSecurityNumberVisibility.SHOW
FieldVisibility.HIDE -> SocialSecurityNumberVisibility.HIDE
}
}

Expand Down
21 changes: 13 additions & 8 deletions ios/Classes/PlatformApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ enum DropInResultType: Int {
case error = 2
}

enum FieldVisibility: Int {
case show = 0
case hide = 1
}

/// Generated class from Pigeon that represents data sent in messages.
struct SessionDTO {
var id: String
Expand Down Expand Up @@ -247,8 +252,8 @@ struct CardsConfigurationDTO {
var showStorePaymentField: Bool
var showCvcForStoredCard: Bool
var showCvc: Bool
var showKcpField: Bool
var showSocialSecurityNumberField: Bool
var kcpFieldVisibility: FieldVisibility
var socialSecurityNumberFieldVisibility: FieldVisibility
var supportedCardTypes: [String?]

static func fromList(_ list: [Any?]) -> CardsConfigurationDTO? {
Expand All @@ -257,8 +262,8 @@ struct CardsConfigurationDTO {
let showStorePaymentField = list[2] as! Bool
let showCvcForStoredCard = list[3] as! Bool
let showCvc = list[4] as! Bool
let showKcpField = list[5] as! Bool
let showSocialSecurityNumberField = list[6] as! Bool
let kcpFieldVisibility = FieldVisibility(rawValue: list[5] as! Int)!
let socialSecurityNumberFieldVisibility = FieldVisibility(rawValue: list[6] as! Int)!
let supportedCardTypes = list[7] as! [String?]

return CardsConfigurationDTO(
Expand All @@ -267,8 +272,8 @@ struct CardsConfigurationDTO {
showStorePaymentField: showStorePaymentField,
showCvcForStoredCard: showCvcForStoredCard,
showCvc: showCvc,
showKcpField: showKcpField,
showSocialSecurityNumberField: showSocialSecurityNumberField,
kcpFieldVisibility: kcpFieldVisibility,
socialSecurityNumberFieldVisibility: socialSecurityNumberFieldVisibility,
supportedCardTypes: supportedCardTypes
)
}
Expand All @@ -279,8 +284,8 @@ struct CardsConfigurationDTO {
showStorePaymentField,
showCvcForStoredCard,
showCvc,
showKcpField,
showSocialSecurityNumberField,
kcpFieldVisibility.rawValue,
socialSecurityNumberFieldVisibility.rawValue,
supportedCardTypes,
]
}
Expand Down
23 changes: 16 additions & 7 deletions ios/Classes/utils/ConfigurationMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class ConfigurationMapper {
dropInConfiguration.paymentMethodsList.allowDisablingStoredPaymentMethods = dropInConfigurationDTO.isRemoveStoredPaymentMethodEnabled

if let cardsConfigurationDTO = dropInConfigurationDTO.cardsConfigurationDTO {
let koreanAuthenticationMode = determineFieldVisibility(visible: cardsConfigurationDTO.showKcpField)
let socialSecurityNumberMode = determineFieldVisibility(visible: cardsConfigurationDTO.showSocialSecurityNumberField)
let koreanAuthenticationMode = cardsConfigurationDTO.kcpFieldVisibility.toCardFieldVisibility()
let socialSecurityNumberMode = cardsConfigurationDTO.socialSecurityNumberFieldVisibility.toCardFieldVisibility()
let storedCardConfiguration = createStoredCardConfiguration(showCvcForStoredCard: cardsConfigurationDTO.showCvcForStoredCard)
let allowedCardTypes = determineAllowedCardTypes(cardTypes: cardsConfigurationDTO.supportedCardTypes)
let billingAddressConfiguration = determineBillingAddressConfiguration(addressMode: cardsConfigurationDTO.addressMode)
Expand Down Expand Up @@ -42,11 +42,7 @@ class ConfigurationMapper {
return dropInConfiguration
}

private func determineFieldVisibility(visible: Bool) -> CardComponent.FieldVisibility {
return visible ? .show : .hide
}

private func createStoredCardConfiguration(showCvcForStoredCard: Bool) -> StoredCardConfiguration {
private func createStoredCardConfiguration(showCvcForStoredCard: Bool?) -> StoredCardConfiguration {
var storedCardConfiguration = StoredCardConfiguration()
storedCardConfiguration.showsSecurityCodeField = showCvcForStoredCard
return storedCardConfiguration;
Expand Down Expand Up @@ -94,3 +90,16 @@ class ConfigurationMapper {
merchantIdentifier: applePayConfigurationDTO.merchantId)
}
}


extension FieldVisibility {

func toCardFieldVisibility() -> CardComponent.FieldVisibility {
switch self {
case .show:
return .show
case .hide:
return .hide
}
}
}
1 change: 1 addition & 0 deletions lib/adyen_checkout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export 'src/generated/platform_api.g.dart'
show
Environment,
AddressMode,
FieldVisibility,
CardAuthMethod,
TotalPriceStatus,
PaymentResultEnum,
Expand Down
21 changes: 13 additions & 8 deletions lib/src/generated/platform_api.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ enum DropInResultType {
error,
}

enum FieldVisibility {
show,
hide,
}

class SessionDTO {
SessionDTO({
required this.id,
Expand Down Expand Up @@ -239,8 +244,8 @@ class CardsConfigurationDTO {
required this.showStorePaymentField,
required this.showCvcForStoredCard,
required this.showCvc,
required this.showKcpField,
required this.showSocialSecurityNumberField,
required this.kcpFieldVisibility,
required this.socialSecurityNumberFieldVisibility,
required this.supportedCardTypes,
});

Expand All @@ -254,9 +259,9 @@ class CardsConfigurationDTO {

bool showCvc;

bool showKcpField;
FieldVisibility kcpFieldVisibility;

bool showSocialSecurityNumberField;
FieldVisibility socialSecurityNumberFieldVisibility;

List<String?> supportedCardTypes;

Expand All @@ -267,8 +272,8 @@ class CardsConfigurationDTO {
showStorePaymentField,
showCvcForStoredCard,
showCvc,
showKcpField,
showSocialSecurityNumberField,
kcpFieldVisibility.index,
socialSecurityNumberFieldVisibility.index,
supportedCardTypes,
];
}
Expand All @@ -281,8 +286,8 @@ class CardsConfigurationDTO {
showStorePaymentField: result[2]! as bool,
showCvcForStoredCard: result[3]! as bool,
showCvc: result[4]! as bool,
showKcpField: result[5]! as bool,
showSocialSecurityNumberField: result[6]! as bool,
kcpFieldVisibility: FieldVisibility.values[result[5]! as int],
socialSecurityNumberFieldVisibility: FieldVisibility.values[result[6]! as int],
supportedCardTypes: (result[7] as List<Object?>?)!.cast<String?>(),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ class CardsConfiguration extends CardsConfigurationDTO {
bool showStorePaymentField = false,
bool showCvcForStoredCard = false,
bool showCvc = true,
bool showKcpField = false,
bool showSocialSecurityNumberField = false,
FieldVisibility kcpFieldVisibility = FieldVisibility.hide,
FieldVisibility socialSecurityNumberFieldVisibility = FieldVisibility.hide,
List<String?> supportedCardTypes = const [],
}) : super(
holderNameRequired: holderNameRequired,
addressMode: addressMode,
showStorePaymentField: showStorePaymentField,
showCvcForStoredCard: showCvcForStoredCard,
showCvc: showCvc,
showKcpField: showKcpField,
showSocialSecurityNumberField: showSocialSecurityNumberField,
kcpFieldVisibility: kcpFieldVisibility,
socialSecurityNumberFieldVisibility:
socialSecurityNumberFieldVisibility,
supportedCardTypes: supportedCardTypes,
);
}
16 changes: 9 additions & 7 deletions lib/src/utils/dto_mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ extension CardsConfigurationMapper on CardsConfiguration {
showStorePaymentField: showStorePaymentField,
showCvcForStoredCard: showCvcForStoredCard,
showCvc: showCvc,
showKcpField: showKcpField,
showSocialSecurityNumberField: showSocialSecurityNumberField,
kcpFieldVisibility: kcpFieldVisibility,
socialSecurityNumberFieldVisibility:
socialSecurityNumberFieldVisibility,
supportedCardTypes: supportedCardTypes,
);
}
Expand Down Expand Up @@ -99,8 +100,8 @@ extension CardsConfigurationDTOCopy on CardsConfigurationDTO {
bool? showStorePaymentField,
bool? showCvcForStoredCard,
bool? showCvc,
bool? showKcpField,
bool? showSocialSecurityNumberField,
FieldVisibility? kcpFieldVisibility,
FieldVisibility? socialSecurityNumberFieldVisibility,
List<String?>? supportedCardTypes,
}) =>
CardsConfigurationDTO(
Expand All @@ -110,9 +111,10 @@ extension CardsConfigurationDTOCopy on CardsConfigurationDTO {
showStorePaymentField ?? this.showStorePaymentField,
showCvcForStoredCard: showCvcForStoredCard ?? this.showCvcForStoredCard,
showCvc: showCvc ?? this.showCvc,
showKcpField: showKcpField ?? this.showKcpField,
showSocialSecurityNumberField:
showSocialSecurityNumberField ?? this.showSocialSecurityNumberField,
kcpFieldVisibility: kcpFieldVisibility ?? this.kcpFieldVisibility,
socialSecurityNumberFieldVisibility:
socialSecurityNumberFieldVisibility ??
this.socialSecurityNumberFieldVisibility,
supportedCardTypes: supportedCardTypes ?? this.supportedCardTypes,
);
}
13 changes: 9 additions & 4 deletions pigeons/platform_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ enum DropInResultType {
error,
}

enum FieldVisibility {
show,
hide,
}

class SessionDTO {
final String id;
final String sessionData;
Expand Down Expand Up @@ -133,8 +138,8 @@ class CardsConfigurationDTO {
final bool showStorePaymentField;
final bool showCvcForStoredCard;
final bool showCvc;
final bool showKcpField;
final bool showSocialSecurityNumberField;
final FieldVisibility kcpFieldVisibility;
final FieldVisibility socialSecurityNumberFieldVisibility;
final List<String?> supportedCardTypes;

CardsConfigurationDTO(
Expand All @@ -143,8 +148,8 @@ class CardsConfigurationDTO {
this.showStorePaymentField,
this.showCvcForStoredCard,
this.showCvc,
this.showKcpField,
this.showSocialSecurityNumberField,
this.kcpFieldVisibility,
this.socialSecurityNumberFieldVisibility,
this.supportedCardTypes,
);
}
Expand Down