diff --git a/android/src/main/kotlin/app/adyen/flutter_adyen/FlutterAdyenPlugin.kt b/android/src/main/kotlin/app/adyen/flutter_adyen/FlutterAdyenPlugin.kt index d3ab6f4..ef44de6 100644 --- a/android/src/main/kotlin/app/adyen/flutter_adyen/FlutterAdyenPlugin.kt +++ b/android/src/main/kotlin/app/adyen/flutter_adyen/FlutterAdyenPlugin.kt @@ -9,6 +9,7 @@ import com.adyen.checkout.components.model.payments.Amount import com.adyen.checkout.components.model.payments.request.PaymentComponentData import com.adyen.checkout.components.model.payments.request.PaymentMethodDetails import com.adyen.checkout.core.api.Environment +import com.adyen.checkout.core.util.LocaleUtil import com.adyen.checkout.dropin.DropIn import com.adyen.checkout.dropin.DropInConfiguration import com.adyen.checkout.dropin.service.DropInService @@ -92,8 +93,14 @@ class FlutterAdyenPlugin : val lineItemString = JSONObject(lineItem).toString() val additionalDataString = JSONObject(additionalData).toString() val localeString = call.argument("locale") ?: "de_DE" - val countryCode = localeString.split("_").last() + val localeParts = localeString.split("_") + val countryCode = localeParts.last() + var locale = Locale(countryCode) + if (localeParts.size > 1) { + locale = Locale(localeParts[0], localeParts[1]) + } + /* Log.e("[Flutter Adyen]", "Client Key from Flutter: $clientKey") Log.e("[Flutter Adyen]", "Environment from Flutter: $env") @@ -103,7 +110,8 @@ class FlutterAdyenPlugin : Log.e("[Flutter Adyen]", "Base URL from Flutter: $baseUrl") Log.e("[Flutter Adyen]", "Currency from Flutter: $currency") Log.e("[Flutter Adyen]", "Shopper Reference from Flutter: $shopperReference") - */ + */ + val environment = when (env) { "LIVE_US" -> Environment.UNITED_STATES @@ -117,9 +125,9 @@ class FlutterAdyenPlugin : try { val jsonObject = JSONObject(paymentMethods ?: "") val paymentMethodsApiResponse = PaymentMethodsApiResponse.SERIALIZER.deserialize(jsonObject) - val shopperLocale = Locale.GERMANY - // val shopperLocale = if (LocaleUtil.isValidLocale(locale)) locale else LocaleUtil.getLocale(nonNullActivity) + // val shopperLocale = Locale.GERMANY // Log.e("[Flutter Adyen] SHOPPER LOCALE", "Shopper Locale from localeString $localeString: $shopperLocale") + val shopperLocale = if (LocaleUtil.isValidLocale(locale)) locale else LocaleUtil.getLocale(nonNullActivity) val cardConfiguration = CardConfiguration.Builder(nonNullActivity, clientKey!!) .setHolderNameRequired(true) .setShopperLocale(shopperLocale) @@ -141,6 +149,7 @@ class FlutterAdyenPlugin : val dropInConfiguration = DropInConfiguration.Builder(nonNullActivity, AdyenDropinService::class.java, clientKey) .addCardConfiguration(cardConfiguration) + .setShopperLocale(shopperLocale) .setEnvironment(environment) .build() @@ -422,4 +431,4 @@ private fun serializePaymentsRequest(paymentsRequest: PaymentsRequest): JSONObje val request = JSONObject(jsonString) print(request) return request -} +} \ No newline at end of file