导航菜单

页面标题

页面副标题

BodyTech v7.6.4 - POSCheckoutActivity.java 源代码

正在查看: BodyTech v7.6.4 应用的 POSCheckoutActivity.java JAVA 源代码文件

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


package com.fitnessmobileapps.fma.views;

import a2.b;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.Html;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.MenuItem;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.StringRes;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.widget.Toolbar;
import androidx.core.widget.TextViewCompat;
import androidx.lifecycle.Observer;
import androidx.preference.PreferenceManager;
import com.android.volley.NetworkResponse;
import com.android.volley.ServerError;
import com.android.volley.VolleyError;
import com.fitnessmobileapps.bodytech39559.R;
import com.fitnessmobileapps.fma.Application;
import com.fitnessmobileapps.fma.core.compose.CustomAlertDialog;
import com.fitnessmobileapps.fma.core.compose.d;
import com.fitnessmobileapps.fma.core.data.remote.StripeKeyManager;
import com.fitnessmobileapps.fma.core.data.remote.model.CreateIdentityUserRequest;
import com.fitnessmobileapps.fma.core.feature.analytics.metrics.MetricsName;
import com.fitnessmobileapps.fma.core.flags.DevelopmentFlags;
import com.fitnessmobileapps.fma.core.flags.FlagsUtilsClassKt;
import com.fitnessmobileapps.fma.exception.PaymentAuthenticationFailure;
import com.fitnessmobileapps.fma.feature.book.presentation.viewmodel.POSViewModel;
import com.fitnessmobileapps.fma.feature.buy.PosCheckoutViewModel;
import com.fitnessmobileapps.fma.feature.common.activity.BmaAppCompatActivity;
import com.fitnessmobileapps.fma.feature.common.navigation.ToolbarKt;
import com.fitnessmobileapps.fma.feature.familyaccounts.domain.interactor.GetSelectedIdentityUserId;
import com.fitnessmobileapps.fma.feature.familyaccounts.presentation.UserSelectionActivity;
import com.fitnessmobileapps.fma.feature.familyaccounts.presentation.UserViewModel;
import com.fitnessmobileapps.fma.model.Appointment;
import com.fitnessmobileapps.fma.model.ClassSchedule;
import com.fitnessmobileapps.fma.model.LocationMBOSettings;
import com.fitnessmobileapps.fma.model.payment.PaymentMethodUIData;
import com.fitnessmobileapps.fma.model.payment.StripeConfiguration;
import com.fitnessmobileapps.fma.util.POSCache;
import com.fitnessmobileapps.fma.util.p0;
import com.fitnessmobileapps.fma.views.stripe.PaymentStatus;
import com.fitnessmobileapps.fma.views.stripe.StripePaymentData;
import com.fitnessmobileapps.fma.views.stripe.StripeWebViewActivity;
import com.fitnessmobileapps.fma.views.widgets.BookAndBuyHeader;
import com.fitnessmobileapps.fma.views.widgets.MiniContractSummaryView;
import com.fitnessmobileapps.fma.views.widgets.SuccessButton;
import com.fitnessmobileapps.fma.views.widgets.custom.TotalsRowView;
import com.google.android.material.snackbar.Snackbar;
import com.mindbodyonline.android.api.sales.model.payments.PaymentConfiguration;
import com.mindbodyonline.android.api.sales.model.payments.PaymentMethod;
import com.mindbodyonline.android.api.sales.model.pos.cart.Cart;
import com.mindbodyonline.android.api.sales.model.pos.cart.CartDiscountItem;
import com.mindbodyonline.android.api.sales.model.pos.cart.CartItem;
import com.mindbodyonline.android.api.sales.model.pos.cart.CartItemDiscount;
import com.mindbodyonline.android.api.sales.model.pos.catalog.CatalogItem;
import com.mindbodyonline.android.api.sales.model.pos.packages.CartPackage;
import com.mindbodyonline.android.api.sales.model.pos.packages.CatalogPackage;
import com.mindbodyonline.android.util.TaskCallback;
import com.mindbodyonline.connect.utils.POSPaymentUtils;
import com.mindbodyonline.domain.ClassTypeObject;
import com.mindbodyonline.domain.dataModels.GiftCard;
import com.mindbodyonline.domain.pos.util.CartItemUtil;
import com.stripe.android.googlepaylauncher.GooglePayLauncher;
import com.stripe.android.paymentsheet.PaymentSheet;
import com.stripe.android.paymentsheet.y;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import kotlin.Lazy;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import lf.b;
import org.koin.android.compat.ViewModelCompat;
import org.koin.java.KoinJavaComponent;
import s2.o1;
import vf.o;

public class POSCheckoutActivity extends BmaAppCompatActivity implements o1.b, o1.f, o1.c, o1.g, p0.a {
    private static final String G0 = POSCheckoutActivity.class.getSimpleName() + ".SAVED_INSTANCE_UPLOADS_ONGOING";
    private TextView A;
    private TextView B;
    private RelativeLayout C;
    private TextView G;
    private TextView H;
    private TextView I;
    private View J;
    private TextView K;
    private TextView L;
    private TextView M;
    private TextView N;
    private SuccessButton O;
    private com.fitnessmobileapps.fma.util.t P;
    private h1.a Q;
    private CatalogItem R;
    private CatalogPackage S;
    private CartPackage T;
    private ClassTypeObject U;
    private Appointment V;
    private ClassSchedule W;
    private s2.o1 X;
    private POSCache Y;
    private Locale Z;

    private NumberFormat f10572a0;

    private Runnable f10573b0;

    private boolean f10574c0;

    Long f10575d;

    private boolean f10576d0;

    private View f10577e;

    private boolean f10578e0;

    private boolean f10579f0;

    private boolean f10580g0;

    private String f10581h0;

    private com.fitnessmobileapps.fma.util.u f10582i0;

    private SharedPreferences f10583j0;

    private BookAndBuyHeader f10584k;

    private com.fitnessmobileapps.fma.views.fragments.dialogs.j f10585k0;

    private com.fitnessmobileapps.fma.views.fragments.dialogs.j f10586l0;

    private lf.b f10587m0;

    private TextView f10588n;

    private lf.b f10589n0;

    private lf.b f10590o0;

    private TextView f10591p;

    private lf.b f10592p0;

    private MiniContractSummaryView f10593q;

    private lf.b f10594q0;

    private TotalsRowView f10595r;

    private com.fitnessmobileapps.fma.views.fragments.dialogs.b f10596r0;

    private lf.b f10597s0;

    private TextView f10598t;

    private PaymentSheet f10599t0;

    private GooglePayLauncher f10600u0;

    private RelativeLayout f10601v;

    private TextView f10603w;

    private TextView f10605x;

    private TextView f10607y;

    private RelativeLayout f10609z;

    private Boolean f10602v0 = Boolean.FALSE;

    private boolean f10604w0 = false;

    private final Lazy<PosCheckoutViewModel> f10606x0 = ViewModelCompat.b(this, PosCheckoutViewModel.class);

    private final Lazy<UserViewModel> f10608y0 = ViewModelCompat.b(this, UserViewModel.class);

    private final Lazy<POSViewModel> f10610z0 = ViewModelCompat.b(this, POSViewModel.class);
    GetSelectedIdentityUserId A0 = (GetSelectedIdentityUserId) KoinJavaComponent.a(GetSelectedIdentityUserId.class);
    private Lazy<com.fitnessmobileapps.fma.feature.buy.d> B0 = KoinJavaComponent.e(com.fitnessmobileapps.fma.feature.buy.d.class);
    private Snackbar.a C0 = new a();
    private ActivityResultLauncher<Intent> D0 = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback() {
        @Override
        public final void onActivityResult(Object obj) {
            POSCheckoutActivity.this.Z0((ActivityResult) obj);
        }
    });
    private boolean E0 = false;
    private final ActivityResultLauncher<Intent> F0 = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback() {
        @Override
        public final void onActivityResult(Object obj) {
            POSCheckoutActivity.this.I0((ActivityResult) obj);
        }
    });

    class a extends Snackbar.a {
        a() {
        }

        @Override
        public void a(Snackbar snackbar, int i10) {
            super.a(snackbar, i10);
            POSCheckoutActivity.this.O.setEnabled(true);
        }

        @Override
        public void b(Snackbar snackbar) {
            super.b(snackbar);
            POSCheckoutActivity.this.O.setEnabled(false);
        }
    }

    class b implements View.OnClickListener {
        b() {
        }

        @Override
        public void onClick(View view) {
            POSCheckoutActivity.this.u0();
        }
    }

    class c extends ud.a<CatalogItem> {
        c() {
        }
    }

    class d extends ud.a<CatalogPackage> {
        d() {
        }
    }

    class e extends ud.a<CartPackage> {
        e() {
        }
    }

    class f implements b.d {
        f() {
        }

        @Override
        public void a(lf.b bVar, View view) {
            bVar.dismiss();
            POSCheckoutActivity.this.V1();
        }
    }

    class g implements b.d {
        g() {
        }

        @Override
        public void a(lf.b bVar, View view) {
            bVar.dismiss();
            POSCheckoutActivity.this.U1();
        }
    }

    public void A0() {
        String str;
        String name;
        CatalogItem catalogItem = this.R;
        String str2 = null;
        if (catalogItem != null) {
            name = catalogItem.getName();
        } else {
            CatalogPackage catalogPackage = this.S;
            if (catalogPackage != null) {
                name = catalogPackage.getName();
            } else {
                CartPackage cartPackage = this.T;
                if (cartPackage == null) {
                    str = null;
                    if (this.V == null && this.W == null) {
                        str2 = this.f10608y0.getValue().v().getValue();
                    }
                    String str3 = str2;
                    if (!this.f10578e0) {
                        if (DevelopmentFlags.V.d()) {
                            c2.c.f1548a.d(MetricsName.CHECKOUT_STANDARD);
                        }
                        com.fitnessmobileapps.fma.util.w0.g(this, getSupportFragmentManager(), com.fitnessmobileapps.fma.views.fragments.dialogs.b.class.getSimpleName(), new DialogInterface.OnDismissListener() {
                            @Override
                            public final void onDismiss(DialogInterface dialogInterface) {
                                POSCheckoutActivity.this.Y0(dialogInterface);
                            }
                        }, str, str3).show(getSupportFragmentManager(), com.fitnessmobileapps.fma.views.fragments.dialogs.b.class.getName());
                        return;
                    } else {
                        Intent intent = new Intent();
                        intent.putExtra("ShoppingCart.ARG_PRODUCT_NAME", str);
                        intent.putExtra("ShoppingCart.ARG_USER_FIRST_NAME", str3);
                        setResult(555, intent);
                        finish();
                        return;
                    }
                }
                name = cartPackage.getCatalogPackage().getName();
            }
        }
        str = name;
        if (this.V == null) {
            str2 = this.f10608y0.getValue().v().getValue();
        }
        String str32 = str2;
        if (!this.f10578e0) {
        }
    }

    private void A1() {
        lf.b c10 = com.fitnessmobileapps.fma.util.w0.c(getSupportFragmentManager(), this.T != null, "ADD_A_CARD_DIALOG_TAG");
        this.f10594q0 = c10;
        c10.P(new b.d() {
            @Override
            public final void a(lf.b bVar, View view) {
                POSCheckoutActivity.this.e1(bVar, view);
            }
        });
    }

    private BigDecimal B0() {
        return H0().subtract(POSPaymentUtils.F(this.Y.c(), "CreditCard", true));
    }

    private void B1() {
        String C0 = C0();
        String D0 = D0();
        if (C0 != null) {
            this.f10588n.setText(C0);
        }
        if (D0 != null) {
            this.f10591p.setVisibility(0);
            this.f10591p.setText(D0);
        } else {
            this.f10591p.setVisibility(8);
        }
        this.f10593q.setVisibility(this.T != null ? 0 : 8);
        CartPackage cartPackage = this.T;
        if (cartPackage != null) {
            this.f10593q.setContractTemplate(cartPackage.getCatalogPackage().getContractTemplate(), this.T.getPricing().getAutopayPrice(), this.Z, this.Y.e(), null);
        }
    }

    private String C0() {
        CartPackage cartPackage = this.T;
        if (cartPackage != null) {
            return cartPackage.getCatalogPackage().getName();
        }
        CatalogItem catalogItem = this.R;
        if (catalogItem != null) {
            return catalogItem.getName();
        }
        CatalogPackage catalogPackage = this.S;
        if (catalogPackage != null) {
            return catalogPackage.getName();
        }
        if (this.f10575d == null || this.Y.c() == null || this.Y.c().getItems().length <= 0) {
            return null;
        }
        return this.Y.c().getItems()[0].getItem().getName();
    }

    private void C1() {
        lf.b bVar = (lf.b) getSupportFragmentManager().findFragmentByTag("CART_FAILURE_DIALOG_TAG");
        this.f10597s0 = bVar;
        if (bVar == null) {
            this.f10597s0 = new lf.b().H(R.string.generic_messsage_cart_error).J(android.R.string.cancel).M(R.string.try_again).G(true).D("CART_FAILURE_DIALOG_TAG");
        }
        this.f10597s0.P(new b.d() {
            @Override
            public final void a(lf.b bVar2, View view) {
                POSCheckoutActivity.this.f1(bVar2, view);
            }
        });
    }

    private String D0() {
        int quantity = (this.T != null || this.Y.c() == null || this.Y.c().getItems().length <= 0) ? 1 : this.Y.c().getItems()[0].getQuantity();
        if (quantity != 1) {
            return getString(R.string.pos_quantity, Integer.valueOf(quantity));
        }
        return null;
    }

    private void D1(View view, TextView textView, TextView textView2, @StringRes int i10, BigDecimal bigDecimal, boolean z10) {
        boolean z11 = bigDecimal.compareTo(BigDecimal.ZERO) > 0;
        String format = this.f10572a0.format(bigDecimal);
        view.setVisibility((z11 || z10) ? 0 : 8);
        String string = getString(i10);
        String string2 = getString(R.string.applied);
        if (!z10) {
            string2 = getString(R.string.balance, format);
        }
        textView.setText(com.fitnessmobileapps.fma.util.w0.a(this, string, string2, getResources().getDimensionPixelSize(R.dimen.subtext_font_size), false, R.color.secondaryTextColor));
        TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(textView, this.f10582i0.c(this, z10 ? 2131231125 : 2131231117, z10 ? R.color.secondaryTextColor : R.color.successAction), (Drawable) null, (Drawable) null, (Drawable) null);
        textView2.setVisibility(z10 ? 0 : 8);
        textView2.setText(getString(R.string.applied_amount_format, format));
    }

    private BigDecimal E0() {
        CartDiscountItem I = POSPaymentUtils.I(this.Y.c());
        if (I == null) {
            return BigDecimal.ZERO;
        }
        BigDecimal bigDecimal = BigDecimal.ZERO;
        for (CartItem cartItem : this.Y.c().getItems()) {
            for (CartItemDiscount cartItemDiscount : cartItem.getPricing().getDiscounts()) {
                if (cartItemDiscount.getCartDiscountItemId().equals(I.getId())) {
                    bigDecimal = bigDecimal.add(cartItemDiscount.getAmount());
                }
            }
        }
        return bigDecimal;
    }

    private void E1() {
        C1();
    }

    private String F0() {
        return new Uri.Builder().scheme("bma39559").authority("mindbody.bma").appendPath("checkout").appendPath("sca").build().toString();
    }

    private void F1() {
        boolean i10 = this.Y.d().i();
        this.f10607y.setVisibility(i10 ? 8 : 0);
        this.f10609z.setVisibility(i10 ? 8 : 0);
        if (i10) {
            return;
        }
        boolean z10 = !POSPaymentUtils.J(this.Y.d().q()).isEmpty();
        D1(this.f10609z, this.A, this.B, R.string.gift_card_label, z10 ? this.Y.c().getTotalAppliedGiftCardBalance() : POSPaymentUtils.w(this.Y.b(), "GiftCard"), z10);
        G1();
        this.f10609z.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                POSCheckoutActivity.this.g1(view);
            }
        });
    }

    private BigDecimal G0() {
        return this.Y.c().getTotals().getSub();
    }

    private void G1() {
        this.f10590o0 = com.fitnessmobileapps.fma.util.w0.h(getSupportFragmentManager(), "GIFT_CARD_CONFIRMATION_DIALOG_TAG", R.string.message_gift_card_usage, new f());
    }

    private BigDecimal H0() {
        return this.Y.c().getTotals().getTotal();
    }

    private void H1() {
        this.f10584k.setVisibility(M0() ? 0 : 8);
        this.f10584k.inflate();
        ClassTypeObject classTypeObject = this.U;
        if (classTypeObject != null) {
            this.f10584k.initWithClass(classTypeObject);
            return;
        }
        Appointment appointment = this.V;
        if (appointment != null) {
            this.f10584k.initWithAppointment(appointment);
            return;
        }
        ClassSchedule classSchedule = this.W;
        if (classSchedule != null) {
            this.f10584k.initWithEnrollment(classSchedule);
        }
    }

    public void I0(ActivityResult activityResult) {
        Intent data = activityResult.getData();
        if (activityResult.getResultCode() == -1) {
            mo.a.i("Stripe_WebPayment_Logs").a("Payment is successful. Proceeding with checkout.", new Object[0]);
            this.f10580g0 = true;
            N1();
            v0(true);
            return;
        }
        if (activityResult.getResultCode() == 0) {
            mo.a.i("Stripe_WebPayment_Logs").a("Payment Process Cancelled or Failed.", new Object[0]);
            s0(data);
            PaymentStatus paymentStatus = activityResult.getData() != null ? (PaymentStatus) activityResult.getData().getParcelableExtra("extra_payment_status") : null;
            if (paymentStatus == null) {
                return;
            }
            PaymentStatus.Status status = paymentStatus.getStatus();
            this.M.setVisibility(8);
            PaymentStatus.Status status2 = PaymentStatus.Status.FAILED;
            if (status == status2 || status == PaymentStatus.Status.TIMED_OUT) {
                this.E0 = true;
                this.N.setText(getString(status == status2 ? R.string.apm_checkout_failed : R.string.apm_checkout_timed_out, this.Y.f().getName()));
                this.N.setTextColor(getResources().getColor(R.color.substituteRed, null));
                this.N.setVisibility(0);
            } else if (status == PaymentStatus.Status.CANCELED) {
                Q1();
            }
            v1();
        }
    }

    private boolean J0() {
        return B0().compareTo(BigDecimal.ZERO) > 0;
    }

    private void J1() {
        CartDiscountItem I = POSPaymentUtils.I(this.Y.c());
        String str = I != null ? I.getCatalogDiscountItem().getProperties().get("PromoCode") : null;
        boolean z10 = str != null;
        this.f10601v.setVisibility(z10 ? 0 : 8);
        this.f10598t.setVisibility(z10 ? 8 : 0);
        if (z10) {
            this.f10605x.setText(getString(R.string.applied_amount_format, this.f10572a0.format(E0())));
            this.f10603w.setText(com.fitnessmobileapps.fma.util.w0.a(this, str, getString(R.string.applied), 12, true, R.color.secondaryTextColor));
        }
    }

    private boolean K0() {
        CartPackage cartPackage = this.T;
        return cartPackage != null && cartPackage.getPricing().getAutopayPrice().compareTo(BigDecimal.ZERO) > 0;
    }

    private void L0() {
        String b10 = new StripeKeyManager(this).b(PaymentConfiguration.TYPE_GOOGLEPAY, "production");
        if (b10 != null) {
            com.stripe.android.PaymentConfiguration.i(this, b10);
            this.f10600u0 = new GooglePayLauncher(this, this.f10606x0.getValue().q(this), new GooglePayLauncher.c() {
                @Override
                public final void a(boolean z10) {
                    POSCheckoutActivity.this.r1(z10);
                }
            }, new GooglePayLauncher.e() {
                @Override
                public final void a(GooglePayLauncher.d dVar) {
                    POSCheckoutActivity.this.s1(dVar);
                }
            });
            p0();
        }
    }

    private void L1() {
        lf.b bVar = (lf.b) getSupportFragmentManager().findFragmentByTag("CHECKOUT_FAILURE_DIALOG_TAG");
        if (bVar == null) {
            bVar = new lf.b().M(android.R.string.ok).V(R.string.error_checkout_failed_title).H(R.string.error_checkout_failed_message).D("CHECKOUT_FAILURE_DIALOG_TAG");
        }
        if (bVar.isVisible()) {
            return;
        }
        bVar.U(getSupportFragmentManager());
    }

    private boolean M0() {
        return (this.U == null && this.V == null && this.W == null) ? false : true;
    }

    private void M1() {
        new CustomAlertDialog().a(new d.FullDiscountedContractPromoError(this), new Function0() {
            @Override
            public final Object invoke() {
                Unit l12;
                l12 = POSCheckoutActivity.this.l1();
                return l12;
            }
        });
    }

    public void N0(com.fitnessmobileapps.fma.views.fragments.dialogs.j jVar, View view) {
        String W = jVar.W();
        if (!TextUtils.isEmpty(W)) {
            if (DevelopmentFlags.V.d()) {
                c2.c.f1548a.a(System.currentTimeMillis(), MetricsName.ADD_GC, null);
            }
            N1();
            this.X.q0(W);
        }
        jVar.Z(null);
        jVar.dismiss();
    }

    private void N1() {
        com.fitnessmobileapps.fma.util.t tVar = this.P;
        if (tVar == null || tVar.m()) {
            return;
        }
        this.P.I();
    }

    public void O0(View view) {
        this.f10586l0.U(getSupportFragmentManager());
    }

    private void O1() {
        String K = POSPaymentUtils.K(this, this.Y.d());
        lf.b bVar = (lf.b) getSupportFragmentManager().findFragmentByTag("ERROR_DIALOG_TAG");
        this.f10587m0 = bVar;
        if (bVar == null) {
            this.f10587m0 = new lf.b().I(K).M(android.R.string.ok).D("ERROR_DIALOG_TAG");
        }
        this.f10587m0.U(getSupportFragmentManager());
    }

    public void P0(com.fitnessmobileapps.fma.views.fragments.dialogs.j jVar, View view) {
        com.fitnessmobileapps.fma.util.d0.a(view.getContext(), view);
        String W = jVar.W();
        if (!TextUtils.isEmpty(W)) {
            if (DevelopmentFlags.V.d()) {
                c2.c.f1548a.a(System.currentTimeMillis(), MetricsName.ADD_PROMO_CODE, null);
            }
            N1();
            this.X.i0(W, this.Y);
        }
        jVar.Z(null);
        jVar.dismiss();
    }

    private void P1(final String str) {
        new qb.b(this).setMessage(R.string.payment_authentication_failed_message).setPositiveButton(R.string.try_again, new DialogInterface.OnClickListener() {
            @Override
            public final void onClick(DialogInterface dialogInterface, int i10) {
                POSCheckoutActivity.this.m1(str, dialogInterface, i10);
            }
        }).setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
            @Override
            public final void onClick(DialogInterface dialogInterface, int i10) {
                POSCheckoutActivity.this.n1(dialogInterface, i10);
            }
        }).show();
    }

    public void Q0(View view) {
        this.f10585k0.U(getSupportFragmentManager());
    }

    private void Q1() {
        new CustomAlertDialog().a(new d.StripePaymentFailure(this), null);
    }

    public void R0(View view) {
        N1();
        this.X.x1(POSPaymentUtils.I(this.Y.c()));
    }

    private void R1(String str, String str2, String str3) {
        this.f10580g0 = true;
        this.F0.launch(StripeWebViewActivity.INSTANCE.a(this, new StripePaymentData(str, str2, str3, this.Y.f().getName(), POSPaymentUtils.n(this.Y.c()))));
    }

    public void S0(StripeConfiguration stripeConfiguration) {
        this.P.l();
        if (DevelopmentFlags.V.d()) {
            c2.c.f1548a.e(System.currentTimeMillis(), MetricsName.CHECKOUT_APM);
        }
        if (stripeConfiguration instanceof StripeConfiguration.StripeGatewayConfiguration) {
            StripeConfiguration.StripeGatewayConfiguration stripeGatewayConfiguration = (StripeConfiguration.StripeGatewayConfiguration) stripeConfiguration;
            this.f10599t0.a(stripeGatewayConfiguration.getStripeGatewayClientSecret(), stripeGatewayConfiguration.getStripeConfiguration());
        } else if (stripeConfiguration instanceof StripeConfiguration.GooglePayConfiguration) {
            this.f10600u0.g(((StripeConfiguration.GooglePayConfiguration) stripeConfiguration).getGooglePayClientSecret());
        } else if (stripeConfiguration instanceof StripeConfiguration.WebPayConfiguration) {
            StripeConfiguration.WebPayConfiguration webPayConfiguration = (StripeConfiguration.WebPayConfiguration) stripeConfiguration;
            R1(webPayConfiguration.getClientSecret(), webPayConfiguration.getPublishableKey(), webPayConfiguration.getPaymentIntentId());
        }
    }

    private void S1() {
        this.X.F1(this);
        this.X.I1(this);
        this.X.G1(this);
        this.X.J1(this);
    }

    public void T0(View view) {
        finish();
    }

    private boolean T1() {
        PaymentMethod q02 = POSPaymentUtils.q0(this.Y.e(), this.Y.b(), this.f10583j0.getString(getString(R.string.last_used_contract_payment_method), null));
        if (B0().compareTo(BigDecimal.ZERO) <= 0 || !this.Y.d().p() || q02 == null) {
            return false;
        }
        this.Y.m(new com.fitnessmobileapps.fma.util.m0(H0()));
        this.Y.d().c(q02, H0());
        return true;
    }

    public void U0(Boolean bool) {
        Intent intent = new Intent(this, (Class<?>) UserSelectionActivity.class);
        intent.putExtra("title_res_id", R.string.who_are_you_buying_for);
        intent.putExtra(CreateIdentityUserRequest.REGION, "retail");
        startActivity(intent);
        overridePendingTransition(R.anim.slide_in_end, R.anim.slide_out_start);
    }

    public void U1() {
        POSPaymentUtils.r0(this.Y.b(), this.Y.d());
        X1();
    }

    public void V1() {
        POSPaymentUtils.s0(this.Y.b(), this.Y.d());
        X1();
    }

    public void W0(String str, DialogInterface dialogInterface, int i10) {
        p1(str);
    }

    private void W1() {
        this.f10576d0 = false;
        this.P.l();
        J1();
        F1();
        y1();
        B1();
        I1();
        K1();
        A1();
    }

    public void X0(DialogInterface dialogInterface, int i10) {
        k0();
    }

    public void Y0(DialogInterface dialogInterface) {
        setResult(555);
        finish();
    }

    public void Z0(ActivityResult activityResult) {
        this.f10579f0 = true;
    }

    public void a1(Boolean bool) {
        this.Y.o(null);
        m();
    }

    public void b1(DialogInterface dialogInterface) {
        Y1();
    }

    public void c1(Unit unit) {
        this.P.l();
        Toast.makeText(this, R.string.generic_error_message, 0).show();
    }

    public void d1(View view) {
        boolean z10 = POSPaymentUtils.t(this.Y.d().q()) != null;
        POSPaymentUtils.t(this.Y.b());
        if (z10) {
            U1();
        } else {
            z1();
            this.f10589n0.U(getSupportFragmentManager());
        }
    }

    public void e1(lf.b bVar, View view) {
        startActivityForResult(AddPaymentCardActivity.B0(this, this.Y.e(), Boolean.FALSE), 444);
        bVar.dismiss();
    }

    public void f1(lf.b bVar, View view) {
        bVar.dismiss();
        this.P.I();
        this.X.w0();
    }

    public void g1(View view) {
        boolean z10 = !POSPaymentUtils.J(this.Y.d().q()).isEmpty();
        BigDecimal w10 = POSPaymentUtils.w(this.Y.b(), "GiftCard");
        if (z10 || w10.compareTo(B0()) > 0) {
            V1();
        } else {
            G1();
            this.f10590o0.U(getSupportFragmentManager());
        }
    }

    public void h1(View view) {
        if (!POSPaymentUtils.L(this.Y.b(), "CreditCard").isEmpty() || of.a0.f39482a.j(this.Y)) {
            startActivityForResult(POSSelectPaymentsActivity.R(this, this.Y, this.f10602v0), 0);
        } else {
            startActivityForResult(AddPaymentCardActivity.B0(this, this.Y.e(), Boolean.FALSE), 444);
        }
    }

    public void i1(View view) {
        startActivityForResult(POSSelectPaymentsActivity.R(this, this.Y, this.f10602v0), 0);
    }

    public void j1(View view) {
        this.f10592p0.U(getSupportFragmentManager());
    }

    private void k0() {
        if (DevelopmentFlags.V.d()) {
            c2.c.f1548a.d(MetricsName.CHECKOUT_STANDARD);
        }
        setResult(667);
        finish();
    }

    public Unit k1(Boolean bool) {
        if (bool.booleanValue()) {
            m();
        } else {
            this.P.l();
            Toast.makeText(this, R.string.generic_error_message, 0).show();
        }
        return Unit.f33247a;
    }

    private boolean l0() {
        PaymentMethod q02 = POSPaymentUtils.q0(this.Y.e(), this.Y.b(), this.f10583j0.getString(getString(R.string.last_used_contract_payment_method), null));
        CartPackage cartPackage = this.T;
        if (cartPackage == null || q02 == null || cartPackage.getContractPaymentMethod() != null || !POSPaymentUtils.n(this.Y.c())) {
            return false;
        }
        this.T.setContractPaymentMethod(q02);
        this.f10583j0.edit().putString(getString(R.string.last_used_contract_payment_method), this.T.getContractPaymentMethod().getUniqueIdentifier()).apply();
        return true;
    }

    public Unit l1() {
        this.P.I();
        this.f10606x0.getValue().u(this.Y.c(), this.A0.c().getValue(), new Function1() {
            @Override
            public final Object invoke(Object obj) {
                Unit k12;
                k12 = POSCheckoutActivity.this.k1((Boolean) obj);
                return k12;
            }
        });
        return Unit.f33247a;
    }

    private void m0() {
        this.C = (RelativeLayout) findViewById(R.id.layout_applied_account_balance);
        this.H = (TextView) findViewById(R.id.text_applied_account_balance_amount);
        this.G = (TextView) findViewById(R.id.text_applied_account_balance);
        TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(this.G, this.f10582i0.c(this, 2131231117, R.color.successAction), (Drawable) null, (Drawable) null, (Drawable) null);
    }

    public void m1(String str, DialogInterface dialogInterface, int i10) {
        p1(str);
    }

    private void n0() {
        com.fitnessmobileapps.fma.views.fragments.dialogs.j jVar = (com.fitnessmobileapps.fma.views.fragments.dialogs.j) getSupportFragmentManager().findFragmentByTag("GIFT_CARD_DIALOG_TAG");
        this.f10586l0 = jVar;
        if (jVar == null) {
            this.f10586l0 = new com.fitnessmobileapps.fma.views.fragments.dialogs.j().X(R.string.gift_card_hint).V(R.string.gift_card_label).H(R.string.gift_card_message).M(R.string.redeem).Y(1).D("GIFT_CARD_DIALOG_TAG");
        }
        this.f10586l0.P(new b.d() {
            @Override
            public final void a(lf.b bVar, View view) {
                POSCheckoutActivity.this.N0((com.fitnessmobileapps.fma.views.fragments.dialogs.j) bVar, view);
            }
        });
        this.f10607y = (TextView) findViewById(R.id.text_add_gc);
        TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(this.f10607y, this.f10582i0.c(this, 2131231117, R.color.successAction), (Drawable) null, (Drawable) null, (Drawable) null);
        this.f10607y.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                POSCheckoutActivity.this.O0(view);
            }
        });
        this.f10609z = (RelativeLayout) findViewById(R.id.layout_applied_gift_card);
        this.B = (TextView) findViewById(R.id.text_applied_gift_card_amount);
        this.A = (TextView) findViewById(R.id.text_applied_gift_card);
    }

    public void n1(DialogInterface dialogInterface, int i10) {
        k0();
    }

    private void o0() {
        com.fitnessmobileapps.fma.views.fragments.dialogs.j jVar = (com.fitnessmobileapps.fma.views.fragments.dialogs.j) getSupportFragmentManager().findFragmentByTag("PROMO_CODE_DIALOG_TAG");
        this.f10585k0 = jVar;
        if (jVar == null) {
            this.f10585k0 = new com.fitnessmobileapps.fma.views.fragments.dialogs.j().X(R.string.promo_code_hint).V(R.string.promo_code_title).Y(1).H(R.string.promo_code_message).M(R.string.redeem).D("PROMO_CODE_DIALOG_TAG");
        }
        this.f10585k0.P(new b.d() {
            @Override
            public final void a(lf.b bVar, View view) {
                POSCheckoutActivity.this.P0((com.fitnessmobileapps.fma.views.fragments.dialogs.j) bVar, view);
            }
        });
        this.f10598t = (TextView) findViewById(R.id.text_add_promo_code);
        TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(this.f10598t, this.f10582i0.c(this, 2131231117, R.color.successAction), (Drawable) null, (Drawable) null, (Drawable) null);
        this.f10598t.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                POSCheckoutActivity.this.Q0(view);
            }
        });
        this.f10601v = (RelativeLayout) findViewById(R.id.layout_applied_promo_code);
        this.f10605x = (TextView) findViewById(R.id.text_applied_promo_code_amount);
        this.f10603w = (TextView) findViewById(R.id.text_applied_promo_code);
        TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(this.f10603w, this.f10582i0.c(this, 2131231125, R.color.successAction), (Drawable) null, (Drawable) null, (Drawable) null);
        this.f10601v.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                POSCheckoutActivity.this.R0(view);
            }
        });
    }

    public void o1(Boolean bool) {
        m();
    }

    private void p0() {
        this.f10606x0.getValue().s().observe(this, new Observer() {
            @Override
            public final void onChanged(Object obj) {
                POSCheckoutActivity.this.S0((StripeConfiguration) obj);
            }
        });
    }

    private void p1(String str) {
        this.D0.launch(SCACustomTabActivity.C(this, str));
    }

    private void q0() {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle(R.string.checkout_title);
        ToolbarKt.j(toolbar, new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                POSCheckoutActivity.this.T0(view);
            }
        });
    }

    private void q1() {
        if (DevelopmentFlags.V.d()) {
            c2.c cVar = c2.c.f1548a;
            if (cVar.c(MetricsName.OPEN_CHECKOUT_REQUEST)) {
                this.X.l0(this.Y, this.V != null, this.W != null);
                return;
            }
            MetricsName metricsName = MetricsName.CHANGE_PAYMENT_METHOD;
            if (cVar.c(metricsName)) {
                this.X.k0(metricsName, this.V != null, this.W != null, true);
                return;
            }
            MetricsName metricsName2 = MetricsName.ADD_GC;
            if (cVar.c(metricsName2)) {
                this.X.k0(metricsName2, this.V != null, this.W != null, true);
                return;
            }
            MetricsName metricsName3 = MetricsName.ADD_PROMO_CODE;
            if (cVar.c(metricsName3)) {
                this.X.k0(metricsName3, this.V != null, this.W != null, true);
            }
        }
    }

    private void r0() {
        r2.j2 c10 = r2.j2.c(findViewById(R.id.checkout_user));
        c10.setLifecycleOwner(this);
        c10.g(Boolean.TRUE);
        c10.i(this.f10608y0.getValue());
        this.f10608y0.getValue().r().observe(this, new Observer() {
            @Override
            public final void onChanged(Object obj) {
                POSCheckoutActivity.this.U0((Boolean) obj);
            }
        });
        this.f10608y0.getValue().v().observe(this, new Observer() {
            @Override
            public final void onChanged(Object obj) {
                POSCheckoutActivity.V0((String) obj);
            }
        });
    }

    public void r1(boolean z10) {
        this.f10602v0 = Boolean.valueOf(z10);
    }

    private void s0(Intent intent) {
        String stringExtra;
        if (intent == null || !intent.hasExtra("payment_intent_id") || (stringExtra = intent.getStringExtra("payment_intent_id")) == null) {
            return;
        }
        this.f10606x0.getValue().l(stringExtra);
        mo.a.i("Stripe_WebPayment_Logs").a("Payment intent cancelled: %s", stringExtra);
    }

    public void s1(GooglePayLauncher.d dVar) {
        String str;
        Map a10;
        this.f10604w0 = true;
        if (dVar instanceof GooglePayLauncher.d.b) {
            N1();
            v0(true);
            str = "completed";
        } else {
            str = dVar instanceof GooglePayLauncher.d.a ? "canceled" : "failed";
        }
        String str2 = str;
        String str3 = this.f10581h0;
        if (str3 == null) {
            str3 = "";
        }
        String str4 = str3;
        o.l lVar = o.l.f44355b;
        String breadcrumbScreenName = PaymentMethodUIData.INSTANCE.getPaymentMethodUIData(this.Y.g()).getBreadcrumbScreenName();
        b.C0002b c0002b = b.C0002b.f139a;
        a10 = s0.a(new Map.Entry[]{new AbstractMap.SimpleEntry(lVar, breadcrumbScreenName), new AbstractMap.SimpleEntry(c0002b.J(), Boolean.valueOf(POSPaymentUtils.n(this.Y.c()))), new AbstractMap.SimpleEntry(c0002b.B(), this.Y.g())});
        a2.a.t("Select third party payment method", str4, "cart-checkout", "select", str2, a10);
    }

    private void t0() {
        if (this.f10576d0) {
            com.fitnessmobileapps.fma.views.fragments.dialogs.b bVar = this.f10596r0;
            if (bVar == null || bVar.isAdded()) {
                return;
            }
            N1();
            return;
        }
        if (this.Y.c() == null) {
            N1();
            this.X.w0();
        } else {
            q1();
            W1();
        }
    }

    public void t1(com.stripe.android.paymentsheet.y yVar) {
        String str;
        Map a10;
        this.f10604w0 = true;
        if (yVar instanceof y.b) {
            N1();
            v0(true);
            str = "completed";
        } else {
            str = yVar instanceof y.a ? "canceled" : "failed";
        }
        String str2 = str;
        String str3 = this.f10581h0;
        if (str3 == null) {
            str3 = "";
        }
        String str4 = str3;
        o.l lVar = o.l.f44355b;
        String breadcrumbScreenName = PaymentMethodUIData.INSTANCE.getPaymentMethodUIData(this.Y.g()).getBreadcrumbScreenName();
        b.C0002b c0002b = b.C0002b.f139a;
        a10 = s0.a(new Map.Entry[]{new AbstractMap.SimpleEntry(lVar, breadcrumbScreenName), new AbstractMap.SimpleEntry(c0002b.J(), Boolean.valueOf(POSPaymentUtils.n(this.Y.c()))), new AbstractMap.SimpleEntry(c0002b.B(), this.Y.g())});
        a2.a.t("Select third party payment method", str4, "cart-checkout", "select", str2, a10);
    }

    private void u1(Bundle bundle) {
        this.R = (CatalogItem) cf.d.c(bundle.getString("ShoppingCart.ARG_SERVICE"), new c().d());
        if (bundle.containsKey("ShoppingCart.ARG_PRODUCT_ID")) {
            this.f10575d = Long.valueOf(bundle.getLong("ShoppingCart.ARG_PRODUCT_ID"));
        }
        this.S = (CatalogPackage) cf.d.c(bundle.getString("ShoppingCart.ARG_PACKAGE"), new d().d());
        this.T = (CartPackage) cf.d.c(bundle.getString("ShoppingCart.ARG_CONTRACT"), new e().d());
        this.U = (ClassTypeObject) bundle.getParcelable("ShoppingCart.ARG_CLASS");
        this.V = (Appointment) bundle.getParcelable("ShoppingCart.ARG_APPOINTMENT");
        this.W = (ClassSchedule) bundle.getParcelable("ShoppingCart.ARG_ENROLLMENT");
        this.f10576d0 = bundle.getBoolean(G0, false);
        this.f10581h0 = bundle.getString("ShoppingCart.ARG_REGION");
    }

    private void v1() {
        this.f10580g0 = false;
        this.P.l();
    }

    public static Intent w0(Context context, CatalogItem catalogItem, ClassTypeObject classTypeObject, Appointment appointment, ClassSchedule classSchedule, String str) {
        Intent intent = new Intent(context, (Class<?>) POSCheckoutActivity.class);
        intent.putExtra("ShoppingCart.ARG_SERVICE", cf.d.g(catalogItem));
        return z0(intent, classTypeObject, appointment, classSchedule, str);
    }

    private void w1(String str, String str2, String str3) {
        if (str2 == null) {
            str2 = "";
        }
        a2.a.q("Cart", str2, str, Integer.valueOf(this.f10606x0.getValue().getUserId().g()), this.Y.c(), this.Z, str3);
    }

    public static Intent x0(Context context, CartPackage cartPackage, String str) {
        Intent intent = new Intent(context, (Class<?>) POSCheckoutActivity.class);
        intent.putExtra("ShoppingCart.ARG_CONTRACT", cf.d.g(cartPackage));
        intent.putExtra("ShoppingCart.ARG_REGION", str);
        return intent;
    }

    private void x1() {
        if (DevelopmentFlags.f6086d0.d()) {
            this.M.setVisibility(0);
            this.M.setMovementMethod(LinkMovementMethod.getInstance());
            this.M.setLinkTextColor(getResources().getColor(R.color.info_dark));
            String string = getString(R.string.contract_checkout_legal);
            this.M.setText(Build.VERSION.SDK_INT >= 24 ? Html.fromHtml(string, 0) : Html.fromHtml(string));
            return;
        }
        if (B0().compareTo(BigDecimal.ZERO) <= 0) {
            this.M.setVisibility(8);
        } else {
            this.M.setVisibility(0);
            this.M.setText(of.a0.f39482a.h(this.Y) ? getString(R.string.pos_checkout_alternate_disclaimer) : getString(R.string.pos_checkout_micro));
        }
    }

    public static Intent y0(Context context, CatalogPackage catalogPackage, ClassTypeObject classTypeObject, Appointment appointment, ClassSchedule classSchedule, String str) {
        Intent intent = new Intent(context, (Class<?>) POSCheckoutActivity.class);
        intent.putExtra("ShoppingCart.ARG_PACKAGE", cf.d.g(catalogPackage));
        return z0(intent, classTypeObject, appointment, classSchedule, str);
    }

    private void y1() {
        boolean j10 = of.a0.f39482a.j(this.Y);
        this.C.setVisibility(j10 ? 8 : 0);
        if (j10) {
            return;
        }
        PaymentMethod t10 = POSPaymentUtils.t(this.Y.b());
        boolean z10 = POSPaymentUtils.t(this.Y.d().q()) != null;
        D1(this.C, this.G, this.H, R.string.account_credit_label, z10 ? this.Y.d().j(t10) : t10 != null ? t10.getBalance() : BigDecimal.ZERO, z10);
        z1();
        this.C.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                POSCheckoutActivity.this.d1(view);
            }
        });
    }

    private static Intent z0(Intent intent, ClassTypeObject classTypeObject, Appointment appointment, ClassSchedule classSchedule, String str) {
        intent.putExtra("ShoppingCart.ARG_CLASS", classTypeObject);
        intent.putExtra("ShoppingCart.ARG_APPOINTMENT", (Parcelable) appointment);
        intent.putExtra("ShoppingCart.ARG_ENROLLMENT", (Parcelable) classSchedule);
        intent.putExtra("ShoppingCart.ARG_REGION", str);
        return intent;
    }

    private void z1() {
        this.f10589n0 = com.fitnessmobileapps.fma.util.w0.h(getSupportFragmentManager(), "ACCOUNT_CREDIT_CONFIRMATION_DIALOG_TAG", R.string.message_account_credit_usage, new g());
    }

    public void I1() {
        List<PaymentMethod> k10 = this.Y.d().k();
        of.a0 a0Var = of.a0.f39482a;
        boolean h10 = a0Var.h(this.Y);
        boolean z10 = J0() || K0();
        CartPackage cartPackage = this.T;
        PaymentMethod contractPaymentMethod = cartPackage != null ? cartPackage.getContractPaymentMethod() : null;
        boolean z11 = (k10.isEmpty() && contractPaymentMethod == null) ? false : true;
        this.I.setVisibility((z11 || !z10 || h10) ? 8 : 0);
        this.I.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                POSCheckoutActivity.this.h1(view);
            }
        });
        if (this.T != null) {
            this.J.setVisibility((z11 || h10) ? 0 : 8);
        } else {
            View view = this.J;
            if ((z11 && z10) || (h10 && z10)) {
                r10 = 0;
            }
            view.setVisibility(r10);
        }
        if (a0Var.h(this.Y)) {
            PaymentMethodUIData paymentMethodUIData = PaymentMethodUIData.INSTANCE.getPaymentMethodUIData(this.Y.g());
            TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(this.L, AppCompatResources.getDrawable(this, paymentMethodUIData.getIconResource()), (Drawable) null, (Drawable) null, (Drawable) null);
            this.L.setText(getString(paymentMethodUIData.getMethodName()));
        } else if (contractPaymentMethod != null) {
            TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(this.L, POSPaymentUtils.y(POSPaymentUtils.E(contractPaymentMethod), this), (Drawable) null, (Drawable) null, (Drawable) null);
            this.L.setText(getString(R.string.pos_card_format, contractPaymentMethod.getCardLastFour()));
        } else if (z11 && z10) {
            Iterator<PaymentMethod> it = k10.iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                PaymentMethod next = it.next();
                if (next.isCreditCard()) {
                    TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(this.L, POSPaymentUtils.y(POSPaymentUtils.E(next), this), (Drawable) null, (Drawable) null, (Drawable) null);
                    this.L.setText(getString(R.string.pos_card_format, next.getCardLastFour()));
                    break;
                }
            }
        }
        this.K.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                POSCheckoutActivity.this.i1(view2);
            }
        });
    }

    public void K1() {
        BigDecimal B0 = B0();
        BigDecimal G02 = G0();
        BigDecimal tax = this.Y.c().getTotals().getTax();
        BigDecimal discount = this.Y.c().getTotals().getDiscount();
        PaymentMethod t10 = POSPaymentUtils.t(this.Y.b());
        this.f10595r.setTotals(B0, G02, tax, discount, this.Y.d().j(t10) != null ? this.Y.d().j(t10) : BigDecimal.ZERO, this.Y.c().getTotalAppliedGiftCardBalance(), this.Y.e());
        this.f10595r.setInfoIcon(this.T != null && CartItemUtil.hasOneTimeItems(this.Y.c(), this.T));
        if (!this.E0 && of.b0.e(this.B0.getValue().invoke(Unit.f33247a).booleanValue())) {
            this.N.setVisibility(8);
            x1();
            if (this.Y.f() != null && (this.Y.f().isPayNow() || this.Y.f().isWeChatPAY())) {
                this.N.setVisibility(0);
                this.N.setText(getString(R.string.apm_message_for_polling, Integer.valueOf(FlagsUtilsClassKt.c().c()), getString(R.string.bma_app_name)));
                this.N.setTextColor(getResources().getColor(R.color.bma_black, null));
            }
        }
        this.E0 = false;
        if (this.T != null) {
            lf.b bVar = (lf.b) getSupportFragmentManager().findFragmentByTag("TODAYS_TOTAL_DIALOG_TAG");
            this.f10592p0 = bVar;
            if (bVar == null) {
                this.f10592p0 = new lf.b().D("TODAYS_TOTAL_DIALOG_TAG").H(POSPaymentUtils.k0(this.Y.c())).M(android.R.string.ok);
            }
            this.f10595r.getTodaysTotalLabel().setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view) {
                    POSCheckoutActivity.this.j1(view);
                }
            });
        }
    }

    protected void X1() {
        this.f10576d0 = true;
        N1();
        POSPaymentUtils.p0(this.Y.c(), this.Y.d().l(), Integer.valueOf(Application.d().c().f().getSiteId()).intValue(), new TaskCallback() {
            @Override
            public final void a(Object obj) {
                POSCheckoutActivity.this.o1((Boolean) obj);
            }

            @Override
            public void b() {
                cf.e.a(this);
            }
        });
    }

    protected void Y1() {
        this.f10576d0 = true;
        N1();
        this.X.O1(this.Y.c(), this.Y.d().l());
    }

    protected void Z1() {
        this.f10576d0 = true;
        N1();
        this.X.N1(this.T, this.A0.c().getValue());
    }

    @Override
    public void a(Exception exc) {
        w1("failed", this.f10581h0, exc.getMessage());
        this.P.l();
        if (exc instanceof PaymentAuthenticationFailure) {
            P1(((PaymentAuthenticationFailure) exc).getAuthenticationRedirectUrl());
        } else {
            L1();
        }
        this.f10580g0 = false;
    }

    @Override
    public void b(Exception exc) {
        this.P.l();
        if (!(exc instanceof ServerError)) {
            Toast.makeText(this, R.string.generic_error_message, 0).show();
            return;
        }
        NetworkResponse networkResponse = ((ServerError) exc).networkResponse;
        if (networkResponse == null || networkResponse.statusCode != 404) {
            return;
        }
        Snackbar.n0(this.f10577e, getString(R.string.error_invalid_gift_card_number), -1).p0(this.C0).a0();
    }

    @Override
    public void c() {
        m();
    }

    @Override
    public void d() {
        k0();
    }

    @Override
    public void e(Exception exc) {
        this.P.l();
        this.f10597s0.U(getSupportFragmentManager());
    }

    @Override
    public void f(Cart cart) {
        this.Y.l(cart);
        this.Y.m(new com.fitnessmobileapps.fma.util.m0(cart));
        this.T = POSPaymentUtils.o0(this.Y.c());
        boolean T1 = T1();
        boolean l02 = l0();
        boolean z10 = T1 || !POSPaymentUtils.U(this.Y.c());
        BigDecimal total = this.Y.c().getTotals().getTotal();
        if (z10) {
            this.Y.d().f();
            X1();
            return;
        }
        if (l02) {
            Z1();
            return;
        }
        if (POSPaymentUtils.n(this.Y.c()) && total != null && total.compareTo(BigDecimal.ZERO) < 1 && cart.getDiscounts().length > 0 && this.Y.f() != null) {
            M1();
            return;
        }
        if (total != null && total.compareTo(BigDecimal.ZERO) < 1 && this.Y.f() != null) {
            of.a0.f39482a.k(this.Y.c(), new TaskCallback() {
                @Override
                public final void a(Object obj) {
                    POSCheckoutActivity.this.a1((Boolean) obj);
                }

                @Override
                public void b() {
                    cf.e.a(this);
                }
            });
        } else {
            q1();
            W1();
        }
    }

    @Override
    public void h() {
        this.f10580g0 = false;
        HashMap hashMap = new HashMap();
        hashMap.put("clientID", String.valueOf(this.f10606x0.getValue().getUserId()));
        if (this.Y.d() != null) {
            hashMap.put("UseAccountBalance", String.valueOf(POSPaymentUtils.t(this.Y.d().q()) != null));
        }
        w1("completed", this.f10581h0, null);
        com.fitnessmobileapps.fma.util.f.b().l("CheckoutShoppingCartWithClient", hashMap);
        this.P.l();
        this.f10606x0.getValue().x();
        Runnable runnable = this.f10573b0;
        if (runnable != null) {
            runnable.run();
        } else {
            A0();
        }
    }

    @Override
    public void i(PaymentConfiguration paymentConfiguration) {
        this.Y.n(paymentConfiguration);
        this.Y.k((ArrayList) paymentConfiguration.getPaymentMethods());
        if (this.Y.c() == null && this.T == null) {
            this.X.L1(this.R, this.f10575d, this.S, this.W, this);
        } else {
            this.X.r0();
        }
    }

    @Override
    public void j(PaymentMethod paymentMethod, String str) {
        if (!POSPaymentUtils.S(paymentMethod)) {
            this.P.l();
            Snackbar.n0(this.f10577e, getString(R.string.error_not_consumer_mode_gift_card_message), -1).p0(this.C0).a0();
            return;
        }
        if (paymentMethod.getBalance().compareTo(BigDecimal.ZERO) <= 0) {
            this.P.l();
            Snackbar.n0(this.f10577e, getString(R.string.gift_card_no_money_left_error_message), -1).p0(this.C0).a0();
            return;
        }
        GiftCard giftCard = new GiftCard();
        giftCard.setName(this.f10572a0.format(paymentMethod.getBalance()) + " " + getString(R.string.gift_card));
        giftCard.setNumber(str);
        giftCard.setAmount(le.b.i(paymentMethod.getBalance()));
        giftCard.setBalance(le.b.i(paymentMethod.getBalance()));
        giftCard.setSiteID(this.Q.r());
        giftCard.setBusinessName(((Application) getApplication()).e().getName());
        giftCard.setUserId(this.f10606x0.getValue().getUserId().g());
        qf.d.E().l(giftCard);
        if (this.Y.a(paymentMethod)) {
            V1();
        } else {
            this.P.l();
        }
    }

    @Override
    public void k(Exception exc) {
        this.P.l();
        this.f10597s0.U(getSupportFragmentManager());
    }

    @Override
    public void l(Exception exc) {
        this.P.l();
        int l02 = POSPaymentUtils.l0(exc);
        if (l02 != 0) {
            Snackbar.m0(this.f10577e, l02, -1).p0(this.C0).a0();
        } else {
            Toast.makeText(this, R.string.generic_error_message, 0).show();
        }
    }

    @Override
    public void m() {
        N1();
        this.X.r0();
    }

    @Override
    public void o(final String str) {
        this.f10578e0 = true;
        new qb.b(this).setMessage(R.string.sca_authentication_message).setPositiveButton(R.string.button_continue, new DialogInterface.OnClickListener() {
            @Override
            public final void onClick(DialogInterface dialogInterface, int i10) {
                POSCheckoutActivity.this.W0(str, dialogInterface, i10);
            }
        }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
            @Override
            public final void onClick(DialogInterface dialogInterface, int i10) {
                POSCheckoutActivity.this.X0(dialogInterface, i10);
            }
        }).show();
    }

    @Override
    protected void onActivityResult(int i10, int i11, Intent intent) {
        PaymentMethod paymentMethod;
        super.onActivityResult(i10, i11, intent);
        if (i11 == 48238492) {
            String stringExtra = intent.getStringExtra("paymentMethodType");
            if (stringExtra != null) {
                POSCache pOSCache = this.Y;
                pOSCache.o(of.b0.a(stringExtra, pOSCache));
                this.f10606x0.getValue().z(this.Y, stringExtra);
                if (of.b0.f() && this.T != null && POSPaymentUtils.n(this.Y.c()) && this.Y.f() != null) {
                    this.T.setContractPaymentMethod(this.Y.f());
                }
            }
            Y1();
            return;
        }
        if (i10 == 0 && i11 == -1) {
            this.Y = new POSCache(intent.getExtras().getBundle(POSSelectPaymentsActivity.U));
            Y1();
            return;
        }
        if (i10 == 444 && i11 == -1 && (paymentMethod = (PaymentMethod) cf.d.b(intent.getStringExtra("ADD_CARD_EXTRA"), PaymentMethod.class)) != null) {
            this.Y.a(paymentMethod);
            this.Y.d().b(paymentMethod);
            if (this.T != null && POSPaymentUtils.n(this.Y.c())) {
                this.T.setContractPaymentMethod(paymentMethod);
            }
            this.f10576d0 = true;
            this.f10596r0.show(getSupportFragmentManager(), "CARD_ADDED_DIALOG_TAG");
        }
    }

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_pos_checkout);
        this.f10606x0.getValue();
        this.Y = POSCache.h(bundle);
        this.f10572a0 = POSPaymentUtils.M();
        this.Z = LocationMBOSettings.getLocale(h1.a.k(this).l());
        this.Q = h1.a.k(this);
        this.P = new com.fitnessmobileapps.fma.util.t(this);
        this.f10582i0 = new com.fitnessmobileapps.fma.util.u();
        this.f10583j0 = PreferenceManager.getDefaultSharedPreferences(this);
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            u1(extras);
        }
        if (bundle != null) {
            u1(bundle);
        }
        if (of.b0.g(this.B0.getValue().invoke(Unit.f33247a).booleanValue())) {
            this.f10599t0 = new PaymentSheet(this, new com.stripe.android.paymentsheet.z() {
                @Override
                public final void b(com.stripe.android.paymentsheet.y yVar) {
                    POSCheckoutActivity.this.t1(yVar);
                }
            });
            p0();
        }
        if (DevelopmentFlags.f6095t.d()) {
            L0();
        }
        this.f10574c0 = this.T == null;
        s2.o1 o1Var = (s2.o1) getLastCustomNonConfigurationInstance();
        this.X = o1Var;
        if (o1Var == null) {
            this.X = new s2.o1(this.f10610z0.getValue());
        }
        this.f10577e = findViewById(android.R.id.content);
        if (M0()) {
            this.f10584k = (BookAndBuyHeader) findViewById(R.id.view_item_header_info);
            H1();
        }
        q0();
        this.f10588n = (TextView) findViewById(R.id.text_cart);
        this.f10591p = (TextView) findViewById(R.id.text_qty);
        this.f10593q = (MiniContractSummaryView) findViewById(R.id.view_contract_details_summary);
        B1();
        r0();
        o0();
        n0();
        m0();
        this.I = (TextView) findViewById(R.id.text_new_payment_method);
        this.J = findViewById(R.id.layout_payment_method);
        this.L = (TextView) findViewById(R.id.text_payment_method);
        this.K = (TextView) findViewById(R.id.text_change_payment_method);
        this.f10595r = (TotalsRowView) findViewById(R.id.view_totals_row);
        this.M = (TextView) findViewById(R.id.text_buy_message);
        this.N = (TextView) findViewById(R.id.text_buy_sub_message);
        SuccessButton successButton = (SuccessButton) findViewById(R.id.button_checkout);
        this.O = successButton;
        successButton.setOnClickListener(new b());
        this.f10596r0 = com.fitnessmobileapps.fma.util.w0.e(getSupportFragmentManager(), "CARD_ADDED_DIALOG_TAG", new DialogInterface.OnDismissListener() {
            @Override
            public final void onDismiss(DialogInterface dialogInterface) {
                POSCheckoutActivity.this.b1(dialogInterface);
            }
        });
        E1();
        String str = this.f10581h0;
        if (str == null) {
            str = "";
        }
        a2.a.L("Cart", "cart-checkout", str, "cart-checkout", null);
        this.f10606x0.getValue().r().observe(this, new Observer() {
            @Override
            public final void onChanged(Object obj) {
                POSCheckoutActivity.this.c1((Unit) obj);
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (this.f10574c0) {
            w1("deleted", this.f10581h0, null);
            this.X.o0();
        }
        this.P = null;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() == 16908332) {
            finish();
        }
        return super.onOptionsItemSelected(menuItem);
    }

    @Override
    public void onPause() {
        super.onPause();
        this.X.e();
        this.P.l();
    }

    @Override
    public void onResume() {
        super.onResume();
        S1();
        if (this.f10604w0) {
            this.f10604w0 = false;
            return;
        }
        mo.a.i("Stripe_WebPayment_Logs").a("onResume of POSCheckoutActivity called.", new Object[0]);
        if (this.f10580g0) {
            this.P.J(R.string.payment_loading_message);
        } else {
            if (!this.f10579f0) {
                t0();
                return;
            }
            this.f10578e0 = true;
            this.P.I();
            this.X.m0(F0());
        }
    }

    @Override
    public Object onRetainCustomNonConfigurationInstance() {
        return this.X;
    }

    @Override
    public void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        bundle.putString("ShoppingCart.ARG_SERVICE", cf.d.g(this.R));
        Long l10 = this.f10575d;
        if (l10 != null) {
            bundle.putLong("ShoppingCart.ARG_PRODUCT_ID", l10.longValue());
        }
        bundle.putString("ShoppingCart.ARG_PACKAGE", cf.d.g(this.S));
        bundle.putString("ShoppingCart.ARG_CONTRACT", cf.d.g(this.T));
        bundle.putParcelable("ShoppingCart.ARG_CLASS", this.U);
        bundle.putParcelable("ShoppingCart.ARG_APPOINTMENT", this.V);
        bundle.putParcelable("ShoppingCart.ARG_ENROLLMENT", this.W);
        bundle.putBundle(POSCache.f10367k, this.Y.j());
        bundle.putBoolean(G0, this.f10576d0);
        bundle.putString("ShoppingCart.ARG_REGION", this.f10581h0);
        this.f10574c0 = false;
    }

    @Override
    public void p(VolleyError volleyError) {
        k(volleyError);
    }

    protected void u0() {
        v0(false);
    }

    protected void v0(boolean z10) {
        Map a10;
        int n02 = z10 ? 0 : POSPaymentUtils.n0(this.Y.c());
        if (n02 != 7) {
            w1("started", this.f10581h0, null);
        } else {
            String str = this.f10581h0;
            if (str == null) {
                str = "";
            }
            String str2 = str;
            o.l lVar = o.l.f44355b;
            String breadcrumbScreenName = PaymentMethodUIData.INSTANCE.getPaymentMethodUIData(this.Y.g()).getBreadcrumbScreenName();
            b.C0002b c0002b = b.C0002b.f139a;
            a10 = s0.a(new Map.Entry[]{new AbstractMap.SimpleEntry(lVar, breadcrumbScreenName), new AbstractMap.SimpleEntry(c0002b.J(), Boolean.valueOf(POSPaymentUtils.n(this.Y.c()))), new AbstractMap.SimpleEntry(c0002b.B(), this.Y.g())});
            a2.a.t("Select third party payment method", str2, "cart-checkout", "select", "started", a10);
        }
        if (n02 == 0) {
            N1();
            if (DevelopmentFlags.V.d()) {
                this.X.M1(this.V != null, this.W != null);
            }
            if (M0()) {
                this.f10573b0 = new Runnable() {
                    @Override
                    public final void run() {
                        POSCheckoutActivity.this.A0();
                    }
                };
            }
            this.X.m0(F0());
            return;
        }
        if (n02 == 1) {
            O1();
            return;
        }
        if (n02 == 4 || n02 == 6) {
            A1();
            this.f10594q0.U(getSupportFragmentManager());
        } else {
            if (n02 != 7) {
                return;
            }
            if (DevelopmentFlags.V.d()) {
                c2.c.f1548a.a(System.currentTimeMillis(), MetricsName.CHECKOUT_APM, null);
            }
            N1();
            this.f10606x0.getValue().p(this, this.A0.c().getValue(), this.Y.g(), this.Y.c(), this.f10608y0.getValue());
        }
    }

    public static void V0(String str) {
    }
}