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

Move BillingDetailsCollectionConfiguration into PaymentSheet #6551

Merged
merged 11 commits into from
Apr 17, 2023
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## XX.XX.XX - 2023-XX-XX

## 20.23.1 - 2023-04-17

### PaymentSheet
* [FIXED][6551](https://github.com/stripe/stripe-android/pull/6551) Fixed a build issue where `BillingDetailsCollectionConfiguration` couldn't be found in the classpath. If you worked around this issue by importing `payments-ui-core` directly, you can undo this change and need to update the import of `BillingDetailsCollectionConfiguration`.
tillh-stripe marked this conversation as resolved.
Show resolved Hide resolved

## 20.23.0 - 2023-04-17

### PaymentSheet
Expand Down
25 changes: 0 additions & 25 deletions payments-ui-core/api/payments-ui-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,6 @@ public final class com/stripe/android/ui/core/Amount$Creator : android/os/Parcel
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/ui/core/BillingDetailsCollectionConfiguration : android/os/Parcelable {
public static final field $stable I
public static final field CREATOR Landroid/os/Parcelable$Creator;
public fun <init> ()V
public fun <init> (Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$CollectionMode;Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$CollectionMode;Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$CollectionMode;Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$AddressCollectionMode;Z)V
public synthetic fun <init> (Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$CollectionMode;Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$CollectionMode;Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$CollectionMode;Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$AddressCollectionMode;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$CollectionMode;
public final fun component2 ()Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$CollectionMode;
public final fun component3 ()Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$CollectionMode;
public final fun component4 ()Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$AddressCollectionMode;
public final fun component5 ()Z
public final fun copy (Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$CollectionMode;Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$CollectionMode;Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$CollectionMode;Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$AddressCollectionMode;Z)Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration;
public static synthetic fun copy$default (Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration;Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$CollectionMode;Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$CollectionMode;Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$CollectionMode;Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$AddressCollectionMode;ZILjava/lang/Object;)Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration;
public fun describeContents ()I
public fun equals (Ljava/lang/Object;)Z
public final fun getAddress ()Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$AddressCollectionMode;
public final fun getAttachDefaultsToPaymentMethod ()Z
public final fun getEmail ()Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$CollectionMode;
public final fun getName ()Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$CollectionMode;
public final fun getPhone ()Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$CollectionMode;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
public fun writeToParcel (Landroid/os/Parcel;I)V
}

public final class com/stripe/android/ui/core/BillingDetailsCollectionConfiguration$AddressCollectionMode : java/lang/Enum {
public static final field Automatic Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$AddressCollectionMode;
public static final field Full Lcom/stripe/android/ui/core/BillingDetailsCollectionConfiguration$AddressCollectionMode;
Expand Down
4 changes: 2 additions & 2 deletions payments-ui-core/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<ID>ConstructorParameterNaming:CardNumberElement.kt$CardNumberElement$val _identifier: IdentifierSpec</ID>
<ID>ConstructorParameterNaming:CvcElement.kt$CvcElement$val _identifier: IdentifierSpec</ID>
<ID>CyclomaticComplexMethod:FormItemSpec.kt$FormItemSpecSerializer$override fun selectDeserializer(element: JsonElement): DeserializationStrategy&lt;out FormItemSpec></ID>
<ID>CyclomaticComplexMethod:LpmRepository.kt$LpmRepository$private fun convertToSupportedPaymentMethod( stripeIntent: StripeIntent, sharedDataSpec: SharedDataSpec, billingDetailsCollectionConfiguration: BillingDetailsCollectionConfiguration = BillingDetailsCollectionConfiguration() )</ID>
<ID>CyclomaticComplexMethod:LpmRepository.kt$LpmRepository$private fun convertToSupportedPaymentMethod( stripeIntent: StripeIntent, sharedDataSpec: SharedDataSpec, billingDetailsCollectionConfiguration: BillingDetailsCollectionConfiguration, )</ID>
<ID>CyclomaticComplexMethod:TransformGoogleToStripeAddress.kt$@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) fun Place.transformGoogleToStripeAddress( context: Context ): com.stripe.android.model.Address</ID>
<ID>CyclomaticComplexMethod:TransformSpecToElements.kt$TransformSpecToElements$fun transform(list: List&lt;FormItemSpec>): List&lt;FormElement></ID>
<ID>EmptyFunctionBlock:CardNumberViewOnlyController.kt$CardNumberViewOnlyController${}</ID>
<ID>ForbiddenComment:Menu.kt$// TODO: Make sure this gets the rounded corner values</ID>
<ID>LongMethod:LpmRepository.kt$LpmRepository$private fun convertToSupportedPaymentMethod( stripeIntent: StripeIntent, sharedDataSpec: SharedDataSpec, billingDetailsCollectionConfiguration: BillingDetailsCollectionConfiguration = BillingDetailsCollectionConfiguration() )</ID>
<ID>LongMethod:LpmRepository.kt$LpmRepository$private fun convertToSupportedPaymentMethod( stripeIntent: StripeIntent, sharedDataSpec: SharedDataSpec, billingDetailsCollectionConfiguration: BillingDetailsCollectionConfiguration, )</ID>
<ID>LongMethod:Menu.kt$@Suppress("ModifierParameter") @Composable internal fun DropdownMenuContent( expandedStates: MutableTransitionState&lt;Boolean>, transformOriginState: MutableState&lt;TransformOrigin>, initialFirstVisibleItemIndex: Int, modifier: Modifier = Modifier, content: LazyListScope.() -> Unit )</ID>
<ID>LongMethod:TransformGoogleToStripeAddress.kt$@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) fun Place.transformGoogleToStripeAddress( context: Context ): com.stripe.android.model.Address</ID>
<ID>LongMethod:TransformGoogleToStripeAddressTest.kt$TransformGoogleToStripeAddressTest$@Test fun `test JP address`()</ID>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.stripe.android.ui.core

import android.os.Parcelable
import androidx.annotation.RestrictTo
import kotlinx.parcelize.Parcelize

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@Parcelize
data class CardBillingDetailsCollectionConfiguration(
val collectName: Boolean = false,
val collectEmail: Boolean = false,
val collectPhone: Boolean = false,
val address: AddressCollectionMode = AddressCollectionMode.Automatic,
) : Parcelable {

val collectAddress: Boolean
get() = address != AddressCollectionMode.Never

enum class AddressCollectionMode {
Automatic,
Never,
Full,
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.stripe.android.ui.core.elements

import androidx.annotation.RestrictTo
import com.stripe.android.ui.core.BillingDetailsCollectionConfiguration
import com.stripe.android.ui.core.CardBillingDetailsCollectionConfiguration
import com.stripe.android.uicore.address.AddressRepository
import com.stripe.android.uicore.address.FieldType
import com.stripe.android.uicore.elements.AddressElement
Expand Down Expand Up @@ -30,8 +30,8 @@ class CardBillingAddressElement(
),
sameAsShippingElement: SameAsShippingElement?,
shippingValuesMap: Map<IdentifierSpec, String?>?,
private val collectionMode: BillingDetailsCollectionConfiguration.AddressCollectionMode =
BillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic,
private val collectionMode: CardBillingDetailsCollectionConfiguration.AddressCollectionMode =
CardBillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic,
) : AddressElement(
identifier,
addressRepository,
Expand All @@ -47,15 +47,15 @@ class CardBillingAddressElement(
val hiddenIdentifiers: Flow<Set<IdentifierSpec>> =
countryDropdownFieldController.rawFieldValue.map { countryCode ->
when (collectionMode) {
BillingDetailsCollectionConfiguration.AddressCollectionMode.Never -> {
CardBillingDetailsCollectionConfiguration.AddressCollectionMode.Never -> {
FieldType.values()
.map { it.identifierSpec }
.toSet()
}
BillingDetailsCollectionConfiguration.AddressCollectionMode.Full -> {
CardBillingDetailsCollectionConfiguration.AddressCollectionMode.Full -> {
emptySet()
}
BillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic -> {
CardBillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic -> {
when (countryCode) {
"US", "GB", "CA" -> {
FieldType.values()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.stripe.android.ui.core.elements

import androidx.annotation.RestrictTo
import com.stripe.android.ui.core.BillingDetailsCollectionConfiguration
import com.stripe.android.ui.core.CardBillingDetailsCollectionConfiguration
import com.stripe.android.ui.core.R
import com.stripe.android.uicore.address.AddressRepository
import com.stripe.android.uicore.elements.IdentifierSpec
Expand All @@ -20,15 +20,15 @@ data class CardBillingSpec(
@SerialName("allowed_country_codes")
val allowedCountryCodes: Set<String> = supportedBillingCountries,
@SerialName("collection_mode")
val collectionMode: BillingDetailsCollectionConfiguration.AddressCollectionMode =
BillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic,
val collectionMode: CardBillingDetailsCollectionConfiguration.AddressCollectionMode =
CardBillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic,
) : FormItemSpec() {
fun transform(
initialValues: Map<IdentifierSpec, String?>,
addressRepository: AddressRepository,
shippingValues: Map<IdentifierSpec, String?>?,
): SectionElement? {
if (collectionMode == BillingDetailsCollectionConfiguration.AddressCollectionMode.Never) {
if (collectionMode == CardBillingDetailsCollectionConfiguration.AddressCollectionMode.Never) {
tillh-stripe marked this conversation as resolved.
Show resolved Hide resolved
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import com.stripe.android.paymentsheet.forms.SofortRequirement
import com.stripe.android.paymentsheet.forms.USBankAccountRequirement
import com.stripe.android.paymentsheet.forms.UpiRequirement
import com.stripe.android.paymentsheet.forms.ZipRequirement
import com.stripe.android.ui.core.BillingDetailsCollectionConfiguration
import com.stripe.android.ui.core.CardBillingDetailsCollectionConfiguration
import com.stripe.android.ui.core.R
import com.stripe.android.ui.core.elements.AfterpayClearpayHeaderElement.Companion.isClearpay
import com.stripe.android.ui.core.elements.CardBillingSpec
Expand Down Expand Up @@ -115,8 +115,8 @@ class LpmRepository constructor(
fun update(
stripeIntent: StripeIntent,
serverLpmSpecs: String?,
billingDetailsCollectionConfiguration: BillingDetailsCollectionConfiguration =
BillingDetailsCollectionConfiguration(),
cardBillingDetailsCollectionConfiguration: CardBillingDetailsCollectionConfiguration =
CardBillingDetailsCollectionConfiguration(),
) {
val expectedLpms = stripeIntent.paymentMethodTypes

Expand All @@ -127,7 +127,7 @@ class LpmRepository constructor(
if (serverLpmObjects.isNotEmpty()) {
serverSpecLoadingState = ServerSpecState.ServerParsed(serverLpmSpecs)
}
update(stripeIntent, serverLpmObjects, billingDetailsCollectionConfiguration)
update(stripeIntent, serverLpmObjects, cardBillingDetailsCollectionConfiguration)
}

// If the server does not return specs, or they are not parsed successfully
Expand All @@ -145,7 +145,7 @@ class LpmRepository constructor(
lpmsNotParsedFromServerSpec
.mapNotNull { mapFromDisk?.get(it) }
.mapNotNull {
convertToSupportedPaymentMethod(stripeIntent, it, billingDetailsCollectionConfiguration)
convertToSupportedPaymentMethod(stripeIntent, it, cardBillingDetailsCollectionConfiguration)
}
.associateBy { it.code }
)
Expand All @@ -169,8 +169,8 @@ class LpmRepository constructor(
private fun update(
stripeIntent: StripeIntent,
lpms: List<SharedDataSpec>?,
billingDetailsCollectionConfiguration: BillingDetailsCollectionConfiguration =
BillingDetailsCollectionConfiguration(),
cardBillingDetailsCollectionConfiguration: CardBillingDetailsCollectionConfiguration =
CardBillingDetailsCollectionConfiguration(),
) {
val parsedSharedData = lpms
?.filter { supportsPaymentMethod(it.type) }
Expand All @@ -182,7 +182,7 @@ class LpmRepository constructor(
// By mapNotNull we will not accept any LPMs that are not known by the platform.
parsedSharedData
?.mapNotNull {
convertToSupportedPaymentMethod(stripeIntent, it, billingDetailsCollectionConfiguration)
convertToSupportedPaymentMethod(stripeIntent, it, cardBillingDetailsCollectionConfiguration)
}
?.toMutableList()
?.let {
Expand Down Expand Up @@ -216,8 +216,7 @@ class LpmRepository constructor(
private fun convertToSupportedPaymentMethod(
stripeIntent: StripeIntent,
sharedDataSpec: SharedDataSpec,
billingDetailsCollectionConfiguration: BillingDetailsCollectionConfiguration =
BillingDetailsCollectionConfiguration()
cardBillingDetailsCollectionConfiguration: CardBillingDetailsCollectionConfiguration,
) = when (sharedDataSpec.type) {
PaymentMethod.Type.Card.code -> SupportedPaymentMethod(
code = "card",
Expand All @@ -230,7 +229,7 @@ class LpmRepository constructor(
tintIconOnSelection = true,
requirement = CardRequirement,
formSpec = if (sharedDataSpec.fields.isEmpty() || sharedDataSpec.fields == listOf(EmptyFormSpec)) {
hardcodedCardSpec(billingDetailsCollectionConfiguration).formSpec
hardcodedCardSpec(cardBillingDetailsCollectionConfiguration).formSpec
} else {
LayoutSpec(sharedDataSpec.fields)
}
Expand Down Expand Up @@ -562,29 +561,25 @@ class LpmRepository constructor(
}

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
val HardcodedCard = hardcodedCardSpec(BillingDetailsCollectionConfiguration())
val HardcodedCard = hardcodedCardSpec(CardBillingDetailsCollectionConfiguration())

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
fun hardcodedCardSpec(
billingDetailsCollectionConfiguration: BillingDetailsCollectionConfiguration
billingDetailsCollectionConfiguration: CardBillingDetailsCollectionConfiguration
): SupportedPaymentMethod {
val specs = listOfNotNull(
ContactInformationSpec(
collectName = false,
collectEmail = billingDetailsCollectionConfiguration.email ==
BillingDetailsCollectionConfiguration.CollectionMode.Always,
collectPhone = billingDetailsCollectionConfiguration.phone ==
BillingDetailsCollectionConfiguration.CollectionMode.Always
collectEmail = billingDetailsCollectionConfiguration.collectEmail,
collectPhone = billingDetailsCollectionConfiguration.collectPhone,
),
CardDetailsSectionSpec(
collectName = billingDetailsCollectionConfiguration.name ==
BillingDetailsCollectionConfiguration.CollectionMode.Always,
collectName = billingDetailsCollectionConfiguration.collectName,
),
CardBillingSpec(
collectionMode = billingDetailsCollectionConfiguration.address,
).takeIf {
billingDetailsCollectionConfiguration.address !=
BillingDetailsCollectionConfiguration.AddressCollectionMode.Never
billingDetailsCollectionConfiguration.collectAddress
},
SaveForFutureUseSpec(),
)
Expand Down
Loading