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

feat: Add android locale support #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -92,8 +93,14 @@ class FlutterAdyenPlugin :
val lineItemString = JSONObject(lineItem).toString()
val additionalDataString = JSONObject(additionalData).toString()
val localeString = call.argument<String>("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")
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -141,6 +149,7 @@ class FlutterAdyenPlugin :

val dropInConfiguration = DropInConfiguration.Builder(nonNullActivity, AdyenDropinService::class.java, clientKey)
.addCardConfiguration(cardConfiguration)
.setShopperLocale(shopperLocale)
.setEnvironment(environment)
.build()

Expand Down Expand Up @@ -422,4 +431,4 @@ private fun serializePaymentsRequest(paymentsRequest: PaymentsRequest): JSONObje
val request = JSONObject(jsonString)
print(request)
return request
}
}