导航菜单

页面标题

页面副标题

Rilo v2.0.21 - PWEUpiFragment.java 源代码

正在查看: Rilo v2.0.21 应用的 PWEUpiFragment.java JAVA 源代码文件

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


package com.easebuzz.payment.kit;

import adapters.PWEUpiIntentsAdapter;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.fragment.app.Fragment;
import clientRequestsApi.RetroAPI;
import com.cashfree.pg.image_caching.database.ImageCachingDatabaseHelper;
import com.cashfree.pg.ui.hidden.utils.AnalyticsConstants;
import com.facebook.GraphResponse;
import com.facebook.appevents.AppEventsConstants;
import com.facebook.appevents.codeless.internal.Constants;
import datamodels.DiscountCodeDataModel;
import datamodels.PWEStaticDataModel;
import datamodels.PWEUPIOptionsDataModel;
import helper.ToStringConverterFactory;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import listeners.KeyBoardListener;
import listeners.PWEUpiOptionListener;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

public class PWEUpiFragment extends Fragment {
    private static int CANCEL_UPI_EXCEPT_COUNT_1 = 0;
    private static int CANCEL_UPI_EXCEPT_COUNT_2 = 0;
    private static int CANCEL_UPI_SERVER_ERROR_COUNT = 0;
    private static int TXN_CHECK_STATUS_EXCEPT_COUNT_1 = 0;
    private static int TXN_CHECK_STATUS_SERVER_COUNT_ERROR = 0;
    private static String selected_upi_payment_option = "";
    Activity activity;
    private Button btn_cancel_upi_request;
    private Button buttonPayUpi;
    private Map checkStatusParametersJsonObj;
    private TimerTask checkStatusTask;
    private PWECouponsActivity couponsActivity;
    private PWEDiscountHelper discountCodeHelper;
    private EditText edUpiAutodebitUsername;
    private EditText etUPIAddress;
    private PWEGeneralHelper generalHelper;
    private ExpandableHeightGridView gridUPIOptions;
    private PWEUpiIntentsAdapter intentUpiOptionAdapter;
    private ImageView ivSendRequest;
    public WebView ivUPIQr;
    public KeyBoardListener keyBoardListener;
    LinearLayout linearNormalUPINoteHolder;
    private LinearLayout linearQrCodeHolder;
    LinearLayout linearScanQrHolder;
    private LinearLayout linearUPIIntentsHolder;
    private LinearLayout linearUpiAddressHolder;
    private LinearLayout linearUpiAutodebitAddHolder;
    private PWEPaymentInfoHandler paymentInfoHandler;
    public ProgressBar progressGeneratingQr;
    private ProgressBar progressUpiLoader;
    private Map submitInitiateParametersJsonObj;
    private TextView textUpiTypeLabel;
    private TextView tvPayUsingNote;
    private TextView tvPayUsingTitle;
    private TextView tvPayUsingUpiIdNote;
    private TextView tvPayUsingUpiIdTitle;
    private TextView tvUpiAddressAutodebitError;
    private TextView tvUpiAddressError;
    private TextView tv_upi_req_text;
    public Dialog upiBottomSheetDialog;
    public Intent upiChooser;
    private View upiView;
    private ArrayList<PWEUPIOptionsDataModel> upi_options_list;
    private String EndPointUrl = "";
    private String upiVA = "";
    private String selectedUpiUsername = "";
    private String upi_request_message = "";
    private String selectedIntentUpiKey = "";
    private String selectedIntentUpiPkg = "";
    public String pwe_qr_link = "";
    private boolean openPaymentOption = true;
    private boolean isDeeplinkFlowCompleted = false;
    private boolean allowCancel = false;
    private boolean is_selected_upi_qr = false;
    private boolean is_check_status_timer_started = false;
    private boolean isCancellingUPIRequest = false;
    private final Handler checkStatusHandler = new Handler();
    private Timer checkStatusTimer = new Timer();
    private int selectedUpiPosition = -1;
    private String selectedUpiType = "";
    private boolean initialUPISelectionFlag = false;
    private int PWE_DEEPLINK_REQUEST_CODE = 4400;
    private String selected_payment_option = "";
    private ActivityResultLauncher<Intent> pweUpiResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
        public void onActivityResult(ActivityResult activityResult) {
            PWEUpiFragment.this.isDeeplinkFlowCompleted = true;
        }
    });

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.activity = getActivity();
        this.paymentInfoHandler = new PWEPaymentInfoHandler(getActivity());
        this.generalHelper = new PWEGeneralHelper(getActivity());
        Object obj = this.activity;
        if (obj instanceof PWECouponsActivity) {
            this.couponsActivity = (PWECouponsActivity) obj;
        }
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        this.upiView = layoutInflater.inflate(R.layout.fragment_pwe_upi, viewGroup, false);
        PWECouponsActivity activity = getActivity();
        if (activity instanceof PWECouponsActivity) {
            this.couponsActivity = activity;
        }
        this.selectedIntentUpiPkg = "";
        this.selectedIntentUpiKey = "";
        this.discountCodeHelper = this.couponsActivity.getDiscountHelper();
        this.initialUPISelectionFlag = false;
        this.selectedUpiType = "";
        CANCEL_UPI_EXCEPT_COUNT_1 = 0;
        this.is_selected_upi_qr = false;
        this.is_check_status_timer_started = false;
        this.openPaymentOption = true;
        this.isDeeplinkFlowCompleted = false;
        PWEStaticHelper.PWE_CURRENT_TRXN_STATUS = this.paymentInfoHandler.getPweLastTransactionStatus();
        this.allowCancel = false;
        this.EndPointUrl = this.generalHelper.getAPIBaseURL();
        this.selected_payment_option = this.paymentInfoHandler.getSelectedPaymentOption();
        initViews();
        if (this.selected_payment_option.equals("upiview")) {
            prepareUpiOptions();
            initializeUpiOptionAdapter();
            if (!this.paymentInfoHandler.getPayUpiQrVisibilityFlag()) {
                this.linearQrCodeHolder.setVisibility(8);
            }
        }
        if (PWEStaticDataModel.IS_APP_REINITIALIZED) {
            resumeUpiPayment("COMPLETE_RESUME");
        } else {
            resumeUpiPayment("PARTIAL_RESUME");
        }
        selectionUpiOption();
        return this.upiView;
    }

    private void resumeUpiPayment(String str) {
        try {
            if (this.paymentInfoHandler.IsTxnSessionExpire()) {
                this.couponsActivity.setTimoutResult();
            }
            String pweUpiSaveState = this.paymentInfoHandler.getPweUpiSaveState();
            PWEStaticHelper.PWE_CURRENT_TRXN_STATUS = this.paymentInfoHandler.getPweLastTransactionStatus();
            JSONObject jSONObject = new JSONObject(pweUpiSaveState);
            this.initialUPISelectionFlag = jSONObject.optBoolean("initialUPISelectionFlag", true);
            this.openPaymentOption = jSONObject.optBoolean("openPaymentOption", true);
            this.isDeeplinkFlowCompleted = jSONObject.optBoolean("isDeeplinkFlowCompleted", false);
            this.is_selected_upi_qr = jSONObject.optBoolean("is_selected_upi_qr", false);
            this.selectedUpiUsername = jSONObject.optString("selected_upi_username", "");
            this.upi_request_message = jSONObject.optString("upi_request_message", "");
            this.selectedIntentUpiKey = jSONObject.optString("selectedIntentUpiKey", "");
            this.selectedIntentUpiPkg = jSONObject.optString("selectedIntentUpiPkg", "");
            this.pwe_qr_link = jSONObject.optString("pwe_qr_link", "");
            this.allowCancel = jSONObject.optBoolean("allowCancel", false);
            this.upiVA = jSONObject.optString("upiVA", "");
            this.selectedUpiType = jSONObject.optString("selected_upi_type", "");
            selected_upi_payment_option = jSONObject.optString("selected_upi_payment_option", "");
            if (str.equals("COMPLETE_RESUME")) {
                initializeUpiOptionAdapter();
                this.couponsActivity.setCustomerPaymentInfo();
            }
            if (!this.selectedUpiUsername.isEmpty() && !this.selectedUpiUsername.equals("") && this.paymentInfoHandler.getIsDiscountCouponApplied()) {
                this.etUPIAddress.setText(this.selectedUpiUsername);
            }
            if (this.selectedUpiType.equals("UPI_ID")) {
                this.etUPIAddress.setEnabled(true);
                this.etUPIAddress.setVisibility(0);
            }
            if (PWEStaticHelper.PWE_CURRENT_TRXN_STATUS.equals("pending")) {
                if (!this.selectedUpiType.equals("UPI_ID") && !this.selectedUpiType.equals("UPI_INTENT")) {
                    updateSelectedView(false, false, false, true, false);
                    disableUpiIdLayouts();
                    checkUPITransactionStatus();
                    return;
                }
                openBottomUPI();
                this.linearUpiAddressHolder.setVisibility(0);
                this.ivSendRequest.setVisibility(8);
                this.progressUpiLoader.setVisibility(0);
                this.tv_upi_req_text.setText(this.upi_request_message);
                this.allowCancel = true;
                checkUPITransactionStatus();
                return;
            }
            this.openPaymentOption = true;
        } catch (JSONException | Exception unused) {
        }
    }

    private void initViews() {
        this.gridUPIOptions = (ExpandableHeightGridView) this.upiView.findViewById(R.id.grid_upi_options);
        if (this.paymentInfoHandler.getPWEDeviceType().equals("TV")) {
            this.gridUPIOptions.setSelector(getResources().getDrawable(R.drawable.pwe_gridview_item_selector));
        }
        this.textUpiTypeLabel = (TextView) this.upiView.findViewById(R.id.text_card_type_label);
        this.tvUpiAddressError = (TextView) this.upiView.findViewById(R.id.text_upi_address_error);
        this.etUPIAddress = (EditText) this.upiView.findViewById(R.id.edit_upi_username);
        this.tvPayUsingTitle = (TextView) this.upiView.findViewById(R.id.text_pay_using_title);
        this.tvPayUsingNote = (TextView) this.upiView.findViewById(R.id.text_pay_using_note);
        this.tvPayUsingUpiIdTitle = (TextView) this.upiView.findViewById(R.id.text_pay_using_upi_id_title);
        this.tvPayUsingUpiIdNote = (TextView) this.upiView.findViewById(R.id.text_pay_using_upiId_note);
        this.linearUpiAddressHolder = (LinearLayout) this.upiView.findViewById(R.id.linear_upi_address_holder);
        this.linearUPIIntentsHolder = (LinearLayout) this.upiView.findViewById(R.id.linear_upi_intents_holder);
        this.linearQrCodeHolder = (LinearLayout) this.upiView.findViewById(R.id.linear_upi_qr_holder);
        this.linearUpiAutodebitAddHolder = (LinearLayout) this.upiView.findViewById(R.id.linear_upi_autodebit_address_holder);
        this.tvUpiAddressAutodebitError = (TextView) this.upiView.findViewById(R.id.text_upi_address_autodebit_error);
        this.edUpiAutodebitUsername = (EditText) this.upiView.findViewById(R.id.edit_upi_autodebit_username);
        this.linearUPIIntentsHolder.setVisibility(8);
        if (this.selected_payment_option.equals("autodebitupiview")) {
            this.linearUPIIntentsHolder.setVisibility(8);
            this.linearQrCodeHolder.setVisibility(8);
            this.linearUpiAddressHolder.setVisibility(8);
            this.linearUpiAutodebitAddHolder.setVisibility(0);
            this.textUpiTypeLabel.setText("Auto Debit UPI");
        } else {
            this.textUpiTypeLabel.setText(AnalyticsConstants.UPI);
            this.linearUpiAutodebitAddHolder.setVisibility(8);
        }
        this.etUPIAddress.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean z) {
                if (!PWEUpiFragment.this.paymentInfoHandler.getPWEDeviceType().equals("TV")) {
                    if (!z || PWEUpiFragment.this.initialUPISelectionFlag) {
                        return;
                    }
                    PWEUpiFragment.this.selectedUpiType = "UPI_ID";
                    PWEUpiFragment.this.updateSelectedView(false, true, false, false, true);
                    return;
                }
                if (z) {
                    PWEUpiFragment.this.linearUpiAddressHolder.setBackground(PWEUpiFragment.this.getResources().getDrawable(R.drawable.pwe_android_tv_image_edit_text));
                } else if (PWEUpiFragment.this.selectedUpiType.equals("UPI_ID")) {
                    PWEUpiFragment.this.linearUpiAddressHolder.setBackground(PWEUpiFragment.this.getResources().getDrawable(R.drawable.pwe_selected_item_background));
                } else {
                    PWEUpiFragment.this.linearUpiAddressHolder.setBackground(PWEUpiFragment.this.getResources().getDrawable(R.drawable.pwe_custom_card_background));
                }
            }
        });
        this.edUpiAutodebitUsername.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean z) {
                try {
                    if (PWEUpiFragment.this.paymentInfoHandler.getPWEDeviceType().equals("TV")) {
                        if (z) {
                            PWEUpiFragment.this.linearUpiAutodebitAddHolder.setBackground(PWEUpiFragment.this.getResources().getDrawable(R.drawable.pwe_android_tv_image_edit_text));
                        } else if (PWEUpiFragment.this.selectedUpiType.equals("UPI_ID")) {
                            PWEUpiFragment.this.linearUpiAutodebitAddHolder.setBackground(PWEUpiFragment.this.getResources().getDrawable(R.drawable.pwe_selected_item_background));
                        } else {
                            PWEUpiFragment.this.linearUpiAutodebitAddHolder.setBackground(PWEUpiFragment.this.getResources().getDrawable(R.drawable.pwe_custom_card_background));
                        }
                    } else if (z && !PWEUpiFragment.this.initialUPISelectionFlag) {
                        PWEUpiFragment.this.selectedUpiType = "UPI_ID";
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        this.linearUpiAddressHolder.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean z) {
                if (PWEUpiFragment.this.paymentInfoHandler.getPWEDeviceType().equals("TV")) {
                    if (z) {
                        PWEUpiFragment.this.linearUpiAddressHolder.setBackground(PWEUpiFragment.this.getResources().getDrawable(R.drawable.pwe_android_tv_image_edit_text));
                    } else if (PWEUpiFragment.this.selectedUpiType.equals("UPI_ID")) {
                        PWEUpiFragment.this.linearUpiAddressHolder.setBackground(PWEUpiFragment.this.getResources().getDrawable(R.drawable.pwe_selected_item_background));
                    } else {
                        PWEUpiFragment.this.linearUpiAddressHolder.setBackground(PWEUpiFragment.this.getResources().getDrawable(R.drawable.pwe_custom_card_background));
                    }
                }
            }
        });
        this.linearUpiAutodebitAddHolder.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean z) {
                if (PWEUpiFragment.this.paymentInfoHandler.getPWEDeviceType().equals("TV")) {
                    if (z) {
                        PWEUpiFragment.this.linearUpiAutodebitAddHolder.setBackground(PWEUpiFragment.this.getResources().getDrawable(R.drawable.pwe_android_tv_image_edit_text));
                    } else if (PWEUpiFragment.this.selectedUpiType.equals("UPI_ID")) {
                        PWEUpiFragment.this.linearUpiAutodebitAddHolder.setBackground(PWEUpiFragment.this.getResources().getDrawable(R.drawable.pwe_selected_item_background));
                    } else {
                        PWEUpiFragment.this.linearUpiAutodebitAddHolder.setBackground(PWEUpiFragment.this.getResources().getDrawable(R.drawable.pwe_custom_card_background));
                    }
                }
            }
        });
        this.linearQrCodeHolder.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean z) {
                if (PWEUpiFragment.this.paymentInfoHandler.getPWEDeviceType().equals("TV")) {
                    if (z) {
                        PWEUpiFragment.this.linearQrCodeHolder.setBackground(PWEUpiFragment.this.getResources().getDrawable(R.drawable.pwe_android_tv_image_edit_text));
                    } else if (PWEUpiFragment.this.selectedUpiType.equals("UPI_QR")) {
                        PWEUpiFragment.this.linearQrCodeHolder.setBackground(PWEUpiFragment.this.getResources().getDrawable(R.drawable.pwe_selected_item_background));
                    } else {
                        PWEUpiFragment.this.linearQrCodeHolder.setBackground(PWEUpiFragment.this.getResources().getDrawable(R.drawable.pwe_custom_card_background));
                    }
                }
            }
        });
        this.keyBoardListener = new KeyBoardListener();
        this.buttonPayUpi = (Button) this.upiView.findViewById(R.id.button_proceed_for_payment);
        if (this.paymentInfoHandler.getPWEDeviceType().equals("TV")) {
            this.buttonPayUpi.setBackground(getActivity().getResources().getDrawable(R.drawable.pwe_android_tv_button));
            this.generalHelper.changeButtonWidth(this.buttonPayUpi);
            this.etUPIAddress.setFilters(new InputFilter[]{new InputFilter.LengthFilter(50)});
        }
        this.buttonPayUpi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                boolean validateAllFields;
                PWEUpiFragment.this.keyBoardListener.hideKeyboard(PWEUpiFragment.this.getActivity());
                if (PWEUpiFragment.this.selected_payment_option.equals("upiview")) {
                    PWEUpiFragment pWEUpiFragment = PWEUpiFragment.this;
                    validateAllFields = pWEUpiFragment.validateAllFields(pWEUpiFragment.tvUpiAddressError);
                } else {
                    PWEUpiFragment pWEUpiFragment2 = PWEUpiFragment.this;
                    validateAllFields = pWEUpiFragment2.validateAllFields(pWEUpiFragment2.tvUpiAddressAutodebitError);
                }
                if (validateAllFields && PWEUpiFragment.this.openPaymentOption) {
                    PWEUpiFragment.this.openPaymentOption = false;
                    PWEUpiFragment.this.openBottomUPI();
                }
            }
        });
        this.etUPIAddress.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                PWEUpiFragment.this.tvUpiAddressError.setText("");
                PWEUpiFragment.this.tvUpiAddressError.setVisibility(8);
            }

            @Override
            public void afterTextChanged(Editable editable) {
                String str;
                if (PWEUpiFragment.this.paymentInfoHandler.getIsDiscountCouponApplied()) {
                    try {
                        str = PWEUpiFragment.this.discountCodeHelper.getUpiVA();
                    } catch (Error | Exception unused) {
                        str = "";
                    }
                    if (editable.toString().trim().equals(str) || editable.toString().trim().equals(PWEUpiFragment.this.selectedUpiUsername)) {
                        return;
                    }
                    PWEUpiFragment.this.couponsActivity.resetDiscountCode();
                }
            }
        });
        this.generalHelper.pweDisableCopyAndPaste(this.etUPIAddress);
        this.linearUpiAddressHolder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                PWEUpiFragment.this.selectedUpiType = "UPI_ID";
                PWEUpiFragment.this.linearUpiAddressHolder.requestFocus();
                PWEUpiFragment.this.updateSelectedView(false, true, false, false, true);
            }
        });
        this.linearQrCodeHolder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                PWEUpiFragment.this.clearUPIAddressFocus();
                PWEUpiFragment.this.linearQrCodeHolder.requestFocus();
                PWEUpiFragment.this.selectedUpiType = "UPI_QR";
                PWEUpiFragment.this.updateSelectedView(false, false, false, true, false);
            }
        });
    }

    public void onResume() {
        this.openPaymentOption = true;
        super.onResume();
    }

    public void onPause() {
        JSONObject jSONObject = new JSONObject();
        if (this.selectedUpiType.equals("UPI_INTENT")) {
            this.upi_request_message = "Processing your request";
        }
        try {
            jSONObject.put("upi_paused", true);
            jSONObject.put("initialUPISelectionFlag", this.initialUPISelectionFlag);
            jSONObject.put("openPaymentOption", this.openPaymentOption);
            jSONObject.put("isDeeplinkFlowCompleted", this.isDeeplinkFlowCompleted);
            jSONObject.put("is_selected_upi_qr", this.is_selected_upi_qr);
            jSONObject.put("selected_upi_username", this.selectedUpiUsername);
            jSONObject.put("selected_upi_payment_option", selected_upi_payment_option);
            jSONObject.put("selectedIntentUpiKey", this.selectedIntentUpiKey);
            jSONObject.put("selectedIntentUpiPkg", this.selectedIntentUpiPkg);
            jSONObject.put("upi_request_message", this.upi_request_message);
            jSONObject.put("pwe_qr_link", this.pwe_qr_link);
            jSONObject.put("allowCancel", this.allowCancel);
            jSONObject.put("upiVA", this.upiVA);
            jSONObject.put("selected_upi_type", this.selectedUpiType);
            this.paymentInfoHandler.setPweUpiSaveState(jSONObject.toString());
            this.paymentInfoHandler.setPweLastTransactionStatus(PWEStaticHelper.PWE_CURRENT_TRXN_STATUS);
        } catch (JSONException | Exception unused) {
        }
        super.onPause();
    }

    private void selectionUpiOption() {
        int i;
        try {
            if (!PWEStaticHelper.PWE_CURRENT_TRXN_STATUS.equals("pending")) {
                if (this.selectedUpiType.equals("UPI_INTENT") && this.intentUpiOptionAdapter != null && this.upi_options_list.size() > 0 && (i = this.selectedUpiPosition) != -1 && i < this.upi_options_list.size()) {
                    PWEUPIOptionsDataModel pWEUPIOptionsDataModel = this.upi_options_list.get(this.selectedUpiPosition);
                    this.intentUpiOptionAdapter.setSelectedUpiOptionKey(pWEUPIOptionsDataModel.getKey());
                    this.selectedIntentUpiKey = pWEUPIOptionsDataModel.getKey();
                    this.selectedIntentUpiPkg = pWEUPIOptionsDataModel.getPkg_name();
                    this.intentUpiOptionAdapter.notifyDataSetChanged();
                    if (!this.paymentInfoHandler.getPayUpiAddressVisibilityFlag()) {
                        hideUpiAddressBar();
                    }
                } else if (this.selectedUpiType.equals("UPI_QR")) {
                    updateSelectedView(false, false, false, true, false);
                    if (!this.paymentInfoHandler.getPayUpiAddressVisibilityFlag()) {
                        hideUpiAddressBar();
                    }
                } else {
                    updateUpiAddressView();
                }
            }
        } catch (Exception unused) {
        }
    }

    private void updateUpiAddressView() {
        if (this.selected_payment_option.equals("autodebitupiview")) {
            this.selectedUpiType = "UPI_ID";
            this.initialUPISelectionFlag = true;
        } else {
            if (this.paymentInfoHandler.getPayUpiAddressVisibilityFlag()) {
                showUpiAddressBar();
                this.selectedUpiType = "UPI_ID";
                this.initialUPISelectionFlag = true;
                updateSelectedView(false, true, false, false, true);
                return;
            }
            hideUpiAddressBar();
            this.selectedUpiType = "UPI_QR";
            updateSelectedView(false, false, false, true, false);
        }
    }

    private void showUpiAddressBar() {
        this.linearUpiAddressHolder.setVisibility(0);
    }

    private void hideUpiAddressBar() {
        this.linearUpiAddressHolder.setVisibility(8);
        this.couponsActivity.setDiscountCodeVisibiliy("hide");
    }

    private void prepareUpiOptions() {
        try {
            this.upi_options_list = new ArrayList<>();
            JSONArray jSONArray = new JSONObject(this.paymentInfoHandler.getUpiListString()).getJSONArray("upi_deeplink_options");
            for (int i = 0; i < jSONArray.length(); i++) {
                PWEUPIOptionsDataModel pWEUPIOptionsDataModel = new PWEUPIOptionsDataModel();
                JSONObject jSONObject = jSONArray.getJSONObject(i);
                JSONObject optJSONObject = jSONObject.optJSONObject("deeplink_conf");
                boolean optBoolean = optJSONObject.optBoolean("enabled", false);
                boolean optBoolean2 = optJSONObject.optBoolean("enabled_android", false);
                if (optBoolean && optBoolean2) {
                    String optString = optJSONObject.optString("pkg_name_android", "");
                    if (isPWEAppInstalled(optString)) {
                        pWEUPIOptionsDataModel.setImage(jSONObject.optString(ImageCachingDatabaseHelper.COLUMN_IMAGE));
                        pWEUPIOptionsDataModel.setKey(jSONObject.optString("key", ""));
                        pWEUPIOptionsDataModel.setLable(jSONObject.optString("label"));
                        pWEUPIOptionsDataModel.setShow_label(jSONObject.optBoolean("showLabel", false));
                        pWEUPIOptionsDataModel.setPkg_name(optString);
                        this.upi_options_list.add(pWEUPIOptionsDataModel);
                    }
                }
            }
        } catch (Exception unused) {
        }
    }

    private void initializeUpiOptionAdapter() {
        if (this.upi_options_list.size() > 0) {
            this.linearUPIIntentsHolder.setVisibility(0);
            ListAdapter pWEUpiIntentsAdapter = new PWEUpiIntentsAdapter(getActivity(), this.upi_options_list, this.paymentInfoHandler);
            this.intentUpiOptionAdapter = pWEUpiIntentsAdapter;
            this.gridUPIOptions.setAdapter(pWEUpiIntentsAdapter);
            this.gridUPIOptions.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
                    if (PWEUpiFragment.this.paymentInfoHandler.getPWEDeviceType().equals("TV")) {
                        PWEUpiFragment.this.intentUpiOptionAdapter.selectUpiOption(view, i);
                        PWEUpiFragment.this.intentUpiOptionAdapter.setSelectedUpiOptionKey(((PWEUPIOptionsDataModel) PWEUpiFragment.this.upi_options_list.get(i)).getKey());
                    }
                }
            });
            this.intentUpiOptionAdapter.setPWEUpiOptionListener(new PWEUpiOptionListener() {
                public void selectUPIOption(PWEUPIOptionsDataModel pWEUPIOptionsDataModel, int i) {
                    PWEUpiFragment.this.is_selected_upi_qr = true;
                    if (PWEUpiFragment.this.paymentInfoHandler.getIsDiscountCouponApplied() && PWEUpiFragment.this.selectedUpiPosition != i) {
                        PWEUpiFragment.this.couponsActivity.resetDiscountCode();
                    }
                    PWEUpiFragment.this.selectedUpiPosition = i;
                    PWEUpiFragment.this.selectedIntentUpiKey = pWEUPIOptionsDataModel.getKey();
                    PWEUpiFragment.this.selectedIntentUpiPkg = pWEUPIOptionsDataModel.getPkg_name();
                    PWEUpiFragment.this.tvUpiAddressError.setText("");
                    PWEUpiFragment.this.tvUpiAddressError.setVisibility(8);
                    PWEUpiFragment.this.selectedUpiType = "UPI_INTENT";
                    PWEUpiFragment.this.clearUPIAddressFocus();
                    PWEUpiFragment.this.updateSelectedView(true, false, false, false, false);
                    PWEUpiFragment.this.selectedUpiUsername = "";
                }
            });
            this.gridUPIOptions.setNumColumns(3);
            this.gridUPIOptions.setExpanded(true);
            return;
        }
        this.gridUPIOptions.setVisibility(8);
        this.linearUPIIntentsHolder.setVisibility(8);
        this.tvPayUsingTitle.setVisibility(8);
    }

    public void updateSelectedView(boolean z, boolean z2, boolean z3, boolean z4, boolean z5) {
        this.tvUpiAddressError.setText("");
        this.tvUpiAddressError.setVisibility(8);
        if (this.paymentInfoHandler.getIsDiscountCouponApplied() && !z2) {
            this.couponsActivity.resetDiscountCode();
        }
        this.is_selected_upi_qr = false;
        if (z5) {
            if (this.paymentInfoHandler.getIsDiscountCouponEnabled()) {
                this.couponsActivity.setDiscountCodeVisibiliy("show");
            }
        } else {
            this.couponsActivity.setDiscountCodeVisibiliy("hide");
        }
        if (z) {
            this.is_selected_upi_qr = true;
            this.selectedUpiUsername = "";
            PWEUpiIntentsAdapter pWEUpiIntentsAdapter = this.intentUpiOptionAdapter;
            if (pWEUpiIntentsAdapter != null) {
                pWEUpiIntentsAdapter.setSelectedUpiOptionKey(this.selectedIntentUpiKey);
            }
        } else if (z2) {
            PWEUpiIntentsAdapter pWEUpiIntentsAdapter2 = this.intentUpiOptionAdapter;
            if (pWEUpiIntentsAdapter2 != null) {
                pWEUpiIntentsAdapter2.setSelectedUpiOptionKey("");
            }
            requestUPIAddressFocus();
            this.selectedUpiPosition = -1;
            this.selectedIntentUpiKey = "";
            this.selectedIntentUpiPkg = "";
        } else if (z3) {
            PWEUpiIntentsAdapter pWEUpiIntentsAdapter3 = this.intentUpiOptionAdapter;
            if (pWEUpiIntentsAdapter3 != null) {
                pWEUpiIntentsAdapter3.setSelectedUpiOptionKey("");
            }
            this.selectedUpiPosition = -1;
            this.selectedUpiUsername = "";
            this.is_selected_upi_qr = true;
            this.selectedIntentUpiKey = "";
            this.selectedIntentUpiPkg = "";
        } else if (z4) {
            PWEUpiIntentsAdapter pWEUpiIntentsAdapter4 = this.intentUpiOptionAdapter;
            if (pWEUpiIntentsAdapter4 != null) {
                pWEUpiIntentsAdapter4.setSelectedUpiOptionKey("");
            }
            this.selectedUpiPosition = -1;
            this.selectedUpiUsername = "";
            this.is_selected_upi_qr = true;
            this.selectedIntentUpiKey = "";
            this.selectedIntentUpiPkg = "";
        }
        updateUI();
        this.initialUPISelectionFlag = false;
    }

    private void updateUI() {
        this.linearUpiAddressHolder.setBackground(getResources().getDrawable(R.drawable.pwe_custom_card_background));
        this.linearUPIIntentsHolder.setBackground(getResources().getDrawable(R.drawable.pwe_custom_card_background));
        this.linearQrCodeHolder.setBackground(getResources().getDrawable(R.drawable.pwe_custom_card_background));
        if (this.selectedUpiType.equals("UPI_ID")) {
            this.linearUpiAddressHolder.setBackground(getResources().getDrawable(R.drawable.pwe_selected_item_background));
        } else if (this.selectedUpiType.equals("UPI_QR")) {
            this.linearQrCodeHolder.setBackground(getResources().getDrawable(R.drawable.pwe_selected_item_background));
        } else {
            this.linearUpiAddressHolder.setBackground(getResources().getDrawable(R.drawable.pwe_custom_card_background));
            this.linearQrCodeHolder.setBackground(getResources().getDrawable(R.drawable.pwe_custom_card_background));
        }
    }

    public void openBottomUPI() {
        View inflate = getLayoutInflater().inflate(R.layout.bottom_sheet_upi, (ViewGroup) null);
        Dialog dialog = new Dialog(getActivity(), R.style.MaterialDialogSheet);
        this.upiBottomSheetDialog = dialog;
        dialog.setContentView(inflate);
        this.upiBottomSheetDialog.getWindow().setLayout(-1, -2);
        this.ivSendRequest = (ImageView) inflate.findViewById(R.id.image_upi_req);
        this.progressUpiLoader = (ProgressBar) inflate.findViewById(R.id.progress_upi_request);
        this.tv_upi_req_text = (TextView) inflate.findViewById(R.id.txt_upi_req);
        this.btn_cancel_upi_request = (Button) inflate.findViewById(R.id.button_cancel_upi_request);
        this.linearNormalUPINoteHolder = (LinearLayout) inflate.findViewById(R.id.linear_normal_upi_note_holder);
        this.linearScanQrHolder = (LinearLayout) inflate.findViewById(R.id.linear_pwe_scan_qr_holder);
        this.progressGeneratingQr = (ProgressBar) inflate.findViewById(R.id.progress_generating_qr);
        this.ivUPIQr = (WebView) inflate.findViewById(R.id.image_pwe_upi_qr_to_scan);
        this.upiBottomSheetDialog.getWindow().setGravity(80);
        this.upiBottomSheetDialog.setCancelable(false);
        if (this.paymentInfoHandler.getPWEDeviceType().equals("TV")) {
            this.btn_cancel_upi_request.setBackground(getActivity().getResources().getDrawable(R.drawable.pwe_android_tv_text_button));
        }
        this.btn_cancel_upi_request.setVisibility(0);
        if (this.is_selected_upi_qr) {
            if (this.selectedUpiType.equals("UPI_QR")) {
                this.btn_cancel_upi_request.setVisibility(8);
            }
            this.linearScanQrHolder.setVisibility(0);
            this.linearNormalUPINoteHolder.setVisibility(8);
            this.progressGeneratingQr.setVisibility(0);
            this.ivUPIQr.setVisibility(8);
        } else {
            this.linearScanQrHolder.setVisibility(8);
            this.progressGeneratingQr.setVisibility(8);
            this.ivUPIQr.setVisibility(8);
            this.linearNormalUPINoteHolder.setVisibility(0);
        }
        this.btn_cancel_upi_request.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (PWEUpiFragment.this.allowCancel) {
                    PWEUpiFragment.this.openPaymentOption = true;
                    PWEUpiFragment.this.isCancellingUPIRequest = true;
                    PWEUpiFragment.this.cancelUPIRequest();
                }
            }
        });
        this.upiBottomSheetDialog.show();
        this.upi_request_message = "Processing your request";
        this.tv_upi_req_text.setText("Processing your request");
        if (PWEStaticHelper.PWE_CURRENT_TRXN_STATUS.equals("pending")) {
            if (this.selectedUpiType.equals("UPI_QR")) {
                this.upiBottomSheetDialog.setCancelable(true);
                this.progressUpiLoader.setVisibility(8);
                this.progressGeneratingQr.setVisibility(8);
                this.upi_request_message = "Scan the QR Code on any UPI Application";
            }
            openUPIApps();
        } else {
            sendUpiRequest();
        }
        this.upiBottomSheetDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialogInterface) {
                PWEUpiFragment.this.openPaymentOption = true;
            }
        });
    }

    private void sendUpiRequest() {
        if (this.selected_payment_option.equals("upiview")) {
            selected_upi_payment_option = "upiview";
            this.upiVA = getCompleteUPIAddress(this.etUPIAddress);
        } else {
            selected_upi_payment_option = "autodebitupiview";
            this.upiVA = getCompleteUPIAddress(this.edUpiAutodebitUsername);
        }
        if (this.selectedUpiType.equals("UPI_QR") || this.selectedUpiType.equals("UPI_INTENT")) {
            this.upiVA = "";
        }
        this.ivSendRequest.setVisibility(4);
        this.progressUpiLoader.setVisibility(0);
        processUPI();
    }

    private void processUPI() {
        getSubmitParameters();
        ((RetroAPI) new Retrofit.Builder().baseUrl(this.EndPointUrl).addConverterFactory(new ToStringConverterFactory()).callFactory(this.generalHelper.getRetrofitConnectionFactory()).build().create(RetroAPI.class)).submitInitiatePayment(this.submitInitiateParametersJsonObj).enqueue(new Callback<String>() {
            public void onResponse(Call<String> call, Response<String> response) {
                try {
                    PWEUpiFragment.this.handleSubmitInitiateUPI(((String) response.body()).toString());
                } catch (Exception unused) {
                    PWEUpiFragment.this.dismissUpiBottomSheet();
                    PWEUpiFragment.this.dismissCheckStatusTimer();
                    PWEUpiFragment.this.couponsActivity.sendFailedResponseMerchant(PWEStaticDataModel.SERVER_ERROR_STR, PWEStaticDataModel.ERROR_DESC_STR, "error_server_error");
                }
            }

            public void onFailure(Call<String> call, Throwable th) {
                PWEUpiFragment.this.openPaymentOption = true;
                PWEUpiFragment.this.generalHelper.showPweToast(PWEStaticDataModel.SERVER_ERROR_STR + ", Please try again");
                PWEUpiFragment.this.dismissUpiBottomSheet();
            }
        });
    }

    public void clearUPIAddressFocus() {
        this.etUPIAddress.setText("");
        this.etUPIAddress.setEnabled(false);
        this.etUPIAddress.setVisibility(8);
    }

    private void requestUPIAddressFocus() {
        this.etUPIAddress.setEnabled(true);
        this.etUPIAddress.setVisibility(0);
        this.etUPIAddress.requestFocus();
    }

    public void handleSubmitInitiateUPI(String str) {
        try {
            try {
                JSONObject jSONObject = new JSONObject(str);
                if (jSONObject.optBoolean("status", false)) {
                    PWEStaticHelper.PWE_CURRENT_TRXN_STATUS = "pending";
                    this.openPaymentOption = true;
                    String str2 = "Processing your request";
                    if (this.selectedUpiType.equals("UPI_ID")) {
                        str2 = "Please accept the payment on your UPI phone application";
                    } else {
                        String optString = jSONObject.optString("qr_link", "");
                        this.pwe_qr_link = optString;
                        if (!optString.equals("")) {
                            if (this.selectedUpiType.equals("UPI_QR")) {
                                String optString2 = jSONObject.optString("message", "Processing your request");
                                this.upiBottomSheetDialog.setCancelable(true);
                                this.progressGeneratingQr.setVisibility(8);
                                str2 = optString2;
                            }
                            disableUpiIdLayouts();
                            openUPIApps();
                        } else {
                            this.couponsActivity.sendFailedResponseMerchant(PWEStaticDataModel.UPIQR_ERROR_STR, PWEStaticDataModel.UPIQR_DESC_STR, "error_server_error");
                        }
                    }
                    this.upi_request_message = str2;
                    this.tv_upi_req_text.setText(str2);
                    this.ivSendRequest.setVisibility(8);
                    this.progressUpiLoader.setVisibility(0);
                    this.allowCancel = true;
                    if (this.paymentInfoHandler.getPaymentMode().equals("test")) {
                        try {
                            new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    PWEUpiFragment.this.checkUPITransactionStatus();
                                }
                            }, 1500L);
                            return;
                        } catch (Error unused) {
                            checkUPITransactionStatus();
                            return;
                        } catch (Exception unused2) {
                            checkUPITransactionStatus();
                            return;
                        }
                    }
                    checkUPITransactionStatus();
                    return;
                }
                this.generalHelper.showPweToast(jSONObject.optString("error", "Please try other payment option."));
                dismissUpiBottomSheet();
            } catch (JSONException unused3) {
                dismissUpiBottomSheet();
                dismissCheckStatusTimer();
                this.couponsActivity.sendFailedResponseMerchant(PWEStaticDataModel.SERVER_ERROR_STR, PWEStaticDataModel.ERROR_DESC_STR, "error_server_error");
            }
        } catch (Error unused4) {
            dismissCheckStatusTimer();
            dismissUpiBottomSheet();
            this.couponsActivity.sendFailedResponseMerchant(PWEStaticDataModel.SERVER_ERROR_STR, PWEStaticDataModel.ERROR_DESC_STR, "error_server_error");
        } catch (Exception unused5) {
            dismissCheckStatusTimer();
            dismissUpiBottomSheet();
            this.couponsActivity.sendFailedResponseMerchant(PWEStaticDataModel.SERVER_ERROR_STR, PWEStaticDataModel.ERROR_DESC_STR, "error_server_error");
        }
    }

    private void openUPIApps() {
        if (!this.paymentInfoHandler.getPaymentMode().equals("test")) {
            openUPIAppsProd();
        } else {
            openUPIAppsSandbox();
        }
    }

    public void openUPIAppsSandbox() {
        if (this.selectedUpiType.equals("UPI_QR")) {
            openQrCode(this.pwe_qr_link);
        }
    }

    public void openUPIAppsProd() {
        throw new UnsupportedOperationException("Method not decompiled: com.easebuzz.payment.kit.PWEUpiFragment.openUPIAppsProd():void");
    }

    private void openQrCode(String str) {
        try {
            this.tv_upi_req_text.setText(this.upi_request_message);
            String str2 = PWEStaticDataModel.UPI_QR_BASE + "chart?cht=qr&chs=180x180&chl=" + URLEncoder.encode(str, "utf-8") + "&chld=H|0";
            this.ivUPIQr.setVisibility(0);
            this.ivUPIQr.loadUrl(str2);
            this.ivUPIQr.setWebViewClient(new WebViewClient());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    private void disableUpiIdLayouts() {
        this.tvPayUsingUpiIdTitle.setTextColor(getActivity().getResources().getColor(R.color.pwe_disable_text_color));
        this.tvPayUsingUpiIdNote.setTextColor(getActivity().getResources().getColor(R.color.pwe_disable_text_color));
        this.etUPIAddress.setHintTextColor(getActivity().getResources().getColor(R.color.pwe_disable_text_color));
        disableLayout(this.linearUpiAddressHolder);
    }

    private void disableLayout(ViewGroup viewGroup) {
        int childCount = viewGroup.getChildCount();
        viewGroup.setEnabled(false);
        for (int i = 0; i < childCount; i++) {
            if (viewGroup.getChildAt(i) instanceof ViewGroup) {
                disableLayout((ViewGroup) viewGroup.getChildAt(i));
            } else {
                viewGroup.getChildAt(i).setEnabled(false);
            }
        }
    }

    public String getCompleteUPIAddress(EditText editText) {
        String str = "";
        try {
            String obj = editText.getText().toString();
            this.selectedUpiUsername = obj;
            this.selectedUpiUsername = obj.trim();
            str = "" + this.selectedUpiUsername;
            return str.trim();
        } catch (Exception e) {
            e.printStackTrace();
            return str;
        }
    }

    public boolean validateAllFields(android.widget.TextView r8) {
        throw new UnsupportedOperationException("Method not decompiled: com.easebuzz.payment.kit.PWEUpiFragment.validateAllFields(android.widget.TextView):boolean");
    }

    public void cancelUPIRequest() {
        this.couponsActivity.showPWELoader();
        this.ivSendRequest.setVisibility(0);
        this.progressUpiLoader.setVisibility(8);
        this.progressGeneratingQr.setVisibility(8);
        this.upi_request_message = "Cancelling upi payment";
        this.tv_upi_req_text.setText("Cancelling upi payment");
        ((RetroAPI) new Retrofit.Builder().baseUrl(this.generalHelper.getUPIAPIBaseURL()).addConverterFactory(new ToStringConverterFactory()).callFactory(this.generalHelper.getRetrofitConnectionFactory()).build().create(RetroAPI.class)).cancelUPIRequest(this.paymentInfoHandler.getMerchantAccessKey()).enqueue(new Callback<String>() {
            public void onResponse(Call<String> call, Response<String> response) {
                PWEUpiFragment.this.couponsActivity.hidePWELoader();
                try {
                    PWEUpiFragment.this.handleCancelUPIRequest(((String) response.body()).toString());
                } catch (Exception unused) {
                    PWEUpiFragment.CANCEL_UPI_EXCEPT_COUNT_1++;
                    if (PWEUpiFragment.CANCEL_UPI_EXCEPT_COUNT_1 <= 2) {
                        PWEUpiFragment.this.generalHelper.showPweToast("Please try again");
                    } else {
                        PWEUpiFragment.this.dismissCheckStatusTimer();
                        PWEUpiFragment.this.couponsActivity.sendFailedResponseMerchant(PWEStaticDataModel.BANK_BACK_PRESSED_STR, PWEStaticDataModel.ERROR_DESC_STR, "bank_back_pressed");
                    }
                }
            }

            public void onFailure(Call<String> call, Throwable th) {
                PWEUpiFragment.this.couponsActivity.hidePWELoader();
                PWEUpiFragment.CANCEL_UPI_SERVER_ERROR_COUNT++;
                if (PWEUpiFragment.CANCEL_UPI_SERVER_ERROR_COUNT <= 2) {
                    PWEUpiFragment.this.generalHelper.showPweToast("Please try again");
                } else {
                    PWEUpiFragment.this.dismissCheckStatusTimer();
                    PWEUpiFragment.this.couponsActivity.sendFailedResponseMerchant(PWEStaticDataModel.SERVER_ERROR_STR, PWEStaticDataModel.ERROR_DESC_STR, "error_server_error");
                }
            }
        });
    }

    public void handleCancelUPIRequest(String str) {
        try {
            JSONObject jSONObject = new JSONObject(str);
            if (jSONObject.getString("status").equals("true")) {
                dismissUpiBottomSheet();
                onUPIResponse(jSONObject.getString("payment_response"));
            } else {
                int i = CANCEL_UPI_EXCEPT_COUNT_2 + 1;
                CANCEL_UPI_EXCEPT_COUNT_2 = i;
                if (i <= 2) {
                    this.generalHelper.showPweToast("Please try again");
                } else {
                    dismissCheckStatusTimer();
                    this.couponsActivity.sendFailedResponseMerchant(PWEStaticDataModel.SERVER_ERROR_STR, PWEStaticDataModel.ERROR_DESC_STR, "error_server_error");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            int i2 = CANCEL_UPI_EXCEPT_COUNT_2 + 1;
            CANCEL_UPI_EXCEPT_COUNT_2 = i2;
            if (i2 <= 3) {
                this.generalHelper.showPweToast("Please try again");
            } else {
                dismissCheckStatusTimer();
                this.couponsActivity.sendFailedResponseMerchant(PWEStaticDataModel.SERVER_ERROR_STR, PWEStaticDataModel.ERROR_DESC_STR, "error_server_error");
            }
        }
    }

    public void onUPIResponse(final String str) {
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                try {
                    String string = new JSONObject(str).getString("status");
                    if (PWEUpiFragment.this.checkStatusTimer != null) {
                        PWEUpiFragment.this.checkStatusTimer.cancel();
                    }
                    if (string.equals(GraphResponse.SUCCESS_KEY)) {
                        PWEUpiFragment.this.dismissCheckStatusTimer();
                        PWEUpiFragment.this.couponsActivity.sendResponseToMerchant("payment_successfull", str, -1);
                    } else {
                        PWEUpiFragment.this.dismissCheckStatusTimer();
                        PWEUpiFragment.this.couponsActivity.sendResponseToMerchant("payment_failed", str, 0);
                    }
                } catch (Exception unused) {
                    PWEUpiFragment.this.dismissCheckStatusTimer();
                    PWEUpiFragment.this.couponsActivity.sendFailedResponseMerchant(PWEStaticDataModel.SERVER_ERROR_STR, PWEStaticDataModel.ERROR_DESC_STR, "error_server_error");
                }
            }
        });
    }

    public void checkUPITransactionStatus() {
        getCheckUPIStatusParameters();
        ((RetroAPI) new Retrofit.Builder().baseUrl(this.generalHelper.getUPIAPIBaseURL()).addConverterFactory(new ToStringConverterFactory()).callFactory(this.generalHelper.getRetrofitConnectionFactory()).build().create(RetroAPI.class)).checkUPIStatus(this.checkStatusParametersJsonObj).enqueue(new Callback<String>() {
            public void onResponse(Call<String> call, Response<String> response) {
                if (response != null) {
                    try {
                        JSONObject jSONObject = new JSONObject(((String) response.body()).toString());
                        if (jSONObject.getString("status").equals("false")) {
                            if (!PWEUpiFragment.this.is_check_status_timer_started) {
                                PWEUpiFragment.this.is_check_status_timer_started = true;
                                PWEUpiFragment.this.initiateCheckStatusTask();
                            }
                        } else if (jSONObject.getString("status").equals("true") && !PWEUpiFragment.this.isCancellingUPIRequest) {
                            PWEUpiFragment.this.dismissUpiBottomSheet();
                            PWEUpiFragment.this.onUPIResponse(jSONObject.getString("payment_response"));
                        }
                    } catch (Exception unused) {
                        PWEUpiFragment.TXN_CHECK_STATUS_EXCEPT_COUNT_1++;
                        if (PWEUpiFragment.TXN_CHECK_STATUS_EXCEPT_COUNT_1 <= 3) {
                            if (PWEUpiFragment.this.is_check_status_timer_started) {
                                return;
                            }
                            PWEUpiFragment.this.is_check_status_timer_started = true;
                            PWEUpiFragment.this.initiateCheckStatusTask();
                            return;
                        }
                        PWEUpiFragment.this.dismissCheckStatusTimer();
                        PWEUpiFragment.this.couponsActivity.sendFailedResponseMerchant(PWEStaticDataModel.SERVER_ERROR_STR, PWEStaticDataModel.ERROR_DESC_STR, "error_server_error");
                    }
                }
            }

            public void onFailure(Call<String> call, Throwable th) {
                PWEUpiFragment.TXN_CHECK_STATUS_SERVER_COUNT_ERROR++;
                if (PWEUpiFragment.TXN_CHECK_STATUS_SERVER_COUNT_ERROR <= 3) {
                    if (PWEUpiFragment.this.is_check_status_timer_started) {
                        return;
                    }
                    PWEUpiFragment.this.is_check_status_timer_started = true;
                    PWEUpiFragment.this.initiateCheckStatusTask();
                    return;
                }
                PWEUpiFragment.this.dismissCheckStatusTimer();
                PWEUpiFragment.this.couponsActivity.sendFailedResponseMerchant(PWEStaticDataModel.SERVER_ERROR_STR, PWEStaticDataModel.ERROR_DESC_STR, "error_server_error");
            }
        });
    }

    public void initiateCheckStatusTask() {
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                PWEUpiFragment.this.checkStatusHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        PWEUpiFragment.this.new PerformBackgroundTask().execute(new String[0]);
                    }
                });
            }
        };
        this.checkStatusTask = timerTask;
        this.checkStatusTimer.scheduleAtFixedRate(timerTask, 0L, 3000L);
    }

    public void dismissCheckStatusTimer() {
        try {
            Timer timer = this.checkStatusTimer;
            if (timer != null) {
                timer.cancel();
            }
        } catch (Error | Exception unused) {
        }
    }

    public class PerformBackgroundTask extends AsyncTask<String, Void, String> {
        public PerformBackgroundTask() {
        }

        @Override
        public String doInBackground(String... strArr) {
            PWEUpiFragment.this.checkUPITransactionStatus();
            return null;
        }
    }

    private void getCheckUPIStatusParameters() {
        HashMap hashMap = new HashMap();
        this.checkStatusParametersJsonObj = hashMap;
        try {
            hashMap.put("paymentoption", selected_upi_payment_option);
            this.checkStatusParametersJsonObj.put("access_key", this.paymentInfoHandler.getMerchantAccessKey());
            this.checkStatusParametersJsonObj.put("userAgent", "userAgent");
            this.checkStatusParametersJsonObj.put("device", Constants.PLATFORM);
            this.checkStatusParametersJsonObj.put("ismobile", AppEventsConstants.EVENT_PARAM_VALUE_YES);
            this.checkStatusParametersJsonObj.put("discount_code", this.paymentInfoHandler.getAppliedDiscountCouponCode());
            this.checkStatusParametersJsonObj.put("upiVA", this.upiVA);
            this.checkStatusParametersJsonObj.put("selected_coupon", this.paymentInfoHandler.getSelectedCouponIdList());
        } catch (Error e) {
            e.printStackTrace();
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    private void getSubmitParameters() {
        HashMap hashMap = new HashMap();
        this.submitInitiateParametersJsonObj = hashMap;
        try {
            hashMap.put("paymentoption", selected_upi_payment_option);
            this.submitInitiateParametersJsonObj.put("access_key", this.paymentInfoHandler.getMerchantAccessKey());
            this.submitInitiateParametersJsonObj.put("userAgent", "userAgent");
            this.submitInitiateParametersJsonObj.put("device", Constants.PLATFORM);
            this.submitInitiateParametersJsonObj.put("ismobile", AppEventsConstants.EVENT_PARAM_VALUE_YES);
            this.submitInitiateParametersJsonObj.put("upiVA", this.upiVA);
            if (this.selected_payment_option.equals("upiview")) {
                this.submitInitiateParametersJsonObj.put("upiQR", Boolean.valueOf(this.is_selected_upi_qr));
                this.submitInitiateParametersJsonObj.put("selected_coupon", this.paymentInfoHandler.getSelectedCouponIdList());
                this.submitInitiateParametersJsonObj.put("discount_code", this.paymentInfoHandler.getAppliedDiscountCouponCode());
            }
        } catch (Error e) {
            e.printStackTrace();
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    public void dismissUpiBottomSheet() {
        try {
            Dialog dialog = this.upiBottomSheetDialog;
            if (dialog == null || !dialog.isShowing()) {
                return;
            }
            this.upiBottomSheetDialog.dismiss();
        } catch (Error | Exception unused) {
        }
    }

    public JSONObject validateDiscountCodeOuter(ArrayList<DiscountCodeDataModel> arrayList, PWEDiscountHelper pWEDiscountHelper) {
        this.discountCodeHelper = pWEDiscountHelper;
        JSONObject jSONObject = new JSONObject();
        String completeUPIAddress = getCompleteUPIAddress(this.etUPIAddress);
        String str = "Please enter UPI ID before applying discount code";
        boolean z = false;
        if (arrayList.size() < 1) {
            str = "Discount codes are not available for this payment mode";
        } else if (completeUPIAddress != null && !completeUPIAddress.isEmpty()) {
            if (!completeUPIAddress.equals("")) {
                if (completeUPIAddress.contains("@")) {
                    boolean startsWith = completeUPIAddress.startsWith("@");
                    String str2 = startsWith ? "Please enter valid UPI ID" : "";
                    boolean z2 = true ^ startsWith;
                    if (!completeUPIAddress.endsWith("@")) {
                        str = str2;
                        z = z2;
                    }
                }
                str = "Please enter valid UPI ID";
            }
        }
        if (z) {
            this.discountCodeHelper.setUpiVA(completeUPIAddress);
        }
        try {
            jSONObject.put("status", z);
            jSONObject.put("toast_error_message", str);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return jSONObject;
    }

    public void onDestroy() {
        this.paymentInfoHandler.setPweUpiSaveState("{}");
        super.onDestroy();
    }

    public void onAttach(Context context) {
        super.onAttach(context);
    }

    public void onDetach() {
        super.onDetach();
    }

    private boolean isPWEAppInstalled(String str) {
        try {
            getActivity().getPackageManager().getPackageInfo(str, 1);
            return true;
        } catch (PackageManager.NameNotFoundException unused) {
            return false;
        }
    }
}