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

Implement support for SetupIntents #3762

Merged
merged 27 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5b5502c
Generalize ConfirmStripeIntentParamsFactory.
brnunes-stripe May 20, 2021
50a2e63
Merge branch 'master' into brnunes/si1
brnunes-stripe May 20, 2021
a6e8399
Make ConfirmStripeIntentParamsFactory a sealed class.
brnunes-stripe May 20, 2021
669d733
Make generic in ConfirmStripeIntentParamsFactory `out`
brnunes-stripe May 20, 2021
ba1344b
Address comment
brnunes-stripe May 20, 2021
a381db0
Merge branch 'master' into brnunes/si3
brnunes-stripe May 21, 2021
f201c24
Delegate processing PaymentFlowResult.Unvalidated to ClientSecret.
brnunes-stripe May 21, 2021
5c0bdff
Break up PaymentFlowResultProcessor for PaymentIntent and SetupIntent
brnunes-stripe May 25, 2021
9c1d698
Documentation
brnunes-stripe May 25, 2021
8a5b80c
Support for SetupIntents.
brnunes-stripe May 25, 2021
6ea12ab
merge master
brnunes-stripe May 25, 2021
8ac4c9a
merge master
brnunes-stripe May 25, 2021
eafa1df
Add back SetupIntent entry points.
brnunes-stripe May 25, 2021
d92ac9f
apiDump
brnunes-stripe May 25, 2021
c632b9b
Make PaymentFlowResultProcessor a sealed class, use mock in tests
brnunes-stripe May 26, 2021
539ada8
PaymentFlowResultProcessor is PaymentIntentFlowResultProcessor for now
brnunes-stripe May 26, 2021
4b80335
PaymentFlowResultProcessor private
brnunes-stripe May 26, 2021
19d63a7
Remove unnecessary cast
brnunes-stripe May 26, 2021
22f3961
Merge branch 'brnunes/si3' into brnunes/si4
brnunes-stripe May 26, 2021
067454a
Fix mock types
brnunes-stripe May 26, 2021
4616339
Merge branch 'brnunes/si3' into brnunes/si4
brnunes-stripe May 26, 2021
42bb01d
Fix mock types
brnunes-stripe May 26, 2021
75a23c2
Merge branch 'brnunes/si3' into brnunes/si4
brnunes-stripe May 26, 2021
7dc0aff
Address comments
brnunes-stripe May 26, 2021
be7ff27
Update error messages.
brnunes-stripe May 26, 2021
f44c52d
Merge branch 'master' into brnunes/si4
brnunes-stripe May 27, 2021
caab8a9
Merge branch 'master' into brnunes/si4
brnunes-stripe May 27, 2021
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
13 changes: 11 additions & 2 deletions payments-core/api/payments-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ public final class com/stripe/android/PaymentIntentResult : com/stripe/android/S
public static synthetic fun copy$default (Lcom/stripe/android/PaymentIntentResult;Lcom/stripe/android/model/PaymentIntent;ILjava/lang/String;ILjava/lang/Object;)Lcom/stripe/android/PaymentIntentResult;
public fun describeContents ()I
public fun equals (Ljava/lang/Object;)Z
public final fun getFailureMessage ()Ljava/lang/String;
public fun getFailureMessage ()Ljava/lang/String;
public fun getIntent ()Lcom/stripe/android/model/PaymentIntent;
public synthetic fun getIntent ()Lcom/stripe/android/model/StripeIntent;
public fun hashCode ()I
Expand Down Expand Up @@ -671,7 +671,7 @@ public final class com/stripe/android/SetupIntentResult : com/stripe/android/Str
public static synthetic fun copy$default (Lcom/stripe/android/SetupIntentResult;Lcom/stripe/android/model/SetupIntent;ILjava/lang/String;ILjava/lang/Object;)Lcom/stripe/android/SetupIntentResult;
public fun describeContents ()I
public fun equals (Ljava/lang/Object;)Z
public final fun getFailureMessage ()Ljava/lang/String;
public fun getFailureMessage ()Ljava/lang/String;
public fun getIntent ()Lcom/stripe/android/model/SetupIntent;
public synthetic fun getIntent ()Lcom/stripe/android/model/StripeIntent;
public fun hashCode ()I
Expand Down Expand Up @@ -919,6 +919,7 @@ public class com/stripe/android/StripeError$Creator : android/os/Parcelable$Crea
}

public abstract class com/stripe/android/StripeIntentResult : com/stripe/android/model/StripeModel {
public abstract fun getFailureMessage ()Ljava/lang/String;
public abstract fun getIntent ()Lcom/stripe/android/model/StripeIntent;
public final fun getOutcome ()I
}
Expand Down Expand Up @@ -2508,6 +2509,7 @@ public final class com/stripe/android/model/PaymentIntent : com/stripe/android/m
public final fun getCurrency ()Ljava/lang/String;
public fun getDescription ()Ljava/lang/String;
public fun getId ()Ljava/lang/String;
public fun getLastErrorMessage ()Ljava/lang/String;
public final fun getLastPaymentError ()Lcom/stripe/android/model/PaymentIntent$Error;
public final fun getNextAction ()Ljava/util/Map;
public fun getNextActionData ()Lcom/stripe/android/model/StripeIntent$NextActionData;
Expand Down Expand Up @@ -3887,6 +3889,7 @@ public final class com/stripe/android/model/SetupIntent : com/stripe/android/mod
public fun getCreated ()J
public fun getDescription ()Ljava/lang/String;
public fun getId ()Ljava/lang/String;
public fun getLastErrorMessage ()Ljava/lang/String;
public final fun getLastSetupError ()Lcom/stripe/android/model/SetupIntent$Error;
public fun getNextActionData ()Lcom/stripe/android/model/StripeIntent$NextActionData;
public fun getNextActionType ()Lcom/stripe/android/model/StripeIntent$NextActionType;
Expand Down Expand Up @@ -4851,6 +4854,7 @@ public abstract interface class com/stripe/android/model/StripeIntent : com/stri
public abstract fun getCreated ()J
public abstract fun getDescription ()Ljava/lang/String;
public abstract fun getId ()Ljava/lang/String;
public abstract fun getLastErrorMessage ()Ljava/lang/String;
public abstract fun getNextActionData ()Lcom/stripe/android/model/StripeIntent$NextActionData;
public abstract fun getNextActionType ()Lcom/stripe/android/model/StripeIntent$NextActionType;
public abstract fun getPaymentMethod ()Lcom/stripe/android/model/PaymentMethod;
Expand Down Expand Up @@ -5363,6 +5367,9 @@ public final class com/stripe/android/paymentsheet/PaymentSheet {
public final fun presentWithPaymentIntent (Ljava/lang/String;)V
public final fun presentWithPaymentIntent (Ljava/lang/String;Lcom/stripe/android/paymentsheet/PaymentSheet$Configuration;)V
public static synthetic fun presentWithPaymentIntent$default (Lcom/stripe/android/paymentsheet/PaymentSheet;Ljava/lang/String;Lcom/stripe/android/paymentsheet/PaymentSheet$Configuration;ILjava/lang/Object;)V
public final fun presentWithSetupIntent (Ljava/lang/String;)V
public final fun presentWithSetupIntent (Ljava/lang/String;Lcom/stripe/android/paymentsheet/PaymentSheet$Configuration;)V
public static synthetic fun presentWithSetupIntent$default (Lcom/stripe/android/paymentsheet/PaymentSheet;Ljava/lang/String;Lcom/stripe/android/paymentsheet/PaymentSheet$Configuration;ILjava/lang/Object;)V
}

public final class com/stripe/android/paymentsheet/PaymentSheet$Configuration : android/os/Parcelable {
Expand Down Expand Up @@ -5428,6 +5435,7 @@ public class com/stripe/android/paymentsheet/PaymentSheet$CustomerConfiguration$
public abstract interface class com/stripe/android/paymentsheet/PaymentSheet$FlowController {
public static final field Companion Lcom/stripe/android/paymentsheet/PaymentSheet$FlowController$Companion;
public abstract fun configureWithPaymentIntent (Ljava/lang/String;Lcom/stripe/android/paymentsheet/PaymentSheet$Configuration;Lcom/stripe/android/paymentsheet/PaymentSheet$FlowController$ConfigCallback;)V
public abstract fun configureWithSetupIntent (Ljava/lang/String;Lcom/stripe/android/paymentsheet/PaymentSheet$Configuration;Lcom/stripe/android/paymentsheet/PaymentSheet$FlowController$ConfigCallback;)V
public abstract fun confirm ()V
public static fun create (Landroidx/activity/ComponentActivity;Lcom/stripe/android/paymentsheet/PaymentOptionCallback;Lcom/stripe/android/paymentsheet/PaymentSheetResultCallback;)Lcom/stripe/android/paymentsheet/PaymentSheet$FlowController;
public static fun create (Landroidx/fragment/app/Fragment;Lcom/stripe/android/paymentsheet/PaymentOptionCallback;Lcom/stripe/android/paymentsheet/PaymentSheetResultCallback;)Lcom/stripe/android/paymentsheet/PaymentSheet$FlowController;
Expand All @@ -5446,6 +5454,7 @@ public abstract interface class com/stripe/android/paymentsheet/PaymentSheet$Flo

public final class com/stripe/android/paymentsheet/PaymentSheet$FlowController$DefaultImpls {
public static synthetic fun configureWithPaymentIntent$default (Lcom/stripe/android/paymentsheet/PaymentSheet$FlowController;Ljava/lang/String;Lcom/stripe/android/paymentsheet/PaymentSheet$Configuration;Lcom/stripe/android/paymentsheet/PaymentSheet$FlowController$ConfigCallback;ILjava/lang/Object;)V
public static synthetic fun configureWithSetupIntent$default (Lcom/stripe/android/paymentsheet/PaymentSheet$FlowController;Ljava/lang/String;Lcom/stripe/android/paymentsheet/PaymentSheet$Configuration;Lcom/stripe/android/paymentsheet/PaymentSheet$FlowController$ConfigCallback;ILjava/lang/Object;)V
}

public abstract class com/stripe/android/paymentsheet/PaymentSheet$FlowController$Result {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ import kotlinx.parcelize.Parcelize
data class PaymentIntentResult internal constructor(
override val intent: PaymentIntent,
@Outcome private val outcomeFromFlow: Int = 0,
val failureMessage: String? = null
override val failureMessage: String? = null
) : StripeIntentResult<PaymentIntent>(outcomeFromFlow)
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ import kotlinx.parcelize.Parcelize
data class SetupIntentResult internal constructor(
override val intent: SetupIntent,
@Outcome private val outcomeFromFlow: Int = 0,
val failureMessage: String? = null
override val failureMessage: String? = null
) : StripeIntentResult<SetupIntent>(outcomeFromFlow)
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import com.stripe.android.model.StripeModel
*
* [intent] is a [StripeIntent] retrieved after confirmation/authentication succeeded or failed.
*/
abstract class StripeIntentResult<T : StripeIntent> internal constructor(
abstract class StripeIntentResult<out T : StripeIntent> internal constructor(
@Outcome private val outcomeFromFlow: Int
) : StripeModel {
abstract val intent: T
abstract val failureMessage: String?

@Outcome
@get:Outcome
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ import com.stripe.android.networking.DefaultAlipayRepository
import com.stripe.android.networking.StripeRepository
import com.stripe.android.payments.BrowserCapabilities
import com.stripe.android.payments.BrowserCapabilitiesSupplier
import com.stripe.android.payments.DefaultPaymentFlowResultProcessor
import com.stripe.android.payments.DefaultReturnUrl
import com.stripe.android.payments.DefaultStripeChallengeStatusReceiver
import com.stripe.android.payments.PaymentFlowFailureMessageFactory
import com.stripe.android.payments.PaymentFlowResult
import com.stripe.android.payments.PaymentIntentFlowResultProcessor
import com.stripe.android.payments.SetupIntentFlowResultProcessor
import com.stripe.android.payments.Stripe3ds2CompletionStarter
import com.stripe.android.stripe3ds2.init.ui.StripeUiCustomization
import com.stripe.android.stripe3ds2.service.StripeThreeDs2Service
Expand Down Expand Up @@ -85,7 +86,14 @@ internal class StripePaymentController internal constructor(
private val uiContext: CoroutineContext = Dispatchers.Main
) : PaymentController {
private val failureMessageFactory = PaymentFlowFailureMessageFactory(context)
private val paymentFlowResultProcessor = DefaultPaymentFlowResultProcessor(
private val paymentIntentFlowResultProcessor = PaymentIntentFlowResultProcessor(
context,
publishableKey,
stripeRepository,
enableLogging,
workContext
)
private val setupIntentFlowResultProcessor = SetupIntentFlowResultProcessor(
context,
publishableKey,
stripeRepository,
Expand Down Expand Up @@ -404,7 +412,7 @@ internal class StripePaymentController internal constructor(
IllegalArgumentException::class
)
override suspend fun getPaymentIntentResult(data: Intent) =
paymentFlowResultProcessor.processPaymentIntent(
paymentIntentFlowResultProcessor.processResult(
PaymentFlowResult.Unvalidated.fromIntent(data)
)

Expand All @@ -429,7 +437,7 @@ internal class StripePaymentController internal constructor(
IllegalArgumentException::class
)
override suspend fun getSetupIntentResult(data: Intent) =
paymentFlowResultProcessor.processSetupIntent(
setupIntentFlowResultProcessor.processResult(
PaymentFlowResult.Unvalidated.fromIntent(data)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ data class PaymentIntent internal constructor(
StripeIntent.Status.Succeeded
).contains(status)

override val lastErrorMessage: String?
get() = lastPaymentError?.message

override fun requiresAction(): Boolean {
return status === StripeIntent.Status.RequiresAction
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ data class SetupIntent internal constructor(
StripeIntent.Status.Succeeded
).contains(status)

override val lastErrorMessage: String?
get() = lastSetupError?.message

override fun requiresAction(): Boolean {
return status === StripeIntent.Status.RequiresAction
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ interface StripeIntent : StripeModel {
*/
val isConfirmed: Boolean

val lastErrorMessage: String?

fun requiresAction(): Boolean

fun requiresConfirmation(): Boolean
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ sealed class PaymentFlowResult {

/**
* The Source is eligible for cancellation.
* See [DefaultPaymentFlowResultProcessor.shouldCancelSource] for usage.
* See [PaymentFlowResultProcessor.shouldCancelIntent] for usage.
*/
internal val canCancelSource: Boolean = false,

Expand Down
Loading