导航菜单

页面标题

页面副标题

Crafto v9.3.3 - PayFragment.java 源代码

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

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


package com.paytmpayments.customuisdk.transaction;

import D2.a;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.webkit.JavascriptInterface;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.airbnb.lottie.LottieAnimationView;
import com.android.volley.VolleyError;
import com.google.gson.i;
import com.paytmpayments.customuisdk.Utils.CardData;
import com.paytmpayments.customuisdk.base.DependencyProvider;
import com.paytmpayments.customuisdk.base.EasyPayProvider;
import com.paytmpayments.customuisdk.base.VisaListener;
import com.paytmpayments.customuisdk.common.BaseActivity;
import com.paytmpayments.customuisdk.common.Constants.SDKConstants;
import com.paytmpayments.customuisdk.common.listeners.PayFragmentInteractor;
import com.paytmpayments.customuisdk.common.utils.CommonUtility;
import com.paytmpayments.customuisdk.common.utils.LogUtility;
import com.paytmpayments.customuisdk.dataSource.OneClickResponse;
import com.paytmpayments.customuisdk.paymethods.datasource.NativeSDKRepository;
import com.paytmpayments.customuisdk.paymethods.datasource.PaymentMethodDataSource;
import com.paytmpayments.customuisdk.paymethods.datasource.PaymentRepository;
import com.paytmpayments.customuisdk.paymethods.model.processtransaction.BankFormItem;
import com.paytmpayments.customuisdk.paymethods.model.processtransaction.ProcessTransactionInfo;
import com.paytmpayments.customuisdk.webRedirection.PaytmWebView;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;

public class PayFragment extends Fragment implements EasyPayProvider.NativeWebClientListener {
    private static final String TAG = "PayFragment";
    private String bankCode;
    private BankFormItem bankFormItem;
    private boolean callBackUrlIntercepted;
    private String cardType;
    private boolean currentState;
    private boolean isOneClickFlow;
    private Activity mActivity;
    private AlertDialog mAlertDialog;
    private Context mContext;
    private View mView;
    private WebView mWebView;
    private OneClickResponse oneClickResponse;
    private PayFragmentInteractor payFragmentInteractor;
    private String payType;
    private PaymentInstrument paymentInstrument;
    private boolean previousState;
    private ProcessTransactionInfo processTransactionInfo;
    private boolean txnStatusHitInProgress;
    private String mAllUrls = "";
    private boolean mIsShowedOnce = false;
    private boolean isRetryEnabled = false;
    private boolean isNewFlow = false;

    public class PaytmJavaScriptInterface {
        private PaytmJavaScriptInterface() {
        }

        public void loadNotifyJavaScript() {
            PayFragment.this.mWebView.evaluateJavascript("(function() { oneClickEnrollConfirmation(); } )();", null);
        }

        @JavascriptInterface
        public synchronized void processResponse(String str) {
            try {
                LogUtility.d(PayFragment.TAG, str);
                try {
                    JSONObject jSONObject = new JSONObject(str);
                    if (!jSONObject.has("retryAllowed") || !jSONObject.getBoolean("retryAllowed") || !jSONObject.has("errorMessage") || TextUtils.isEmpty(jSONObject.getString("errorMessage"))) {
                        PayFragment.this.finishSdk(str);
                    } else if (DependencyProvider.getUtilitiesHelper().isServerSDK()) {
                        PayUtility.finishSdk(PayFragment.this.mActivity, str, true, jSONObject.getString("errorMessage"));
                    } else {
                        PayFragment.this.payFragmentInteractor.backToCashierPage(PayFragment.this, jSONObject.getString("errorMessage"), true);
                    }
                } catch (Exception e) {
                    PayFragment.this.logException(e, "processResponse");
                    PayFragment.this.finishSdk(str);
                }
            } catch (Throwable th2) {
                throw th2;
            }
        }

        @JavascriptInterface
        public void setOneClickToken(String str) {
            if (PayFragment.this.mContext != null) {
                LogUtility.d(PayFragment.TAG, "oneClickToken= " + str);
                LogUtility.d(PayFragment.TAG, "previous state " + PayFragment.this.previousState);
                PayFragment payFragment = PayFragment.this;
                payFragment.setOneClickTokensdk(payFragment.mContext, PayFragment.this.paymentInstrument.getCardDetails(), str);
            }
        }

        @JavascriptInterface
        public void setPaRes(String str) {
            LogUtility.d(PayFragment.TAG, "pares is: " + str);
            DependencyProvider.getVisaHelper().verifyDevice(PayFragment.this.paymentInstrument.getCardDetails().getFirstSixDigit(), PayFragment.this.paymentInstrument.getCardDetails().getLastFourDigit(), PayFragment.this.paymentInstrument.getCardDetails().getExpiryDate(), str, CommonUtility.getEncryptedAuthCode(PayFragment.this.paymentInstrument.getOneClickInfo()), DependencyProvider.getMerchantHelper().getCustomerId(), CommonUtility.getCorrelationId(PayFragment.this.paymentInstrument.getOneClickInfo()), new VisaListener() {
                @Override
                public void onRequestEnd(boolean z, String str2) {
                    LogUtility.d(PayFragment.TAG, "setPaRas:onRequestEnd:calling loadNotifyJavaScript " + z + " " + str2);
                    PaytmJavaScriptInterface.this.loadNotifyJavaScript();
                }

                @Override
                public void onRequestError(String str2, String str3, String str4) {
                    LogUtility.d(PayFragment.TAG, "setPaRas:onRequestError:calling loadNotifyJavaScript");
                    PaytmJavaScriptInterface.this.loadNotifyJavaScript();
                }

                @Override
                public void onRequestStart() {
                }
            });
        }
    }

    public void dismissAlertDialog() {
        NativeSDKRepository.getInstance(this.mContext).notifyServerAboutCloseOrder();
        if (DependencyProvider.getCallbackListener() != null) {
            DependencyProvider.getCallbackListener().onBackPressedCancelTransaction();
        }
        Intent intent = new Intent("kill");
        intent.putExtra(SDKConstants.SAVE_ACTIVITY, "none");
        a.a(this.mContext.getApplicationContext()).c(intent);
        AlertDialog alertDialog = this.mAlertDialog;
        if (alertDialog != null) {
            alertDialog.dismiss();
        }
    }

    public void finishSdk(String str) {
        Bundle bundle = new Bundle();
        bundle.putString(SDKConstants.RESPONSE, str);
        if (this.isOneClickFlow && this.paymentInstrument != null) {
            this.currentState = DependencyProvider.getVisaHelper().isEnrollmentSucess(this.paymentInstrument.getCardDetails().getFirstSixDigit(), this.paymentInstrument.getCardDetails().getLastFourDigit(), this.paymentInstrument.getCardDetails().getExpiryDate(), DependencyProvider.getMerchantHelper().getCustomerId());
            LogUtility.d(TAG, "current state " + this.currentState);
            OneClickResponse oneClickInfoResponse = PayUtility.getOneClickInfoResponse(this.previousState, this.currentState, this.isOneClickFlow, true);
            this.oneClickResponse = oneClickInfoResponse;
            if (oneClickInfoResponse != null) {
                bundle.putParcelable(SDKConstants.ONE_CLICK_RESPONSE, oneClickInfoResponse);
            }
        }
        if (DependencyProvider.getCallbackListener() != null) {
            if (this.paymentInstrument == null) {
                DependencyProvider.getUtilitiesHelper().sendTransactionResponse(bundle, null, null);
            } else if (!DependencyProvider.getPaytmHelper().isPaytmApp(this.mContext) || DependencyProvider.getMerchantHelper().isAppInvoke()) {
                DependencyProvider.getUtilitiesHelper().sendTransactionResponse(bundle, this.paymentInstrument.getGaPaymentMethod(), this.paymentInstrument.getmPGParams());
            } else {
                DependencyProvider.getUtilitiesHelper().sendTransactionResponse(null, this.paymentInstrument.getGaPaymentMethod(), this.paymentInstrument.getmPGParams());
            }
        }
        Intent intent = new Intent("kill");
        intent.putExtra(SDKConstants.SAVE_ACTIVITY, "none");
        a.a(this.mActivity.getApplicationContext()).c(intent);
        if (DependencyProvider.getMerchantHelper().isTransparentAppInvoke()) {
            return;
        }
        this.mActivity.finish();
    }

    private byte[] getPostData() {
        if (this.bankFormItem.getContent() == null) {
            return null;
        }
        Map map = (Map) this.bankFormItem.getContent();
        StringBuilder sb = new StringBuilder();
        int size = map.size();
        int i = 0;
        for (String str : map.keySet()) {
            if (map.get(str) != null) {
                sb.append(URLEncoder.encode(str, "UTF-8") + "=" + URLEncoder.encode((String) map.get(str), "UTF-8"));
                if (i < size - 1) {
                    sb.append("&");
                }
                i++;
            }
        }
        if (DependencyProvider.getMerchantHelper().isAppInvoke()) {
            sb.append("&appCallbackUrl=true");
        }
        return sb.toString().getBytes();
    }

    public void hideLoaderDialog() {
        Activity activity = this.mActivity;
        if (activity == null || activity.isFinishing()) {
            return;
        }
        this.mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                PayFragment.this.mView.findViewById(R.id.cv_progressView).setVisibility(8);
            }
        });
    }

    private void hitTransactionStatusAPI() {
        this.txnStatusHitInProgress = true;
        showLoaderDialog();
        PaymentRepository.Companion.getInstance(DependencyProvider.getAppContext()).makeTransactionRequest(new PaymentMethodDataSource.Callback<ProcessTransactionInfo>() {
            @Override
            public void onErrorResponse(VolleyError volleyError, ProcessTransactionInfo processTransactionInfo) {
                LogUtility.d(PayFragment.TAG, "Transaction Status Error Response");
                PayFragment.this.processTransactionStatusApiResponse(processTransactionInfo);
            }

            @Override
            public void onResponse(ProcessTransactionInfo processTransactionInfo) {
                LogUtility.d(PayFragment.TAG, "Transaction Status Success");
                PayFragment.this.processTransactionStatusApiResponse(processTransactionInfo);
            }
        });
    }

    private void initWebView() {
        WebView webView = (WebView) this.mView.findViewById(R.id.wv_payment);
        this.mWebView = webView;
        webView.getSettings().setJavaScriptEnabled(true);
        this.mWebView.getSettings().setDomStorageEnabled(true);
        this.mWebView.addJavascriptInterface(new PaytmJavaScriptInterface(), PaytmWebView.HTML_OUT);
        this.mWebView.requestFocus(130);
        if (DependencyProvider.getEasyPayProvider() != null) {
            if (TextUtils.isEmpty(this.bankCode) || TextUtils.isEmpty(this.payType)) {
                LogUtility.d(TAG, "Bank Details are empty so not starting assist");
            } else {
                DependencyProvider.getEasyPayProvider().startConfigAssist(this.mContext, DependencyProvider.getMerchantHelper().isPaytmAssistEnabled(), DependencyProvider.getMerchantHelper().isPaytmAssistEnabled(), R.id.easypayBrowserFragment, this.mWebView, (Activity) this.mContext, DependencyProvider.getMerchantHelper().getOrderId(), DependencyProvider.getMerchantHelper().getMid());
                DependencyProvider.getEasyPayProvider().startAssist();
                DependencyProvider.getEasyPayProvider().setBankInfo(this.bankCode, this.payType, this.cardType);
            }
            this.mWebView.setWebViewClient(DependencyProvider.getEasyPayProvider().getWebClientInstance(this.mActivity));
            this.mWebView.setWebChromeClient(new WebChromeClient());
            DependencyProvider.getEasyPayProvider().addAssistWebClientListener(this);
        }
    }

    public void logException(Exception exc, String str) {
        if (DependencyProvider.getEventLogger() != null) {
            DependencyProvider.getEventLogger().sendCrashLogs("com.paytmpayments.customuisdk.transaction", str, exc);
        }
    }

    private void postPgdata() {
        BankFormItem bankFormItem = this.bankFormItem;
        if (bankFormItem == null || bankFormItem.getActionUrl() == null) {
            return;
        }
        try {
            final byte[] postData = getPostData();
            this.mActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    try {
                        PayFragment.this.mWebView.postUrl(PayFragment.this.bankFormItem.getActionUrl(), postData);
                    } catch (Exception e) {
                        PayFragment.this.logException(e, "postPgdata");
                        LogUtility.d("", e.getMessage());
                    }
                }
            });
        } catch (UnsupportedEncodingException | Exception e) {
            logException(e, "postPgdata");
            LogUtility.d("", e.getMessage());
        }
    }

    private void processInterceptedUrl(String str, final WebView webView) {
        try {
            HashMap<String, String> hashMap = new HashMap<>();
            hashMap.put(SDKConstants.KEY_PAGE_URL, str);
            hashMap.put(SDKConstants.KEY_STATUS, SDKConstants.VALUE_SUCCESS);
            if (DependencyProvider.getEventLogger() != null) {
                DependencyProvider.getEventLogger().sendLogs(SDKConstants.CUI_EVENT_CATEGORY, SDKConstants.ACTION_H5_INTERCEPT, hashMap);
            }
            LogUtility.d(TAG, "Dynamic callBackURL intercepted - before finishing");
            Uri parse = Uri.parse(str);
            String queryParameter = parse.getQueryParameter("retryAllowed");
            final String queryParameter2 = parse.getQueryParameter("errorMessage");
            Activity activity = this.mActivity;
            if (activity != null && !activity.isFinishing()) {
                this.mActivity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        PayFragment.this.showLoaderDialog();
                    }
                });
            }
            LogUtility.d(TAG, "Retry Allowed:" + queryParameter);
            if (TextUtils.isEmpty(queryParameter) || !Boolean.valueOf(queryParameter).booleanValue()) {
                this.isRetryEnabled = false;
                Activity activity2 = this.mActivity;
                if (activity2 != null && !activity2.isFinishing()) {
                    this.mActivity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if (PayFragment.this.paymentInstrument != null) {
                                HashMap<String, String> hashMap2 = new HashMap<>();
                                hashMap2.put(SDKConstants.KEY_PAYMENT_OPTION_TYPE, PayFragment.this.paymentInstrument.getGaPaymentMode());
                                hashMap2.put(SDKConstants.KEY_PAYMENT_MODE_TYPE, PayFragment.this.paymentInstrument.getGaPaymentMode());
                                hashMap2.put(SDKConstants.KEY_PAYMENT_STATUS, SDKConstants.VALUE_SUCCESS);
                                if (DependencyProvider.getEventLogger() != null) {
                                    DependencyProvider.getEventLogger().sendLogs(SDKConstants.PG_EVENT_CATEGORY, "pay_complete", hashMap2);
                                }
                                DependencyProvider.getPaytmHelper().sendGaEvents(DependencyProvider.getPaytmHelper().getGenericEventParams("", "pay_complete", PayFragment.this.paymentInstrument.getGaPaymentMethod(), PayFragment.this.paymentInstrument.getGaPaymentMode(), PayFragment.this.paymentInstrument.getGaFlowType(), "Web Redirection:Status Unknown"));
                            }
                        }
                    });
                }
                LogUtility.d(TAG, "CallBackUrl intercepted - Hitting Api Call");
                hitTransactionStatusAPI();
                return;
            }
            this.isRetryEnabled = true;
            hideLoaderDialog();
            Activity activity3 = this.mActivity;
            if (activity3 == null || activity3.isFinishing()) {
                return;
            }
            this.mActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    try {
                        webView.stopLoading();
                        if (PayFragment.this.paymentInstrument != null) {
                            HashMap<String, String> hashMap2 = new HashMap<>();
                            hashMap2.put(SDKConstants.KEY_ERROR_MSG, queryParameter2);
                            if (DependencyProvider.getEventLogger() != null) {
                                DependencyProvider.getEventLogger().sendLogs(SDKConstants.CUI_EVENT_CATEGORY, "pay_clicked_error", hashMap2);
                            }
                            DependencyProvider.getPaytmHelper().sendGaEvents(DependencyProvider.getPaytmHelper().getGenericEventParams("", "pay_clicked_error", PayFragment.this.paymentInstrument.getGaPaymentMethod(), queryParameter2, PayFragment.this.paymentInstrument.getGaFlowType(), ""));
                        }
                        PayFragment.this.payFragmentInteractor.backToCashierPage(PayFragment.this, queryParameter2, true);
                    } catch (Exception e) {
                        PayFragment.this.logException(e, "processInterceptedUrl");
                        LogUtility.d(PayFragment.TAG, "Unable to stop webview" + e.toString());
                    }
                }
            });
        } catch (Exception e) {
            logException(e, "processInterceptedUrl");
            webView.stopLoading();
        }
    }

    public void processTransactionStatusApiResponse(ProcessTransactionInfo processTransactionInfo) {
        if (this.callBackUrlIntercepted) {
            LogUtility.d(TAG, "Dynamic callBackURL finished and Txn Status API response received");
            processTxnStatusResponse(processTransactionInfo);
        } else {
            this.processTransactionInfo = processTransactionInfo;
            this.txnStatusHitInProgress = false;
        }
    }

    private void processTxnStatusResponse(ProcessTransactionInfo processTransactionInfo) {
        String str;
        LogUtility.d(TAG, "Sending response back" + new i().h(processTransactionInfo));
        if (this.isRetryEnabled) {
            return;
        }
        if (processTransactionInfo == null || processTransactionInfo.getBody() == null || processTransactionInfo.getBody().getTxnInfo() == null) {
            str = null;
        } else {
            HashMap<String, String> hashMap = new HashMap<>();
            hashMap.put(SDKConstants.KEY_PAYMENT_OPTION_TYPE, this.paymentInstrument.getGaPaymentMode());
            hashMap.put(SDKConstants.KEY_PAYMENT_MODE_TYPE, this.paymentInstrument.getGaPaymentMode());
            hashMap.put(SDKConstants.KEY_PAYMENT_STATUS, SDKConstants.VALUE_SUCCESS);
            if (DependencyProvider.getEventLogger() != null) {
                DependencyProvider.getEventLogger().sendLogs(SDKConstants.PG_EVENT_CATEGORY, "pay_complete", hashMap);
            }
            str = new i().h(processTransactionInfo.getBody().getTxnInfo());
        }
        finishSdk(str);
    }

    public void setOneClickTokensdk(Context context, CardData cardData, String str) {
        DependencyProvider.getVisaHelper().setEnrollmentData(cardData.getFirstSixDigit(), cardData.getLastFourDigit(), cardData.getExpiryDate(), DependencyProvider.getMerchantHelper().getCustomerId(), str);
    }

    public void showLoaderDialog() {
        Activity activity = this.mActivity;
        if (activity == null || activity.isFinishing()) {
            return;
        }
        this.mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                LottieAnimationView findViewById = PayFragment.this.mView.findViewById(R.id.ltv_loading);
                if (findViewById != null) {
                    findViewById.setVisibility(0);
                    findViewById.setAnimation("Payments-Loader.json");
                    findViewById.loop(true);
                    findViewById.playAnimation();
                }
                PayFragment.this.mView.findViewById(R.id.cv_progressView).setVisibility(0);
            }
        });
    }

    private String stringDefaultValue(String str, String str2) {
        return TextUtils.isEmpty(str) ? str2 : str;
    }

    public void loadPG() {
        if (!DependencyProvider.getUtilitiesHelper().isNetworkAvailable(this.mContext)) {
            if (DependencyProvider.getUtilitiesHelper().isBankOfferTransactionActivity(this.payFragmentInteractor)) {
                this.payFragmentInteractor.backToCashierPage(this, "", true);
                return;
            } else {
                DependencyProvider.getUtilitiesHelper().showNoInternetDialog(this.mContext, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        PayFragment.this.payFragmentInteractor.backToCashierPage(PayFragment.this, "", false);
                    }
                });
                return;
            }
        }
        if (this.isNewFlow && this.bankFormItem != null) {
            postPgdata();
            return;
        }
        PaymentInstrument paymentInstrument = this.paymentInstrument;
        if (paymentInstrument != null) {
            postPgdata(paymentInstrument);
        }
    }

    public void onActivityCreated(Bundle bundle) {
        super.onActivityCreated(bundle);
        hideLoaderDialog();
        initWebView();
        loadPG();
    }

    public void onAttach(@NotNull Context context) {
        super.onAttach(context);
        try {
            Bf.a.d(context, false);
        } catch (Exception e) {
            logException(e, "onAttach");
        }
        this.mContext = context;
        Activity activity = (Activity) context;
        this.mActivity = activity;
        if (activity instanceof PayFragmentInteractor) {
            this.payFragmentInteractor = (PayFragmentInteractor) activity;
        }
    }

    public void onBackPressed() {
        DependencyProvider.getPaytmHelper().sendGaEvents(DependencyProvider.getPaytmHelper().getGenericEventParams(SDKConstants.BACK_BUTTON_PG_SCREEN, "", ""));
        DependencyProvider.getUtilitiesHelper().showTwoButtonDialogNew(this.mContext, getString(R.string.native_back_press_title), getString(R.string.common_yes), getString(R.string.common_no), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                PayFragment.this.dismissAlertDialog();
                DependencyProvider.getPaytmHelper().sendGaEvents(DependencyProvider.getPaytmHelper().getGenericEventParams(SDKConstants.GA_KEY_CANCEL_PAYMENT, SDKConstants.VALUE_YES, ""));
                if (DependencyProvider.getEasyPayProvider() != null) {
                    DependencyProvider.getEasyPayProvider().onBackPressClicked();
                }
            }
        }, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                if (PayFragment.this.mAlertDialog != null) {
                    PayFragment.this.mAlertDialog.dismiss();
                }
                DependencyProvider.getPaytmHelper().sendGaEvents(DependencyProvider.getPaytmHelper().getGenericEventParams(SDKConstants.GA_KEY_CANCEL_PAYMENT, SDKConstants.VALUE_NO, ""));
            }
        });
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (bundle == null) {
            bundle = getArguments();
        }
        if (bundle != null) {
            this.paymentInstrument = (PaymentInstrument) bundle.getSerializable(SDKConstants.PAYMENT_INFO);
        }
        this.bankCode = bundle == null ? "" : stringDefaultValue(bundle.getString(SDKConstants.BANK_CODE), "");
        this.payType = bundle == null ? "" : stringDefaultValue(bundle.getString(SDKConstants.PAY_TYPE), "");
        this.cardType = bundle != null ? stringDefaultValue(bundle.getString(SDKConstants.CARD_TYPE), "") : "";
        if (bundle != null && bundle.getSerializable(SDKConstants.EXTRA_BANK_FORM_ITEM) != null) {
            this.bankFormItem = (BankFormItem) bundle.getSerializable(SDKConstants.EXTRA_BANK_FORM_ITEM);
        }
        if (bundle != null) {
            this.isNewFlow = bundle.getBoolean(SDKConstants.EXTRA_NEW_FLOW, false);
            this.isOneClickFlow = bundle.getBoolean(SDKConstants.ONE_CLICK_FLOW, false);
        }
        if (this.paymentInstrument == null || !this.isOneClickFlow || DependencyProvider.getMerchantHelper().getCustomerId() == null) {
            return;
        }
        this.previousState = DependencyProvider.getVisaHelper().isEnrollmentSucess(this.paymentInstrument.getCardDetails().getFirstSixDigit(), this.paymentInstrument.getCardDetails().getLastFourDigit(), this.paymentInstrument.getCardDetails().getExpiryDate(), DependencyProvider.getMerchantHelper().getCustomerId());
    }

    public View onCreateView(@NonNull LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        this.mView = layoutInflater.inflate(R.layout.paytm_fragment_pay_layout, viewGroup, false);
        DependencyProvider.getPaytmHelper().sendGaEvents(DependencyProvider.getPaytmHelper().getGenericEventParams("", SDKConstants.PG_SCREEN_LOADED, "bank_page", "", "", SDKConstants.GA_NATIVE_PLUS));
        return this.mView;
    }

    public void onDestroy() {
        super.onDestroy();
        if (DependencyProvider.getEasyPayProvider() != null) {
            DependencyProvider.getEasyPayProvider().removeAssist();
            DependencyProvider.getEasyPayProvider().removeAssistWebClientListener(this);
        }
    }

    public void onResume() {
        super.onResume();
        try {
            Context context = this.mContext;
            if (context != null) {
                Bf.a.d(context, false);
            }
        } catch (Exception e) {
            logException(e, "onResume");
        }
        Object obj = this.mActivity;
        if (obj instanceof BaseActivity) {
            ((BaseActivity) obj).hideKeyboard();
        }
    }

    @Override
    public void onWcPageFinish(WebView webView, String str) {
        try {
            HashMap<String, String> hashMap = new HashMap<>();
            hashMap.put(SDKConstants.KEY_PAGE_URL, str);
            hashMap.put(SDKConstants.KEY_STATUS, SDKConstants.VALUE_SUCCESS);
            if (DependencyProvider.getEventLogger() != null) {
                DependencyProvider.getEventLogger().sendLogs(SDKConstants.CUI_EVENT_CATEGORY, SDKConstants.ACTION_H5_LOAD, hashMap);
            }
            if (this.mActivity.isFinishing() || this.isRetryEnabled) {
                return;
            }
            String callBackUrl = DependencyProvider.getMerchantHelper().getCallBackUrl();
            boolean z = !TextUtils.isEmpty(callBackUrl) && str.contains(callBackUrl);
            if (!this.mIsShowedOnce && !z) {
                hideLoaderDialog();
            }
            this.mIsShowedOnce = true;
            if (DependencyProvider.getUtilitiesHelper().isBankOfferTransactionActivity(this.payFragmentInteractor)) {
                this.payFragmentInteractor.onWebPageFinish();
            } else {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if (PayFragment.this.payFragmentInteractor != null) {
                            PayFragment.this.payFragmentInteractor.onWebPageFinish();
                        }
                    }
                }, 200L);
            }
            View view = this.mView;
            int i = R.id.parentLayout;
            if (view.findViewById(i).getVisibility() == 4) {
                this.mView.findViewById(i).setVisibility(0);
                this.mView.findViewById(i).startAnimation(AnimationUtils.loadAnimation(this.mContext, R.anim.paytm_slide_in_right));
                PayFragmentInteractor payFragmentInteractor = this.payFragmentInteractor;
                if (payFragmentInteractor != null) {
                    payFragmentInteractor.addPageVisibleGAEvent();
                }
            }
            if (str != null && str.contains("/theia/paytmCallback?ORDER_ID")) {
                webView.loadUrl(PaytmWebView.JAVA_SCRIPT);
                return;
            }
            if (str == null || TextUtils.isEmpty(callBackUrl) || !str.contains(callBackUrl)) {
                return;
            }
            LogUtility.d(TAG, "Dynamic callBackURL finished");
            this.callBackUrlIntercepted = true;
            if (this.txnStatusHitInProgress) {
                return;
            }
            LogUtility.d(TAG, "Txn Status finished hitting");
            processTxnStatusResponse(this.processTransactionInfo);
        } catch (Exception e) {
            logException(e, "onWcPageFinish");
            LogUtility.d(TAG, e.toString());
        }
    }

    @Override
    public void onWcPageStart(WebView webView, String str, Bitmap bitmap) {
        try {
            if (this.mActivity.isFinishing()) {
                return;
            }
            StringBuilder sb = new StringBuilder();
            sb.append(this.mAllUrls);
            sb.append(this.mAllUrls.length() > 0 ? "|" : "");
            sb.append(str);
            this.mAllUrls = sb.toString();
            if (this.isRetryEnabled) {
                return;
            }
            LogUtility.d("TAG", str);
            if (str == null || !str.toLowerCase().contains(SDKConstants.PG_CALL_BACK)) {
                return;
            }
            webView.stopLoading();
            DependencyProvider.getUtilitiesHelper().sendTransactionResponse(null, this.paymentInstrument.getGaPaymentMethod(), this.paymentInstrument.getmPGParams());
            Intent intent = new Intent("kill");
            intent.putExtra(SDKConstants.SAVE_ACTIVITY, "none");
            a.a(this.mContext.getApplicationContext()).c(intent);
        } catch (Exception e) {
            logException(e, "onWcPageStart");
            LogUtility.d(TAG, e.toString());
        }
    }

    @Override
    public void onWcShouldInterceptRequest(final WebView webView, String str) {
        String callBackUrl = DependencyProvider.getMerchantHelper().getCallBackUrl();
        if (!TextUtils.isEmpty(str) && !TextUtils.isEmpty("js/hideloader.js") && str.contains("js/hideloader.js")) {
            this.mActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    PayFragment.this.hideLoaderDialog();
                }
            });
            return;
        }
        if (TextUtils.isEmpty(str) || !str.toLowerCase().contains("https://cart.paytm.com/payment/status")) {
            if (!TextUtils.isEmpty(str) && str.contains(SDKConstants.PG_CALL_BACK)) {
                Activity activity = this.mActivity;
                if (activity == null || activity.isFinishing()) {
                    return;
                }
                this.mActivity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            webView.stopLoading();
                        } catch (Exception e) {
                            PayFragment.this.logException(e, "onWcShouldInterceptRequest");
                            LogUtility.d(PayFragment.TAG, "Unable to stop webview" + e.toString());
                        }
                    }
                });
                return;
            }
            if (TextUtils.isEmpty(callBackUrl) || !str.contains(callBackUrl) || str.contains("theia/paytmCallback")) {
                return;
            }
        }
        processInterceptedUrl(str, webView);
    }

    @Override
    public boolean onWcShouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
        try {
            if (this.mActivity.isFinishing()) {
                return true;
            }
            webResourceRequest.getRequestHeaders().get("Location").contains(SDKConstants.PG_CALL_BACK);
            return false;
        } catch (Exception e) {
            LogUtility.d(TAG, e.toString());
            return false;
        }
    }

    @Override
    public void onWcSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
        sslErrorHandler.cancel();
    }

    private byte[] getPostData(PaymentInstrument paymentInstrument) {
        HashMap<String, String> hashMap = paymentInstrument.getmPGParams();
        StringBuilder sb = new StringBuilder();
        int size = hashMap.size();
        int i = 0;
        for (String str : hashMap.keySet()) {
            sb.append(URLEncoder.encode(str, "UTF-8"));
            sb.append("=");
            sb.append(URLEncoder.encode(hashMap.get(str), "UTF-8"));
            if (i < size - 1) {
                sb.append("&");
            }
            i++;
        }
        if (DependencyProvider.getMerchantHelper().isAppInvoke()) {
            sb.append("&appCallbackUrl=true");
        }
        return sb.toString().getBytes();
    }

    private void postPgdata(final PaymentInstrument paymentInstrument) {
        try {
            final byte[] postData = getPostData(paymentInstrument);
            this.mActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    try {
                        PayFragment.this.mWebView.postUrl(paymentInstrument.getmPGUrlToHit(), postData);
                    } catch (Exception e) {
                        PayFragment.this.logException(e, "postPgdata");
                        LogUtility.d(PayFragment.TAG, e.getMessage());
                    }
                }
            });
        } catch (UnsupportedEncodingException | Exception e) {
            logException(e, "postPgdata");
            LogUtility.d(TAG, e.getMessage());
        }
    }

    @Override
    public void onWcReceivedError(WebView webView, WebResourceError webResourceError, WebResourceRequest webResourceRequest) {
    }
}