Skip to content

Commit

Permalink
Merge pull request #84 from Adyen/feature/improveLocalization
Browse files Browse the repository at this point in the history
Improve shopper local
  • Loading branch information
Robert-SD authored Dec 21, 2023
2 parents 9ae1963 + 8c4ff40 commit 6aeef9e
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class CheckoutPlatformApi(
when (configuration) {
is CardComponentConfigurationDTO -> {
return configuration.cardConfiguration.toNativeModel(
"${configuration.shopperLocale}",
activity,
configuration.shopperLocale,
configuration.environment.toNativeModel(),
configuration.clientKey,
configuration.analyticsOptionsDTO.mapToAnalyticsConfiguration(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ data class DropInConfigurationDTO (
val clientKey: String,
val countryCode: String,
val amount: AmountDTO,
val shopperLocale: String,
val shopperLocale: String? = null,
val cardConfigurationDTO: CardConfigurationDTO? = null,
val applePayConfigurationDTO: ApplePayConfigurationDTO? = null,
val googlePayConfigurationDTO: GooglePayConfigurationDTO? = null,
Expand All @@ -272,7 +272,7 @@ data class DropInConfigurationDTO (
val clientKey = list[1] as String
val countryCode = list[2] as String
val amount = AmountDTO.fromList(list[3] as List<Any?>)
val shopperLocale = list[4] as String
val shopperLocale = list[4] as String?
val cardConfigurationDTO: CardConfigurationDTO? = (list[5] as List<Any?>?)?.let {
CardConfigurationDTO.fromList(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ abstract class BaseCardComponent(
private val componentWrapperView = ComponentWrapperView(activity, componentFlutterApi)
private val intentListener = Consumer<Intent> { handleIntent(it) }
val cardConfiguration = configuration.cardConfiguration.toNativeModel(
"${configuration.shopperLocale}",
context,
configuration.shopperLocale,
environment,
configuration.clientKey,
configuration.analyticsOptionsDTO.mapToAnalyticsConfiguration(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ object ConfigurationMapper {
fun DropInConfigurationDTO.mapToDropInConfiguration(context: Context): DropInConfiguration {
val environment = environment.toNativeModel()
val amount = amount.toNativeModel()
val locale = Locale.forLanguageTag(shopperLocale)
val dropInConfiguration = DropInConfiguration.Builder(locale, environment, clientKey)
val dropInConfiguration = buildDropInConfiguration(context, shopperLocale, environment)
val analyticsConfiguration = analyticsOptionsDTO.mapToAnalyticsConfiguration()

isRemoveStoredPaymentMethodEnabled.let {
Expand All @@ -71,8 +70,8 @@ object ConfigurationMapper {

if (cardConfigurationDTO != null) {
val cardConfiguration = cardConfigurationDTO.toNativeModel(
shopperLocale,
context,
shopperLocale,
environment,
clientKey,
analyticsConfiguration,
Expand All @@ -82,32 +81,51 @@ object ConfigurationMapper {
}

if (googlePayConfigurationDTO != null) {
val googlePayConfiguration = buildGooglePayConfiguration(locale, environment, googlePayConfigurationDTO)
val googlePayConfiguration =
buildGooglePayConfiguration(context, shopperLocale, environment, googlePayConfigurationDTO)
dropInConfiguration.addGooglePayConfiguration(googlePayConfiguration)
}

if (cashAppPayConfigurationDTO != null) {
val cashAppPayConfiguration = buildCashAppPayConfiguration(locale, environment, cashAppPayConfigurationDTO)
val cashAppPayConfiguration =
buildCashAppPayConfiguration(context, shopperLocale, environment, cashAppPayConfigurationDTO)
dropInConfiguration.addCashAppPayConfiguration(cashAppPayConfiguration)
}

dropInConfiguration.setAmount(amount)
return dropInConfiguration.build()
}

private fun DropInConfigurationDTO.buildDropInConfiguration(
context: Context,
shopperLocale: String?,
environment: com.adyen.checkout.core.Environment,
): DropInConfiguration.Builder {
return if (shopperLocale != null) {
val locale = Locale.forLanguageTag(shopperLocale)
DropInConfiguration.Builder(locale, environment, clientKey)
} else {
DropInConfiguration.Builder(context, environment, clientKey)
}
}

fun CardConfigurationDTO.toNativeModel(
shopperLocale: String,
context: Context,
shopperLocale: String?,
environment: com.adyen.checkout.core.Environment,
clientKey: String,
analyticsConfiguration: AnalyticsConfiguration,
amount: Amount,
): CardConfiguration {
val locale = Locale.forLanguageTag(shopperLocale)

return CardConfiguration.Builder(
shopperLocale = locale, environment = environment, clientKey = clientKey
).setAddressConfiguration(addressMode.mapToAddressConfiguration())
val cardConfiguration = if (shopperLocale != null) {
val locale = Locale.forLanguageTag(shopperLocale)
CardConfiguration.Builder(locale, environment, clientKey)
} else {
CardConfiguration.Builder(context, environment, clientKey)
}

return cardConfiguration.setAddressConfiguration(addressMode.mapToAddressConfiguration())
.setAmount(amount)
.setShowStorePaymentField(showStorePaymentField).setHideCvcStoredCard(!showCvcForStoredCard)
.setHideCvc(!showCvc).setKcpAuthVisibility(determineKcpAuthVisibility(kcpFieldVisibility))
Expand All @@ -128,24 +146,35 @@ object ConfigurationMapper {
}

private fun DropInConfigurationDTO.buildGooglePayConfiguration(
shopperLocale: Locale,
context: Context,
shopperLocale: String?,
environment: com.adyen.checkout.core.Environment,
googlePayConfigurationDTO: GooglePayConfigurationDTO
): GooglePayConfiguration {
val googlePayConfigurationBuilder = GooglePayConfiguration.Builder(
shopperLocale, environment, clientKey
)

val googlePayConfigurationBuilder = if (shopperLocale != null) {
val locale = Locale.forLanguageTag(shopperLocale)
GooglePayConfiguration.Builder(locale, environment, clientKey)
} else {
GooglePayConfiguration.Builder(context, environment, clientKey)
}

return googlePayConfigurationDTO.mapToGooglePayConfiguration(googlePayConfigurationBuilder)
}

private fun DropInConfigurationDTO.buildCashAppPayConfiguration(
shopperLocale: Locale,
context: Context,
shopperLocale: String?,
environment: com.adyen.checkout.core.Environment,
cashAppPayConfigurationDTO: CashAppPayConfigurationDTO
): CashAppPayConfiguration {
val cashAppPayConfigurationBuilder = CashAppPayConfiguration.Builder(
shopperLocale, environment, clientKey
)
val cashAppPayConfigurationBuilder = if (shopperLocale != null) {
val locale = Locale.forLanguageTag(shopperLocale)
CashAppPayConfiguration.Builder(locale, environment, clientKey)
} else {
CashAppPayConfiguration.Builder(context, environment, clientKey)
}

return cashAppPayConfigurationDTO.mapToCashAppPayConfiguration(cashAppPayConfigurationBuilder)
}

Expand Down
2 changes: 1 addition & 1 deletion example/lib/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Config {
static const String merchantAccount = "TestMerchantCheckout";
static const String merchantName = "Test Merchant";
static const String countryCode = "NL";
static const String shopperLocale = "nl_NL";
static const String shopperLocale = "nl-NL";
static const String shopperReference = "Test reference";
static const Environment environment = Environment.test;
static const String baseUrl = "checkout-test.adyen.com";
Expand Down
4 changes: 2 additions & 2 deletions ios/Classes/PlatformApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ struct DropInConfigurationDTO {
var clientKey: String
var countryCode: String
var amount: AmountDTO
var shopperLocale: String
var shopperLocale: String? = nil
var cardConfigurationDTO: CardConfigurationDTO? = nil
var applePayConfigurationDTO: ApplePayConfigurationDTO? = nil
var googlePayConfigurationDTO: GooglePayConfigurationDTO? = nil
Expand All @@ -201,7 +201,7 @@ struct DropInConfigurationDTO {
let clientKey = list[1] as! String
let countryCode = list[2] as! String
let amount = AmountDTO.fromList(list[3] as! [Any?])!
let shopperLocale = list[4] as! String
let shopperLocale: String? = nilOrValue(list[4])
var cardConfigurationDTO: CardConfigurationDTO? = nil
if let cardConfigurationDTOList: [Any?] = nilOrValue(list[5]) {
cardConfigurationDTO = CardConfigurationDTO.fromList(cardConfigurationDTOList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CardAdvancedComponent: BaseCardComponent {
cardComponentConfiguration: CardComponentConfigurationDTO
) throws -> CardComponent {
let adyenContext = try cardComponentConfiguration.createAdyenContext()
let cardConfiguration = cardComponentConfiguration.cardConfiguration.mapToCardComponentConfiguration()
let cardConfiguration = cardComponentConfiguration.cardConfiguration.mapToCardComponentConfiguration(shopperLocale: cardComponentConfiguration.shopperLocale)
let paymentMethod: AnyCardPaymentMethod = isStoredPaymentMethod ? try JSONDecoder().decode(StoredCardPaymentMethod.self, from: Data(paymentMethodString.utf8)) : try JSONDecoder().decode(CardPaymentMethod.self, from: Data(paymentMethodString.utf8))
presentationDelegate = CardPresentationDelegate(topViewController: getViewController())
actionComponent = buildActionComponent(adyenContext: adyenContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CardSessionComponent: BaseCardComponent {
session: AdyenSession
) throws -> CardComponent {
let adyenContext = try cardComponentConfiguration.createAdyenContext()
let cardConfiguration = cardComponentConfiguration.cardConfiguration.mapToCardComponentConfiguration()
let cardConfiguration = cardComponentConfiguration.cardConfiguration.mapToCardComponentConfiguration(shopperLocale: cardComponentConfiguration.shopperLocale)
/*
let paymentMethod: AnyCardPaymentMethod = isStoredPaymentMethod ? try JSONDecoder().decode(StoredCardPaymentMethod.self, from: Data(paymentMethodString.utf8)) : try JSONDecoder().decode(CardPaymentMethod.self, from: Data(paymentMethodString.utf8))
*/
Expand Down
8 changes: 6 additions & 2 deletions ios/Classes/utils/ConfigurationMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class ConfigurationMapper {
allowedCardTypes: allowedCardTypes,
billingAddress: billingAddressConfiguration
)

if let shopperLocal = dropInConfigurationDTO.shopperLocale {
dropInConfiguration.localizationParameters = LocalizationParameters(enforcedLocale: shopperLocal)
}
dropInConfiguration.card = cardConfiguration
}

Expand Down Expand Up @@ -114,16 +116,18 @@ extension DropInConfigurationDTO {
}

extension CardConfigurationDTO {
func mapToCardComponentConfiguration() -> CardComponent.Configuration {
func mapToCardComponentConfiguration(shopperLocale : String?) -> CardComponent.Configuration {
var formComponentStyle = FormComponentStyle()
formComponentStyle.backgroundColor = UIColor.white
let localizationParameters = shopperLocale != nil ? LocalizationParameters(enforcedLocale: shopperLocale!) : nil
let koreanAuthenticationMode = kcpFieldVisibility.toCardFieldVisibility()
let socialSecurityNumberMode = socialSecurityNumberFieldVisibility.toCardFieldVisibility()
let storedCardConfiguration = createStoredCardConfiguration(showCvcForStoredCard: showCvcForStoredCard)
let allowedCardTypes = determineAllowedCardTypes(cardTypes: supportedCardTypes)
let billingAddressConfiguration = determineBillingAddressConfiguration(addressMode: addressMode)
return CardComponent.Configuration(
style: formComponentStyle,
localizationParameters: localizationParameters,
showsHolderNameField: holderNameRequired,
showsStorePaymentMethodField: showStorePaymentField,
showsSecurityCodeField: showCvc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class CardComponentConfiguration extends BaseConfiguration {
required super.clientKey,
required super.countryCode,
required super.amount,
required super.shopperLocale,
super.shopperLocale,
CardConfiguration? cardConfiguration,
AnalyticsOptions? analyticsOptions,
}) : cardConfiguration = cardConfiguration ?? const CardConfiguration(),
Expand Down
6 changes: 3 additions & 3 deletions lib/src/generated/platform_api.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class DropInConfigurationDTO {
required this.clientKey,
required this.countryCode,
required this.amount,
required this.shopperLocale,
this.shopperLocale,
this.cardConfigurationDTO,
this.applePayConfigurationDTO,
this.googlePayConfigurationDTO,
Expand All @@ -201,7 +201,7 @@ class DropInConfigurationDTO {

AmountDTO amount;

String shopperLocale;
String? shopperLocale;

CardConfigurationDTO? cardConfigurationDTO;

Expand Down Expand Up @@ -244,7 +244,7 @@ class DropInConfigurationDTO {
clientKey: result[1]! as String,
countryCode: result[2]! as String,
amount: AmountDTO.decode(result[3]! as List<Object?>),
shopperLocale: result[4]! as String,
shopperLocale: result[4] as String?,
cardConfigurationDTO: result[5] != null
? CardConfigurationDTO.decode(result[5]! as List<Object?>)
: null,
Expand Down
2 changes: 1 addition & 1 deletion pigeons/platform_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class DropInConfigurationDTO {
final String clientKey;
final String countryCode;
final AmountDTO amount;
final String shopperLocale;
final String? shopperLocale;
final CardConfigurationDTO? cardConfigurationDTO;
final ApplePayConfigurationDTO? applePayConfigurationDTO;
final GooglePayConfigurationDTO? googlePayConfigurationDTO;
Expand Down

0 comments on commit 6aeef9e

Please sign in to comment.