Skip to content
Merged
Show file tree
Hide file tree
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 @@ -187,6 +187,7 @@ private class FinancialConnectionsConsumerSessionRepositoryImpl(
email = email,
phoneNumber = phoneNumber,
country = country,
countryInferringMethod = "PHONE_NUMBER",
name = null,
locale = locale,
amount = elementsSessionContext?.amount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ sealed class PaymentMethodExtraParams(
@Parcelize
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
data class Card(
val setAsDefault: Boolean? = null
val setAsDefault: Boolean? = null,
val phoneNumberCountry: String? = null,
) : PaymentMethodExtraParams(PaymentMethod.Type.Card) {
override fun createTypeParams(): List<Pair<String, Any?>> {
return listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SignUpParamsTest {
email = "[email protected]",
phoneNumber = "1234567890",
country = "US",
countryInferringMethod = "PHONE_NUMBER",
name = "John Doe",
locale = locale,
amount = 1000L,
Expand Down Expand Up @@ -50,6 +51,7 @@ class SignUpParamsTest {
email = "[email protected]",
phoneNumber = "1234567890",
country = "US",
countryInferringMethod = "PHONE_NUMBER",
name = null,
locale = null,
amount = null,
Expand Down Expand Up @@ -79,6 +81,7 @@ class SignUpParamsTest {
email = "[email protected]",
phoneNumber = "1234567890",
country = "US",
countryInferringMethod = "PHONE_NUMBER",
name = "",
locale = Locale.US,
amount = 1000L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data class SignUpParams(
val email: String,
val phoneNumber: String?,
val country: String?,
val countryInferringMethod: String,
val name: String?,
val locale: Locale?,
val amount: Long?,
Expand All @@ -24,7 +25,8 @@ data class SignUpParams(
"amount" to amount,
"currency" to currency,
"consent_action" to consentAction.value,
"request_surface" to requestSurface
"request_surface" to requestSurface,
"country_inferring_method" to countryInferringMethod,
)

locale?.let {
Expand All @@ -33,7 +35,6 @@ data class SignUpParams(

phoneNumber?.takeIf { it.isNotBlank() }?.let {
params["phone_number"] = it
params["country_inferring_method"] = "PHONE_NUMBER"
}

country?.takeIf { it.isNotBlank() }?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class ConsumersApiServiceImplTest {
email = email,
phoneNumber = "+15555555568",
country = "US",
countryInferringMethod = "PHONE_NUMBER",
name = null,
locale = Locale.US,
amount = 1234,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ class FieldValuesToParamsMapConverter {
)
PaymentMethod.Type.Card.code -> PaymentMethodExtraParams.Card(
setAsDefault =
fieldValuePairsForExtras[IdentifierSpec.SetAsDefaultPaymentMethod]?.value?.toBoolean()
fieldValuePairsForExtras[IdentifierSpec.SetAsDefaultPaymentMethod]?.value?.toBoolean(),
phoneNumberCountry = fieldValuePairsForExtras[IdentifierSpec.PhoneNumberCountry]?.value,
)
PaymentMethod.Type.Link.code -> PaymentMethodExtraParams.Link(
setAsDefault =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ internal class LinkControllerInteractor @Inject constructor(
email = email,
phoneNumber = phone,
country = country,
countryInferringMethod = "PHONE_NUMBER",
name = name,
consentAction = SignUpConsentAction.Implied
).toResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ internal class DefaultLinkAccountManager @Inject constructor(
is UserInput.SignUp -> signUpIfValidSessionState(
email = userInput.email,
country = userInput.country,
countryInferringMethod = userInput.countryInferringMethod,
phone = userInput.phone,
name = userInput.name,
consentAction = userInput.consentAction,
Expand Down Expand Up @@ -189,6 +190,7 @@ internal class DefaultLinkAccountManager @Inject constructor(
email: String,
phone: String?,
country: String?,
countryInferringMethod: String,
name: String?,
consentAction: SignUpConsentAction
): Result<LinkAccount> {
Expand Down Expand Up @@ -223,6 +225,7 @@ internal class DefaultLinkAccountManager @Inject constructor(
email = email,
phone = phone,
country = country,
countryInferringMethod = countryInferringMethod,
name = name,
consentAction = consentAction
).onSuccess {
Expand All @@ -238,23 +241,31 @@ internal class DefaultLinkAccountManager @Inject constructor(
email: String,
phone: String?,
country: String?,
countryInferringMethod: String,
name: String?,
consentAction: SignUpConsentAction
): Result<LinkAccount> =
linkRepository.consumerSignUp(email, phone, country, name, consentAction.consumerAction)
.map { consumerSessionSignup ->
setAccount(
consumerSession = consumerSessionSignup.consumerSession,
publishableKey = consumerSessionSignup.publishableKey,
displayablePaymentDetails = null,
linkAuthIntentInfo = null,
)
}
linkRepository.consumerSignUp(
email = email,
phone = phone,
country = country,
countryInferringMethod = countryInferringMethod,
name = name,
consentAction = consentAction.consumerAction
).map { consumerSessionSignup ->
setAccount(
consumerSession = consumerSessionSignup.consumerSession,
publishableKey = consumerSessionSignup.publishableKey,
displayablePaymentDetails = null,
linkAuthIntentInfo = null,
)
}

override suspend fun mobileSignUp(
email: String,
phone: String,
country: String,
countryInferringMethod: String,
name: String?,
verificationToken: String,
appId: String,
Expand All @@ -265,6 +276,7 @@ internal class DefaultLinkAccountManager @Inject constructor(
email = email,
phoneNumber = phone,
country = country,
countryInferringMethod = countryInferringMethod,
consentAction = consentAction.consumerAction,
verificationToken = verificationToken,
appId = appId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ internal class DefaultLinkAuth @Inject constructor(
email: String,
phoneNumber: String,
country: String,
countryInferringMethod: String,
name: String?,
consentAction: SignUpConsentAction
): LinkAuthResult {
Expand All @@ -32,6 +33,7 @@ internal class DefaultLinkAuth @Inject constructor(
email = email,
phoneNumber = phoneNumber,
country = country,
countryInferringMethod = countryInferringMethod,
name = name,
consentAction = consentAction
)
Expand All @@ -40,6 +42,7 @@ internal class DefaultLinkAuth @Inject constructor(
email = email,
phone = phoneNumber,
country = country,
countryInferringMethod = countryInferringMethod,
name = name,
consentAction = consentAction
)
Expand Down Expand Up @@ -75,6 +78,7 @@ internal class DefaultLinkAuth @Inject constructor(
email: String,
phoneNumber: String,
country: String,
countryInferringMethod: String,
name: String?,
consentAction: SignUpConsentAction
): Result<LinkAccount> {
Expand All @@ -84,6 +88,7 @@ internal class DefaultLinkAuth @Inject constructor(
email = email,
phone = phoneNumber,
country = country,
countryInferringMethod = countryInferringMethod,
name = name,
consentAction = consentAction,
verificationToken = verificationToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ internal interface LinkAccountManager {
email: String,
phone: String?,
country: String?,
countryInferringMethod: String,
name: String?,
consentAction: SignUpConsentAction
): Result<LinkAccount>
Expand All @@ -90,6 +91,7 @@ internal interface LinkAccountManager {
email: String,
phone: String,
country: String,
countryInferringMethod: String,
name: String?,
verificationToken: String,
appId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ internal interface LinkAuth {
email: String,
phoneNumber: String,
country: String,
countryInferringMethod: String,
name: String?,
consentAction: SignUpConsentAction
): LinkAuthResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ internal class LinkApiRepository @Inject constructor(
email: String,
phone: String?,
country: String?,
countryInferringMethod: String,
name: String?,
consentAction: ConsumerSignUpConsentAction
): Result<ConsumerSessionSignup> = withContext(workContext) {
Expand All @@ -140,6 +141,7 @@ internal class LinkApiRepository @Inject constructor(
email = email,
phoneNumber = phone,
country = country,
countryInferringMethod = countryInferringMethod,
name = name,
locale = locale,
amount = null,
Expand All @@ -157,6 +159,7 @@ internal class LinkApiRepository @Inject constructor(
email: String,
phoneNumber: String,
country: String,
countryInferringMethod: String,
consentAction: ConsumerSignUpConsentAction,
amount: Long?,
currency: String?,
Expand All @@ -169,6 +172,7 @@ internal class LinkApiRepository @Inject constructor(
email = email,
phoneNumber = phoneNumber,
country = country,
countryInferringMethod = countryInferringMethod,
name = name,
locale = locale,
amount = amount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ internal interface LinkRepository {
email: String,
phone: String?,
country: String?,
countryInferringMethod: String,
name: String?,
consentAction: ConsumerSignUpConsentAction
): Result<ConsumerSessionSignup>
Expand All @@ -79,6 +80,7 @@ internal interface LinkRepository {
email: String,
phoneNumber: String,
country: String,
countryInferringMethod: String,
consentAction: ConsumerSignUpConsentAction,
amount: Long?,
currency: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ internal sealed class UserInput : Parcelable {
val phone: String?,
val country: String?,
val name: String?,
val consentAction: SignUpConsentAction
val consentAction: SignUpConsentAction,
val countryInferringMethod: String = "PHONE_NUMBER",
) : UserInput()
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ internal class SignUpViewModel @Inject constructor(
email = emailController.fieldValue.value,
phoneNumber = phoneNumberController.getE164PhoneNumber(phoneNumberController.fieldValue.value),
country = phoneNumberController.getCountryCode(),
countryInferringMethod = "PHONE_NUMBER",
name = nameController.fieldValue.value,
consentAction = SignUpConsentAction.Implied
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ internal class LinkInlineSignupConfirmationDefinition(
linkInlineSignupConfirmationOption: LinkInlineSignupConfirmationOption,
): PaymentMethodConfirmationOption {
val configuration = linkInlineSignupConfirmationOption.linkConfiguration
val userInput = linkInlineSignupConfirmationOption.userInput
val userInput = linkInlineSignupConfirmationOption.sanitizedUserInput

return when (linkConfigurationCoordinator.getAccountStatusFlow(configuration).first()) {
AccountStatus.Verified -> createOptionAfterAttachingToLink(linkInlineSignupConfirmationOption, userInput)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,39 @@ internal data class LinkInlineSignupConfirmationOption(
val extraParams: PaymentMethodExtraParams?,
val saveOption: PaymentMethodSaveOption,
val linkConfiguration: LinkConfiguration,
val userInput: UserInput,
private val userInput: UserInput,
) : ConfirmationHandler.Option {
enum class PaymentMethodSaveOption(val setupFutureUsage: ConfirmPaymentIntentParams.SetupFutureUsage?) {
RequestedReuse(ConfirmPaymentIntentParams.SetupFutureUsage.OffSession),
RequestedNoReuse(ConfirmPaymentIntentParams.SetupFutureUsage.Blank),
NoRequest(null)
}

val sanitizedUserInput: UserInput
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

get() = when (userInput) {
is UserInput.SignIn -> {
userInput
}
is UserInput.SignUp -> {
val didSeeFullSignupForm = userInput.phone != null
val phone = userInput.phone ?: createParams.billingDetails?.phone

val country = if (didSeeFullSignupForm) {
userInput.country
} else {
// The user saw the Link signup opt-in checkbox, so infer the country from the phone number
// or the billing details.
val billingPhoneCountry = (extraParams as? PaymentMethodExtraParams.Card)?.phoneNumberCountry
billingPhoneCountry ?: createParams.billingDetails?.address?.country
}

val countryInferringMethod = if (phone != null) "PHONE_NUMBER" else "BILLING_ADDRESS"

userInput.copy(
phone = phone,
country = country,
countryInferringMethod = countryInferringMethod,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ internal object TestFactory {
const val AMOUNT = 100L
const val CURRENCY = "USD"
const val COUNTRY = "US"
const val COUNTRY_INFERRING_METHOD = "PHONE_NUMBER"

val VERIFIED_SESSION = ConsumerSession.VerificationSession(
type = ConsumerSession.VerificationSession.SessionType.Sms,
Expand Down
Loading
Loading