package com.bytedance.globalpayment.iap.service.provider;

import X.C0187TMf;
import X.C0207TMz;
import X.C0213TNf;
import X.C0234TOa;
import X.C0242TOi;
import X.C0244TOk;
import X.C0245TOl;
import X.TN2;
import X.TN3;
import X.TND;
import X.TNE;
import X.TNF;
import X.TNG;
import X.TNH;
import X.TNI;
import X.TNJ;
import X.TNK;
import X.TNL;
import X.TNO;
import X.TNT;
import X.TNU;
import X.TNY;
import X.TOA;
import X.TOE;
import X.TOM;
import X.TOQ;
import android.app.Activity;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.bytedance.fresco.nativeheif.BuildConfig;
import com.bytedance.globalpayment.iap.common.ability.model.OrderData;
import com.bytedance.globalpayment.iap.common.ability.model.OrderInfo;
import com.bytedance.globalpayment.iap.common.ability.model.enums.PayType;
import com.bytedance.globalpayment.iap.model.AbsIapChannelOrderData;
import com.bytedance.globalpayment.iap.model.AbsIapProduct;
import com.bytedance.globalpayment.iap.model.AbsResult;
import com.bytedance.globalpayment.iap.model.IapPaymentMethod;
import com.bytedance.globalpayment.iap.state.extra.ExtraConsumeState;
import com.bytedance.globalpayment.iap.state.nomal.ConsumeProductState;
import com.bytedance.globalpayment.iap.state.pre.PreregisterConsumeState;
import com.bytedance.globalpayment.service.manager.PaymentServiceManager;
import com.bytedance.globalpayment.service.manager.iap.IapExternalService;
import com.bytedance.ugc.glue.monitor.UGCMonitor;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONObject;

public class IapServiceProvider extends TNL implements TOM, C0242TOi, IapExternalService {
    public final String TAG = IapServiceProvider.class.getSimpleName();
    public final TNY mOnResumeQueryUnAckEdOrderListener = C0234TOa.LIZ;
    public TNY mQueryUnAckEdOrderListener = new TNY() {
        static {
            Covode.recordClassIndex(27119);
        }

        public final void onQueryFinished(IapPaymentMethod iapPaymentMethod, AbsResult absResult, List<AbsIapChannelOrderData> list) {
            C0187TMf.LIZ().LJ();
            if (absResult != null && list != null) {
                if (absResult.getCode() != 0) {
                    C0187TMf.LIZ().LJ();
                    absResult.getMessage();
                } else if (list.isEmpty()) {
                    C0187TMf.LIZ().LJ();
                } else {
                    C0187TMf.LIZ().LJ();
                    list.size();
                    if (iapPaymentMethod != IapPaymentMethod.GOOGLE || !PaymentServiceManager.get().getGoogleIapExternalService().getRestoreGoogleOrderService().isEnableRestoreOrder()) {
                        for (AbsIapChannelOrderData next : list) {
                            C0187TMf.LIZ().LJ();
                            next.isSubscription();
                            next.isAcknowledged();
                            next.getOrderState();
                            if (next.isOrderStateSuccess()) {
                                String channelOrderId = next.getChannelOrderId();
                                String developerPayload = next.getDeveloperPayload();
                                if ((iapPaymentMethod == IapPaymentMethod.GOOGLE && (!TextUtils.isEmpty(channelOrderId) || !TextUtils.isEmpty(developerPayload))) || iapPaymentMethod == IapPaymentMethod.AMAZON) {
                                    IapServiceProvider.this.executeUnUploadTokenOrder(iapPaymentMethod, next);
                                }
                            }
                        }
                    }
                }
            }
        }
    };

    static {
        Covode.recordClassIndex(27118);
    }

    public C0242TOi getIapInternalService() {
        return this;
    }

    public boolean hasInitEd() {
        return this.mInitEd.get();
    }

    public void queryRewards() {
        queryRewards((TOE) null);
    }

    public void onAppResume() {
        if (this.mInitEd.get()) {
            queryRewardsInternal(true, (TOE) null);
            if (C0187TMf.LIZ().LJIIIIZZ().LIZLLL().LJI) {
                TN3.LIZLLL().LIZJ().LIZ(IapPaymentMethod.GOOGLE, this.mOnResumeQueryUnAckEdOrderListener);
            }
        }
    }

    public void init() {
        if (this.mInitEd.getAndSet(true)) {
            TOA.LJFF().LIZ().LIZ(IapPaymentMethod.GOOGLE, new TN2(401, 4011, "init failed because repeated init"));
            TOA.LJFF().LIZ().LIZ(IapPaymentMethod.AMAZON, new TN2(401, 4011, "init failed because repeated init"));
            return;
        }
        if (C0187TMf.LIZ().LJIIIIZZ().LIZLLL().LJI) {
            PaymentServiceManager.get().getGoogleIapExternalService().setGpListener(this);
            PaymentServiceManager.get().getGoogleIapExternalService().init(new C0245TOl() {
                static {
                    Covode.recordClassIndex(27120);
                }

                public final void LIZ(TN2 tn2) {
                    if (tn2 == null) {
                        TOA.LJFF().LIZ().LIZ(IapPaymentMethod.GOOGLE, new TN2(401, 4012, "google init failed"));
                    } else if (tn2.getCode() == 0) {
                        TOA.LJFF().LIZ().LIZ(IapPaymentMethod.GOOGLE, new TN2(0, 0, "init success"));
                        IapServiceProvider.this.tryRestoreUnAckOrder(IapPaymentMethod.GOOGLE);
                    } else {
                        TNU LIZ2 = TOA.LJFF().LIZ();
                        IapPaymentMethod iapPaymentMethod = IapPaymentMethod.GOOGLE;
                        LIZ2.LIZ(iapPaymentMethod, new TN2(401, 4012, "google response code is: " + tn2.getCode() + " message is : " + tn2.getMessage()));
                    }
                }
            });
        }
        if (C0187TMf.LIZ().LJIIIIZZ().LIZLLL().LJII) {
            PaymentServiceManager.get().getAmazonIapExternalService().init(new C0245TOl() {
                static {
                    Covode.recordClassIndex(27121);
                }

                public final void LIZ(TN2 tn2) {
                    if (tn2 == null) {
                        TOA.LJFF().LIZ().LIZ(IapPaymentMethod.AMAZON, new TN2(401, 4012, "amazon init failed"));
                    } else if (tn2.getCode() == 0) {
                        TOA.LJFF().LIZ().LIZ(IapPaymentMethod.AMAZON, new TN2(0, 0, "init success"));
                        IapServiceProvider.this.tryRestoreUnAckOrder(IapPaymentMethod.AMAZON);
                    } else {
                        TNU LIZ2 = TOA.LJFF().LIZ();
                        IapPaymentMethod iapPaymentMethod = IapPaymentMethod.AMAZON;
                        LIZ2.LIZ(iapPaymentMethod, new TN2(401, 4012, "amazon response code is: " + tn2.getCode() + " message is : " + tn2.getMessage()));
                    }
                }
            });
        }
    }

    /* renamed from: com.bytedance.globalpayment.iap.service.provider.IapServiceProvider$9  reason: invalid class name */
    public static /* synthetic */ class AnonymousClass9 {
        public static final /* synthetic */ int[] LIZ;

        /* JADX WARNING: Can't wrap try/catch for region: R(22:0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|(3:21|22|24)) */
        /* JADX WARNING: Can't wrap try/catch for region: R(24:0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|24) */
        /* JADX WARNING: Failed to process nested try/catch */
        /* JADX WARNING: Missing exception handler attribute for start block: B:11:0x0043 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:13:0x004e */
        /* JADX WARNING: Missing exception handler attribute for start block: B:15:0x0059 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:17:0x0065 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:19:0x0071 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:21:0x007d */
        /* JADX WARNING: Missing exception handler attribute for start block: B:3:0x0017 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:5:0x0022 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:7:0x002d */
        /* JADX WARNING: Missing exception handler attribute for start block: B:9:0x0038 */
        static {
            /*
                r0 = 27127(0x69f7, float:3.8013E-41)
                com.bytedance.covode.number.Covode.recordClassIndex(r0)
                X.TNG[] r0 = X.TNG.values()
                int r0 = r0.length
                int[] r2 = new int[r0]
                LIZ = r2
                X.TNG r0 = X.TNG.CreateOrder     // Catch:{ NoSuchFieldError -> 0x0017 }
                int r1 = r0.ordinal()     // Catch:{ NoSuchFieldError -> 0x0017 }
                r0 = 1
                r2[r1] = r0     // Catch:{ NoSuchFieldError -> 0x0017 }
            L_0x0017:
                int[] r2 = LIZ     // Catch:{ NoSuchFieldError -> 0x0022 }
                X.TNG r0 = X.TNG.PerformPay     // Catch:{ NoSuchFieldError -> 0x0022 }
                int r1 = r0.ordinal()     // Catch:{ NoSuchFieldError -> 0x0022 }
                r0 = 2
                r2[r1] = r0     // Catch:{ NoSuchFieldError -> 0x0022 }
            L_0x0022:
                int[] r2 = LIZ     // Catch:{ NoSuchFieldError -> 0x002d }
                X.TNG r0 = X.TNG.AmazonPay     // Catch:{ NoSuchFieldError -> 0x002d }
                int r1 = r0.ordinal()     // Catch:{ NoSuchFieldError -> 0x002d }
                r0 = 3
                r2[r1] = r0     // Catch:{ NoSuchFieldError -> 0x002d }
            L_0x002d:
                int[] r2 = LIZ     // Catch:{ NoSuchFieldError -> 0x0038 }
                X.TNG r0 = X.TNG.UploadToken     // Catch:{ NoSuchFieldError -> 0x0038 }
                int r1 = r0.ordinal()     // Catch:{ NoSuchFieldError -> 0x0038 }
                r0 = 4
                r2[r1] = r0     // Catch:{ NoSuchFieldError -> 0x0038 }
            L_0x0038:
                int[] r2 = LIZ     // Catch:{ NoSuchFieldError -> 0x0043 }
                X.TNG r0 = X.TNG.QueryOrder     // Catch:{ NoSuchFieldError -> 0x0043 }
                int r1 = r0.ordinal()     // Catch:{ NoSuchFieldError -> 0x0043 }
                r0 = 5
                r2[r1] = r0     // Catch:{ NoSuchFieldError -> 0x0043 }
            L_0x0043:
                int[] r2 = LIZ     // Catch:{ NoSuchFieldError -> 0x004e }
                X.TNG r0 = X.TNG.ExtraUploadToken     // Catch:{ NoSuchFieldError -> 0x004e }
                int r1 = r0.ordinal()     // Catch:{ NoSuchFieldError -> 0x004e }
                r0 = 6
                r2[r1] = r0     // Catch:{ NoSuchFieldError -> 0x004e }
            L_0x004e:
                int[] r2 = LIZ     // Catch:{ NoSuchFieldError -> 0x0059 }
                X.TNG r0 = X.TNG.ExtraQueryOrder     // Catch:{ NoSuchFieldError -> 0x0059 }
                int r1 = r0.ordinal()     // Catch:{ NoSuchFieldError -> 0x0059 }
                r0 = 7
                r2[r1] = r0     // Catch:{ NoSuchFieldError -> 0x0059 }
            L_0x0059:
                int[] r2 = LIZ     // Catch:{ NoSuchFieldError -> 0x0065 }
                X.TNG r0 = X.TNG.PreregisterCreateOrder     // Catch:{ NoSuchFieldError -> 0x0065 }
                int r1 = r0.ordinal()     // Catch:{ NoSuchFieldError -> 0x0065 }
                r0 = 8
                r2[r1] = r0     // Catch:{ NoSuchFieldError -> 0x0065 }
            L_0x0065:
                int[] r2 = LIZ     // Catch:{ NoSuchFieldError -> 0x0071 }
                X.TNG r0 = X.TNG.PreregisterUploadToken     // Catch:{ NoSuchFieldError -> 0x0071 }
                int r1 = r0.ordinal()     // Catch:{ NoSuchFieldError -> 0x0071 }
                r0 = 9
                r2[r1] = r0     // Catch:{ NoSuchFieldError -> 0x0071 }
            L_0x0071:
                int[] r2 = LIZ     // Catch:{ NoSuchFieldError -> 0x007d }
                X.TNG r0 = X.TNG.PreregisterQueryOrder     // Catch:{ NoSuchFieldError -> 0x007d }
                int r1 = r0.ordinal()     // Catch:{ NoSuchFieldError -> 0x007d }
                r0 = 10
                r2[r1] = r0     // Catch:{ NoSuchFieldError -> 0x007d }
            L_0x007d:
                int[] r2 = LIZ     // Catch:{ NoSuchFieldError -> 0x0089 }
                X.TNG r0 = X.TNG.Consume     // Catch:{ NoSuchFieldError -> 0x0089 }
                int r1 = r0.ordinal()     // Catch:{ NoSuchFieldError -> 0x0089 }
                r0 = 11
                r2[r1] = r0     // Catch:{ NoSuchFieldError -> 0x0089 }
            L_0x0089:
                return
            */
            throw new UnsupportedOperationException("Method not decompiled: com.bytedance.globalpayment.iap.service.provider.IapServiceProvider.AnonymousClass9.<clinit>():void");
        }
    }

    public void acquireReward(TNK tnk) {
        acquireReward(tnk, (TOE) null);
    }

    public void getChannelUserData(IapPaymentMethod iapPaymentMethod) {
        getChannelUserData(iapPaymentMethod, (TOE) null);
    }

    public void queryHasSubscriptionProducts(IapPaymentMethod iapPaymentMethod) {
        queryHasSubscriptionProducts(iapPaymentMethod, (TOE) null);
    }

    public void addIapObserver(TOE toe) {
        TOA.LJFF().LIZ().LIZ(toe);
    }

    public void jumpToSubscriptionManagerPage(IapPaymentMethod iapPaymentMethod) {
        TN3.LIZLLL().LIZJ().LIZ(iapPaymentMethod);
    }

    public void onOrderTimeout(OrderInfo orderInfo) {
        TOA.LJFF().LIZ().LIZ(orderInfo);
    }

    public void queryRewards(TOE toe) {
        if (this.mInitEd.get()) {
            queryRewardsInternal(false, toe);
        }
    }

    public void removeAcquireRewards(String str) {
        if (this.mRewards != null) {
            this.mRewards.remove(str);
        }
    }

    public void removeIapObserver(TOE toe) {
        TOA.LJFF().LIZ().LIZIZ(toe);
    }

    public void onCJBillingCallback(OrderData orderData) {
        orderData.setOrderFromOtherSystem(true);
        getIapInternalService();
        new TNI(this).LIZ(orderData);
    }

    public void setProductInterceptor(C0207TMz tMz) {
        C0187TMf.LIZ().LJ();
        TOA.LJFF().LJ().LIZ(tMz);
    }

    public void updateHost(String str) {
        C0187TMf.LIZ().LJ();
        TOA.LJFF().LJ().LIZ(str);
    }

    public boolean isSupportPaymentMethod(IapPaymentMethod iapPaymentMethod) {
        if (iapPaymentMethod == IapPaymentMethod.GOOGLE) {
            return PaymentServiceManager.get().getGoogleIapExternalService().isSupportGooglePay();
        }
        if (iapPaymentMethod == IapPaymentMethod.AMAZON) {
            return PaymentServiceManager.get().getAmazonIapExternalService().isSupportAmazonPay();
        }
        return false;
    }

    public void tryRestoreUnAckOrder(IapPaymentMethod iapPaymentMethod) {
        if (iapPaymentMethod == IapPaymentMethod.GOOGLE && !C0187TMf.LIZ().LJII().LIZLLL()) {
            TN3.LIZLLL().LIZJ().LIZ(iapPaymentMethod, this.mQueryUnAckEdOrderListener);
        }
        if (iapPaymentMethod == IapPaymentMethod.AMAZON) {
            TN3.LIZLLL().LIZJ().LIZ(iapPaymentMethod, this.mQueryUnAckEdOrderListener);
        }
    }

    public void onIapOrderFinished(OrderData orderData) {
        if (orderData.isFinished()) {
            this.mPayingRequests.remove(orderData);
        }
        if (orderData.isSuccess()) {
            C0187TMf.LIZ().LJ();
            orderData.getProductId();
            this.mUnSuccessEdProductIds.remove(orderData.getProductId());
            return;
        }
        AbsIapChannelOrderData absIapChannelOrderData = orderData.getAbsIapChannelOrderData();
        if (absIapChannelOrderData != null && absIapChannelOrderData.getOrderState() == 1 && !orderData.isConsumed() && !orderData.isQuerySucceed()) {
            this.mUnSuccessEdProductIds.add(orderData.getProductId());
        }
    }

    public TNO getNextState(TNO tno) {
        TNG LIZ = tno.LIZ();
        TOE toe = tno.LIZJ;
        switch (AnonymousClass9.LIZ[LIZ.ordinal()]) {
            case 1:
                OrderData orderData = tno.LIZ;
                TNT LIZJ = TN3.LIZLLL().LIZJ();
                IapPaymentMethod iapPaymentMethod = orderData.getIapPaymentMethod();
                getIapInternalService();
                TNO LIZ2 = LIZJ.LIZ(iapPaymentMethod, this, this.mActivity.get());
                LIZ2.LIZJ = toe;
                return LIZ2;
            case 2:
            case UGCMonitor.STATUS_RESPONSE /*3*/:
                getIapInternalService();
                TNJ tnj = new TNJ(this);
                tnj.LIZJ = toe;
                return tnj;
            case UGCMonitor.STATUS_FINISH /*4*/:
                getIapInternalService();
                TNF tnf = new TNF(this);
                tnf.LIZJ = toe;
                return tnf;
            case 5:
                getIapInternalService();
                ConsumeProductState consumeProductState = new ConsumeProductState(this);
                consumeProductState.LIZJ = toe;
                return consumeProductState;
            case 6:
                getIapInternalService();
                TND tnd = new TND(this);
                tnd.LIZJ = toe;
                return tnd;
            case 7:
                getIapInternalService();
                ExtraConsumeState extraConsumeState = new ExtraConsumeState(this);
                extraConsumeState.LIZJ = toe;
                return extraConsumeState;
            case 8:
                getIapInternalService();
                TNH tnh = new TNH(this);
                tnh.LIZJ = toe;
                return tnh;
            case 9:
                getIapInternalService();
                TNE tne = new TNE(this);
                tne.LIZJ = toe;
                return tne;
            case 10:
                getIapInternalService();
                PreregisterConsumeState preregisterConsumeState = new PreregisterConsumeState(this);
                preregisterConsumeState.LIZJ = toe;
                return preregisterConsumeState;
            default:
                return null;
        }
    }

    public void newPay(Activity activity, TNK tnk) {
        newPay(activity, tnk, (TOE) null);
    }

    public void onPurchasesUpdated(TN2 tn2, List<AbsIapChannelOrderData> list) {
        queryRewardsInternal(true, (TOE) null);
    }

    public void getChannelUserData(IapPaymentMethod iapPaymentMethod, TOE toe) {
        TN3.LIZLLL().LIZJ().LIZ(iapPaymentMethod, toe);
    }

    public void queryHasSubscriptionProducts(IapPaymentMethod iapPaymentMethod, TOE toe) {
        if (this.mInitEd.get()) {
            TN3.LIZLLL().LIZJ().LIZIZ(iapPaymentMethod, toe);
        }
    }

    public void executeUnUploadTokenOrder(final IapPaymentMethod iapPaymentMethod, final AbsIapChannelOrderData absIapChannelOrderData) {
        if (this.mInitEd.get()) {
            final String productId = absIapChannelOrderData.getProductId();
            for (Object obj : this.mPayingRequests.toArray()) {
                if (TextUtils.equals(((OrderData) obj).getProductId(), productId)) {
                    C0187TMf.LIZ().LJ();
                    return;
                }
            }
            C0187TMf.LIZ().LJ();
            absIapChannelOrderData.getChannelOrderId();
            ArrayList arrayList = new ArrayList();
            arrayList.add(productId);
            TN3.LIZLLL().LIZJ().LIZ(iapPaymentMethod, (List<String>) arrayList, absIapChannelOrderData.isSubscription(), (TOQ<AbsIapProduct>) new TOQ<AbsIapProduct>() {
                static {
                    Covode.recordClassIndex(27126);
                }

                public final void LIZ(AbsResult absResult, List<AbsIapProduct> list) {
                    C0187TMf.LIZ().LJ();
                    absIapChannelOrderData.getChannelOrderId();
                    if (absResult.getCode() != 0) {
                        IapServiceProvider iapServiceProvider = IapServiceProvider.this;
                        IapPaymentMethod iapPaymentMethod = iapPaymentMethod;
                        AbsIapChannelOrderData absIapChannelOrderData = absIapChannelOrderData;
                        iapServiceProvider.restoreOrderByUploadToken(iapPaymentMethod, absIapChannelOrderData, (AbsIapProduct) null, absIapChannelOrderData.isSubscription());
                        return;
                    }
                    for (AbsIapProduct next : list) {
                        if (next.getProductId().equals(productId)) {
                            IapServiceProvider iapServiceProvider2 = IapServiceProvider.this;
                            IapPaymentMethod iapPaymentMethod2 = iapPaymentMethod;
                            AbsIapChannelOrderData absIapChannelOrderData2 = absIapChannelOrderData;
                            iapServiceProvider2.restoreOrderByUploadToken(iapPaymentMethod2, absIapChannelOrderData2, next, absIapChannelOrderData2.isSubscription());
                        }
                    }
                }
            });
        }
    }

    public void acquireReward(TNK tnk, TOE toe) {
        if (this.mInitEd.get()) {
            final TNK tnk2 = tnk;
            final TOE toe2 = toe;
            if (tnk2 == null) {
                TN2 tn2 = new TN2(201, 2011, "pipoRequest is null when preregisterRewardsPay.");
                tn2.LIZIZ = tnk2;
                tn2.LIZJ = PayType.PRE;
                TOA.LJFF().LIZIZ().LIZ(tn2, (OrderInfo) null, toe2);
                TOA.LJFF().LIZ().LIZ(tn2, (OrderInfo) null);
                return;
            }
            final OrderData orderData = new OrderData(tnk2, PayType.PRE);
            orderData.setIapPaymentMethod(IapPaymentMethod.GOOGLE);
            String productId = orderData.getProductId();
            C0187TMf.LIZ().LJ();
            C0213TNf tNf = new C0213TNf(productId, orderData.getOrderId(), tnk2.LJI, PayType.PRE, orderData);
            orderData.setIapPayMonitor(tNf);
            tNf.LIZ();
            TN3.LIZLLL().LIZ().LIZIZ(orderData);
            if (this.mRewards.containsKey(productId)) {
                orderData.setAbsIapChannelOrderData(this.mRewards.get(productId));
                acquireRewardInternal(orderData, toe2);
                return;
            }
            final String str = productId;
            PaymentServiceManager.get().getGoogleIapExternalService().queryUnAckEdOrderFromChannel(new TNY() {
                static {
                    Covode.recordClassIndex(27125);
                }

                public final void onQueryFinished(IapPaymentMethod iapPaymentMethod, AbsResult absResult, List<AbsIapChannelOrderData> list) {
                    int code = absResult.getCode();
                    String str = BuildConfig.VERSION_NAME;
                    if (code != 0) {
                        int code2 = absResult.getCode();
                        TN2 tn2 = new TN2(203, code2, "query purchases success in preregisterRewardsPay, result message is: " + absResult.getMessage());
                        if (orderData.getIapPayRequest() != null) {
                            str = orderData.getIapPayRequest().LJIIJ;
                        }
                        tn2.LIZ = str;
                        tn2.LIZIZ = tnk2;
                        tn2.LIZJ = PayType.PRE;
                        C0187TMf.LIZ().LJ();
                        absResult.getMessage();
                        TOA.LJFF().LIZIZ().LIZ(tn2, orderData.buildOrderInfo(), toe2);
                        TOA.LJFF().LIZ().LIZ(tn2, orderData.buildOrderInfo());
                        return;
                    }
                    if (list != null) {
                        C0187TMf.LIZ().LJ();
                        list.size();
                        for (AbsIapChannelOrderData next : list) {
                            String channelOrderId = next.getChannelOrderId();
                            String developerPayload = next.getDeveloperPayload();
                            if (TextUtils.isEmpty(channelOrderId) && TextUtils.isEmpty(developerPayload)) {
                                IapServiceProvider.this.mRewards.put(next.getProductId(), next);
                            }
                        }
                    }
                    if (IapServiceProvider.this.mRewards.containsKey(str)) {
                        orderData.setAbsIapChannelOrderData(IapServiceProvider.this.mRewards.get(str));
                        IapServiceProvider.this.acquireRewardInternal(orderData, toe2);
                        return;
                    }
                    TN2 tn22 = new TN2(203, 2031, "doesn't has preregisterReward [" + str + "]");
                    if (orderData.getIapPayRequest() != null) {
                        str = orderData.getIapPayRequest().LJIIJ;
                    }
                    tn22.LIZ = str;
                    tn22.LIZIZ = tnk2;
                    tn22.LIZIZ = tnk2;
                    tn22.LIZJ = PayType.PRE;
                    C0187TMf.LIZ().LJ();
                    TOA.LJFF().LIZIZ().LIZ(tn22, orderData.buildOrderInfo(), toe2);
                    TOA.LJFF().LIZ().LIZ(tn22, orderData.buildOrderInfo());
                }
            });
        }
    }

    public void queryProductDetails(IapPaymentMethod iapPaymentMethod, List<String> list, String str) {
        queryProductDetails(iapPaymentMethod, list, str, (TOE) null);
    }

    public void querySubscriptionDetails(IapPaymentMethod iapPaymentMethod, List<String> list, String str) {
        querySubscriptionDetails(iapPaymentMethod, list, str, (TOE) null);
    }

    public void jumpToNotExpiredSubscriptionManagerPage(IapPaymentMethod iapPaymentMethod, String str, String str2) {
        TN3.LIZLLL().LIZJ().LIZ(iapPaymentMethod, str, str2);
    }

    public void updateHostAndOrderPlatform(String str, String str2, int i) {
        C0187TMf.LIZ().LJ();
        TOA.LJFF().LJ().LIZ(str, str2, i);
    }

    public static final /* synthetic */ void lambda$new$0$IapServiceProvider(IapPaymentMethod iapPaymentMethod, AbsResult absResult, List list) {
        if (absResult != null && absResult.getCode() == 0 && list != null) {
            C0244TOk tOk = new C0244TOk();
            try {
                JSONObject jSONObject = new JSONObject();
                tOk.add(jSONObject, "list", list.toString());
                tOk.add(jSONObject, "size", (long) list.size());
                C0187TMf.LIZ().LIZLLL().LIZ("pipo_on_resume", jSONObject, (JSONObject) null, (JSONObject) null);
            } catch (Throwable unused) {
            }
            for (Object obj : list.toArray()) {
                if (obj != null) {
                    AbsIapChannelOrderData absIapChannelOrderData = (AbsIapChannelOrderData) obj;
                    if (!TextUtils.isEmpty(absIapChannelOrderData.getSelfOrderId()) && absIapChannelOrderData.getOrderState() != 2) {
                        PaymentServiceManager.get().getIapExternalService().executeUnUploadTokenOrder(IapPaymentMethod.GOOGLE, absIapChannelOrderData);
                    }
                }
            }
        }
    }

    public void onQueryFinished(IapPaymentMethod iapPaymentMethod, AbsResult absResult, List<AbsIapChannelOrderData> list) {
        if (absResult != null && list != null) {
            if (absResult.getCode() != 0) {
                C0187TMf.LIZ().LJ();
                absResult.getMessage();
            } else if (list.isEmpty()) {
                C0187TMf.LIZ().LJ();
            } else {
                C0187TMf.LIZ().LJ();
                list.size();
                if (!C0187TMf.LIZ().LJII().LIZLLL()) {
                    for (AbsIapChannelOrderData next : list) {
                        C0187TMf.LIZ().LJ();
                        next.isSubscription();
                        next.isAcknowledged();
                        next.getOrderState();
                        if (next.isOrderStateSuccess()) {
                            String channelOrderId = next.getChannelOrderId();
                            String developerPayload = next.getDeveloperPayload();
                            if (!TextUtils.isEmpty(channelOrderId) || !TextUtils.isEmpty(developerPayload)) {
                                executeUnUploadTokenOrder(iapPaymentMethod, next);
                            }
                        }
                    }
                }
            }
        }
    }

    public void newPay(Activity activity, TNK tnk, TOE toe) {
        if (this.mInitEd.get()) {
            this.mActivity = new WeakReference<>(activity);
            final TOE toe2 = toe;
            if (tnk == null) {
                TN2 tn2 = new TN2(201, 2011, "PipoPayManger.executeNewPay:pipoRequest is null.");
                tn2.LIZIZ = tnk;
                tn2.LIZJ = PayType.NOMAL;
                TOA.LJFF().LIZIZ().LIZ(tn2, (OrderInfo) null, toe2);
                TOA.LJFF().LIZ().LIZ(tn2, (OrderInfo) null);
                return;
            }
            final OrderData orderData = new OrderData(tnk, PayType.NOMAL);
            C0213TNf tNf = new C0213TNf(orderData.getProductId(), orderData.getOrderId(), tnk.LJI, PayType.NOMAL, orderData);
            orderData.setIapPayMonitor(tNf);
            tNf.LIZ();
            TN3.LIZLLL().LIZ().LIZIZ(orderData);
            final IapPaymentMethod iapPaymentMethod = orderData.getIapPaymentMethod();
            if (this.mUnSuccessEdProductIds.contains(orderData.getProductId())) {
                final C0213TNf tNf2 = tNf;
                TN3.LIZLLL().LIZJ().LIZ(iapPaymentMethod, (TNY) new TNY() {
                    static {
                        Covode.recordClassIndex(27122);
                    }

                    public final void onQueryFinished(IapPaymentMethod iapPaymentMethod, AbsResult absResult, List<AbsIapChannelOrderData> list) {
                        if (absResult != null && list != null && absResult.getCode() == 0 && !list.isEmpty()) {
                            for (Object obj : list.toArray()) {
                                AbsIapChannelOrderData absIapChannelOrderData = (AbsIapChannelOrderData) obj;
                                if (TextUtils.equals(absIapChannelOrderData.getProductId(), orderData.getProductId())) {
                                    OrderData orderData = orderData;
                                    C0213TNf tNf = tNf2;
                                    C0187TMf.LIZ().LJ();
                                    OrderInfo buildOrderInfo = orderData.buildOrderInfo();
                                    TN2 tn2 = new TN2();
                                    tn2.LIZ = buildOrderInfo.getExtraPayload();
                                    tn2.LIZJ = PayType.NOMAL;
                                    tn2.withErrorCode(208);
                                    tn2.withMessage("PipoPayManger: executeNewPay failed because cur productId is unfinished :" + orderData.getProductId() + ", then call back unFinish error");
                                    tNf.LIZ(tn2, (TNG) null);
                                    TN3.LIZLLL().LIZ().LIZ(orderData, tn2);
                                    TOA.LJFF().LIZIZ().LIZ(tn2, buildOrderInfo, toe2);
                                    TOA.LJFF().LIZ().LIZ(tn2, buildOrderInfo);
                                    IapServiceProvider.this.executeUnUploadTokenOrder(iapPaymentMethod, absIapChannelOrderData);
                                    return;
                                }
                            }
                        }
                        IapServiceProvider.this.executeNewPayInternal(orderData, toe2);
                    }
                });
            } else {
                executeNewPayInternal(orderData, toe2);
            }
            tryRestoreUnAckOrder(iapPaymentMethod);
        }
    }

    public void queryProductDetails(final IapPaymentMethod iapPaymentMethod, List<String> list, final String str, final TOE toe) {
        if (this.mInitEd.get()) {
            TN3.LIZLLL().LIZJ().LIZ(iapPaymentMethod, list, false, (TOQ<AbsIapProduct>) new TOQ<AbsIapProduct>() {
                static {
                    Covode.recordClassIndex(27123);
                }

                public final void LIZ(AbsResult absResult, List<AbsIapProduct> list) {
                    if (absResult.getCode() == 0) {
                        TN2 tn2 = new TN2(0, 0, "query success in queryProductDetails.");
                        tn2.LIZ = str;
                        TOA.LJFF().LIZIZ().LIZ(iapPaymentMethod, tn2, list, toe);
                        TOA.LJFF().LIZ().LIZ(iapPaymentMethod, tn2, list);
                        return;
                    }
                    C0187TMf.LIZ().LJ();
                    int code = absResult.getCode();
                    TN2 tn22 = new TN2(301, code, "query product list details from chanel service has error, result: " + absResult.getMessage());
                    tn22.LIZ = str;
                    TOA.LJFF().LIZIZ().LIZ(iapPaymentMethod, tn22, list, toe);
                    TOA.LJFF().LIZ().LIZ(iapPaymentMethod, tn22, list);
                }
            });
        }
    }

    public void querySubscriptionDetails(IapPaymentMethod iapPaymentMethod, List<String> list, final String str, final TOE toe) {
        if (this.mInitEd.get()) {
            PaymentServiceManager.get().getGoogleIapExternalService().queryProductDetails(list, true, new TOQ<AbsIapProduct>() {
                static {
                    Covode.recordClassIndex(27124);
                }

                public final void LIZ(AbsResult absResult, List<AbsIapProduct> list) {
                    if (absResult.getCode() == 0) {
                        TN2 tn2 = new TN2(0, 0, "query success in querySubscriptionDetails.");
                        tn2.LIZ = str;
                        TOA.LJFF().LIZIZ().LIZ(tn2, list, toe);
                        TOA.LJFF().LIZ().LIZ(tn2, list);
                        return;
                    }
                    C0187TMf.LIZ().LJ();
                    int code = absResult.getCode();
                    TN2 tn22 = new TN2(301, code, "query product list details from google service has error, result: " + absResult.getMessage());
                    tn22.LIZ = str;
                    TOA.LJFF().LIZIZ().LIZ(tn22, list, toe);
                    TOA.LJFF().LIZ().LIZ(tn22, list);
                }
            });
        }
    }
}
