diff --git a/payments-core/api/payments-core.api b/payments-core/api/payments-core.api index 57352f74092..d45913e5fff 100644 --- a/payments-core/api/payments-core.api +++ b/payments-core/api/payments-core.api @@ -499,30 +499,6 @@ public final class com/stripe/android/PaymentConfiguration$Companion { public static synthetic fun init$default (Lcom/stripe/android/PaymentConfiguration$Companion;Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)V } -public abstract interface class com/stripe/android/PaymentController { - public abstract fun confirmAndAuthenticateAlipay (Lcom/stripe/android/model/ConfirmPaymentIntentParams;Lcom/stripe/android/AlipayAuthenticator;Lcom/stripe/android/networking/ApiRequest$Options;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun confirmWeChatPay (Lcom/stripe/android/model/ConfirmPaymentIntentParams;Lcom/stripe/android/networking/ApiRequest$Options;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun getAuthenticateSourceResult (Landroid/content/Intent;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun getPaymentIntentResult (Landroid/content/Intent;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun getSetupIntentResult (Landroid/content/Intent;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun handleNextAction (Lcom/stripe/android/view/AuthActivityStarterHost;Lcom/stripe/android/model/StripeIntent;Lcom/stripe/android/networking/ApiRequest$Options;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun registerLaunchersWithActivityResultCaller (Landroidx/activity/result/ActivityResultCaller;Landroidx/activity/result/ActivityResultCallback;)V - public abstract fun shouldHandlePaymentResult (ILandroid/content/Intent;)Z - public abstract fun shouldHandleSetupResult (ILandroid/content/Intent;)Z - public abstract fun shouldHandleSourceResult (ILandroid/content/Intent;)Z - public abstract fun startAuth (Lcom/stripe/android/view/AuthActivityStarterHost;Ljava/lang/String;Lcom/stripe/android/networking/ApiRequest$Options;Lcom/stripe/android/PaymentController$StripeIntentType;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun startAuthenticateSource (Lcom/stripe/android/view/AuthActivityStarterHost;Lcom/stripe/android/model/Source;Lcom/stripe/android/networking/ApiRequest$Options;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun startConfirmAndAuth (Lcom/stripe/android/view/AuthActivityStarterHost;Lcom/stripe/android/model/ConfirmStripeIntentParams;Lcom/stripe/android/networking/ApiRequest$Options;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun unregisterLaunchers ()V -} - -public final class com/stripe/android/PaymentController$StripeIntentType : java/lang/Enum { - public static final field PaymentIntent Lcom/stripe/android/PaymentController$StripeIntentType; - public static final field SetupIntent Lcom/stripe/android/PaymentController$StripeIntentType; - public static fun valueOf (Ljava/lang/String;)Lcom/stripe/android/PaymentController$StripeIntentType; - public static fun values ()[Lcom/stripe/android/PaymentController$StripeIntentType; -} - public final class com/stripe/android/PaymentIntentResult : com/stripe/android/StripeIntentResult { public static final field $stable I public static final field CREATOR Landroid/os/Parcelable$Creator; @@ -5084,28 +5060,6 @@ public final class com/stripe/android/payments/PaymentFlowResult$Unvalidated$Com public synthetic fun write (Ljava/lang/Object;Landroid/os/Parcel;I)V } -public abstract class com/stripe/android/payments/PaymentFlowResultProcessor { - public static final field $stable I - public synthetic fun (Landroid/content/Context;Ljavax/inject/Provider;Lcom/stripe/android/networking/StripeRepository;ZLkotlin/coroutines/CoroutineContext;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public synthetic fun (Landroid/content/Context;Ljavax/inject/Provider;Lcom/stripe/android/networking/StripeRepository;ZLkotlin/coroutines/CoroutineContext;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - protected abstract fun cancelStripeIntent (Lcom/stripe/android/model/StripeIntent;Lcom/stripe/android/networking/ApiRequest$Options;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - protected abstract fun createStripeIntentResult (Lcom/stripe/android/model/StripeIntent;ILjava/lang/String;)Lcom/stripe/android/StripeIntentResult; - protected final fun getStripeRepository ()Lcom/stripe/android/networking/StripeRepository; - public fun processResult (Lcom/stripe/android/payments/PaymentFlowResult$Unvalidated;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - protected abstract fun retrieveStripeIntent (Ljava/lang/String;Lcom/stripe/android/networking/ApiRequest$Options;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - -public class com/stripe/android/payments/PaymentIntentFlowResultProcessor : com/stripe/android/payments/PaymentFlowResultProcessor { - public static final field $stable I - public fun (Landroid/content/Context;Ljavax/inject/Provider;Lcom/stripe/android/networking/StripeRepository;ZLkotlin/coroutines/CoroutineContext;)V - public synthetic fun (Landroid/content/Context;Ljavax/inject/Provider;Lcom/stripe/android/networking/StripeRepository;ZLkotlin/coroutines/CoroutineContext;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - protected fun cancelStripeIntent (Lcom/stripe/android/model/PaymentIntent;Lcom/stripe/android/networking/ApiRequest$Options;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public synthetic fun cancelStripeIntent (Lcom/stripe/android/model/StripeIntent;Lcom/stripe/android/networking/ApiRequest$Options;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - protected fun createStripeIntentResult (Lcom/stripe/android/model/PaymentIntent;ILjava/lang/String;)Lcom/stripe/android/PaymentIntentResult; - public synthetic fun createStripeIntentResult (Lcom/stripe/android/model/StripeIntent;ILjava/lang/String;)Lcom/stripe/android/StripeIntentResult; - protected fun retrieveStripeIntent (Ljava/lang/String;Lcom/stripe/android/networking/ApiRequest$Options;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; -} - public abstract interface class com/stripe/android/payments/core/ActivityResultLauncherHost { public abstract fun onLauncherInvalidated ()V public abstract fun onNewActivityResultCaller (Landroidx/activity/result/ActivityResultCaller;Landroidx/activity/result/ActivityResultCallback;)V @@ -5298,30 +5252,6 @@ public final class com/stripe/android/payments/core/injection/PaymentCommonModul public static fun providePaymentConfiguration (Landroid/content/Context;)Lcom/stripe/android/PaymentConfiguration; } -public final class com/stripe/android/payments/core/injection/PaymentCommonModule_Companion_ProvidePaymentFlowResultProcessor$payments_core_releaseFactory : dagger/internal/Factory { - public fun (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)V - public static fun create (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)Lcom/stripe/android/payments/core/injection/PaymentCommonModule_Companion_ProvidePaymentFlowResultProcessor$payments_core_releaseFactory; - public fun get ()Lcom/stripe/android/payments/PaymentFlowResultProcessor; - public synthetic fun get ()Ljava/lang/Object; - public static fun providePaymentFlowResultProcessor$payments_core_release (Lcom/stripe/android/paymentsheet/model/ClientSecret;Lcom/stripe/android/payments/PaymentIntentFlowResultProcessor;Lcom/stripe/android/payments/SetupIntentFlowResultProcessor;)Lcom/stripe/android/payments/PaymentFlowResultProcessor; -} - -public final class com/stripe/android/payments/core/injection/PaymentCommonModule_Companion_ProvidePaymentIntentFlowResultProcessor$payments_core_releaseFactory : dagger/internal/Factory { - public fun (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)V - public static fun create (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)Lcom/stripe/android/payments/core/injection/PaymentCommonModule_Companion_ProvidePaymentIntentFlowResultProcessor$payments_core_releaseFactory; - public fun get ()Lcom/stripe/android/payments/PaymentIntentFlowResultProcessor; - public synthetic fun get ()Ljava/lang/Object; - public static fun providePaymentIntentFlowResultProcessor$payments_core_release (Landroid/content/Context;Ldagger/Lazy;Lcom/stripe/android/networking/StripeApiRepository;ZLkotlin/coroutines/CoroutineContext;)Lcom/stripe/android/payments/PaymentIntentFlowResultProcessor; -} - -public final class com/stripe/android/payments/core/injection/PaymentCommonModule_Companion_ProvideSetupIntentFlowResultProcessor$payments_core_releaseFactory : dagger/internal/Factory { - public fun (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)V - public static fun create (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)Lcom/stripe/android/payments/core/injection/PaymentCommonModule_Companion_ProvideSetupIntentFlowResultProcessor$payments_core_releaseFactory; - public fun get ()Lcom/stripe/android/payments/SetupIntentFlowResultProcessor; - public synthetic fun get ()Ljava/lang/Object; - public static fun provideSetupIntentFlowResultProcessor$payments_core_release (Landroid/content/Context;Ldagger/Lazy;Lcom/stripe/android/networking/StripeApiRepository;ZLkotlin/coroutines/CoroutineContext;)Lcom/stripe/android/payments/SetupIntentFlowResultProcessor; -} - public final class com/stripe/android/payments/core/injection/PaymentCommonModule_Companion_ProvideStripeApiRepository$payments_core_releaseFactory : dagger/internal/Factory { public fun (Ljavax/inject/Provider;Ljavax/inject/Provider;)V public static fun create (Ljavax/inject/Provider;Ljavax/inject/Provider;)Lcom/stripe/android/payments/core/injection/PaymentCommonModule_Companion_ProvideStripeApiRepository$payments_core_releaseFactory; @@ -5330,14 +5260,6 @@ public final class com/stripe/android/payments/core/injection/PaymentCommonModul public static fun provideStripeApiRepository$payments_core_release (Landroid/content/Context;Ldagger/Lazy;)Lcom/stripe/android/networking/StripeApiRepository; } -public final class com/stripe/android/payments/core/injection/PaymentCommonModule_Companion_ProvideStripePaymentController$payments_core_releaseFactory : dagger/internal/Factory { - public fun (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)V - public static fun create (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)Lcom/stripe/android/payments/core/injection/PaymentCommonModule_Companion_ProvideStripePaymentController$payments_core_releaseFactory; - public fun get ()Lcom/stripe/android/PaymentController; - public synthetic fun get ()Ljava/lang/Object; - public static fun provideStripePaymentController$payments_core_release (Landroid/content/Context;Lcom/stripe/android/networking/StripeApiRepository;Ldagger/Lazy;Z)Lcom/stripe/android/PaymentController; -} - public final class com/stripe/android/payments/core/injection/PaymentLauncherModule_ProvideApiRequestOptionsFactory : dagger/internal/Factory { public fun (Lcom/stripe/android/payments/core/injection/PaymentLauncherModule;Ljavax/inject/Provider;Ljavax/inject/Provider;)V public static fun create (Lcom/stripe/android/payments/core/injection/PaymentLauncherModule;Ljavax/inject/Provider;Ljavax/inject/Provider;)Lcom/stripe/android/payments/core/injection/PaymentLauncherModule_ProvideApiRequestOptionsFactory; diff --git a/payments-core/src/main/java/com/stripe/android/PaymentController.kt b/payments-core/src/main/java/com/stripe/android/PaymentController.kt index 5f73bf616c3..58b98d267bf 100644 --- a/payments-core/src/main/java/com/stripe/android/PaymentController.kt +++ b/payments-core/src/main/java/com/stripe/android/PaymentController.kt @@ -5,7 +5,6 @@ import android.content.Intent import androidx.activity.result.ActivityResultCallback import androidx.activity.result.ActivityResultCaller import androidx.activity.result.ActivityResultLauncher -import androidx.annotation.RestrictTo import androidx.fragment.app.Fragment import com.stripe.android.exception.APIConnectionException import com.stripe.android.exception.APIException @@ -22,9 +21,7 @@ import com.stripe.android.networking.ApiRequest import com.stripe.android.payments.PaymentFlowResult import com.stripe.android.view.AuthActivityStarterHost -// originally made public for paymentsheet -@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) -interface PaymentController { +internal interface PaymentController { /** * Confirm the Stripe Intent and resolve any next actions */ diff --git a/payments-core/src/main/java/com/stripe/android/payments/PaymentFlowResultProcessor.kt b/payments-core/src/main/java/com/stripe/android/payments/PaymentFlowResultProcessor.kt index 5583fb91da1..fc301f0303f 100644 --- a/payments-core/src/main/java/com/stripe/android/payments/PaymentFlowResultProcessor.kt +++ b/payments-core/src/main/java/com/stripe/android/payments/PaymentFlowResultProcessor.kt @@ -1,7 +1,6 @@ package com.stripe.android.payments import android.content.Context -import androidx.annotation.RestrictTo import com.stripe.android.Logger import com.stripe.android.PaymentController import com.stripe.android.PaymentIntentResult @@ -20,8 +19,7 @@ import kotlin.coroutines.CoroutineContext /** * Class responsible for processing the result of a [PaymentController] confirm operation. */ -@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) // For paymentsheet -sealed class PaymentFlowResultProcessor>( +internal sealed class PaymentFlowResultProcessor>( context: Context, private val publishableKeyProvider: Provider, protected val stripeRepository: StripeRepository, @@ -110,8 +108,7 @@ sealed class PaymentFlowResultProcessor, stripeRepository: StripeRepository, diff --git a/payments-core/src/main/java/com/stripe/android/payments/core/injection/PaymentCommonModule.kt b/payments-core/src/main/java/com/stripe/android/payments/core/injection/PaymentCommonModule.kt index 0eca68950f5..9f306698f41 100644 --- a/payments-core/src/main/java/com/stripe/android/payments/core/injection/PaymentCommonModule.kt +++ b/payments-core/src/main/java/com/stripe/android/payments/core/injection/PaymentCommonModule.kt @@ -3,21 +3,12 @@ package com.stripe.android.payments.core.injection import android.content.Context import androidx.annotation.RestrictTo import com.stripe.android.PaymentConfiguration -import com.stripe.android.PaymentController -import com.stripe.android.StripeIntentResult -import com.stripe.android.StripePaymentController -import com.stripe.android.model.StripeIntent import com.stripe.android.networking.AnalyticsRequestExecutor import com.stripe.android.networking.AnalyticsRequestFactory import com.stripe.android.networking.DefaultAnalyticsRequestExecutor import com.stripe.android.networking.StripeApiRepository import com.stripe.android.networking.StripeRepository -import com.stripe.android.payments.PaymentFlowResultProcessor -import com.stripe.android.payments.PaymentIntentFlowResultProcessor -import com.stripe.android.payments.SetupIntentFlowResultProcessor import com.stripe.android.paymentsheet.model.ClientSecret -import com.stripe.android.paymentsheet.model.PaymentIntentClientSecret -import com.stripe.android.paymentsheet.model.SetupIntentClientSecret import dagger.Binds import dagger.Lazy import dagger.Module @@ -25,7 +16,6 @@ import dagger.Provides import javax.inject.Named import javax.inject.Provider import javax.inject.Singleton -import kotlin.coroutines.CoroutineContext /** * Common module providing payment related dependencies. @@ -71,71 +61,6 @@ abstract class PaymentCommonModule { { lazyPaymentConfiguration.get().publishableKey } ) - @Provides - @Singleton - internal fun provideStripePaymentController( - appContext: Context, - stripeApiRepository: StripeApiRepository, - lazyPaymentConfiguration: Lazy, - @Named(ENABLE_LOGGING) enableLogging: Boolean - ): PaymentController { - return StripePaymentController( - appContext, - { lazyPaymentConfiguration.get().publishableKey }, - stripeApiRepository, - enableLogging - ) - } - - @Provides - @Singleton - internal fun providePaymentIntentFlowResultProcessor( - appContext: Context, - lazyPaymentConfiguration: Lazy, - stripeApiRepository: StripeApiRepository, - @Named(ENABLE_LOGGING) enableLogging: Boolean, - @IOContext workContext: CoroutineContext - ) = PaymentIntentFlowResultProcessor( - appContext, - { lazyPaymentConfiguration.get().publishableKey }, - stripeApiRepository, - enableLogging, - workContext - ) - - @Provides - @Singleton - internal fun provideSetupIntentFlowResultProcessor( - appContext: Context, - lazyPaymentConfiguration: Lazy, - stripeApiRepository: StripeApiRepository, - @Named(ENABLE_LOGGING) enableLogging: Boolean, - @IOContext workContext: CoroutineContext - ) = SetupIntentFlowResultProcessor( - appContext, - { lazyPaymentConfiguration.get().publishableKey }, - stripeApiRepository, - enableLogging, - workContext - ) - - /** - * Fetch the correct [PaymentFlowResultProcessor] based on current [ClientSecret]. - * - * Should always be injected with [Provider]. - */ - @Provides - internal fun providePaymentFlowResultProcessor( - clientSecret: ClientSecret, - paymentIntentFlowResultProcessor: PaymentIntentFlowResultProcessor, - setupIntentFlowResultProcessor: SetupIntentFlowResultProcessor - ): PaymentFlowResultProcessor> { - return when (clientSecret) { - is PaymentIntentClientSecret -> paymentIntentFlowResultProcessor - is SetupIntentClientSecret -> setupIntentFlowResultProcessor - } - } - @Provides @Singleton fun provideAnalyticsRequestFactory( diff --git a/paymentsheet/api/paymentsheet.api b/paymentsheet/api/paymentsheet.api index 2e0fc458475..2ed7bc8e060 100644 --- a/paymentsheet/api/paymentsheet.api +++ b/paymentsheet/api/paymentsheet.api @@ -537,11 +537,11 @@ public final class com/stripe/android/paymentsheet/flowcontroller/DefaultFlowCon } public final class com/stripe/android/paymentsheet/flowcontroller/DefaultFlowController_Factory : dagger/internal/Factory { - public fun (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)V - public static fun create (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)Lcom/stripe/android/paymentsheet/flowcontroller/DefaultFlowController_Factory; + public fun (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)V + public static fun create (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)Lcom/stripe/android/paymentsheet/flowcontroller/DefaultFlowController_Factory; public fun get ()Lcom/stripe/android/paymentsheet/flowcontroller/DefaultFlowController; public synthetic fun get ()Ljava/lang/Object; - public static fun newInstance (Lkotlinx/coroutines/CoroutineScope;Landroidx/lifecycle/LifecycleOwner;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;Lcom/stripe/android/paymentsheet/model/PaymentOptionFactory;Lcom/stripe/android/paymentsheet/PaymentOptionCallback;Lcom/stripe/android/paymentsheet/PaymentSheetResultCallback;Landroidx/activity/result/ActivityResultCaller;ILcom/stripe/android/paymentsheet/flowcontroller/FlowControllerInitializer;Lcom/stripe/android/paymentsheet/analytics/EventReporter;Lcom/stripe/android/paymentsheet/flowcontroller/FlowControllerViewModel;Lcom/stripe/android/PaymentController;Ldagger/Lazy;Ljavax/inject/Provider;Lkotlin/coroutines/CoroutineContext;)Lcom/stripe/android/paymentsheet/flowcontroller/DefaultFlowController; + public static fun newInstance (Lkotlinx/coroutines/CoroutineScope;Landroidx/lifecycle/LifecycleOwner;Lkotlin/jvm/functions/Function0;Lcom/stripe/android/paymentsheet/model/PaymentOptionFactory;Lcom/stripe/android/paymentsheet/PaymentOptionCallback;Lcom/stripe/android/paymentsheet/PaymentSheetResultCallback;Landroidx/activity/result/ActivityResultCaller;ILcom/stripe/android/paymentsheet/flowcontroller/FlowControllerInitializer;Lcom/stripe/android/paymentsheet/analytics/EventReporter;Lcom/stripe/android/paymentsheet/flowcontroller/FlowControllerViewModel;Lcom/stripe/android/payments/paymentlauncher/StripePaymentLauncherAssistedFactory;Ldagger/Lazy;Lkotlin/coroutines/CoroutineContext;)Lcom/stripe/android/paymentsheet/flowcontroller/DefaultFlowController; } public final class com/stripe/android/paymentsheet/forms/FormViewModel_Factory : dagger/internal/Factory { diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowController.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowController.kt index a63100ee256..19080ad6a6a 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowController.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowController.kt @@ -12,21 +12,21 @@ import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.OnLifecycleEvent import androidx.lifecycle.ViewModelStoreOwner import com.stripe.android.PaymentConfiguration -import com.stripe.android.PaymentController -import com.stripe.android.StripeIntentResult import com.stripe.android.googlepaylauncher.GooglePayEnvironment import com.stripe.android.googlepaylauncher.GooglePayPaymentMethodLauncher import com.stripe.android.googlepaylauncher.GooglePayPaymentMethodLauncherContract +import com.stripe.android.model.ConfirmPaymentIntentParams +import com.stripe.android.model.ConfirmSetupIntentParams import com.stripe.android.model.PaymentIntent -import com.stripe.android.model.StripeIntent -import com.stripe.android.networking.ApiRequest -import com.stripe.android.payments.PaymentFlowResult -import com.stripe.android.payments.PaymentFlowResultProcessor import com.stripe.android.payments.core.injection.Injectable import com.stripe.android.payments.core.injection.Injector import com.stripe.android.payments.core.injection.InjectorKey import com.stripe.android.payments.core.injection.UIContext import com.stripe.android.payments.core.injection.WeakMapInjectorRegistry +import com.stripe.android.payments.paymentlauncher.PaymentLauncher +import com.stripe.android.payments.paymentlauncher.PaymentLauncherContract +import com.stripe.android.payments.paymentlauncher.PaymentResult +import com.stripe.android.payments.paymentlauncher.StripePaymentLauncherAssistedFactory import com.stripe.android.paymentsheet.PaymentOptionCallback import com.stripe.android.paymentsheet.PaymentOptionContract import com.stripe.android.paymentsheet.PaymentOptionResult @@ -45,7 +45,6 @@ import com.stripe.android.paymentsheet.model.PaymentOptionFactory import com.stripe.android.paymentsheet.model.PaymentSelection import com.stripe.android.paymentsheet.model.SavedSelection import com.stripe.android.paymentsheet.model.SetupIntentClientSecret -import com.stripe.android.view.AuthActivityStarterHost import dagger.Lazy import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.isActive @@ -53,7 +52,6 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import kotlinx.parcelize.Parcelize import javax.inject.Inject -import javax.inject.Provider import javax.inject.Singleton import kotlin.coroutines.CoroutineContext @@ -63,7 +61,6 @@ internal class DefaultFlowController @Inject internal constructor( private val lifecycleScope: CoroutineScope, lifecycleOwner: LifecycleOwner, private val statusBarColor: () -> Int?, - private val authHostSupplier: () -> AuthActivityStarterHost, private val paymentOptionFactory: PaymentOptionFactory, private val paymentOptionCallback: PaymentOptionCallback, private val paymentResultCallback: PaymentSheetResultCallback, @@ -73,22 +70,12 @@ internal class DefaultFlowController @Inject internal constructor( private val flowControllerInitializer: FlowControllerInitializer, private val eventReporter: EventReporter, private val viewModel: FlowControllerViewModel, - private val paymentController: PaymentController, + private val paymentLauncherFactory: StripePaymentLauncherAssistedFactory, /** * [PaymentConfiguration] is [Lazy] because the client might set publishableKey and * stripeAccountId after creating a [DefaultFlowController]. */ private val lazyPaymentConfiguration: Lazy, - /** - * [PaymentFlowResultProcessor] is wrapped with [Provider] because it needs - * [FlowControllerViewModel.initData] to be set, which might happen multiple times post - * [DefaultFlowController] creation and after [configureWithPaymentIntent] or - * [configureWithPaymentIntent] is called. - * TODO: Observe on [FlowControllerViewModel.initData] change and initialize - * paymentFlowResultProcessor afterwards. - */ - private val paymentFlowResultProcessorProvider: - Provider>>, @UIContext private val uiContext: CoroutineContext ) : PaymentSheet.FlowController, Injector { private val paymentOptionActivityLauncher: ActivityResultLauncher @@ -101,6 +88,8 @@ internal class DefaultFlowController @Inject internal constructor( */ lateinit var flowControllerComponent: FlowControllerComponent + private var paymentLauncher: PaymentLauncher? = null + override fun inject(injectable: Injectable<*>) { when (injectable) { is PaymentOptionsViewModel.Factory -> { @@ -114,15 +103,19 @@ internal class DefaultFlowController @Inject internal constructor( object : LifecycleObserver { @OnLifecycleEvent(Lifecycle.Event.ON_CREATE) fun onCreate() { - paymentController.registerLaunchersWithActivityResultCaller( - activityResultCaller, - ::onPaymentFlowResult + paymentLauncher = paymentLauncherFactory.create( + { lazyPaymentConfiguration.get().publishableKey }, + { lazyPaymentConfiguration.get().stripeAccountId }, + activityResultCaller.registerForActivityResult( + PaymentLauncherContract(), + ::onPaymentResult + ) ) } @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) fun onDestroy() { - paymentController.unregisterLaunchers() + paymentLauncher = null } } ) @@ -270,14 +263,14 @@ internal class DefaultFlowController @Inject internal constructor( else -> null }?.let { confirmParams -> lifecycleScope.launch { - paymentController.startConfirmAndAuth( - authHostSupplier(), - confirmParams, - ApiRequest.Options( - apiKey = lazyPaymentConfiguration.get().publishableKey, - stripeAccount = lazyPaymentConfiguration.get().stripeAccountId - ) - ) + when (confirmParams) { + is ConfirmPaymentIntentParams -> { + paymentLauncher?.confirm(confirmParams) + } + is ConfirmSetupIntentParams -> { + paymentLauncher?.confirm(confirmParams) + } + } } } } @@ -394,49 +387,35 @@ internal class DefaultFlowController @Inject internal constructor( } } - internal fun onPaymentFlowResult( - paymentFlowResult: PaymentFlowResult.Unvalidated - ) { + internal fun onPaymentResult(paymentResult: PaymentResult) { lifecycleScope.launch { - runCatching { - paymentFlowResultProcessorProvider.get().processResult( - paymentFlowResult - ) - }.fold( - onSuccess = { - withContext(uiContext) { - paymentResultCallback.onPaymentSheetResult( - createPaymentSheetResult(it) - ) - } - }, - onFailure = { - withContext(uiContext) { - paymentResultCallback.onPaymentSheetResult( - PaymentSheetResult.Failed(it) - ) - } + paymentResultCallback.onPaymentSheetResult( + withContext(uiContext) { + createPaymentSheetResult(paymentResult) } ) } } private fun createPaymentSheetResult( - stripeIntentResult: StripeIntentResult - ) = when (stripeIntentResult.outcome) { - StripeIntentResult.Outcome.SUCCEEDED -> { + paymentResult: PaymentResult + ): PaymentSheetResult = when (paymentResult) { + is PaymentResult.Completed -> { PaymentSheetResult.Completed } - StripeIntentResult.Outcome.CANCELED -> { + is PaymentResult.Canceled -> { PaymentSheetResult.Canceled } + is PaymentResult.Failed -> { + PaymentSheetResult.Failed( + IllegalArgumentException( + "Failed to confirm intent: ${paymentResult.throwable.message}" + ) + ) + } else -> { PaymentSheetResult.Failed( - error = stripeIntentResult.intent.lastErrorMessage?.let { - IllegalArgumentException( - "Failed to confirm ${stripeIntentResult.intent.javaClass.simpleName}: $it" - ) - } ?: RuntimeException("Failed to complete payment.") + RuntimeException("Failed to complete payment.") ) } } @@ -459,7 +438,6 @@ internal class DefaultFlowController @Inject internal constructor( lifecycleOwner: LifecycleOwner, activityResultCaller: ActivityResultCaller, statusBarColor: () -> Int?, - authHostSupplier: () -> AuthActivityStarterHost, paymentOptionFactory: PaymentOptionFactory, paymentOptionCallback: PaymentOptionCallback, paymentResultCallback: PaymentSheetResultCallback @@ -472,7 +450,6 @@ internal class DefaultFlowController @Inject internal constructor( .lifeCycleOwner(lifecycleOwner) .activityResultCaller(activityResultCaller) .statusBarColor(statusBarColor) - .authHostSupplier(authHostSupplier) .paymentOptionFactory(paymentOptionFactory) .paymentOptionCallback(paymentOptionCallback) .paymentResultCallback(paymentResultCallback) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/FlowControllerFactory.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/FlowControllerFactory.kt index 08ba2886d4d..b7f0e64bbde 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/FlowControllerFactory.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/flowcontroller/FlowControllerFactory.kt @@ -11,7 +11,6 @@ import com.stripe.android.paymentsheet.PaymentOptionCallback import com.stripe.android.paymentsheet.PaymentSheet import com.stripe.android.paymentsheet.PaymentSheetResultCallback import com.stripe.android.paymentsheet.model.PaymentOptionFactory -import com.stripe.android.view.AuthActivityStarterHost import kotlinx.coroutines.CoroutineScope internal class FlowControllerFactory( @@ -21,7 +20,6 @@ internal class FlowControllerFactory( private val appContext: Context, private val activityResultCaller: ActivityResultCaller, private val statusBarColor: () -> Int?, - private val authHostSupplier: () -> AuthActivityStarterHost, private val paymentOptionFactory: PaymentOptionFactory, private val paymentOptionCallback: PaymentOptionCallback, private val paymentResultCallback: PaymentSheetResultCallback @@ -37,7 +35,6 @@ internal class FlowControllerFactory( activity.applicationContext, activity, { activity.window.statusBarColor }, - { AuthActivityStarterHost.create(activity) }, PaymentOptionFactory(activity.resources), paymentOptionCallback, paymentResultCallback @@ -54,7 +51,6 @@ internal class FlowControllerFactory( fragment.requireContext(), fragment, { fragment.activity?.window?.statusBarColor }, - { AuthActivityStarterHost.create(fragment) }, PaymentOptionFactory(fragment.resources), paymentOptionCallback, paymentResultCallback @@ -68,7 +64,6 @@ internal class FlowControllerFactory( lifecycleOwner = lifecycleOwner, activityResultCaller = activityResultCaller, statusBarColor = statusBarColor, - authHostSupplier = authHostSupplier, paymentOptionFactory = paymentOptionFactory, paymentOptionCallback = paymentOptionCallback, paymentResultCallback = paymentResultCallback diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/injection/FlowControllerComponent.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/injection/FlowControllerComponent.kt index 85adcb1a270..0369870623d 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/injection/FlowControllerComponent.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/injection/FlowControllerComponent.kt @@ -12,7 +12,6 @@ import com.stripe.android.paymentsheet.PaymentOptionsViewModel import com.stripe.android.paymentsheet.PaymentSheetResultCallback import com.stripe.android.paymentsheet.flowcontroller.DefaultFlowController import com.stripe.android.paymentsheet.model.PaymentOptionFactory -import com.stripe.android.view.AuthActivityStarterHost import dagger.BindsInstance import dagger.Component import kotlinx.coroutines.CoroutineScope @@ -52,9 +51,6 @@ internal interface FlowControllerComponent { @BindsInstance fun statusBarColor(statusBarColor: () -> Int?): Builder - @BindsInstance - fun authHostSupplier(authHostSupplier: () -> AuthActivityStarterHost): Builder - @BindsInstance fun paymentOptionFactory(paymentOptionFactory: PaymentOptionFactory): Builder diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetActivityTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetActivityTest.kt index 77f9255c2c5..1b993429e1c 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetActivityTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetActivityTest.kt @@ -12,8 +12,6 @@ import com.google.common.truth.Truth.assertThat import com.stripe.android.ApiKeyFixtures import com.stripe.android.Logger import com.stripe.android.PaymentConfiguration -import com.stripe.android.PaymentController -import com.stripe.android.PaymentIntentResult import com.stripe.android.googlepaylauncher.GooglePayPaymentMethodLauncher import com.stripe.android.googlepaylauncher.GooglePayPaymentMethodLauncherContract import com.stripe.android.googlepaylauncher.GooglePayPaymentMethodLauncherFactory @@ -24,7 +22,6 @@ import com.stripe.android.model.PaymentIntentFixtures import com.stripe.android.model.PaymentMethod import com.stripe.android.model.PaymentMethodCreateParamsFixtures import com.stripe.android.model.PaymentMethodFixtures -import com.stripe.android.payments.PaymentFlowResultProcessor import com.stripe.android.payments.paymentlauncher.PaymentResult import com.stripe.android.payments.paymentlauncher.StripePaymentLauncherAssistedFactory import com.stripe.android.paymentsheet.PaymentSheetViewModel.CheckoutIdentifier @@ -54,9 +51,7 @@ import kotlinx.coroutines.test.setMain import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith -import org.mockito.kotlin.any import org.mockito.kotlin.mock -import org.mockito.kotlin.whenever import org.robolectric.RobolectricTestRunner import kotlin.test.AfterTest import kotlin.test.BeforeTest @@ -499,10 +494,6 @@ internal class PaymentSheetActivityTest { @Test fun `successful payment should dismiss bottom sheet`() { - val viewModel = createViewModel( - paymentIntentResult = PaymentIntentResult(PaymentIntentFixtures.PI_SUCCEEDED) - ) - val scenario = activityScenario(viewModel) scenario.launch(intent).onActivity { activity -> // wait for bottom sheet to animate in @@ -713,14 +704,8 @@ internal class PaymentSheetActivityTest { private fun createViewModel( paymentIntent: PaymentIntent = PAYMENT_INTENT, - paymentMethods: List = PAYMENT_METHODS, - paymentIntentResult: PaymentIntentResult = PaymentIntentResult(paymentIntent) + paymentMethods: List = PAYMENT_METHODS ): PaymentSheetViewModel = runBlocking { - val paymentFlowResultProcessor = - mock>() - whenever(paymentFlowResultProcessor.processResult(any())).thenReturn(paymentIntentResult) - - val mockPaymentLauncher: PaymentController = mock() PaymentSheetViewModel( ApplicationProvider.getApplicationContext(), PaymentSheetFixtures.ARGS_CUSTOMER_WITH_GOOGLEPAY, diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowControllerTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowControllerTest.kt index bcd2f244f28..1551b08bc8e 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowControllerTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/flowcontroller/DefaultFlowControllerTest.kt @@ -7,14 +7,12 @@ import androidx.activity.result.ActivityResultLauncher import androidx.core.content.ContextCompat import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleOwner +import androidx.lifecycle.LifecycleRegistry import androidx.lifecycle.ViewModelProvider import androidx.test.core.app.ApplicationProvider import com.google.common.truth.Truth.assertThat import com.stripe.android.ApiKeyFixtures import com.stripe.android.PaymentConfiguration -import com.stripe.android.PaymentController -import com.stripe.android.PaymentIntentResult -import com.stripe.android.StripeIntentResult import com.stripe.android.googlepaylauncher.GooglePayEnvironment import com.stripe.android.googlepaylauncher.GooglePayPaymentMethodLauncher import com.stripe.android.googlepaylauncher.GooglePayPaymentMethodLauncherContract @@ -26,9 +24,10 @@ import com.stripe.android.model.PaymentMethodCreateParams import com.stripe.android.model.PaymentMethodCreateParamsFixtures import com.stripe.android.model.PaymentMethodFixtures import com.stripe.android.model.StripeIntent -import com.stripe.android.networking.ApiRequest -import com.stripe.android.payments.PaymentFlowResult -import com.stripe.android.payments.PaymentFlowResultProcessor +import com.stripe.android.payments.paymentlauncher.PaymentLauncherContract +import com.stripe.android.payments.paymentlauncher.PaymentResult +import com.stripe.android.payments.paymentlauncher.StripePaymentLauncher +import com.stripe.android.payments.paymentlauncher.StripePaymentLauncherAssistedFactory import com.stripe.android.paymentsheet.PaymentOptionCallback import com.stripe.android.paymentsheet.PaymentOptionContract import com.stripe.android.paymentsheet.PaymentOptionResult @@ -44,7 +43,6 @@ import com.stripe.android.paymentsheet.model.PaymentOptionFactory import com.stripe.android.paymentsheet.model.PaymentSelection import com.stripe.android.paymentsheet.model.SavedSelection import com.stripe.android.view.ActivityScenarioFactory -import com.stripe.android.view.AuthActivityStarterHost import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.Job @@ -76,12 +74,10 @@ internal class DefaultFlowControllerTest { private val paymentOptionCallback = mock() private val paymentResultCallback = mock() - private val paymentController = mock() + private val paymentLauncherAssistedFactory = mock() + private val paymentLauncher = mock() private val eventReporter = mock() - private val flowResultProcessor = - mock>>() - private val paymentOptionActivityLauncher = mock>() @@ -129,7 +125,20 @@ internal class DefaultFlowControllerTest { ) ).thenReturn(googlePayActivityLauncher) - whenever(lifeCycleOwner.lifecycle).thenReturn(mock()) + whenever( + activityResultCaller.registerForActivityResult( + any(), + any() + ) + ).thenReturn(mock()) + + whenever(paymentLauncherAssistedFactory.create(any(), any(), any())) + .thenReturn(paymentLauncher) + + // set lifecycle to CREATED to trigger creation of payment launcher object within flowController. + val lifecycle = LifecycleRegistry(lifeCycleOwner) + lifecycle.currentState = Lifecycle.State.CREATED + whenever(lifeCycleOwner.lifecycle).thenReturn(lifecycle) } @AfterTest @@ -403,8 +412,8 @@ internal class DefaultFlowControllerTest { } @Test - fun `confirmPayment() without paymentSelection should not call paymentController`() { - verifyNoMoreInteractions(paymentController) + fun `confirmPayment() without paymentSelection should not call paymentLauncher`() { + verifyNoMoreInteractions(paymentLauncher) flowController.configureWithPaymentIntent( PaymentSheetFixtures.CLIENT_SECRET, PaymentSheetFixtures.CONFIG_CUSTOMER_WITH_GOOGLEPAY @@ -414,7 +423,7 @@ internal class DefaultFlowControllerTest { } @Test - fun `confirmPaymentSelection() with new card payment method should start paymentController`() = + fun `confirmPaymentSelection() with new card payment method should start paymentlauncher`() = runBlockingTest { flowController.confirmPaymentSelection( NEW_CARD_PAYMENT_SELECTION, @@ -438,7 +447,7 @@ internal class DefaultFlowControllerTest { } @Test - fun `confirmPaymentSelection() with generic payment method should start paymentController`() { + fun `confirmPaymentSelection() with generic payment method should start paymentLauncher`() { flowController.confirmPaymentSelection( GENERIC_PAYMENT_SELECTION, InitData( @@ -474,15 +483,9 @@ internal class DefaultFlowControllerTest { mandateId = null, mandateData = null, ) - val apiOptions = ApiRequest.Options( - apiKey = ApiKeyFixtures.FAKE_PUBLISHABLE_KEY, - stripeAccount = null - ) - verify(paymentController).startConfirmAndAuth( - any(), + verify(paymentLauncher).confirm( eq(confirmPaymentIntentParams), - eq(apiOptions) ) } @@ -534,7 +537,7 @@ internal class DefaultFlowControllerTest { } @Test - fun `onGooglePayResult() when PaymentData result should invoke startConfirmAndAuth() with expected params`() = + fun `onGooglePayResult() when PaymentData result should invoke confirm() with expected params`() = testDispatcher.runBlockingTest { flowController.configureWithPaymentIntent( PaymentSheetFixtures.CLIENT_SECRET, @@ -548,13 +551,10 @@ internal class DefaultFlowControllerTest { ) ) - verify(paymentController).startConfirmAndAuth( - any(), - argWhere { - val params = (it as ConfirmPaymentIntentParams) + verify(paymentLauncher).confirm( + argWhere { params: ConfirmPaymentIntentParams -> params.paymentMethodId == "pm_123456789" - }, - any() + } ) } @@ -580,15 +580,8 @@ internal class DefaultFlowControllerTest { } @Test - fun `onPaymentFlowResult when succeeded should invoke callback with Completed`() = + fun `onPaymentResult when succeeded should invoke callback with Completed`() = testDispatcher.runBlockingTest { - whenever(flowResultProcessor.processResult(any())).thenReturn( - PaymentIntentResult( - PaymentIntentFixtures.PI_WITH_SHIPPING, - StripeIntentResult.Outcome.SUCCEEDED - ) - ) - var isReadyState = false flowController.configureWithPaymentIntent( PaymentSheetFixtures.CLIENT_SECRET @@ -598,12 +591,7 @@ internal class DefaultFlowControllerTest { assertThat(isReadyState) .isTrue() - flowController.onPaymentFlowResult( - PaymentFlowResult.Unvalidated( - clientSecret = PaymentSheetFixtures.CLIENT_SECRET, - flowOutcome = StripeIntentResult.Outcome.CANCELED - ) - ) + flowController.onPaymentResult(PaymentResult.Completed) verify(paymentResultCallback).onPaymentSheetResult( argWhere { paymentResult -> @@ -613,87 +601,8 @@ internal class DefaultFlowControllerTest { } @Test - fun `onPaymentFlowResult when processing payment method which has delay should invoke callback with Completed`() = + fun `onPaymentResult when canceled should invoke callback with Cancelled`() = testDispatcher.runBlockingTest { - whenever(flowResultProcessor.processResult(any())).thenReturn( - PaymentIntentResult( - PaymentIntentFixtures.PI_WITH_SHIPPING.copy( - paymentMethod = PaymentMethodFixtures.SEPA_DEBIT_PAYMENT_METHOD, - status = StripeIntent.Status.Processing - ), - StripeIntentResult.Outcome.UNKNOWN - ) - ) - - var isReadyState = false - flowController.configureWithPaymentIntent( - PaymentSheetFixtures.CLIENT_SECRET - ) { isReady, _ -> - isReadyState = isReady - } - assertThat(isReadyState) - .isTrue() - - flowController.onPaymentFlowResult( - PaymentFlowResult.Unvalidated( - clientSecret = PaymentSheetFixtures.CLIENT_SECRET, - flowOutcome = StripeIntentResult.Outcome.UNKNOWN - ) - ) - - verify(paymentResultCallback).onPaymentSheetResult( - argWhere { paymentResult -> - paymentResult is PaymentSheetResult.Completed - } - ) - } - - @Test - fun `onPaymentFlowResult when processing payment method which does not have delay should invoke callback with Failed`() = - testDispatcher.runBlockingTest { - whenever(flowResultProcessor.processResult(any())).thenReturn( - PaymentIntentResult( - PaymentIntentFixtures.PI_WITH_SHIPPING.copy( - paymentMethod = PaymentMethodFixtures.CARD_PAYMENT_METHOD, - status = StripeIntent.Status.Processing - ), - StripeIntentResult.Outcome.UNKNOWN - ) - ) - - var isReadyState = false - flowController.configureWithPaymentIntent( - PaymentSheetFixtures.CLIENT_SECRET - ) { isReady, _ -> - isReadyState = isReady - } - assertThat(isReadyState) - .isTrue() - - flowController.onPaymentFlowResult( - PaymentFlowResult.Unvalidated( - clientSecret = PaymentSheetFixtures.CLIENT_SECRET, - flowOutcome = StripeIntentResult.Outcome.UNKNOWN - ) - ) - - verify(paymentResultCallback).onPaymentSheetResult( - argWhere { paymentResult -> - paymentResult is PaymentSheetResult.Failed - } - ) - } - - @Test - fun `onPaymentFlowResult when canceled should invoke callback with Cancelled`() = - testDispatcher.runBlockingTest { - whenever(flowResultProcessor.processResult(any())).thenReturn( - PaymentIntentResult( - PaymentIntentFixtures.CANCELLED, - StripeIntentResult.Outcome.CANCELED - ) - ) - var isReadyState = false flowController.configureWithPaymentIntent( PaymentSheetFixtures.CLIENT_SECRET @@ -703,12 +612,7 @@ internal class DefaultFlowControllerTest { assertThat(isReadyState) .isTrue() - flowController.onPaymentFlowResult( - PaymentFlowResult.Unvalidated( - clientSecret = PaymentSheetFixtures.CLIENT_SECRET, - flowOutcome = StripeIntentResult.Outcome.CANCELED - ) - ) + flowController.onPaymentResult(PaymentResult.Canceled) verify(paymentResultCallback).onPaymentSheetResult( argWhere { paymentResult -> @@ -718,21 +622,9 @@ internal class DefaultFlowControllerTest { } @Test - fun `onPaymentFlowResult when error should invoke callback with Failed`() = + fun `onPaymentResult when error should invoke callback with Failed`() = testDispatcher.runBlockingTest { - whenever(flowResultProcessor.processResult(any())).thenReturn( - PaymentIntentResult( - PaymentIntentFixtures.PI_WITH_LAST_PAYMENT_ERROR, - StripeIntentResult.Outcome.FAILED - ) - ) - - flowController.onPaymentFlowResult( - PaymentFlowResult.Unvalidated( - clientSecret = PaymentSheetFixtures.CLIENT_SECRET, - flowOutcome = StripeIntentResult.Outcome.CANCELED - ) - ) + flowController.onPaymentResult(PaymentResult.Failed(Throwable("error"))) verify(paymentResultCallback).onPaymentSheetResult( argWhere { paymentResult -> @@ -759,7 +651,6 @@ internal class DefaultFlowControllerTest { testScope, lifeCycleOwner, { activity.window.statusBarColor }, - { AuthActivityStarterHost.create(activity) }, PaymentOptionFactory(activity.resources), paymentOptionCallback, paymentResultCallback, @@ -768,9 +659,8 @@ internal class DefaultFlowControllerTest { flowControllerInitializer, eventReporter, ViewModelProvider(activity)[FlowControllerViewModel::class.java], - paymentController, + paymentLauncherAssistedFactory, { PaymentConfiguration.getInstance(activity) }, - { flowResultProcessor }, testDispatcher ) diff --git a/paymentsheet/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/paymentsheet/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 00000000000..1f0955d450f --- /dev/null +++ b/paymentsheet/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline