导航菜单

页面标题

页面副标题

Crafto v9.3.3 - PaymentSheetViewModel.java 源代码

正在查看: Crafto v9.3.3 应用的 PaymentSheetViewModel.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.stripe.android.paymentsheet;

import Hk.p;
import android.app.Application;
import android.os.Bundle;
import androidx.lifecycle.N;
import androidx.lifecycle.Q;
import androidx.lifecycle.S;
import androidx.lifecycle.T;
import androidx.lifecycle.e0;
import androidx.lifecycle.q0;
import androidx.lifecycle.r0;
import androidx.lifecycle.s0;
import androidx.lifecycle.w0;
import com.stripe.android.PaymentConfiguration;
import com.stripe.android.camera.scanui.CameraView;
import com.stripe.android.core.Logger;
import com.stripe.android.core.injection.IOContext;
import com.stripe.android.core.injection.InjectWithFallbackKt;
import com.stripe.android.core.injection.Injectable;
import com.stripe.android.core.injection.InjectorKey;
import com.stripe.android.core.injection.InjectorKt;
import com.stripe.android.googlepaylauncher.GooglePayEnvironment;
import com.stripe.android.googlepaylauncher.GooglePayPaymentMethodLauncher;
import com.stripe.android.googlepaylauncher.GooglePayPaymentMethodLauncherContract;
import com.stripe.android.googlepaylauncher.injection.GooglePayPaymentMethodLauncherFactory;
import com.stripe.android.link.LinkActivityResult;
import com.stripe.android.link.LinkPaymentDetails;
import com.stripe.android.link.injection.LinkPaymentLauncherFactory;
import com.stripe.android.model.ConfirmPaymentIntentParams;
import com.stripe.android.model.ConfirmSetupIntentParams;
import com.stripe.android.model.ConfirmStripeIntentParams;
import com.stripe.android.model.PaymentIntent;
import com.stripe.android.model.PaymentMethod;
import com.stripe.android.model.StripeIntent;
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.PaymentSheet;
import com.stripe.android.paymentsheet.PaymentSheetContract;
import com.stripe.android.paymentsheet.PaymentSheetResult;
import com.stripe.android.paymentsheet.analytics.EventReporter;
import com.stripe.android.paymentsheet.injection.DaggerPaymentSheetLauncherComponent;
import com.stripe.android.paymentsheet.injection.PaymentSheetViewModelModule;
import com.stripe.android.paymentsheet.injection.PaymentSheetViewModelSubcomponent;
import com.stripe.android.paymentsheet.model.ConfirmStripeIntentParamsFactory;
import com.stripe.android.paymentsheet.model.FragmentConfig;
import com.stripe.android.paymentsheet.model.PaymentIntentClientSecret;
import com.stripe.android.paymentsheet.model.PaymentSelection;
import com.stripe.android.paymentsheet.model.PaymentSheetViewState;
import com.stripe.android.paymentsheet.model.StripeIntentValidator;
import com.stripe.android.paymentsheet.paymentdatacollection.ach.ACHText;
import com.stripe.android.paymentsheet.repositories.CustomerRepository;
import com.stripe.android.paymentsheet.repositories.StripeIntentRepository;
import com.stripe.android.paymentsheet.viewmodels.BaseSheetViewModel;
import com.stripe.android.ui.core.forms.resources.ResourceRepository;
import dl.H;
import dl.J;
import java.util.Iterator;
import kotlin.Metadata;
import kotlin.NoWhenBranchMatchedException;
import kotlin.Unit;
import kotlin.coroutines.CoroutineContext;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import org.jetbrains.annotations.NotNull;

@Metadata
public final class PaymentSheetViewModel extends BaseSheetViewModel<TransitionTarget> {

    @NotNull
    private final S<PaymentSheetResult> _paymentSheetResult;

    @NotNull
    private final S<BaseSheetViewModel.Event<ConfirmStripeIntentParams>> _startConfirm;

    @NotNull
    private final S<PaymentSheetViewState> _viewState;

    @NotNull
    private final PaymentSheetContract.Args args;

    @NotNull
    private CheckoutIdentifier checkoutIdentifier;

    @NotNull
    private final ConfirmStripeIntentParamsFactory<ConfirmStripeIntentParams> confirmParamsFactory;
    private final GooglePayPaymentMethodLauncher.Config googlePayLauncherConfig;
    private GooglePayPaymentMethodLauncher googlePayPaymentMethodLauncher;

    @NotNull
    private final GooglePayPaymentMethodLauncherFactory googlePayPaymentMethodLauncherFactory;
    private PaymentSelection lastSelectedPaymentMethod;

    @NotNull
    private final Ti.a<PaymentConfiguration> lazyPaymentConfig;
    private PaymentSelection.New newPaymentSelection;
    private PaymentLauncher paymentLauncher;

    @NotNull
    private final StripePaymentLauncherAssistedFactory paymentLauncherFactory;

    @NotNull
    private final N<PaymentSheetResult> paymentSheetResult;

    @NotNull
    private final Q<Boolean> showTopContainer;

    @NotNull
    private final N<BaseSheetViewModel.Event<ConfirmStripeIntentParams>> startConfirm;

    @NotNull
    private final StripeIntentRepository stripeIntentRepository;

    @NotNull
    private final StripeIntentValidator stripeIntentValidator;

    @NotNull
    private final N<PaymentSheetViewState> viewState;

    @Metadata
    public enum CheckoutIdentifier {
        SheetTopGooglePay,
        SheetBottomBuy,
        None
    }

    @Metadata
    public static final class Factory extends androidx.lifecycle.a implements Injectable<FallbackInitializeParam> {

        @NotNull
        private final Function0<Application> applicationSupplier;

        @NotNull
        private final Function0<PaymentSheetContract.Args> starterArgsSupplier;
        public xk.a<PaymentSheetViewModelSubcomponent.Builder> subComponentBuilderProvider;

        @Metadata
        public static final class FallbackInitializeParam {

            @NotNull
            private final Application application;

            public FallbackInitializeParam(@NotNull Application application) {
                Intrinsics.checkNotNullParameter(application, "application");
                this.application = application;
            }

            public static FallbackInitializeParam copy$default(FallbackInitializeParam fallbackInitializeParam, Application application, int i, Object obj) {
                if ((i & 1) != 0) {
                    application = fallbackInitializeParam.application;
                }
                return fallbackInitializeParam.copy(application);
            }

            @NotNull
            public final Application component1() {
                return this.application;
            }

            @NotNull
            public final FallbackInitializeParam copy(@NotNull Application application) {
                Intrinsics.checkNotNullParameter(application, "application");
                return new FallbackInitializeParam(application);
            }

            public boolean equals(Object obj) {
                if (this == obj) {
                    return true;
                }
                return (obj instanceof FallbackInitializeParam) && Intrinsics.areEqual(this.application, ((FallbackInitializeParam) obj).application);
            }

            @NotNull
            public final Application getApplication() {
                return this.application;
            }

            public int hashCode() {
                return this.application.hashCode();
            }

            @NotNull
            public String toString() {
                return "FallbackInitializeParam(application=" + this.application + ')';
            }
        }

        public Factory(Function0 function0, Function0 function02, W3.f fVar, Bundle bundle, int i, DefaultConstructorMarker defaultConstructorMarker) {
            this(function0, function02, fVar, (i & 8) != 0 ? null : bundle);
        }

        @NotNull
        public r0 create(@NotNull al.c cVar, @NotNull y2.a aVar) {
            return w0.a(this, cVar, aVar);
        }

        @NotNull
        public final xk.a<PaymentSheetViewModelSubcomponent.Builder> getSubComponentBuilderProvider() {
            xk.a<PaymentSheetViewModelSubcomponent.Builder> aVar = this.subComponentBuilderProvider;
            if (aVar != null) {
                return aVar;
            }
            Intrinsics.throwUninitializedPropertyAccessException("subComponentBuilderProvider");
            return null;
        }

        public final void setSubComponentBuilderProvider(@NotNull xk.a<PaymentSheetViewModelSubcomponent.Builder> aVar) {
            Intrinsics.checkNotNullParameter(aVar, "<set-?>");
            this.subComponentBuilderProvider = aVar;
        }

        public Factory(@NotNull Function0<? extends Application> function0, @NotNull Function0<PaymentSheetContract.Args> function02, @NotNull W3.f fVar, Bundle bundle) {
            super(fVar, bundle);
            Intrinsics.checkNotNullParameter(function0, "applicationSupplier");
            Intrinsics.checkNotNullParameter(function02, "starterArgsSupplier");
            Intrinsics.checkNotNullParameter(fVar, "owner");
            this.applicationSupplier = function0;
            this.starterArgsSupplier = function02;
        }

        @NotNull
        public <T extends r0> T create(@NotNull String str, @NotNull Class<T> cls, @NotNull e0 e0Var) {
            Intrinsics.checkNotNullParameter(str, "key");
            Intrinsics.checkNotNullParameter(cls, "modelClass");
            Intrinsics.checkNotNullParameter(e0Var, "savedStateHandle");
            PaymentSheetContract.Args args = (PaymentSheetContract.Args) this.starterArgsSupplier.invoke();
            InjectWithFallbackKt.injectWithFallback(this, args.getInjectorKey$paymentsheet_release(), new FallbackInitializeParam((Application) this.applicationSupplier.invoke()));
            return ((PaymentSheetViewModelSubcomponent.Builder) getSubComponentBuilderProvider().get()).paymentSheetViewModelModule(new PaymentSheetViewModelModule(args)).savedStateHandle(e0Var).build().getViewModel();
        }

        @Override
        public void fallbackInitialize(@NotNull FallbackInitializeParam fallbackInitializeParam) {
            Intrinsics.checkNotNullParameter(fallbackInitializeParam, "arg");
            DaggerPaymentSheetLauncherComponent.builder().application(fallbackInitializeParam.getApplication()).injectorKey(InjectorKt.DUMMY_INJECTOR_KEY).build().inject(this);
        }
    }

    @Metadata
    public static abstract class TransitionTarget {

        @Metadata
        public static final class AddPaymentMethodFull extends TransitionTarget {
            public static final int $stable = 8;

            @NotNull
            private final FragmentConfig fragmentConfig;

            public AddPaymentMethodFull(@NotNull FragmentConfig fragmentConfig) {
                super(null);
                Intrinsics.checkNotNullParameter(fragmentConfig, "fragmentConfig");
                this.fragmentConfig = fragmentConfig;
            }

            public static AddPaymentMethodFull copy$default(AddPaymentMethodFull addPaymentMethodFull, FragmentConfig fragmentConfig, int i, Object obj) {
                if ((i & 1) != 0) {
                    fragmentConfig = addPaymentMethodFull.getFragmentConfig();
                }
                return addPaymentMethodFull.copy(fragmentConfig);
            }

            @NotNull
            public final FragmentConfig component1() {
                return getFragmentConfig();
            }

            @NotNull
            public final AddPaymentMethodFull copy(@NotNull FragmentConfig fragmentConfig) {
                Intrinsics.checkNotNullParameter(fragmentConfig, "fragmentConfig");
                return new AddPaymentMethodFull(fragmentConfig);
            }

            public boolean equals(Object obj) {
                if (this == obj) {
                    return true;
                }
                return (obj instanceof AddPaymentMethodFull) && Intrinsics.areEqual(getFragmentConfig(), ((AddPaymentMethodFull) obj).getFragmentConfig());
            }

            @Override
            @NotNull
            public FragmentConfig getFragmentConfig() {
                return this.fragmentConfig;
            }

            public int hashCode() {
                return getFragmentConfig().hashCode();
            }

            @NotNull
            public String toString() {
                return "AddPaymentMethodFull(fragmentConfig=" + getFragmentConfig() + ')';
            }
        }

        @Metadata
        public static final class AddPaymentMethodSheet extends TransitionTarget {
            public static final int $stable = 8;

            @NotNull
            private final FragmentConfig fragmentConfig;

            public AddPaymentMethodSheet(@NotNull FragmentConfig fragmentConfig) {
                super(null);
                Intrinsics.checkNotNullParameter(fragmentConfig, "fragmentConfig");
                this.fragmentConfig = fragmentConfig;
            }

            public static AddPaymentMethodSheet copy$default(AddPaymentMethodSheet addPaymentMethodSheet, FragmentConfig fragmentConfig, int i, Object obj) {
                if ((i & 1) != 0) {
                    fragmentConfig = addPaymentMethodSheet.getFragmentConfig();
                }
                return addPaymentMethodSheet.copy(fragmentConfig);
            }

            @NotNull
            public final FragmentConfig component1() {
                return getFragmentConfig();
            }

            @NotNull
            public final AddPaymentMethodSheet copy(@NotNull FragmentConfig fragmentConfig) {
                Intrinsics.checkNotNullParameter(fragmentConfig, "fragmentConfig");
                return new AddPaymentMethodSheet(fragmentConfig);
            }

            public boolean equals(Object obj) {
                if (this == obj) {
                    return true;
                }
                return (obj instanceof AddPaymentMethodSheet) && Intrinsics.areEqual(getFragmentConfig(), ((AddPaymentMethodSheet) obj).getFragmentConfig());
            }

            @Override
            @NotNull
            public FragmentConfig getFragmentConfig() {
                return this.fragmentConfig;
            }

            public int hashCode() {
                return getFragmentConfig().hashCode();
            }

            @NotNull
            public String toString() {
                return "AddPaymentMethodSheet(fragmentConfig=" + getFragmentConfig() + ')';
            }
        }

        @Metadata
        public static final class SelectSavedPaymentMethod extends TransitionTarget {
            public static final int $stable = 8;

            @NotNull
            private final FragmentConfig fragmentConfig;

            public SelectSavedPaymentMethod(@NotNull FragmentConfig fragmentConfig) {
                super(null);
                Intrinsics.checkNotNullParameter(fragmentConfig, "fragmentConfig");
                this.fragmentConfig = fragmentConfig;
            }

            public static SelectSavedPaymentMethod copy$default(SelectSavedPaymentMethod selectSavedPaymentMethod, FragmentConfig fragmentConfig, int i, Object obj) {
                if ((i & 1) != 0) {
                    fragmentConfig = selectSavedPaymentMethod.getFragmentConfig();
                }
                return selectSavedPaymentMethod.copy(fragmentConfig);
            }

            @NotNull
            public final FragmentConfig component1() {
                return getFragmentConfig();
            }

            @NotNull
            public final SelectSavedPaymentMethod copy(@NotNull FragmentConfig fragmentConfig) {
                Intrinsics.checkNotNullParameter(fragmentConfig, "fragmentConfig");
                return new SelectSavedPaymentMethod(fragmentConfig);
            }

            public boolean equals(Object obj) {
                if (this == obj) {
                    return true;
                }
                return (obj instanceof SelectSavedPaymentMethod) && Intrinsics.areEqual(getFragmentConfig(), ((SelectSavedPaymentMethod) obj).getFragmentConfig());
            }

            @Override
            @NotNull
            public FragmentConfig getFragmentConfig() {
                return this.fragmentConfig;
            }

            public int hashCode() {
                return getFragmentConfig().hashCode();
            }

            @NotNull
            public String toString() {
                return "SelectSavedPaymentMethod(fragmentConfig=" + getFragmentConfig() + ')';
            }
        }

        public TransitionTarget(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }

        @NotNull
        public abstract FragmentConfig getFragmentConfig();

        private TransitionTarget() {
        }
    }

    @Metadata
    public class WhenMappings {
        public static final int[] $EnumSwitchMapping$0;

        static {
            int[] iArr = new int[PaymentSheet.GooglePayConfiguration.Environment.values().length];
            iArr[PaymentSheet.GooglePayConfiguration.Environment.Production.ordinal()] = 1;
            $EnumSwitchMapping$0 = iArr;
        }
    }

    public PaymentSheetViewModel(@NotNull Application application, @NotNull PaymentSheetContract.Args args, @NotNull EventReporter eventReporter, @NotNull Ti.a<PaymentConfiguration> aVar, @NotNull StripeIntentRepository stripeIntentRepository, @NotNull StripeIntentValidator stripeIntentValidator, @NotNull CustomerRepository customerRepository, @NotNull PrefsRepository prefsRepository, @NotNull ResourceRepository resourceRepository, @NotNull StripePaymentLauncherAssistedFactory stripePaymentLauncherAssistedFactory, @NotNull GooglePayPaymentMethodLauncherFactory googlePayPaymentMethodLauncherFactory, @NotNull Logger logger, @IOContext @NotNull CoroutineContext coroutineContext, @InjectorKey @NotNull String str, @NotNull e0 e0Var, @NotNull LinkPaymentLauncherFactory linkPaymentLauncherFactory) {
        super(application, args.getConfig$paymentsheet_release(), eventReporter, customerRepository, prefsRepository, coroutineContext, logger, str, resourceRepository, e0Var, linkPaymentLauncherFactory);
        Intrinsics.checkNotNullParameter(application, "application");
        Intrinsics.checkNotNullParameter(args, "args");
        Intrinsics.checkNotNullParameter(eventReporter, "eventReporter");
        Intrinsics.checkNotNullParameter(aVar, "lazyPaymentConfig");
        Intrinsics.checkNotNullParameter(stripeIntentRepository, "stripeIntentRepository");
        Intrinsics.checkNotNullParameter(stripeIntentValidator, "stripeIntentValidator");
        Intrinsics.checkNotNullParameter(customerRepository, "customerRepository");
        Intrinsics.checkNotNullParameter(prefsRepository, "prefsRepository");
        Intrinsics.checkNotNullParameter(resourceRepository, "resourceRepository");
        Intrinsics.checkNotNullParameter(stripePaymentLauncherAssistedFactory, "paymentLauncherFactory");
        Intrinsics.checkNotNullParameter(googlePayPaymentMethodLauncherFactory, "googlePayPaymentMethodLauncherFactory");
        Intrinsics.checkNotNullParameter(logger, "logger");
        Intrinsics.checkNotNullParameter(coroutineContext, "workContext");
        Intrinsics.checkNotNullParameter(str, "injectorKey");
        Intrinsics.checkNotNullParameter(e0Var, "savedStateHandle");
        Intrinsics.checkNotNullParameter(linkPaymentLauncherFactory, "linkPaymentLauncherFactory");
        this.args = args;
        this.lazyPaymentConfig = aVar;
        this.stripeIntentRepository = stripeIntentRepository;
        this.stripeIntentValidator = stripeIntentValidator;
        this.paymentLauncherFactory = stripePaymentLauncherAssistedFactory;
        this.googlePayPaymentMethodLauncherFactory = googlePayPaymentMethodLauncherFactory;
        this.confirmParamsFactory = ConfirmStripeIntentParamsFactory.Companion.createFactory(args.getClientSecret$paymentsheet_release());
        S<PaymentSheetResult> s = new S<>();
        this._paymentSheetResult = s;
        this.paymentSheetResult = s;
        S<BaseSheetViewModel.Event<ConfirmStripeIntentParams>> s2 = new S<>();
        this._startConfirm = s2;
        this.startConfirm = s2;
        GooglePayPaymentMethodLauncher.Config config = null;
        S<PaymentSheetViewState> s3 = new S<>((Object) null);
        this._viewState = s3;
        Q a = q0.a(s3);
        Intrinsics.checkNotNullExpressionValue(a, "distinctUntilChanged(this)");
        this.viewState = a;
        this.checkoutIdentifier = CheckoutIdentifier.SheetBottomBuy;
        PaymentSheet.GooglePayConfiguration googlePayConfig = args.getGooglePayConfig();
        if (googlePayConfig != null) {
            if (googlePayConfig.getCurrencyCode() != null || isProcessingPaymentIntent$paymentsheet_release()) {
                config = new GooglePayPaymentMethodLauncher.Config(WhenMappings.$EnumSwitchMapping$0[googlePayConfig.getEnvironment().ordinal()] == 1 ? GooglePayEnvironment.Production : GooglePayEnvironment.Test, googlePayConfig.getCountryCode(), getMerchantName$paymentsheet_release(), false, null, false, false, 120, null);
            } else {
                logger.warning("GooglePayConfiguration.currencyCode is required in order to use Google Pay when processing a Setup Intent");
            }
        }
        this.googlePayLauncherConfig = config;
        final Q<Boolean> q = new Q<>();
        Iterator it = kotlin.collections.t.i(new N[]{isLinkEnabled$paymentsheet_release(), isGooglePayReady$paymentsheet_release(), getFragmentConfigEvent()}).iterator();
        while (it.hasNext()) {
            q.a((N) it.next(), new T() {
                public final void onChanged(Object obj) {
                    boolean z;
                    Q<Boolean> q2 = q;
                    Object value = this.isLinkEnabled$paymentsheet_release().getValue();
                    Boolean bool = Boolean.TRUE;
                    if (Intrinsics.areEqual(value, bool) || Intrinsics.areEqual(this.isGooglePayReady$paymentsheet_release().getValue(), bool)) {
                        BaseSheetViewModel.Event event = (BaseSheetViewModel.Event) this.getFragmentConfigEvent().getValue();
                        if ((event != null ? (FragmentConfig) event.peekContent() : null) != null) {
                            z = true;
                            q2.setValue(Boolean.valueOf(z));
                        }
                    }
                    z = false;
                    q2.setValue(Boolean.valueOf(z));
                }
            });
        }
        this.showTopContainer = q;
        eventReporter.onInit(getConfig$paymentsheet_release());
        if (this.googlePayLauncherConfig == null) {
            e0Var.e(Boolean.FALSE, BaseSheetViewModel.SAVE_GOOGLE_PAY_READY);
        }
    }

    private final void confirmPaymentSelection(PaymentSelection paymentSelection) {
        ConfirmStripeIntentParams create = paymentSelection instanceof PaymentSelection.Saved ? this.confirmParamsFactory.create((PaymentSelection.Saved) paymentSelection) : paymentSelection instanceof PaymentSelection.New ? this.confirmParamsFactory.create((PaymentSelection.New) paymentSelection) : null;
        if (create != null) {
            this._startConfirm.setValue(new BaseSheetViewModel.Event(create));
        }
    }

    private final PaymentResult convertToPaymentResult(LinkActivityResult linkActivityResult) {
        if (linkActivityResult instanceof LinkActivityResult.Success) {
            return PaymentResult.Completed.INSTANCE;
        }
        if (linkActivityResult instanceof LinkActivityResult.Canceled) {
            return PaymentResult.Canceled.INSTANCE;
        }
        if (linkActivityResult instanceof LinkActivityResult.Failed) {
            return new PaymentResult.Failed(((LinkActivityResult.Failed) linkActivityResult).getError());
        }
        throw new NoWhenBranchMatchedException();
    }

    public static final void m656getButtonStateObservable$lambda0(PaymentSheetViewModel paymentSheetViewModel, CheckoutIdentifier checkoutIdentifier, Q q, PaymentSheetViewState paymentSheetViewState) {
        Intrinsics.checkNotNullParameter(paymentSheetViewModel, "this$0");
        Intrinsics.checkNotNullParameter(checkoutIdentifier, "$checkoutIdentifier");
        Intrinsics.checkNotNullParameter(q, "$outputLiveData");
        if (paymentSheetViewModel.checkoutIdentifier == checkoutIdentifier) {
            q.setValue(paymentSheetViewState);
        }
    }

    public final void onStripeIntentFetchResponse(StripeIntent stripeIntent) {
        StripeIntent a;
        try {
            p.a aVar = Hk.p.b;
            a = this.stripeIntentValidator.requireValid(stripeIntent);
        } catch (Throwable th) {
            p.a aVar2 = Hk.p.b;
            a = Hk.q.a(th);
        }
        Throwable a2 = Hk.p.a(a);
        if (a2 != null) {
            onFatal(a2);
            return;
        }
        getSavedStateHandle().e(stripeIntent, BaseSheetViewModel.SAVE_STRIPE_INTENT);
        updatePaymentMethods(stripeIntent);
        setupLink(stripeIntent, true);
        resetViewState$default(this, null, 1, null);
    }

    public final void processPayment(StripeIntent stripeIntent, PaymentResult paymentResult) {
        StripeIntent a;
        r1 = null;
        PaymentSelection paymentSelection = null;
        if (!(paymentResult instanceof PaymentResult.Completed)) {
            getEventReporter$paymentsheet_release().onPaymentFailure((PaymentSelection) getSelection$paymentsheet_release().getValue());
            try {
                p.a aVar = Hk.p.b;
                a = this.stripeIntentValidator.requireValid(stripeIntent);
            } catch (Throwable th) {
                p.a aVar2 = Hk.p.b;
                a = Hk.q.a(th);
            }
            Throwable a2 = Hk.p.a(a);
            if (a2 == null) {
                resetViewState(paymentResult instanceof PaymentResult.Failed ? ((PaymentResult.Failed) paymentResult).getThrowable().getLocalizedMessage() : null);
                return;
            } else {
                onFatal(a2);
                return;
            }
        }
        getEventReporter$paymentsheet_release().onPaymentSuccess((PaymentSelection) getSelection$paymentsheet_release().getValue());
        PaymentSelection paymentSelection2 = (PaymentSelection) getSelection$paymentsheet_release().getValue();
        if (paymentSelection2 instanceof PaymentSelection.New) {
            PaymentMethod paymentMethod = stripeIntent.getPaymentMethod();
            if (paymentMethod != null) {
                paymentSelection = new PaymentSelection.Saved(paymentMethod);
            }
        } else if (Intrinsics.areEqual(paymentSelection2, PaymentSelection.GooglePay.INSTANCE)) {
            paymentSelection = (PaymentSelection) getSelection$paymentsheet_release().getValue();
        } else if (paymentSelection2 instanceof PaymentSelection.Saved) {
            paymentSelection = (PaymentSelection) getSelection$paymentsheet_release().getValue();
        } else if (paymentSelection2 != null) {
            throw new NoWhenBranchMatchedException();
        }
        if (paymentSelection != null) {
            getPrefsRepository().savePaymentSelection(paymentSelection);
        }
        this._viewState.setValue(new PaymentSheetViewState.FinishProcessing(new Function0<Unit>() {
            {
                super(0);
            }

            public Object invoke() {
                m657invoke();
                return Unit.a;
            }

            public final void m657invoke() {
                PaymentSheetViewModel.this.get_paymentSheetResult$paymentsheet_release().setValue(PaymentSheetResult.Completed.INSTANCE);
            }
        }));
    }

    private final void resetViewState(String str) {
        this._viewState.setValue(new PaymentSheetViewState.Reset(str != null ? new BaseSheetViewModel.UserErrorMessage(str) : null));
        getSavedStateHandle().e(Boolean.FALSE, BaseSheetViewModel.SAVE_PROCESSING);
    }

    public static void resetViewState$default(PaymentSheetViewModel paymentSheetViewModel, String str, int i, Object obj) {
        if ((i & 1) != 0) {
            str = null;
        }
        paymentSheetViewModel.resetViewState(str);
    }

    private final void startProcessing(CheckoutIdentifier checkoutIdentifier) {
        if (this.checkoutIdentifier != checkoutIdentifier) {
            this._viewState.setValue(new PaymentSheetViewState.Reset(null, 1, null));
        }
        this.checkoutIdentifier = checkoutIdentifier;
        getSavedStateHandle().e(Boolean.TRUE, BaseSheetViewModel.SAVE_PROCESSING);
        this._viewState.setValue(PaymentSheetViewState.StartProcessing.INSTANCE);
    }

    public final void checkout(@NotNull CheckoutIdentifier checkoutIdentifier) {
        GooglePayPaymentMethodLauncher googlePayPaymentMethodLauncher;
        String currencyCode;
        Long amount;
        Intrinsics.checkNotNullParameter(checkoutIdentifier, "checkoutIdentifier");
        startProcessing(checkoutIdentifier);
        PaymentSelection paymentSelection = (PaymentSelection) getSelection$paymentsheet_release().getValue();
        if (!(paymentSelection instanceof PaymentSelection.GooglePay)) {
            confirmPaymentSelection(paymentSelection);
            return;
        }
        StripeIntent stripeIntent = (StripeIntent) getStripeIntent$paymentsheet_release().getValue();
        if (stripeIntent == null || (googlePayPaymentMethodLauncher = this.googlePayPaymentMethodLauncher) == null) {
            return;
        }
        boolean z = stripeIntent instanceof PaymentIntent;
        PaymentIntent paymentIntent = z ? (PaymentIntent) stripeIntent : null;
        if (paymentIntent == null || (currencyCode = paymentIntent.getCurrency()) == null) {
            PaymentSheet.GooglePayConfiguration googlePayConfig = this.args.getGooglePayConfig();
            currencyCode = googlePayConfig != null ? googlePayConfig.getCurrencyCode() : null;
            if (currencyCode == null) {
                currencyCode = CameraView.FILL_ASPECT_RATIO;
            }
        }
        PaymentIntent paymentIntent2 = z ? (PaymentIntent) stripeIntent : null;
        googlePayPaymentMethodLauncher.present(currencyCode, (paymentIntent2 == null || (amount = paymentIntent2.getAmount()) == null) ? 0 : (int) amount.longValue(), stripeIntent.getId());
    }

    public final void confirmStripeIntent(@NotNull ConfirmStripeIntentParams confirmStripeIntentParams) {
        PaymentLauncher a;
        Intrinsics.checkNotNullParameter(confirmStripeIntentParams, "confirmStripeIntentParams");
        try {
            p.a aVar = Hk.p.b;
            a = this.paymentLauncher;
        } catch (Throwable th) {
            p.a aVar2 = Hk.p.b;
            a = Hk.q.a(th);
        }
        if (a == null) {
            throw new IllegalArgumentException("Required value was null.".toString());
        }
        Throwable a2 = Hk.p.a(a);
        if (a2 != null) {
            onFatal(a2);
            return;
        }
        PaymentLauncher paymentLauncher = a;
        if (confirmStripeIntentParams instanceof ConfirmPaymentIntentParams) {
            paymentLauncher.confirm((ConfirmPaymentIntentParams) confirmStripeIntentParams);
        } else if (confirmStripeIntentParams instanceof ConfirmSetupIntentParams) {
            paymentLauncher.confirm((ConfirmSetupIntentParams) confirmStripeIntentParams);
        }
    }

    @NotNull
    public final PaymentSheetContract.Args getArgs$paymentsheet_release() {
        return this.args;
    }

    @NotNull
    public final Q<PaymentSheetViewState> getButtonStateObservable$paymentsheet_release(@NotNull final CheckoutIdentifier checkoutIdentifier) {
        Intrinsics.checkNotNullParameter(checkoutIdentifier, "checkoutIdentifier");
        final Q<PaymentSheetViewState> q = new Q<>();
        q.a(this.viewState, new T() {
            public final void onChanged(Object obj) {
                PaymentSheetViewModel.m656getButtonStateObservable$lambda0(PaymentSheetViewModel.this, checkoutIdentifier, q, (PaymentSheetViewState) obj);
            }
        });
        return q;
    }

    @NotNull
    public final CheckoutIdentifier getCheckoutIdentifier$paymentsheet_release() {
        return this.checkoutIdentifier;
    }

    public final GooglePayPaymentMethodLauncher.Config getGooglePayLauncherConfig$paymentsheet_release() {
        return this.googlePayLauncherConfig;
    }

    public final GooglePayPaymentMethodLauncher getGooglePayPaymentMethodLauncher$paymentsheet_release() {
        return this.googlePayPaymentMethodLauncher;
    }

    public final PaymentSelection getLastSelectedPaymentMethod$paymentsheet_release() {
        return this.lastSelectedPaymentMethod;
    }

    @Override
    public PaymentSelection.New getNewPaymentSelection() {
        return this.newPaymentSelection;
    }

    public final PaymentLauncher getPaymentLauncher$paymentsheet_release() {
        return this.paymentLauncher;
    }

    @NotNull
    public final N<PaymentSheetResult> getPaymentSheetResult$paymentsheet_release() {
        return this.paymentSheetResult;
    }

    @NotNull
    public final Q<Boolean> getShowTopContainer$paymentsheet_release() {
        return this.showTopContainer;
    }

    @NotNull
    public final N<BaseSheetViewModel.Event<ConfirmStripeIntentParams>> getStartConfirm$paymentsheet_release() {
        return this.startConfirm;
    }

    @NotNull
    public final N<PaymentSheetViewState> getViewState$paymentsheet_release() {
        return this.viewState;
    }

    @NotNull
    public final S<PaymentSheetResult> get_paymentSheetResult$paymentsheet_release() {
        return this._paymentSheetResult;
    }

    @NotNull
    public final S<PaymentSheetViewState> get_viewState$paymentsheet_release() {
        return this._viewState;
    }

    public final boolean isProcessingPaymentIntent$paymentsheet_release() {
        return this.args.getClientSecret$paymentsheet_release() instanceof PaymentIntentClientSecret;
    }

    public final boolean maybeFetchStripeIntent$paymentsheet_release() {
        if (getStripeIntent$paymentsheet_release().getValue() != null) {
            return false;
        }
        dl.g.b(s0.a(this), (CoroutineContext) null, (J) null, new PaymentSheetViewModel$maybeFetchStripeIntent$1(this, null), 3);
        return true;
    }

    @Override
    public void onError(Integer num) {
        String str;
        if (num != null) {
            str = getApplication().getResources().getString(num.intValue());
        } else {
            str = null;
        }
        onError(str);
    }

    @Override
    public void onFatal(@NotNull Throwable th) {
        Intrinsics.checkNotNullParameter(th, "throwable");
        getLogger().error("Payment Sheet error", th);
        get_fatal().setValue(th);
        this._paymentSheetResult.setValue(new PaymentSheetResult.Failed(th));
    }

    @Override
    public void onFinish() {
        this._paymentSheetResult.setValue(PaymentSheetResult.Completed.INSTANCE);
    }

    public final void onGooglePayResult$paymentsheet_release(@NotNull GooglePayPaymentMethodLauncher.Result result) {
        Intrinsics.checkNotNullParameter(result, "result");
        setContentVisible(true);
        if (result instanceof GooglePayPaymentMethodLauncher.Result.Completed) {
            confirmPaymentSelection(new PaymentSelection.Saved(((GooglePayPaymentMethodLauncher.Result.Completed) result).getPaymentMethod()));
            return;
        }
        if (!(result instanceof GooglePayPaymentMethodLauncher.Result.Failed)) {
            if (result instanceof GooglePayPaymentMethodLauncher.Result.Canceled) {
                resetViewState$default(this, null, 1, null);
            }
        } else {
            GooglePayPaymentMethodLauncher.Result.Failed failed = (GooglePayPaymentMethodLauncher.Result.Failed) result;
            getLogger().error("Error processing Google Pay payment", failed.getError());
            getEventReporter$paymentsheet_release().onPaymentFailure(PaymentSelection.GooglePay.INSTANCE);
            onError(Integer.valueOf(failed.getErrorCode() == 3 ? R.string.stripe_failure_connection_error : R.string.stripe_internal_error));
        }
    }

    @Override
    public void onLinkActivityResult(@NotNull LinkActivityResult linkActivityResult) {
        Intrinsics.checkNotNullParameter(linkActivityResult, "result");
        super.onLinkActivityResult(linkActivityResult);
        onPaymentResult(convertToPaymentResult(linkActivityResult));
    }

    @Override
    public void onLinkLaunched() {
        super.onLinkLaunched();
        startProcessing(CheckoutIdentifier.SheetBottomBuy);
    }

    @Override
    public void onLinkPaymentDetailsCollected(LinkPaymentDetails linkPaymentDetails) {
        Unit unit;
        if (linkPaymentDetails != null) {
            updateSelection(new PaymentSelection.New.Link(linkPaymentDetails));
            checkout(CheckoutIdentifier.SheetBottomBuy);
            unit = Unit.a;
        } else {
            unit = null;
        }
        if (unit == null) {
            checkout(CheckoutIdentifier.SheetBottomBuy);
        }
    }

    @Override
    public void onPaymentResult(@NotNull PaymentResult paymentResult) {
        Intrinsics.checkNotNullParameter(paymentResult, "paymentResult");
        dl.g.b(s0.a(this), (CoroutineContext) null, (J) null, new PaymentSheetViewModel$onPaymentResult$1(this, paymentResult, null), 3);
    }

    @Override
    public void onUserCancel() {
        this._paymentSheetResult.setValue(PaymentSheetResult.Canceled.INSTANCE);
    }

    @Override
    public void registerFromActivity(@NotNull i.b bVar) {
        Intrinsics.checkNotNullParameter(bVar, "activityResultCaller");
        super.registerFromActivity(bVar);
        StripePaymentLauncherAssistedFactory stripePaymentLauncherAssistedFactory = this.paymentLauncherFactory;
        Function0<String> function0 = new Function0<String>() {
            {
                super(0);
            }

            @NotNull
            public final String invoke() {
                Ti.a aVar;
                aVar = PaymentSheetViewModel.this.lazyPaymentConfig;
                return ((PaymentConfiguration) aVar.get()).getPublishableKey();
            }
        };
        Function0<String> function02 = new Function0<String>() {
            {
                super(0);
            }

            public final String invoke() {
                Ti.a aVar;
                aVar = PaymentSheetViewModel.this.lazyPaymentConfig;
                return ((PaymentConfiguration) aVar.get()).getStripeAccountId();
            }
        };
        i.c<PaymentLauncherContract.Args> registerForActivityResult = bVar.registerForActivityResult(new PaymentLauncherContract(), new i.a() {
            public final void onActivityResult(Object obj) {
                PaymentSheetViewModel.this.onPaymentResult((PaymentResult) obj);
            }
        });
        Intrinsics.checkNotNullExpressionValue(registerForActivityResult, "activityResultCaller.reg…ymentResult\n            )");
        this.paymentLauncher = stripePaymentLauncherAssistedFactory.create(function0, function02, registerForActivityResult);
    }

    public final void setCheckoutIdentifier$paymentsheet_release(@NotNull CheckoutIdentifier checkoutIdentifier) {
        Intrinsics.checkNotNullParameter(checkoutIdentifier, "<set-?>");
        this.checkoutIdentifier = checkoutIdentifier;
    }

    public final void setGooglePayPaymentMethodLauncher$paymentsheet_release(GooglePayPaymentMethodLauncher googlePayPaymentMethodLauncher) {
        this.googlePayPaymentMethodLauncher = googlePayPaymentMethodLauncher;
    }

    public final void setLastSelectedPaymentMethod$paymentsheet_release(PaymentSelection paymentSelection) {
        this.lastSelectedPaymentMethod = paymentSelection;
    }

    @Override
    public void setNewPaymentSelection(PaymentSelection.New r1) {
        this.newPaymentSelection = r1;
    }

    public final void setPaymentLauncher$paymentsheet_release(PaymentLauncher paymentLauncher) {
        this.paymentLauncher = paymentLauncher;
    }

    public final void setupGooglePay(@NotNull H h, @NotNull i.c<GooglePayPaymentMethodLauncherContract.Args> cVar) {
        Intrinsics.checkNotNullParameter(h, "lifecycleScope");
        Intrinsics.checkNotNullParameter(cVar, "activityResultLauncher");
        GooglePayPaymentMethodLauncher.Config config = this.googlePayLauncherConfig;
        if (config != null) {
            this.googlePayPaymentMethodLauncher = GooglePayPaymentMethodLauncherFactory.DefaultImpls.create$default(this.googlePayPaymentMethodLauncherFactory, h, config, new GooglePayPaymentMethodLauncher.ReadyCallback() {
                @Override
                public final void onReady(boolean z) {
                    PaymentSheetViewModel.this.getSavedStateHandle().e(Boolean.valueOf(z), BaseSheetViewModel.SAVE_GOOGLE_PAY_READY);
                }
            }, cVar, false, 16, null);
        }
    }

    @Override
    public void unregisterFromActivity() {
        super.unregisterFromActivity();
        this.paymentLauncher = null;
    }

    public final void updatePaymentMethods(@NotNull StripeIntent stripeIntent) {
        Intrinsics.checkNotNullParameter(stripeIntent, "stripeIntent");
        dl.g.b(s0.a(this), (CoroutineContext) null, (J) null, new PaymentSheetViewModel$updatePaymentMethods$1(this, stripeIntent, null), 3);
    }

    @Override
    public void updateSelection(PaymentSelection paymentSelection) {
        super.updateSelection(paymentSelection);
        if ((paymentSelection instanceof PaymentSelection.Saved) && ((PaymentSelection.Saved) paymentSelection).getPaymentMethod().type == PaymentMethod.Type.USBankAccount) {
            ACHText aCHText = ACHText.INSTANCE;
            Application application = getApplication();
            Intrinsics.checkNotNullExpressionValue(application, "getApplication()");
            updateBelowButtonText(aCHText.getContinueMandateText(application));
        }
    }

    @Override
    public void onError(String str) {
        resetViewState(str);
    }

    public static void getGooglePayLauncherConfig$paymentsheet_release$annotations() {
    }

    public static void getGooglePayPaymentMethodLauncher$paymentsheet_release$annotations() {
    }

    public static void get_paymentSheetResult$paymentsheet_release$annotations() {
    }

    public static void get_viewState$paymentsheet_release$annotations() {
    }
}