导航菜单

页面标题

页面副标题

Mint v5.7.3 - RazorPayCheckout.java 源代码

正在查看: Mint v5.7.3 应用的 RazorPayCheckout.java JAVA 源代码文件

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


package com.htmedia.mint.razorpay.utils;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.htmedia.mint.AppController;
import com.htmedia.mint.htsubscription.CheckSubscriptionFromLocal;
import com.htmedia.mint.htsubscription.GetUserSubscriptionDetail;
import com.htmedia.mint.htsubscription.MSError;
import com.htmedia.mint.htsubscription.ParseSubscriptionDetail;
import com.htmedia.mint.htsubscription.SubscriptionConverter;
import com.htmedia.mint.htsubscription.SubscriptionPlanSingleton;
import com.htmedia.mint.htsubscription.WebEngageAnalytices;
import com.htmedia.mint.piano.PianoResponse;
import com.htmedia.mint.pojo.Content;
import com.htmedia.mint.pojo.config.Config;
import com.htmedia.mint.pojo.config.Razorpay;
import com.htmedia.mint.pojo.razorpay.CreateOrder;
import com.htmedia.mint.pojo.razorpay.Hostedpage;
import com.htmedia.mint.pojo.subscription.plandetail.htapi.MintPlanWithZSPlan;
import com.htmedia.mint.pojo.subscription.plandetail.htapi.SubsPlans;
import com.htmedia.mint.pojo.subscription.userdetail.MintSubscriptionDetail;
import com.htmedia.mint.razorpay.JWTTokenBuilder;
import com.htmedia.mint.razorpay.presenter.OrderCreatePresenter;
import com.htmedia.mint.razorpay.presenter.OrderCreatePresenterInterface;
import com.htmedia.mint.razorpay.presenter.OrderCreateViewInterface;
import com.htmedia.mint.razorpay.presenter.PaymentValidationPresenter;
import com.htmedia.mint.razorpay.presenter.PaymentValidationPresenterInterface;
import com.htmedia.mint.razorpay.presenter.PaymentValidationViewInterface;
import com.htmedia.mint.utils.f0;
import com.htmedia.mint.utils.n;
import com.htmedia.mint.utils.o1;
import com.htmedia.mint.utils.q;
import com.razorpay.Checkout;
import com.razorpay.PaymentData;
import com.snowplowanalytics.snowplow.tracker.constants.Parameters;
import com.taboola.android.global_components.eventsmanager.TBLEventType;
import com.thoughtbot.expandablerecyclerview.BuildConfig;
import com.zoho.zsm.inapppurchase.model.ZSPlan;
import f5.a;
import f6.d;
import in.juspay.hyper.constants.LogCategory;
import in.juspay.hypersdk.core.PaymentConstants;
import java.util.HashMap;
import n4.b;
import n4.e;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class RazorPayCheckout implements OrderCreateViewInterface, PaymentValidationViewInterface {
    private final AppCompatActivity appCompatActivity;
    private int autoRecurringMandateDiscount;
    private Content content;
    private String funnelName;
    private boolean isAutoRecurring;
    private boolean isPaymentForMandates;
    private String lastAccessUrl;
    private MintPlanWithZSPlan mintPlanWithZSPlan;
    private MintSubscriptionDetail mintSubscriptionDetail;
    private OrderCreatePresenterInterface orderCreatePresenterInterface;
    private String orderId;
    private ProgressDialog pDialog;
    private String paymentOption;
    private PaymentValidationPresenterInterface paymentValidationPresenterInterface;
    private q.v payment_type;
    private String pianoExp;
    private String premiumStory;
    private SubsPlans subsPlans;
    private q.g0 subsscreen;

    static class AnonymousClass2 {
        static final int[] $SwitchMap$com$htmedia$mint$utils$AppConstants$PAYMENT_TYPE;

        static {
            int[] iArr = new int[q.v.values().length];
            $SwitchMap$com$htmedia$mint$utils$AppConstants$PAYMENT_TYPE = iArr;
            try {
                iArr[q.v.UPI.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$com$htmedia$mint$utils$AppConstants$PAYMENT_TYPE[q.v.NETBANKING.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                $SwitchMap$com$htmedia$mint$utils$AppConstants$PAYMENT_TYPE[q.v.WALLET.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
        }
    }

    public RazorPayCheckout(AppCompatActivity appCompatActivity) {
        this.lastAccessUrl = "https://www.livemint.com";
        this.autoRecurringMandateDiscount = 0;
        this.funnelName = BuildConfig.FLAVOR;
        this.pianoExp = BuildConfig.FLAVOR;
        this.appCompatActivity = appCompatActivity;
        initVariables();
    }

    public RazorPayCheckout(AppCompatActivity appCompatActivity, q.v vVar, boolean z) {
        this.lastAccessUrl = "https://www.livemint.com";
        this.autoRecurringMandateDiscount = 0;
        this.funnelName = BuildConfig.FLAVOR;
        this.pianoExp = BuildConfig.FLAVOR;
        this.appCompatActivity = appCompatActivity;
        this.payment_type = vVar;
        this.isAutoRecurring = z;
        initVariables();
    }

    public RazorPayCheckout(boolean z, AppCompatActivity appCompatActivity, q.v vVar, int i) {
        this.lastAccessUrl = "https://www.livemint.com";
        this.funnelName = BuildConfig.FLAVOR;
        this.pianoExp = BuildConfig.FLAVOR;
        this.appCompatActivity = appCompatActivity;
        this.isPaymentForMandates = z;
        this.payment_type = vVar;
        this.autoRecurringMandateDiscount = i;
        if (!z) {
            initVariables();
        } else {
            SubscriptionPlanSingleton.getInstance().setMintSubscriptionDetail(AppController.j().l());
            initVariablesForMandates();
        }
    }

    private void createOrderForMandates() {
        try {
            JSONObject jSONObject = new JSONObject();
            JSONObject jSONObject2 = new JSONObject();
            String mobile = this.mintSubscriptionDetail.getMobile();
            boolean isEmpty = TextUtils.isEmpty(mobile);
            String str = BuildConfig.FLAVOR;
            if (!isEmpty && mobile.contains("+")) {
                mobile = mobile.replace("+", BuildConfig.FLAVOR).trim();
            }
            jSONObject2.put(TBLEventType.DEFAULT, mobile);
            jSONObject2.put("displayName", this.mintSubscriptionDetail.getDisplayName());
            jSONObject2.put("salutation", this.mintSubscriptionDetail.getSalutation());
            jSONObject2.put("firstName", this.mintSubscriptionDetail.getFirstName());
            jSONObject2.put("lastName", this.mintSubscriptionDetail.getLastName());
            jSONObject2.put("email", this.mintSubscriptionDetail.getEmail());
            jSONObject2.put("id", this.mintSubscriptionDetail.getId());
            jSONObject2.put("lastAccessUrl", this.lastAccessUrl);
            jSONObject2.put("customerId", this.mintSubscriptionDetail.getZohoCustomerId());
            jSONObject.put("platform", "Android");
            jSONObject.put("sourcePlatform", "ANDROID_RAZORPAY");
            jSONObject.put("redirectionUrl", "https://www.livemint.com");
            jSONObject.put("countryCode", "IN");
            jSONObject.put("city", "others");
            jSONObject.put("customer", jSONObject2);
            jSONObject.put("subscriptionId", this.mintSubscriptionDetail.getSubscriptionID());
            jSONObject.put("recurring", "1");
            jSONObject.put("isNonRecurringSubscriptionMandate", true);
            JSONArray jSONArray = new JSONArray();
            JSONObject jSONObject3 = new JSONObject();
            jSONObject3.put("gatewayName", "razorpay");
            jSONObject3.put("paymentGateway", "razorpay");
            jSONArray.put(jSONObject3);
            jSONObject.put("paymentGateways", jSONArray);
            jSONObject.put("paymentSource", "Razorpay");
            jSONObject.put("paymentMethod", "card");
            String string = this.appCompatActivity.getResources().getString(2131952728);
            jSONObject.put("productId", string);
            OrderCreatePresenter orderCreatePresenter = new OrderCreatePresenter(this.appCompatActivity, new OrderCreateViewInterface() {
                @Override
                public void onCreateOrder(CreateOrder createOrder) {
                    RazorPayCheckout.this.onCreateOrderForMandate(createOrder);
                }

                @Override
                public void onError(int i, String str2) {
                    RazorPayCheckout.this.dismissProgressDialog();
                    Toast.makeText((Context) RazorPayCheckout.this.appCompatActivity, (CharSequence) str2, 0).show();
                }

                @Override
                public void onError(String str2) {
                    RazorPayCheckout.this.dismissProgressDialog();
                    Toast.makeText((Context) RazorPayCheckout.this.appCompatActivity, (CharSequence) str2, 0).show();
                }
            });
            String generateToken = JWTTokenBuilder.generateToken(this.mintSubscriptionDetail.getId() + "~" + this.mintSubscriptionDetail.getEmail());
            HashMap<String, String> hashMap = new HashMap<>();
            hashMap.put("ProductId", string);
            hashMap.put("SubscriptionAuth", generateToken);
            Config g = AppController.j().g();
            Razorpay razorpay = g != null ? g.getRazorpay() : null;
            String domain = razorpay != null ? razorpay.getDomain() : BuildConfig.FLAVOR;
            if (razorpay != null) {
                str = razorpay.getUpdateNonRecurringSubscriptionUrl();
            }
            if (!str.startsWith("http")) {
                str = domain + str;
            }
            orderCreatePresenter.createOrder(1, "OrderMandateApi", str, jSONObject, hashMap, false, false);
            o1.a("[orderRequest]", jSONObject.toString());
        } catch (JSONException | Exception unused) {
        }
    }

    private void createOrderRequest() {
        String str;
        SubsPlans subsPlans = this.subsPlans;
        if (subsPlans == null || TextUtils.isEmpty(subsPlans.getPlanCode()) || this.mintSubscriptionDetail == null) {
            return;
        }
        try {
            JSONObject jSONObject = new JSONObject();
            JSONObject jSONObject2 = new JSONObject();
            String mobile = this.mintSubscriptionDetail.getMobile();
            boolean isEmpty = TextUtils.isEmpty(mobile);
            String str2 = BuildConfig.FLAVOR;
            if (!isEmpty && mobile.contains("+")) {
                mobile = mobile.replace("+", BuildConfig.FLAVOR).trim();
            }
            jSONObject2.put(TBLEventType.DEFAULT, mobile);
            jSONObject2.put("displayName", this.mintSubscriptionDetail.getDisplayName());
            jSONObject2.put("salutation", this.mintSubscriptionDetail.getSalutation());
            jSONObject2.put("firstName", this.mintSubscriptionDetail.getFirstName());
            jSONObject2.put("lastName", this.mintSubscriptionDetail.getLastName());
            jSONObject2.put("email", this.mintSubscriptionDetail.getEmail());
            jSONObject2.put("id", this.mintSubscriptionDetail.getId());
            jSONObject2.put("lastAccessUrl", this.lastAccessUrl);
            if (this.subsscreen == q.g0.DEVICE_ID_OFFER) {
                JSONObject jSONObject3 = new JSONObject();
                jSONObject3.put("platform", "Android");
                jSONObject3.put("device_id", d.b(this.appCompatActivity));
                jSONObject3.put("device_type", "Android");
                jSONObject2.put("device_details", jSONObject3);
                jSONObject.put("creationMode", "campaign");
            }
            jSONObject.put("customer", jSONObject2);
            if (SubscriptionConverter.isSubscriptionUpgradeOrRenewal(this.subsscreen)) {
                jSONObject.put("subscriptionId", this.mintSubscriptionDetail.getSubscriptionID());
            }
            jSONObject.put("planCode", this.subsPlans.getPlanCode());
            if (this.mintPlanWithZSPlan.isCouponApplied()) {
                jSONObject.put("couponCode", this.mintPlanWithZSPlan.getCouponCode());
            }
            jSONObject.put(LogCategory.ACTION, getAction());
            if (this.isAutoRecurring && this.payment_type == q.v.UPI) {
                jSONObject.put("paymentMethod", PaymentConstants.WIDGET_UPI);
            }
            jSONObject.put("recurring", this.isAutoRecurring ? 1 : 0);
            jSONObject.put("countryCode", "IN");
            jSONObject.put("city", "others");
            jSONObject.put("platform", "Android");
            jSONObject.put("sourcePlatform", "ANDROID_RAZORPAY");
            jSONObject.put("paymentSource", "Razorpay");
            jSONObject.put("redirectionUrl", "https://www.livemint.com");
            String generateToken = JWTTokenBuilder.generateToken(this.mintSubscriptionDetail.getId() + "~" + this.mintSubscriptionDetail.getEmail());
            HashMap<String, String> hashMap = new HashMap<>();
            hashMap.put("ProductId", this.appCompatActivity.getResources().getString(2131952728));
            hashMap.put("SubscriptionAuth", generateToken);
            Config g = AppController.j().g();
            Razorpay razorpay = g != null ? g.getRazorpay() : null;
            String domain = razorpay != null ? razorpay.getDomain() : BuildConfig.FLAVOR;
            String orderid = razorpay != null ? razorpay.getOrderid() : BuildConfig.FLAVOR;
            if (SubscriptionConverter.isSubscriptionUpgradeOrRenewal(this.subsscreen)) {
                if (razorpay != null) {
                    str2 = razorpay.getChangeplan();
                }
                orderid = str2;
            }
            if (orderid.startsWith("http")) {
                str = orderid;
            } else {
                str = domain + orderid;
            }
            if (SubscriptionConverter.isSubscriptionNew(this.subsscreen)) {
                this.orderCreatePresenterInterface.createOrder(1, "OrderApi", str, jSONObject, hashMap, false, false);
            } else if (SubscriptionConverter.isSubscriptionUpgradeOrRenewal(this.subsscreen)) {
                this.orderCreatePresenterInterface.createOrder(4, "ChangePlan", str, jSONObject, hashMap, false, false);
            }
        } catch (JSONException e) {
            o1.b("TAG", "createOrderRequest: " + e, e);
        }
    }

    private String getAction() {
        MintPlanWithZSPlan mintPlanWithZSPlan;
        q.g0 g0Var = this.subsscreen;
        if (g0Var == q.g0.DEVICE_ID_OFFER || g0Var == q.g0.PARTNER_COUPON_PAGE) {
            return "trial";
        }
        if (g0Var == q.g0.NEW_PLAN_PAGE && (mintPlanWithZSPlan = this.mintPlanWithZSPlan) != null && mintPlanWithZSPlan.isTrialCoupon() && this.mintPlanWithZSPlan.isCouponApplied()) {
            return TextUtils.isEmpty(this.mintPlanWithZSPlan.getDiscountType()) ? "trial" : this.mintPlanWithZSPlan.getDiscountType();
        }
        q.g0 g0Var2 = this.subsscreen;
        if (g0Var2 == q.g0.MANAGE_PLAN_PAGE) {
            return "change";
        }
        if (g0Var2 != q.g0.ADVANCE_RENEWAL) {
            return "subscribe";
        }
        MintSubscriptionDetail mintSubscriptionDetail = this.mintSubscriptionDetail;
        return (mintSubscriptionDetail == null || !mintSubscriptionDetail.isSubscriptionActive()) ? "post_expiry" : "advance_renew";
    }

    private void getPlanInfo() {
        MintPlanWithZSPlan mintPlanWithZSPlan = SubscriptionPlanSingleton.getInstance().getMintPlanWithZSPlan();
        this.mintPlanWithZSPlan = mintPlanWithZSPlan;
        this.subsPlans = mintPlanWithZSPlan.getSubsPlans();
    }

    private String getUserSubscriptionStatus() {
        q.g0 g0Var = this.subsscreen;
        return (g0Var == q.g0.NEW_PLAN_PAGE || g0Var == q.g0.PARTNER_PAGE || g0Var == q.g0.DEVICE_ID_OFFER || g0Var == q.g0.PARTNER_COUPON_PAGE) ? "new" : g0Var == q.g0.MANAGE_PLAN_PAGE ? "upgraded" : g0Var == q.g0.ADVANCE_RENEWAL ? "advance_renew" : BuildConfig.FLAVOR;
    }

    private HashMap<String, String> getValueFromErrorMessage(HashMap<String, String> hashMap, JSONObject jSONObject, String str) {
        hashMap.put("code", jSONObject.optString("code"));
        hashMap.put(Parameters.CD_DESCRIPTION, jSONObject.optString(Parameters.CD_DESCRIPTION));
        hashMap.put("source", jSONObject.optString("source"));
        hashMap.put("step", jSONObject.optString("step"));
        hashMap.put("reason", jSONObject.optString("reason"));
        JSONObject optJSONObject = jSONObject.optJSONObject("metadata");
        hashMap.put("razorpay_payment_id", optJSONObject != null ? optJSONObject.optString("payment_id") : BuildConfig.FLAVOR);
        String optString = optJSONObject != null ? optJSONObject.optString(PaymentConstants.ORDER_ID) : str;
        if (!TextUtils.isEmpty(str)) {
            str = optString;
        }
        hashMap.put("razorpay_order_id", str);
        return hashMap;
    }

    private void initAnalyticsVariables() {
        this.lastAccessUrl = TextUtils.isEmpty(SubscriptionPlanSingleton.getInstance().getLastAccessUrl()) ? this.lastAccessUrl : SubscriptionPlanSingleton.getInstance().getLastAccessUrl();
        this.funnelName = SubscriptionPlanSingleton.getInstance().getFunnelName();
        this.premiumStory = SubscriptionPlanSingleton.getInstance().getPremiumStory();
        this.subsscreen = SubscriptionPlanSingleton.getInstance().getSubsscreen();
        this.pianoExp = SubscriptionPlanSingleton.getInstance().getPianoExpName();
        initPaymentOptions();
    }

    private void initPaymentOptions() {
        q.v vVar = this.payment_type;
        this.paymentOption = vVar != null ? vVar.name() : BuildConfig.FLAVOR;
    }

    private void initProgressDialogAndShow() {
        ProgressDialog progressDialog = this.pDialog;
        if (progressDialog != null && !progressDialog.isShowing()) {
            this.pDialog.show();
            return;
        }
        if (this.pDialog == null) {
            ProgressDialog progressDialog2 = new ProgressDialog(this.appCompatActivity);
            this.pDialog = progressDialog2;
            progressDialog2.setMessage("Please wait...!");
            this.pDialog.setCancelable(false);
            if (this.pDialog.isShowing()) {
                return;
            }
            this.pDialog.show();
        }
    }

    private void initVariables() {
        this.orderCreatePresenterInterface = new OrderCreatePresenter(this.appCompatActivity, this);
        this.paymentValidationPresenterInterface = new PaymentValidationPresenter(this.appCompatActivity, this);
        initAnalyticsVariables();
        setUserInfo();
        getPlanInfo();
        createOrderRequest();
        initProgressDialogAndShow();
    }

    private void initVariablesForMandates() {
        this.paymentValidationPresenterInterface = new PaymentValidationPresenter(this.appCompatActivity, this);
        initPaymentOptions();
        setUserInfo();
        createOrderForMandates();
        initProgressDialogAndShow();
    }

    public void onCreateOrderForMandate(com.htmedia.mint.pojo.razorpay.CreateOrder r12) {
        throw new UnsupportedOperationException("Method not decompiled: com.htmedia.mint.razorpay.utils.RazorPayCheckout.onCreateOrderForMandate(com.htmedia.mint.pojo.razorpay.CreateOrder):void");
    }

    private JSONObject parseErrorJson(String str, String str2, JSONObject jSONObject) {
        HashMap<String, String> valueFromErrorMessage;
        HashMap<String, String> hashMap = new HashMap<>();
        if (!str.contains("=")) {
            if (!TextUtils.isEmpty(str)) {
                try {
                    JSONObject jSONObject2 = new JSONObject(str);
                    JSONObject optJSONObject = jSONObject2.optJSONObject("error");
                    valueFromErrorMessage = optJSONObject == null ? getValueFromErrorMessage(hashMap, jSONObject2, str2) : getValueFromErrorMessage(hashMap, optJSONObject, str2);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            return setErrorValueOnJsonObject(hashMap, jSONObject);
        }
        String[] split = str.split("=");
        if (split != null && split.length > 1) {
            String str3 = split[1];
            if (!TextUtils.isEmpty(str3)) {
                try {
                    JSONObject jSONObject3 = new JSONObject(str3);
                    JSONObject optJSONObject2 = jSONObject3.optJSONObject("error");
                    valueFromErrorMessage = optJSONObject2 == null ? getValueFromErrorMessage(hashMap, jSONObject3, str2) : getValueFromErrorMessage(hashMap, optJSONObject2, str2);
                } catch (JSONException e2) {
                    e2.printStackTrace();
                }
            }
        }
        return setErrorValueOnJsonObject(hashMap, jSONObject);
        hashMap = valueFromErrorMessage;
        return setErrorValueOnJsonObject(hashMap, jSONObject);
    }

    private JSONObject setErrorValueOnJsonObject(HashMap<String, String> hashMap, JSONObject jSONObject) {
        for (String str : hashMap.keySet()) {
            try {
                jSONObject.put(str, hashMap.get(str));
            } catch (JSONException unused) {
            }
        }
        return jSONObject;
    }

    private void setUserInfo() {
        MintSubscriptionDetail mintSubscriptionDetail = SubscriptionPlanSingleton.getInstance().getMintSubscriptionDetail();
        this.mintSubscriptionDetail = mintSubscriptionDetail;
        if (mintSubscriptionDetail == null) {
            this.mintSubscriptionDetail = new MintSubscriptionDetail();
        }
        this.mintSubscriptionDetail.setId(f0.G1(this.appCompatActivity, "userClient"));
        String G1 = f0.G1(this.appCompatActivity, "userName");
        this.mintSubscriptionDetail.setEmail(f0.F1(this.appCompatActivity));
        this.mintSubscriptionDetail.setSalutation(BuildConfig.FLAVOR);
        if (TextUtils.isEmpty(G1)) {
            this.mintSubscriptionDetail.setDisplayName(BuildConfig.FLAVOR);
            this.mintSubscriptionDetail.setFirstName(BuildConfig.FLAVOR);
            this.mintSubscriptionDetail.setLastName(BuildConfig.FLAVOR);
        } else {
            this.mintSubscriptionDetail.setDisplayName(G1);
            if (G1.contains(" ")) {
                String substring = G1.substring(G1.lastIndexOf(" "));
                if (!TextUtils.isEmpty(substring)) {
                    substring = substring.trim();
                }
                this.mintSubscriptionDetail.setFirstName(G1.substring(0, G1.lastIndexOf(" ")));
                this.mintSubscriptionDetail.setLastName(substring);
            } else {
                this.mintSubscriptionDetail.setFirstName(G1);
                this.mintSubscriptionDetail.setLastName(G1);
            }
        }
        String G12 = f0.G1(this.appCompatActivity, "userPhoneNumber");
        if (!TextUtils.isEmpty(G12) && !G12.contains("+")) {
            G12 = "+" + G12;
        }
        if (TextUtils.isEmpty(G12)) {
            this.mintSubscriptionDetail.setMobile(BuildConfig.FLAVOR);
        } else {
            this.mintSubscriptionDetail.setMobile(G12);
        }
    }

    private void syncPaymentWithServer(MintSubscriptionDetail mintSubscriptionDetail, boolean z) {
        dismissProgressDialog();
        MintPlanWithZSPlan mintPlanWithZSPlan = this.mintPlanWithZSPlan;
        if (mintPlanWithZSPlan != null) {
            mintPlanWithZSPlan.setOrderId(this.orderId);
        }
        Content content = this.funnelName.equalsIgnoreCase("Paywall") ? SubscriptionPlanSingleton.getInstance().getContent() : null;
        a.e(this.appCompatActivity, "payment_success", a.d, a.f, content, (String) null);
        q.g0 g0Var = this.subsscreen;
        if (g0Var != null && g0Var == q.g0.ADVANCE_RENEWAL) {
            if (this.content == null) {
                this.content = SubscriptionPlanSingleton.getInstance().getContent();
            }
            e.h("payment_success", this.content, this.funnelName, mintSubscriptionDetail, this.mintPlanWithZSPlan);
        } else if (g0Var != null && g0Var == q.g0.NEW_PLAN_PAGE) {
            MintPlanWithZSPlan mintPlanWithZSPlan2 = this.mintPlanWithZSPlan;
            String str = this.funnelName;
            String str2 = this.premiumStory;
            String store = (z ? WebEngageAnalytices.PAYMENTSTORE.RAZOR_PAY : WebEngageAnalytices.PAYMENTSTORE.PLAY_STORE).getStore();
            q.v vVar = this.payment_type;
            WebEngageAnalytices.trackPaymentStatus("Payment Success", mintSubscriptionDetail, mintPlanWithZSPlan2, (MSError) null, str, str2, store, vVar != null ? vVar.name() : BuildConfig.FLAVOR, this.isAutoRecurring);
            n.A(this.appCompatActivity, n.h1, "plan_page", n.t0, content, null);
        }
        GetUserSubscriptionDetail.SyncSubscriptionAsyncTask syncSubscriptionAsyncTask = new GetUserSubscriptionDetail.SyncSubscriptionAsyncTask(this.appCompatActivity);
        if (!TextUtils.isEmpty(this.premiumStory)) {
            syncSubscriptionAsyncTask.setPremiumStory(this.premiumStory);
        }
        if (!TextUtils.isEmpty(this.funnelName)) {
            syncSubscriptionAsyncTask.setFunnelEntry(this.funnelName);
        }
        syncSubscriptionAsyncTask.setZsPlan((ZSPlan) null);
        syncSubscriptionAsyncTask.setPianoExp(this.pianoExp);
        q.g0 g0Var2 = this.subsscreen;
        if (g0Var2 == q.g0.NEW_PLAN_PAGE || g0Var2 == q.g0.PARTNER_PAGE || g0Var2 == q.g0.DEVICE_ID_OFFER || g0Var2 == q.g0.PARTNER_COUPON_PAGE) {
            syncSubscriptionAsyncTask.setUserSubscriptionStatus("new");
        } else if (g0Var2 == q.g0.MANAGE_PLAN_PAGE) {
            syncSubscriptionAsyncTask.setUserSubscriptionStatus("upgraded");
        } else if (g0Var2 == q.g0.ADVANCE_RENEWAL) {
            syncSubscriptionAsyncTask.setUserSubscriptionStatus("advance_renew");
        }
        syncSubscriptionAsyncTask.setSubsscreen(this.subsscreen);
        if (z) {
            syncSubscriptionAsyncTask.setOrderId(this.orderId);
        }
        syncSubscriptionAsyncTask.setMintPlanWithZSPlan(this.mintPlanWithZSPlan);
        syncSubscriptionAsyncTask.setPaymentFromRzorPay(z);
        syncSubscriptionAsyncTask.execute(mintSubscriptionDetail);
    }

    private void syncSubscriptionSuccess(MintSubscriptionDetail mintSubscriptionDetail) {
        q.g0 g0Var;
        MintPlanWithZSPlan mintPlanWithZSPlan = this.mintPlanWithZSPlan;
        if (mintPlanWithZSPlan != null && mintPlanWithZSPlan.getSubsPlans() != null && ((g0Var = this.subsscreen) == q.g0.NEW_PLAN_PAGE || g0Var == q.g0.ADVANCE_RENEWAL || g0Var == q.g0.PARTNER_PAGE || g0Var == q.g0.DEVICE_ID_OFFER || g0Var == q.g0.PARTNER_COUPON_PAGE)) {
            CheckSubscriptionFromLocal.updateAdFreeUserFromPlan(mintSubscriptionDetail, this.mintPlanWithZSPlan.getSubsPlans(), this.appCompatActivity);
        }
        syncPaymentWithServer(mintSubscriptionDetail, true);
    }

    private void verifyPayment(boolean z, String str, PaymentData paymentData) {
        String str2;
        initProgressDialogAndShow();
        try {
            JSONObject jSONObject = new JSONObject();
            JSONObject jSONObject2 = new JSONObject();
            jSONObject2.put("email", this.mintSubscriptionDetail.getEmail());
            jSONObject2.put("id", this.mintSubscriptionDetail.getId());
            jSONObject.put("customer", jSONObject2);
            JSONObject jSONObject3 = new JSONObject();
            if (z) {
                jSONObject3.put("status", "payment_captured");
                if (paymentData != null) {
                    jSONObject3.put("razorpay_payment_id", paymentData.getPaymentId());
                    jSONObject3.put("razorpay_order_id", paymentData.getOrderId());
                    jSONObject3.put(PaymentConstants.SIGNATURE, paymentData.getSignature());
                }
            } else {
                jSONObject3.put("status", "payment_failed");
                jSONObject3 = parseErrorJson(str, this.orderId, jSONObject3);
                if (TextUtils.isEmpty(jSONObject3.optString("razorpay_payment_id"))) {
                    Toast.makeText((Context) this.appCompatActivity, (CharSequence) "Payment cancelled", 0).show();
                    dismissProgressDialog();
                    return;
                }
            }
            JSONObject jSONObject4 = new JSONObject();
            jSONObject4.put("platform", "Android");
            String s = AppController.j().s();
            if (TextUtils.isEmpty(s)) {
                s = "_ABTestGroup_COOKIE_NOT_FOUND";
            }
            jSONObject4.put("vendor", s);
            jSONObject4.put("paywallReason", this.premiumStory);
            jSONObject4.put("userSubscriptionStatus", getUserSubscriptionStatus());
            jSONObject4.put("userLoggedInStatus", WebEngageAnalytices.getUserState());
            jSONObject4.put("funnelEntry", this.funnelName);
            jSONObject4.put("experiment1", this.pianoExp);
            boolean isEmpty = TextUtils.isEmpty(WebEngageAnalytices.VALUE_CAMPAIGN_NAME);
            String str3 = BuildConfig.FLAVOR;
            if (isEmpty) {
                jSONObject4.put("campaignName", BuildConfig.FLAVOR);
            } else {
                jSONObject4.put("campaignName", WebEngageAnalytices.VALUE_CAMPAIGN_NAME);
            }
            if (TextUtils.isEmpty(WebEngageAnalytices.VALUE_CAMPAIGN_SOURCE)) {
                jSONObject4.put("campaignSource", BuildConfig.FLAVOR);
            } else {
                jSONObject4.put("campaignSource", WebEngageAnalytices.VALUE_CAMPAIGN_SOURCE);
            }
            if (TextUtils.isEmpty(WebEngageAnalytices.VALUE_CAMPAIGN_MEDIUM)) {
                jSONObject4.put("campaignMedium", BuildConfig.FLAVOR);
            } else {
                jSONObject4.put("campaignMedium", WebEngageAnalytices.VALUE_CAMPAIGN_MEDIUM);
            }
            String ltsPiano = PianoResponse.getLtsPiano();
            if (!TextUtils.isEmpty(ltsPiano)) {
                jSONObject4.put("pianoLTS", ltsPiano);
            }
            JSONObject jSONObject5 = new JSONObject();
            jSONObject5.put("eventData", jSONObject4);
            jSONObject5.put("customerId", this.mintSubscriptionDetail.getId());
            jSONObject5.put("email", this.mintSubscriptionDetail.getEmail());
            jSONObject.put("subscriptionEvent", jSONObject5);
            jSONObject3.put("gateway", "Razorpay");
            jSONObject.put("payment", jSONObject3);
            jSONObject.put(PaymentConstants.ORDER_ID, this.orderId);
            String generateToken = JWTTokenBuilder.generateToken(this.mintSubscriptionDetail.getId() + "~" + this.mintSubscriptionDetail.getEmail());
            HashMap<String, String> hashMap = new HashMap<>();
            hashMap.put("ProductId", this.appCompatActivity.getResources().getString(2131952728));
            hashMap.put("SubscriptionAuth", generateToken);
            Config g = AppController.j().g();
            Razorpay razorpay = g != null ? g.getRazorpay() : null;
            String domain = razorpay != null ? razorpay.getDomain() : BuildConfig.FLAVOR;
            if (razorpay != null) {
                str3 = razorpay.getValidatepayment();
            }
            if (str3.startsWith("http")) {
                str2 = str3;
            } else {
                str2 = domain + str3;
            }
            this.paymentValidationPresenterInterface.checkPayment(1, "OrderApi", str2, this.subsscreen, this.subsPlans, jSONObject, hashMap, false, false);
        } catch (JSONException unused) {
        }
    }

    public void dismissProgressDialog() {
        try {
            ProgressDialog progressDialog = this.pDialog;
            if (progressDialog != null && progressDialog.isShowing()) {
                this.pDialog.dismiss();
            }
        } catch (IllegalArgumentException unused) {
        } catch (Throwable th) {
            this.pDialog = null;
            throw th;
        }
        this.pDialog = null;
    }

    @Override
    public void onCreateOrder(CreateOrder createOrder) {
        dismissProgressDialog();
        createOrder.getCode();
        String message = createOrder.getMessage();
        this.orderId = createOrder.getOrderId();
        String currencyCode = this.subsPlans.getCurrencyCode();
        MintPlanWithZSPlan mintPlanWithZSPlan = this.mintPlanWithZSPlan;
        double recurringPrice = (mintPlanWithZSPlan == null || !mintPlanWithZSPlan.isCouponApplied()) ? this.subsPlans.getRecurringPrice() : this.mintPlanWithZSPlan.getDiscountPrice();
        if (createOrder.getSubscription() != null && createOrder.getSubscription().getPlan() != null) {
            if (!TextUtils.isEmpty(createOrder.getSubscription().getPlan().getCurrencyCode())) {
                currencyCode = createOrder.getSubscription().getPlan().getCurrencyCode();
            }
            recurringPrice = createOrder.getSubscription().getPlan().getPrice();
        }
        String str = currencyCode;
        double d = recurringPrice;
        boolean isEmpty = TextUtils.isEmpty(this.orderId);
        String str2 = BuildConfig.FLAVOR;
        if (!isEmpty) {
            this.mintPlanWithZSPlan.setTrialDaysDiscountPrice(this.subsPlans.getCurrencySymbol() + ((int) d));
            startPayment(this.orderId, TextUtils.isEmpty(createOrder.getRazorpayCustomerId()) ? BuildConfig.FLAVOR : createOrder.getRazorpayCustomerId(), str, d, this.isAutoRecurring);
            return;
        }
        if (SubscriptionConverter.isSubscriptionUpgradeOrRenewal(this.subsscreen)) {
            return;
        }
        String status = createOrder.getSubscription() != null ? createOrder.getSubscription().getStatus() : BuildConfig.FLAVOR;
        if (TextUtils.isEmpty(status) || !"live".equalsIgnoreCase(status)) {
            Toast.makeText((Context) this.appCompatActivity, (CharSequence) message, 1).show();
            return;
        }
        MintSubscriptionDetail parseCouponSubscriptionObject = ParseSubscriptionDetail.parseCouponSubscriptionObject(createOrder.getSubscription());
        Hostedpage hostedpage = createOrder.getHostedpage();
        if (hostedpage != null) {
            str2 = hostedpage.getHostedpageId();
        }
        this.orderId = str2;
        syncSubscriptionSuccess(parseCouponSubscriptionObject);
    }

    @Override
    public void onError(int i, String str) {
        onError(str);
    }

    @Override
    public void onError(String str) {
        dismissProgressDialog();
        if (this.isPaymentForMandates) {
            return;
        }
        Toast.makeText((Context) this.appCompatActivity, (CharSequence) str, 0).show();
    }

    public void onPaymentError(int i, String str, PaymentData paymentData) {
        MSError mSError = new MSError();
        StringBuilder sb2 = new StringBuilder();
        sb2.append(i);
        String str2 = BuildConfig.FLAVOR;
        sb2.append(BuildConfig.FLAVOR);
        mSError.setCode(sb2.toString());
        mSError.setMessage(str);
        String str3 = this.subsscreen == q.g0.MANAGE_PLAN_PAGE ? "Change Plan Payment Failed" : "Payment Failed";
        MintPlanWithZSPlan mintPlanWithZSPlan = this.mintPlanWithZSPlan;
        String str4 = this.funnelName;
        String str5 = this.premiumStory;
        String store = WebEngageAnalytices.PAYMENTSTORE.RAZOR_PAY.getStore();
        q.v vVar = this.payment_type;
        if (vVar != null) {
            str2 = vVar.name();
        }
        WebEngageAnalytices.trackPaymentStatus(str3, (MintSubscriptionDetail) null, mintPlanWithZSPlan, mSError, str4, str5, store, str2, this.isAutoRecurring);
        MintPlanWithZSPlan mintPlanWithZSPlan2 = SubscriptionPlanSingleton.getInstance().getMintPlanWithZSPlan();
        if (mintPlanWithZSPlan2 != null && mintPlanWithZSPlan2.getSubsPlans() != null && mintPlanWithZSPlan2.getSubsPlans().getPlanType() != null) {
            String planType = mintPlanWithZSPlan2.getSubsPlans().getPlanType();
            if (SubscriptionConverter.PLAN_CATEGORY.MINT.getPlanCategory().equalsIgnoreCase(planType)) {
                n.x(this.appCompatActivity, n.i1, "plan_page", n.u0, this.content, null, mSError, null);
            } else if (SubscriptionConverter.PLAN_CATEGORY.WSJ.getPlanCategory().equalsIgnoreCase(planType)) {
                n.x(this.appCompatActivity, n.j1, "plan_page", n.u0, this.content, null, mSError, null);
            } else if (SubscriptionConverter.PLAN_CATEGORY.ECO.getPlanCategory().equalsIgnoreCase(planType)) {
                n.x(this.appCompatActivity, n.m1, "plan_page", n.u0, this.content, null, mSError, null);
            } else if (SubscriptionConverter.PLAN_CATEGORY.BARRONS.getPlanCategory().equalsIgnoreCase(planType)) {
                n.x(this.appCompatActivity, n.k1, "plan_page", n.u0, this.content, null, mSError, null);
            } else if (SubscriptionConverter.PLAN_CATEGORY.WSJ_BARRONS.getPlanCategory().equalsIgnoreCase(planType)) {
                n.x(this.appCompatActivity, n.l1, "plan_page", n.u0, this.content, null, mSError, null);
            }
        }
        verifyPayment(false, str, paymentData);
        if (this.isPaymentForMandates) {
            w9.e eVar = new w9.e();
            eVar.b("Payment_Status", "Failed");
            eVar.b("Payment_Method", "Card");
            eVar.b("Payment Source", "Razorpay");
            eVar.b("Platform", "Android");
            eVar.b("Domain", "LM");
            eVar.b("Failed_Reason", n.s0(str, 100));
            b.w("Autopay Setup Status", eVar);
        }
    }

    public void onPaymentSuccess(String str, PaymentData paymentData) {
        if (this.isPaymentForMandates) {
            w9.e eVar = new w9.e();
            eVar.b("Payment_Status", "Success");
            eVar.b("Payment_Method", "Card");
            eVar.b("Payment Source", "Razorpay");
            eVar.b("Platform", "Android");
            eVar.b("Domain", "LM");
            b.w("Autopay Setup Status", eVar);
            f0.L3(this.appCompatActivity, "Congratulations, you've now claimed " + this.autoRecurringMandateDiscount + "% discount on your next auto-debit");
        }
        verifyPayment(true, BuildConfig.FLAVOR, paymentData);
    }

    @Override
    public void paymentSuccess(MintSubscriptionDetail mintSubscriptionDetail) {
        syncSubscriptionSuccess(mintSubscriptionDetail);
    }

    public void startPayment(String str, String str2, String str3, double d, boolean z) {
        Razorpay razorpay;
        Activity activity;
        Activity activity2;
        Checkout checkout;
        Activity activity3 = this.appCompatActivity;
        Checkout checkout2 = new Checkout();
        if (activity3 != null && activity3.getApplicationContext() != null) {
            Checkout.preload(activity3.getApplicationContext());
        }
        Config g = AppController.j().g();
        String str4 = BuildConfig.FLAVOR;
        String razorPayId = (g == null || g.getRazorpay() == null) ? BuildConfig.FLAVOR : g.getRazorpay().getRazorPayId();
        if (!TextUtils.isEmpty(razorPayId)) {
            checkout2.setKeyID(razorPayId);
        }
        if (g != null) {
            try {
                razorpay = g.getRazorpay();
            } catch (Exception e) {
                e = e;
                activity = activity3;
                Toast.makeText(activity, "Error in payment: " + e.getMessage(), 0).show();
                e.printStackTrace();
            }
        } else {
            razorpay = null;
        }
        SubsPlans subsPlans = this.subsPlans;
        String name = subsPlans != null ? subsPlans.getName() : BuildConfig.FLAVOR;
        SubsPlans subsPlans2 = this.subsPlans;
        if (subsPlans2 != null) {
            str4 = subsPlans2.getDescription();
        }
        if (razorpay != null) {
            if (!TextUtils.isEmpty(razorpay.getCheckoutName())) {
                name = razorpay.getCheckoutName();
            }
            if (!TextUtils.isEmpty(razorpay.getCheckoutDesc())) {
                str4 = razorpay.getCheckoutDesc();
            }
        }
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("name", name);
        jSONObject.put(Parameters.CD_DESCRIPTION, str4);
        jSONObject.put("image", "https://images.livemint.com/icons/mintfavi.svg");
        jSONObject.put("send_sms_hash", true);
        jSONObject.put("allow_rotation", false);
        jSONObject.put(PaymentConstants.ORDER_ID, str);
        if (z && !TextUtils.isEmpty(str2)) {
            jSONObject.put(PaymentConstants.CUSTOMER_ID, str2);
        }
        jSONObject.put("currency", str3);
        jSONObject.put(PaymentConstants.AMOUNT, d);
        JSONObject jSONObject2 = new JSONObject();
        jSONObject2.put("enabled", false);
        jSONObject2.put("max_count", 4);
        jSONObject.put("retry", jSONObject2);
        JSONObject jSONObject3 = new JSONObject();
        String displayName = this.mintSubscriptionDetail.getDisplayName();
        String email = this.mintSubscriptionDetail.getEmail();
        String mobile = this.mintSubscriptionDetail.getMobile();
        if (!TextUtils.isEmpty(displayName)) {
            jSONObject3.put("name", this.mintSubscriptionDetail.getDisplayName());
        }
        if (!TextUtils.isEmpty(email)) {
            jSONObject3.put("email", this.mintSubscriptionDetail.getEmail());
        }
        if (TextUtils.isEmpty(mobile)) {
            jSONObject3.put("contact", "0000000000");
        } else {
            jSONObject3.put("contact", this.mintSubscriptionDetail.getMobile());
        }
        JSONObject jSONObject4 = new JSONObject();
        q.v vVar = this.payment_type;
        try {
            if (vVar != null) {
                int i = AnonymousClass2.$SwitchMap$com$htmedia$mint$utils$AppConstants$PAYMENT_TYPE[vVar.ordinal()];
                activity2 = activity3;
                checkout = checkout2;
                if (i == 1) {
                    jSONObject3.put("method", PaymentConstants.WIDGET_UPI);
                    jSONObject4.put("netbanking", "0");
                    jSONObject4.put("card", "0");
                    jSONObject4.put(PaymentConstants.WIDGET_UPI, "1");
                    jSONObject4.put("wallet", "0");
                } else if (i == 2) {
                    jSONObject3.put("method", "netbanking");
                    jSONObject4.put("netbanking", "1");
                    jSONObject4.put("card", "0");
                    jSONObject4.put(PaymentConstants.WIDGET_UPI, "0");
                    jSONObject4.put("wallet", "0");
                } else if (i != 3) {
                    jSONObject3.put("method", "card");
                    jSONObject4.put("netbanking", "0");
                    jSONObject4.put("card", "1");
                    jSONObject4.put(PaymentConstants.WIDGET_UPI, "0");
                    jSONObject4.put("wallet", "0");
                } else {
                    jSONObject3.put("method", "wallet");
                    jSONObject4.put("netbanking", "0");
                    jSONObject4.put("card", "0");
                    jSONObject4.put(PaymentConstants.WIDGET_UPI, "0");
                    jSONObject4.put("wallet", "1");
                }
            } else {
                activity2 = activity3;
                checkout = checkout2;
            }
            jSONObject.put("prefill", jSONObject3);
            jSONObject.put("recurring", z);
            jSONObject.put("remember_customer", true);
            jSONObject.put("theme.color", "#f7941e");
            JSONObject jSONObject5 = new JSONObject();
            jSONObject5.put("email", false);
            jSONObject5.put("contact", false);
            jSONObject5.put("name", false);
            jSONObject.put("readonly", jSONObject5);
            jSONObject.put("method", jSONObject4);
            activity = activity2;
        } catch (Exception e2) {
            e = e2;
            activity = activity2;
        }
        try {
            checkout.open(activity, jSONObject);
        } catch (Exception e3) {
            e = e3;
            Toast.makeText(activity, "Error in payment: " + e.getMessage(), 0).show();
            e.printStackTrace();
        }
    }
}