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

Don't use payment method in the exception. #7871

Closed
wants to merge 1 commit into from
Closed
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 @@ -56,7 +56,6 @@ import com.stripe.android.paymentsheet.state.GooglePayState
import com.stripe.android.paymentsheet.state.PaymentSheetLoader
import com.stripe.android.paymentsheet.state.PaymentSheetState
import com.stripe.android.paymentsheet.state.WalletsState
import com.stripe.android.paymentsheet.state.asPaymentSheetLoadingException
import com.stripe.android.paymentsheet.ui.HeaderTextFactory
import com.stripe.android.paymentsheet.ui.ModifiableEditPaymentMethodViewInteractor
import com.stripe.android.paymentsheet.ui.PrimaryButton
Expand Down Expand Up @@ -341,7 +340,7 @@ internal class PaymentSheetViewModel @Inject internal constructor(
if (pendingResult is InternalPaymentResult.Completed) {
// If we just received a transaction result after process death, we don't error. Instead, we dismiss
// PaymentSheet and return a `Completed` result to the caller.
val usedPaymentMethod = error.asPaymentSheetLoadingException.usedPaymentMethod
val usedPaymentMethod = stripeIntent.value?.paymentMethod
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Need to pipe the payment method here from the intent in the loader.

handlePaymentCompleted(usedPaymentMethod, finishImmediately = true)
} else {
setStripeIntent(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,18 @@ internal object StripeIntentValidator {
fun requireValid(
stripeIntent: StripeIntent
): StripeIntent {
val paymentMethod = stripeIntent.paymentMethod

val exception = when {
stripeIntent is PaymentIntent && stripeIntent.confirmationMethod != Automatic -> {
PaymentSheetLoadingException.InvalidConfirmationMethod(stripeIntent.confirmationMethod)
}
stripeIntent is PaymentIntent && stripeIntent.isInTerminalState -> {
PaymentSheetLoadingException.PaymentIntentInTerminalState(paymentMethod, stripeIntent.status)
PaymentSheetLoadingException.PaymentIntentInTerminalState(stripeIntent.status)
}
stripeIntent is PaymentIntent && (stripeIntent.amount == null || stripeIntent.currency == null) -> {
PaymentSheetLoadingException.MissingAmountOrCurrency
}
stripeIntent is SetupIntent && stripeIntent.isInTerminalState -> {
PaymentSheetLoadingException.SetupIntentInTerminalState(paymentMethod, stripeIntent.status)
PaymentSheetLoadingException.SetupIntentInTerminalState(stripeIntent.status)
}
else -> {
// valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@ package com.stripe.android.paymentsheet.state

import com.stripe.android.core.exception.StripeException
import com.stripe.android.model.PaymentIntent
import com.stripe.android.model.PaymentMethod
import com.stripe.android.model.StripeIntent
import com.stripe.android.paymentsheet.state.PaymentSheetLoadingException.Unknown

internal sealed class PaymentSheetLoadingException : Throwable() {

abstract val type: String
abstract val usedPaymentMethod: PaymentMethod?

data class InvalidConfirmationMethod(
private val confirmationMethod: PaymentIntent.ConfirmationMethod,
) : PaymentSheetLoadingException() {

override val usedPaymentMethod: PaymentMethod? = null

override val type: String = "invalidConfirmationMethod"

override val message: String = """
Expand All @@ -31,8 +27,6 @@ internal sealed class PaymentSheetLoadingException : Throwable() {
private val supported: String,
) : PaymentSheetLoadingException() {

override val usedPaymentMethod: PaymentMethod? = null

override val type: String = "noPaymentMethodTypesAvailable"

override val message: String
Expand All @@ -41,7 +35,6 @@ internal sealed class PaymentSheetLoadingException : Throwable() {
}

data class PaymentIntentInTerminalState(
override val usedPaymentMethod: PaymentMethod?,
private val status: StripeIntent.Status?,
) : PaymentSheetLoadingException() {

Expand All @@ -55,7 +48,6 @@ internal sealed class PaymentSheetLoadingException : Throwable() {
}

data class SetupIntentInTerminalState(
override val usedPaymentMethod: PaymentMethod?,
private val status: StripeIntent.Status?,
) : PaymentSheetLoadingException() {

Expand All @@ -69,7 +61,6 @@ internal sealed class PaymentSheetLoadingException : Throwable() {
}

object MissingAmountOrCurrency : PaymentSheetLoadingException() {
override val usedPaymentMethod: PaymentMethod? = null
override val type: String = "missingAmountOrCurrency"
override val message: String = "PaymentIntent must contain amount and currency."
}
Expand All @@ -82,8 +73,6 @@ internal sealed class PaymentSheetLoadingException : Throwable() {
get() = StripeException.create(cause).analyticsValue()

override val message: String? = cause.message

override val usedPaymentMethod: PaymentMethod? = null
}
}

Expand Down
Loading