@@ -1008,11 +1008,6 @@ class PaymentSheet internal constructor(
10081008 Default ,
10091009 }
10101010
1011- enum class LayoutType {
1012- Tabs ,
1013- Accordion
1014- }
1015-
10161011 enum class PaymentMethodsArrangement {
10171012 Default ,
10181013 Grid
@@ -1045,68 +1040,116 @@ class PaymentSheet internal constructor(
10451040 }
10461041 }
10471042
1048- @Parcelize
1049- data class Layout (
1050- /* *
1051- * The type of layout to display payment methods in.
1052- * Can be Tabs or Accordion.
1053- */
1054- val type : LayoutType ? = null ,
1043+ sealed class Layout : Parcelable {
1044+ abstract val bundle: Bundle
1045+
1046+ @Parcelize
1047+ data class Tabs (
1048+ val showOneClickWalletsOnTop : Boolean = true ,
1049+ val paymentMethodsArrangement : PaymentMethodsArrangement = PaymentMethodsArrangement .Default ,
1050+ val savedMethodCustomization : SavedMethodCustomization ? = null
1051+ ) : Layout() {
1052+ override val bundle: Bundle
1053+ get() {
1054+ return Bundle ().apply {
1055+ putString(" type" , " tabs" )
1056+ putBoolean(" showOneClickWalletsOnTop" , showOneClickWalletsOnTop)
1057+ putString(
1058+ " paymentMethodsArrangementForTabs" ,
1059+ paymentMethodsArrangement.name.lowercase()
1060+ )
1061+ putBoolean(" defaultCollapsed" , false )
1062+ putBoolean(" radios" , false )
1063+ putBoolean(" spacedAccordionItems" , false )
1064+ putBundle(" savedMethodCustomization" , savedMethodCustomization?.bundle)
1065+ }
1066+ }
10551067
1056- /* *
1057- * Whether to show one-click wallets (like Google Pay, Apple Pay) at the top of the payment sheet.
1058- */
1059- val showOneClickWalletsOnTop : Boolean? = null ,
1068+ class Builder {
1069+ private var showOneClickWalletsOnTop: Boolean = true
1070+ private var paymentMethodsArrangement: PaymentMethodsArrangement =
1071+ PaymentMethodsArrangement .Default
1072+ private var savedMethodCustomization: SavedMethodCustomization ? = null
10601073
1061- /* *
1062- * The arrangement of payment methods in tabs layout.
1063- * Can be Default or Grid.
1064- */
1065- val paymentMethodsArrangementForTabs : PaymentMethodsArrangement ? = null ,
1074+ fun setShowOneClickWalletsOnTop (value : Boolean ) =
1075+ apply { this .showOneClickWalletsOnTop = value }
10661076
1067- /* *
1068- * Whether accordion items should be collapsed by default.
1069- */
1070- val defaultCollapsed : Boolean? = null ,
1071-
1072- /* *
1073- * Show radio buttons instead of accordion style.
1074- */
1075- val radios : Boolean? = null ,
1077+ fun setPaymentMethodsArrangement (value : PaymentMethodsArrangement ) =
1078+ apply { this .paymentMethodsArrangement = value }
10761079
1077- /* *
1078- * Add spacing between accordion items.
1079- */
1080- val spacedAccordionItems : Boolean? = null ,
1080+ fun setSavedMethodCustomization (value : SavedMethodCustomization ) =
1081+ apply { this .savedMethodCustomization = value }
10811082
1082- /* *
1083- * Maximum number of accordion items to show before "show more".
1084- */
1085- val maxAccordionItems : Int? = null ,
1083+ fun build () = Tabs (
1084+ showOneClickWalletsOnTop,
1085+ paymentMethodsArrangement,
1086+ savedMethodCustomization
1087+ )
1088+ }
1089+ }
10861090
1087- /* *
1088- * Customization options for saved payment methods display.
1089- */
1090- val savedMethodCustomization : SavedMethodCustomization ? = null
1091- ) : Parcelable {
1092- val bundle: Bundle
1093- get() {
1094- return Bundle ().apply {
1095- putString(" type" , type?.name?.lowercase())
1096- putBoolean(" showOneClickWalletsOnTop" , showOneClickWalletsOnTop ? : true )
1097- putString(
1098- " paymentMethodsArrangementForTabs" ,
1099- paymentMethodsArrangementForTabs?.name?.lowercase()
1100- )
1101- putBoolean(" defaultCollapsed" , defaultCollapsed ? : false )
1102- putBoolean(" radios" , radios ? : false )
1103- putBoolean(" spacedAccordionItems" , spacedAccordionItems ? : false )
1104- if (maxAccordionItems != null ) {
1091+ @Parcelize
1092+ data class Accordion (
1093+ val showOneClickWalletsOnTop : Boolean = true ,
1094+ val defaultCollapsed : Boolean = false ,
1095+ val radios : Boolean = false ,
1096+ val spacedAccordionItems : Boolean = false ,
1097+ val maxAccordionItems : Int = 4 ,
1098+ val savedMethodCustomization : SavedMethodCustomization ? = null
1099+ ) : Layout() {
1100+ override val bundle: Bundle
1101+ get() {
1102+ return Bundle ().apply {
1103+ putString(" type" , " accordion" )
1104+ putBoolean(" showOneClickWalletsOnTop" , showOneClickWalletsOnTop)
1105+ putString(
1106+ " paymentMethodsArrangementForTabs" ,
1107+ PaymentMethodsArrangement .Default .name.lowercase()
1108+ )
1109+ putBoolean(" defaultCollapsed" , defaultCollapsed)
1110+ putBoolean(" radios" , radios)
1111+ putBoolean(" spacedAccordionItems" , spacedAccordionItems)
11051112 putInt(" maxAccordionItems" , maxAccordionItems)
1113+ putBundle(" savedMethodCustomization" , savedMethodCustomization?.bundle)
11061114 }
1107- putBundle(" savedMethodCustomization" , savedMethodCustomization?.bundle)
11081115 }
1116+
1117+ class Builder {
1118+ private var showOneClickWalletsOnTop: Boolean = true
1119+ private var defaultCollapsed: Boolean = false
1120+ private var radios: Boolean = false
1121+ private var spacedAccordionItems: Boolean = false
1122+ private var maxAccordionItems: Int = 4
1123+ private var savedMethodCustomization: SavedMethodCustomization ? = null
1124+
1125+ fun setShowOneClickWalletsOnTop (value : Boolean ) =
1126+ apply { this .showOneClickWalletsOnTop = value }
1127+
1128+ fun setDefaultCollapsed (value : Boolean ) =
1129+ apply { this .defaultCollapsed = value }
1130+
1131+ fun setRadios (value : Boolean ) =
1132+ apply { this .radios = value }
1133+
1134+ fun setSpacedAccordionItems (value : Boolean ) =
1135+ apply { this .spacedAccordionItems = value }
1136+
1137+ fun setMaxAccordionItems (value : Int ) =
1138+ apply { this .maxAccordionItems = value }
1139+
1140+ fun setSavedMethodCustomization (value : SavedMethodCustomization ) =
1141+ apply { this .savedMethodCustomization = value }
1142+
1143+ fun build () = Accordion (
1144+ showOneClickWalletsOnTop,
1145+ defaultCollapsed,
1146+ radios,
1147+ spacedAccordionItems,
1148+ maxAccordionItems,
1149+ savedMethodCustomization
1150+ )
11091151 }
1152+ }
11101153 }
11111154
11121155 /* *
0 commit comments