Skip to content

Commit 262575e

Browse files
committed
feat: support set country code and locale after initialization
1 parent a2dc655 commit 262575e

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

affirm/src/main/java/com/affirm/android/Affirm.java

+44
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,50 @@ public static void setMerchantName(@Nullable String merchantName) {
611611
.build());
612612
}
613613

614+
/**
615+
* Updates the country code used by Affirm after initialization.
616+
*
617+
* @param countryCode Set the country code to be used by Affirm. Must not be null or empty.
618+
*/
619+
public static void setCountryCode(@NonNull String countryCode) {
620+
if (!isInitialized()) {
621+
AffirmLog.w("Affirm has not been initialized");
622+
return;
623+
}
624+
625+
if (countryCode.isEmpty()) {
626+
AffirmLog.w("Country code is empty. Please provide a valid country code.");
627+
return;
628+
}
629+
630+
AffirmPlugins.get().setConfiguration(
631+
new Affirm.Configuration.Builder(AffirmPlugins.get().getConfiguration())
632+
.setCountryCode(countryCode)
633+
.build());
634+
}
635+
636+
/**
637+
* Updates the locale used by Affirm after initialization.
638+
*
639+
* @param locale Set the locale to be used by Affirm. Must not be null or empty.
640+
*/
641+
public static void setLocale(@NonNull String locale) {
642+
if (!isInitialized()) {
643+
AffirmLog.w("Affirm has not been initialized");
644+
return;
645+
}
646+
647+
if (locale.isEmpty()) {
648+
AffirmLog.w("Locale is empty. Please provide a valid locale string.");
649+
return;
650+
}
651+
652+
AffirmPlugins.get().setConfiguration(
653+
new Affirm.Configuration.Builder(AffirmPlugins.get().getConfiguration())
654+
.setLocale(locale)
655+
.build());
656+
}
657+
614658
private static boolean isInitialized() {
615659
return AffirmPlugins.get() != null;
616660
}

0 commit comments

Comments
 (0)