32
32
import static android .app .Activity .RESULT_CANCELED ;
33
33
import static android .app .Activity .RESULT_OK ;
34
34
import static com .affirm .android .AffirmColor .AFFIRM_COLOR_TYPE_BLUE ;
35
+ import static com .affirm .android .AffirmConstants .AFFIRM_NOT_INITIALIZED_MESSAGE ;
35
36
import static com .affirm .android .AffirmConstants .CHECKOUT_ERROR ;
36
37
import static com .affirm .android .AffirmConstants .CHECKOUT_TOKEN ;
37
38
import static com .affirm .android .AffirmConstants .COUNTY_CODE_CAN ;
@@ -566,7 +567,7 @@ public static void initialize(@NonNull Configuration configuration) {
566
567
public static void setPublicKeyAndMerchantName (@ NonNull String publicKey ,
567
568
@ Nullable String merchantName ) {
568
569
if (!isInitialized ()) {
569
- AffirmLog .w ("Affirm has not been initialized" );
570
+ AffirmLog .w (AFFIRM_NOT_INITIALIZED_MESSAGE );
570
571
return ;
571
572
}
572
573
@@ -584,7 +585,7 @@ public static void setPublicKeyAndMerchantName(@NonNull String publicKey,
584
585
*/
585
586
public static void setPublicKey (@ NonNull String publicKey ) {
586
587
if (!isInitialized ()) {
587
- AffirmLog .w ("Affirm has not been initialized" );
588
+ AffirmLog .w (AFFIRM_NOT_INITIALIZED_MESSAGE );
588
589
return ;
589
590
}
590
591
@@ -601,7 +602,7 @@ public static void setPublicKey(@NonNull String publicKey) {
601
602
*/
602
603
public static void setMerchantName (@ Nullable String merchantName ) {
603
604
if (!isInitialized ()) {
604
- AffirmLog .w ("Affirm has not been initialized" );
605
+ AffirmLog .w (AFFIRM_NOT_INITIALIZED_MESSAGE );
605
606
return ;
606
607
}
607
608
@@ -611,6 +612,50 @@ public static void setMerchantName(@Nullable String merchantName) {
611
612
.build ());
612
613
}
613
614
615
+ /**
616
+ * Updates the country code used by Affirm after initialization.
617
+ *
618
+ * @param countryCode Set the country code to be used by Affirm. Must not be null or empty.
619
+ */
620
+ public static void setCountryCode (@ NonNull String countryCode ) {
621
+ if (!isInitialized ()) {
622
+ AffirmLog .w (AFFIRM_NOT_INITIALIZED_MESSAGE );
623
+ return ;
624
+ }
625
+
626
+ if (countryCode .isEmpty ()) {
627
+ AffirmLog .w ("Country code is empty. Please provide a valid country code." );
628
+ return ;
629
+ }
630
+
631
+ AffirmPlugins .get ().setConfiguration (
632
+ new Affirm .Configuration .Builder (AffirmPlugins .get ().getConfiguration ())
633
+ .setCountryCode (countryCode )
634
+ .build ());
635
+ }
636
+
637
+ /**
638
+ * Updates the locale used by Affirm after initialization.
639
+ *
640
+ * @param locale Set the locale to be used by Affirm. Must not be null or empty.
641
+ */
642
+ public static void setLocale (@ NonNull String locale ) {
643
+ if (!isInitialized ()) {
644
+ AffirmLog .w (AFFIRM_NOT_INITIALIZED_MESSAGE );
645
+ return ;
646
+ }
647
+
648
+ if (locale .isEmpty ()) {
649
+ AffirmLog .w ("Locale is empty. Please provide a valid locale string." );
650
+ return ;
651
+ }
652
+
653
+ AffirmPlugins .get ().setConfiguration (
654
+ new Affirm .Configuration .Builder (AffirmPlugins .get ().getConfiguration ())
655
+ .setLocale (locale )
656
+ .build ());
657
+ }
658
+
614
659
private static boolean isInitialized () {
615
660
return AffirmPlugins .get () != null ;
616
661
}
0 commit comments