Skip to content

Commit

Permalink
Move Link inline signup to confirmation definition
Browse files Browse the repository at this point in the history
  • Loading branch information
samer-stripe committed Jan 24, 2025
1 parent 6e58b87 commit d41d00d
Show file tree
Hide file tree
Showing 35 changed files with 1,541 additions and 938 deletions.
16 changes: 16 additions & 0 deletions paymentsheet/api/paymentsheet.api
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,22 @@ public final class com/stripe/android/paymentelement/confirmation/link/LinkConfi
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/paymentelement/confirmation/linkinline/LinkInlineSignupConfirmationDefinition$Result$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/paymentelement/confirmation/linkinline/LinkInlineSignupConfirmationDefinition$Result;
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun newArray (I)[Lcom/stripe/android/paymentelement/confirmation/linkinline/LinkInlineSignupConfirmationDefinition$Result;
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/paymentelement/confirmation/linkinline/LinkInlineSignupConfirmationOption$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/paymentelement/confirmation/linkinline/LinkInlineSignupConfirmationOption;
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun newArray (I)[Lcom/stripe/android/paymentelement/confirmation/linkinline/LinkInlineSignupConfirmationOption;
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/paymentelement/embedded/DefaultEmbeddedConfigurationHandler$Arguments$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/paymentelement/embedded/DefaultEmbeddedConfigurationHandler$Arguments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,13 @@ internal class LinkTest {
response.testBodyFromFile("payment-intent-confirm.json")
}

networkRule.enqueue(
method("POST"),
path("/v1/consumers/sessions/log_out"),
) { response ->
response.testBodyFromFile("consumer-session-logout-success.json")
}

page.clickPrimaryButton()
}

Expand Down Expand Up @@ -721,6 +728,13 @@ internal class LinkTest {
response.testBodyFromFile("payment-intent-confirm.json")
}

networkRule.enqueue(
method("POST"),
path("/v1/consumers/sessions/log_out"),
) { response ->
response.testBodyFromFile("consumer-session-logout-success.json")
}

page.clickPrimaryButton()
}

Expand Down Expand Up @@ -784,6 +798,13 @@ internal class LinkTest {
response.testBodyFromFile("payment-intent-confirm.json")
}

networkRule.enqueue(
method("POST"),
path("/v1/consumers/sessions/log_out"),
) { response ->
response.testBodyFromFile("consumer-session-logout-success.json")
}

page.clickPrimaryButton()
}

Expand Down Expand Up @@ -832,6 +853,13 @@ internal class LinkTest {
response.testBodyFromFile("payment-intent-confirm.json")
}

networkRule.enqueue(
method("POST"),
path("/v1/consumers/sessions/log_out"),
) { response ->
response.testBodyFromFile("consumer-session-logout-success.json")
}

page.clickPrimaryButton()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,21 @@ internal class DefaultLinkAccountManager @Inject constructor(
return runCatching {
requireNotNull(linkAccount.value)
}.mapCatching { account ->
linkRepository.logOut(
consumerSessionClientSecret = account.clientSecret,
consumerAccountPublishableKey = consumerPublishableKey,
).getOrThrow()
}.onSuccess {
errorReporter.report(ErrorReporter.SuccessEvent.LINK_LOG_OUT_SUCCESS)
Logger.getInstance(BuildConfig.DEBUG).debug("Logged out of Link successfully")
}.onFailure { error ->
errorReporter.report(ErrorReporter.ExpectedErrorEvent.LINK_LOG_OUT_FAILURE, StripeException.create(error))
Logger.getInstance(BuildConfig.DEBUG).warning("Failed to log out of Link: $error")
runCatching {
linkRepository.logOut(
consumerSessionClientSecret = account.clientSecret,
consumerAccountPublishableKey = consumerPublishableKey,
).getOrThrow()
}.onSuccess {
errorReporter.report(ErrorReporter.SuccessEvent.LINK_LOG_OUT_SUCCESS)
Logger.getInstance(BuildConfig.DEBUG).debug("Logged out of Link successfully")
}.onFailure { error ->
errorReporter.report(
ErrorReporter.ExpectedErrorEvent.LINK_LOG_OUT_FAILURE,
StripeException.create(error)
)
Logger.getInstance(BuildConfig.DEBUG).warning("Failed to log out of Link: $error")
}.getOrThrow()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import kotlinx.parcelize.Parcelize
/**
* Valid user input into the inline sign up view.
*/
@Parcelize
internal sealed class UserInput : Parcelable {
/**
* Represents an input that is valid for signing in to a link account.
*/
@Parcelize
data class SignIn(
val email: String
) : UserInput()

/**
* Represents an input that is valid for signing up to a link account.
*/
@Parcelize
data class SignUp(
val email: String,
val phone: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,67 +8,114 @@ import com.stripe.android.paymentelement.confirmation.bacs.BacsConfirmationOptio
import com.stripe.android.paymentelement.confirmation.epms.ExternalPaymentMethodConfirmationOption
import com.stripe.android.paymentelement.confirmation.gpay.GooglePayConfirmationOption
import com.stripe.android.paymentelement.confirmation.link.LinkConfirmationOption
import com.stripe.android.paymentelement.confirmation.linkinline.LinkInlineSignupConfirmationOption
import com.stripe.android.paymentsheet.model.PaymentSelection

internal fun PaymentSelection.toConfirmationOption(
configuration: CommonConfiguration,
linkConfiguration: LinkConfiguration?,
): ConfirmationHandler.Option? {
return when (this) {
is PaymentSelection.Saved -> PaymentMethodConfirmationOption.Saved(
paymentMethod = paymentMethod,
is PaymentSelection.Saved -> toConfirmationOption()
is PaymentSelection.ExternalPaymentMethod -> toConfirmationOption()
is PaymentSelection.New.USBankAccount -> toConfirmationOption()
is PaymentSelection.New.LinkInline -> toConfirmationOption(linkConfiguration)
is PaymentSelection.New -> toConfirmationOption()
is PaymentSelection.GooglePay -> toConfirmationOption(configuration)
is PaymentSelection.Link -> toConfirmationOption(linkConfiguration)
}
}

private fun PaymentSelection.Saved.toConfirmationOption(): PaymentMethodConfirmationOption.Saved {
return PaymentMethodConfirmationOption.Saved(
paymentMethod = paymentMethod,
optionsParams = paymentMethodOptionsParams,
)
}

private fun PaymentSelection.ExternalPaymentMethod.toConfirmationOption(): ExternalPaymentMethodConfirmationOption {
return ExternalPaymentMethodConfirmationOption(
type = type,
billingDetails = billingDetails,
)
}

private fun PaymentSelection.New.USBankAccount.toConfirmationOption(): PaymentMethodConfirmationOption {
return if (instantDebits != null) {
// For Instant Debits, we create the PaymentMethod inside the bank auth flow. Therefore,
// we can just use the already created object here.
PaymentMethodConfirmationOption.Saved(
paymentMethod = instantDebits.paymentMethod,
optionsParams = paymentMethodOptionsParams,
)
is PaymentSelection.ExternalPaymentMethod -> ExternalPaymentMethodConfirmationOption(
type = type,
billingDetails = billingDetails,
} else {
PaymentMethodConfirmationOption.New(
createParams = paymentMethodCreateParams,
optionsParams = paymentMethodOptionsParams,
shouldSave = customerRequestedSave == PaymentSelection.CustomerRequestedSave.RequestReuse,
)
is PaymentSelection.New.USBankAccount -> {
if (instantDebits != null) {
// For Instant Debits, we create the PaymentMethod inside the bank auth flow. Therefore,
// we can just use the already created object here.
PaymentMethodConfirmationOption.Saved(
paymentMethod = instantDebits.paymentMethod,
optionsParams = paymentMethodOptionsParams,
)
} else {
PaymentMethodConfirmationOption.New(
createParams = paymentMethodCreateParams,
optionsParams = paymentMethodOptionsParams,
shouldSave = customerRequestedSave == PaymentSelection.CustomerRequestedSave.RequestReuse,
)
}
}
is PaymentSelection.New -> {
if (paymentMethodCreateParams.typeCode == PaymentMethod.Type.BacsDebit.code) {
BacsConfirmationOption(
createParams = paymentMethodCreateParams,
optionsParams = paymentMethodOptionsParams,
)
} else {
PaymentMethodConfirmationOption.New(
createParams = paymentMethodCreateParams,
optionsParams = paymentMethodOptionsParams,
shouldSave = customerRequestedSave == PaymentSelection.CustomerRequestedSave.RequestReuse,
)
}
}

private fun PaymentSelection.New.LinkInline.toConfirmationOption(
linkConfiguration: LinkConfiguration?
): LinkInlineSignupConfirmationOption? {
return linkConfiguration?.let {
LinkInlineSignupConfirmationOption(
createParams = paymentMethodCreateParams,
optionsParams = paymentMethodOptionsParams,
userInput = input,
linkConfiguration = linkConfiguration,
saveOption = when (customerRequestedSave) {
PaymentSelection.CustomerRequestedSave.RequestReuse ->
LinkInlineSignupConfirmationOption.PaymentMethodSaveOption.RequestedReuse
PaymentSelection.CustomerRequestedSave.RequestNoReuse ->
LinkInlineSignupConfirmationOption.PaymentMethodSaveOption.RequestedNoReuse
PaymentSelection.CustomerRequestedSave.NoRequest ->
LinkInlineSignupConfirmationOption.PaymentMethodSaveOption.NoRequest
}
}
is PaymentSelection.GooglePay -> configuration.googlePay?.let { googlePay ->
GooglePayConfirmationOption(
config = GooglePayConfirmationOption.Config(
environment = googlePay.environment,
merchantName = configuration.merchantDisplayName,
merchantCountryCode = googlePay.countryCode,
merchantCurrencyCode = googlePay.currencyCode,
customAmount = googlePay.amount,
customLabel = googlePay.label,
billingDetailsCollectionConfiguration = configuration.billingDetailsCollectionConfiguration,
cardBrandFilter = PaymentSheetCardBrandFilter(configuration.cardBrandAcceptance)
)
)
}
}

private fun PaymentSelection.New.toConfirmationOption(): ConfirmationHandler.Option {
return if (paymentMethodCreateParams.typeCode == PaymentMethod.Type.BacsDebit.code) {
BacsConfirmationOption(
createParams = paymentMethodCreateParams,
optionsParams = paymentMethodOptionsParams,
)
} else {
PaymentMethodConfirmationOption.New(
createParams = paymentMethodCreateParams,
optionsParams = paymentMethodOptionsParams,
shouldSave = customerRequestedSave == PaymentSelection.CustomerRequestedSave.RequestReuse,
)
}
}

private fun PaymentSelection.GooglePay.toConfirmationOption(
configuration: CommonConfiguration,
): GooglePayConfirmationOption? {
return configuration.googlePay?.let { googlePay ->
GooglePayConfirmationOption(
config = GooglePayConfirmationOption.Config(
environment = googlePay.environment,
merchantName = configuration.merchantDisplayName,
merchantCountryCode = googlePay.countryCode,
merchantCurrencyCode = googlePay.currencyCode,
customAmount = googlePay.amount,
customLabel = googlePay.label,
billingDetailsCollectionConfiguration = configuration.billingDetailsCollectionConfiguration,
cardBrandFilter = PaymentSheetCardBrandFilter(configuration.cardBrandAcceptance)
)
}
is PaymentSelection.Link -> linkConfiguration?.let {
LinkConfirmationOption(configuration = linkConfiguration)
}
)
}
}

private fun PaymentSelection.Link.toConfirmationOption(
linkConfiguration: LinkConfiguration?
): LinkConfirmationOption? {
return linkConfiguration?.let {
LinkConfirmationOption(configuration = linkConfiguration)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.stripe.android.paymentelement.confirmation.bacs.BacsConfirmationModul
import com.stripe.android.paymentelement.confirmation.epms.ExternalPaymentMethodConfirmationModule
import com.stripe.android.paymentelement.confirmation.gpay.GooglePayConfirmationModule
import com.stripe.android.paymentelement.confirmation.link.LinkConfirmationModule
import com.stripe.android.paymentelement.confirmation.linkinline.LinkInlineSignupConfirmationModule
import dagger.Module

@Module(
Expand All @@ -13,6 +14,7 @@ import dagger.Module
ExternalPaymentMethodConfirmationModule::class,
GooglePayConfirmationModule::class,
LinkConfirmationModule::class,
LinkInlineSignupConfirmationModule::class,
]
)
internal interface PaymentElementConfirmationModule
Loading

0 comments on commit d41d00d

Please sign in to comment.