导航菜单

页面标题

页面副标题

Housing v14.7.8 - RzpGpayMerged.java 源代码

正在查看: Housing v14.7.8 应用的 RzpGpayMerged.java JAVA 源代码文件

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


package com.razorpay;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import androidx.annotation.NonNull;
import com.google.android.apps.nbu.paisa.inapp.client.api.PaymentsClient;
import com.google.android.apps.nbu.paisa.inapp.client.api.Wallet;
import com.google.android.apps.nbu.paisa.inapp.client.api.WalletUtils;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.newrelic.agent.android.instrumentation.Instrumented;
import com.newrelic.agent.android.instrumentation.JSONObjectInstrumentation;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Objects;
import org.json.JSONException;
import org.json.JSONObject;

@Instrumented
class RzpGpayMerged implements OnCompleteListener<Boolean>, RzpPlugin {
    private static int LOAD_PAYMENT_DATA_REQUEST_CODE = 1;
    private JSONObject apiResponse;
    private PaymentsClient mPaymentClient;
    private RzpPluginRegisterCallback registerCallback;
    private RzpInternalCallback rzpInternalCallback;
    private boolean isUpiOnly = false;
    private Task<Boolean> cardsTask = null;
    private Task<Boolean> upiTask = null;

    public void genericOnPaymentFailure(String str, int i, String str2) {
        if (this.isUpiOnly) {
            this.rzpInternalCallback.onPaymentError(5, RzpGpayUtilMerged.makeErrorPayload(str, str2));
        } else {
            this.rzpInternalCallback.onPaymentError(5, RzpGpayUtilMerged.makeMergedExternalSDKErrorPayload(this.apiResponse, i, str2));
        }
    }

    private void genericOnPaymentSuccess() {
        if (this.isUpiOnly) {
            this.rzpInternalCallback.onPaymentSuccess(RzpGpayUtilMerged.makeExternalSDKPayload(this.apiResponse));
        } else {
            this.rzpInternalCallback.onPaymentSuccess(RzpGpayUtilMerged.makeMergedExternalSDKPayload(this.apiResponse));
        }
    }

    private void handleResultStatusCode(int i) {
        if (i == 405) {
            genericOnPaymentFailure("BAD_REQUEST_ERROR", 1, "There is a problem with merchant's account.");
        } else if (i != 409) {
            genericOnPaymentFailure("BAD_REQUEST_ERROR", 1, "An internal error has occurred");
        } else {
            genericOnPaymentFailure("BAD_REQUEST_ERROR", 1, "There is a problem with your Google Pay account.");
        }
    }

    private void processPaymentResponse(String str) {
        AnalyticsUtil.trackEvent(AnalyticsEvent.GOOGLEPAY_VERIFY_PAYMENT_CALLED);
        if (verifyPaymentResponse(str)) {
            AnalyticsUtil.trackEvent(AnalyticsEvent.GOOGLEPAY_VERIFY_PAYMENT_SUCCESS_CALLED);
            genericOnPaymentSuccess();
        } else {
            AnalyticsUtil.trackEvent(AnalyticsEvent.GOOGLEPAY_VERIFY_PAYMENT_ERROR_CALLED);
            genericOnPaymentFailure("BAD_REQUEST_ERROR", 1, "Payment was not successful.");
        }
    }

    private static boolean verifyPaymentResponse(String str) {
        try {
            return new JSONObject(new JSONObject(new JSONObject(str).getJSONObject("paymentMethodData").getJSONObject("tokenizationData").getString("token")).getString("signedMessage")).getJSONObject("paymentMethodDetails").getString("status").equals("SUCCESS");
        } catch (JSONException unused) {
            AnalyticsUtil.trackEvent(AnalyticsEvent.GOOGLEPAY_VERIFY_PAYMENT_EXCEPTION);
            return false;
        }
    }

    @Override
    public boolean doesHandlePayload(String str, JSONObject jSONObject, Activity activity) {
        if (jSONObject != null) {
            try {
                if (jSONObject.has("method") && jSONObject.getString("method").equalsIgnoreCase("upi") && jSONObject.getString("_[app]").equalsIgnoreCase("com.google.android.apps.nbu.paisa.user")) {
                    return true;
                }
            } catch (JSONException unused) {
            }
        }
        if (jSONObject != null && jSONObject.has("type") && jSONObject.getString("type").equalsIgnoreCase("application")) {
            if (jSONObject.getString("application_name").equalsIgnoreCase("google_pay")) {
                return true;
            }
        }
        return false;
    }

    @Override
    public RzpPluginCompatibilityResponse isCompatible(String str, int i, String str2) {
        if (str.equalsIgnoreCase(BuildConfig.SDK_TYPE) && i > 27) {
            return new RzpPluginCompatibilityResponse(true, null);
        }
        if (!str.equalsIgnoreCase("standard") || i <= 18) {
            return new RzpPluginCompatibilityResponse(false, str.equalsIgnoreCase(BuildConfig.SDK_TYPE) ? "Razorpay's GooglePay plugin requires a min SDK Version 3.8.8 Please update." : str.equalsIgnoreCase("standard") ? "Razorpay's GooglePay plugin requires a min SDK Version 1.5.6 Please update." : "Incompatible Razorpay sdk version. Please update the base sdk");
        }
        return new RzpPluginCompatibilityResponse(true, null);
    }

    @Override
    public void isRegistered(Context context, RzpPluginRegisterCallback rzpPluginRegisterCallback) {
        this.registerCallback = rzpPluginRegisterCallback;
        AnalyticsUtil.trackEvent(AnalyticsEvent.GOOGLEPAY_CHECK_REGISTER_CALLED);
        try {
            this.mPaymentClient = Wallet.getPaymentsClient();
            AnalyticsUtil.trackEvent(AnalyticsEvent.GOOGLEPAY_PAYMENT_IS_REGISTERED_CALLED);
            PaymentsClient paymentsClient = this.mPaymentClient;
            JSONObject isReadyToPayRequest = RzpGpayUtilMerged.getIsReadyToPayRequest();
            Objects.requireNonNull(isReadyToPayRequest);
            this.upiTask = paymentsClient.isReadyToPay(context, JSONObjectInstrumentation.toString(isReadyToPayRequest));
            PaymentsClient paymentsClient2 = this.mPaymentClient;
            JSONObject cardsIsReadyToPayRequest = RzpGpayUtilMerged.getCardsIsReadyToPayRequest();
            Objects.requireNonNull(cardsIsReadyToPayRequest);
            this.cardsTask = paymentsClient2.isReadyToPay(context, JSONObjectInstrumentation.toString(cardsIsReadyToPayRequest));
        } catch (NoSuchAlgorithmException e) {
            AnalyticsUtil.reportError(getClass().getName(), "error:exception", e.getMessage());
        }
        Task<Boolean> task = this.cardsTask;
        Objects.requireNonNull(task);
        task.addOnCompleteListener(this);
        Task<Boolean> task2 = this.upiTask;
        Objects.requireNonNull(task2);
        task2.addOnCompleteListener(this);
    }

    @Override
    public void onActivityResult(String str, int i, int i2, Intent intent) {
        if (i == LOAD_PAYMENT_DATA_REQUEST_CODE) {
            if (i2 == -1) {
                AnalyticsUtil.trackEvent(AnalyticsEvent.GOOGLEPAY_PAYMENT_CALLBACK_SUCCESS);
                processPaymentResponse(WalletUtils.getPaymentDataFromIntent(intent));
            } else if (i2 == 0) {
                AnalyticsUtil.trackEvent(AnalyticsEvent.GOOGLEPAY_PAYMENT_CALLBACK_CANCELLED);
                genericOnPaymentFailure("BAD_REQUEST_ERROR", 0, "Payment canceled.");
            } else {
                if (i2 != 1) {
                    return;
                }
                handleResultStatusCode(intent.getIntExtra("errorCode", 8));
            }
        }
    }

    public void onComplete(@NonNull Task<Boolean> task) {
        boolean booleanValue = ((Boolean) task.getResult()).booleanValue();
        if (!task.equals(this.cardsTask)) {
            BaseUtils.setCompatibleWithGooglePay(booleanValue);
        } else {
            BaseUtils.setIsGpayCardsUpiRegistered(booleanValue);
            this.registerCallback.onResponse(booleanValue);
        }
    }

    @Override
    public void processPayment(String str, HashMap<String, Object> hashMap, Activity activity, RzpInternalCallback rzpInternalCallback) {
    }

    public void setApiResponse(JSONObject jSONObject) {
        this.apiResponse = jSONObject;
    }

    public void setIsUpiOnly(boolean z) {
        this.isUpiOnly = z;
    }

    public void setRzpInternalCallback(RzpInternalCallback rzpInternalCallback) {
        this.rzpInternalCallback = rzpInternalCallback;
    }

    @Override
    public void processPayment(String str, final JSONObject jSONObject, final Activity activity, RzpInternalCallback rzpInternalCallback) {
        try {
            this.rzpInternalCallback = rzpInternalCallback;
            this.mPaymentClient = Wallet.getPaymentsClient();
            if (jSONObject.has("type") && jSONObject.getString("type").equalsIgnoreCase("application")) {
                this.apiResponse = jSONObject;
                JSONObject jSONObject2 = jSONObject.getJSONObject("request").getJSONArray("content").getJSONObject(0);
                try {
                    AnalyticsUtil.trackEvent(AnalyticsEvent.GOOGLEPAY_PROCESS_PAYMENT_CARDS_UPI_CALLED);
                    this.mPaymentClient.loadPaymentData(activity, jSONObject2 == null ? jSONObject2.toString() : JSONObjectInstrumentation.toString(jSONObject2), LOAD_PAYMENT_DATA_REQUEST_CODE);
                    return;
                } catch (Exception e) {
                    AnalyticsUtil.reportError(getClass().getName(), "S0", e.getMessage());
                    genericOnPaymentFailure("BAD_REQUEST", 1, "An internal error has occurred");
                    return;
                }
            }
            if (!jSONObject.has("url_data")) {
                HashMap hashMap = new HashMap();
                hashMap.put("Content-Type", "application/x-www-form-urlencoded");
                Owl.post("https://api.razorpay.com/v1/payments/create/ajax", RzpGpayUtilMerged.makeApiPayload(jSONObject), hashMap, new Callback() {
                    @Override
                    public void run(ResponseObject responseObject) {
                        try {
                            RzpGpayMerged.this.isUpiOnly = true;
                            RzpGpayMerged.this.apiResponse = new JSONObject(responseObject.getResponseResult());
                            JSONObject jSONObject3 = new JSONObject(responseObject.getResponseResult());
                            if (responseObject.getResponseCode() >= 400) {
                                RzpGpayMerged.this.genericOnPaymentFailure("BAD_REQUEST_ERROR", 1, "An error occurred while fetching payment details from API.");
                            }
                            if (jSONObject3.has("error")) {
                                AnalyticsUtil.trackEvent(AnalyticsEvent.GOOGLEPAY_PROCESS_PAYMENT_PAYLOAD_ERROR);
                                RzpGpayMerged.this.genericOnPaymentFailure("BAD_REQUEST_ERROR", 1, JSONObjectInstrumentation.toString(jSONObject3));
                            } else {
                                RzpGpayMerged.this.mPaymentClient.loadPaymentData(activity, RzpGpayUtilMerged.getPaymentRequestData(responseObject.getResponseResult(), jSONObject), RzpGpayMerged.LOAD_PAYMENT_DATA_REQUEST_CODE);
                                AnalyticsUtil.trackEvent(AnalyticsEvent.GOOGLEPAY_PROCESS_PAYMENT_STANDARD_CALLED);
                            }
                        } catch (Exception e2) {
                            AnalyticsUtil.reportError("RzpGpayMerged", "S0", e2.getMessage());
                            RzpGpayMerged.this.genericOnPaymentFailure("BAD_REQUEST_ERROR", 1, "An internal error has occurred.");
                        }
                    }
                });
                return;
            }
            this.isUpiOnly = true;
            try {
                String obj = jSONObject.get("url_data").toString();
                try {
                    this.apiResponse = RzpGpayUtilMerged.getUpiData(obj);
                    AnalyticsUtil.trackEvent(AnalyticsEvent.GOOGLEPAY_PROCESS_PAYMENT_CUSTOMUI_CALLED);
                    this.mPaymentClient.loadPaymentData(activity, RzpGpayUtilMerged.getPaymentRequestData(obj, jSONObject), LOAD_PAYMENT_DATA_REQUEST_CODE);
                    return;
                } catch (Exception unused) {
                    genericOnPaymentFailure("BAD_REQUEST_ERROR", 1, "An internal error has occurred");
                    return;
                }
            } catch (Exception e2) {
                AnalyticsUtil.reportError(getClass().getName(), "error:exception", e2.getMessage());
                genericOnPaymentFailure("BAD_REQUEST_ERROR", 1, "An internal error has occurred");
                return;
            }
        } catch (Exception e3) {
            AnalyticsUtil.reportError(getClass().getName(), "error:exception", e3.getMessage());
            genericOnPaymentFailure("BAD_REQUEST_ERROR", 1, "An internal error has occurred.");
        }
        AnalyticsUtil.reportError(getClass().getName(), "error:exception", e3.getMessage());
        genericOnPaymentFailure("BAD_REQUEST_ERROR", 1, "An internal error has occurred.");
    }

    @Override
    public void isRegistered(Context context) {
        Task task;
        this.mPaymentClient = Wallet.getPaymentsClient();
        AnalyticsUtil.trackEvent(AnalyticsEvent.GOOGLEPAY_CHECK_REGISTER_CALLED);
        Task task2 = null;
        try {
            AnalyticsUtil.trackEvent(AnalyticsEvent.GOOGLEPAY_PAYMENT_IS_REGISTERED_CALLED);
            PaymentsClient paymentsClient = this.mPaymentClient;
            JSONObject isReadyToPayRequest = RzpGpayUtilMerged.getIsReadyToPayRequest();
            Objects.requireNonNull(isReadyToPayRequest);
            task = paymentsClient.isReadyToPay(context, JSONObjectInstrumentation.toString(isReadyToPayRequest));
            try {
                PaymentsClient paymentsClient2 = this.mPaymentClient;
                JSONObject cardsIsReadyToPayRequest = RzpGpayUtilMerged.getCardsIsReadyToPayRequest();
                Objects.requireNonNull(cardsIsReadyToPayRequest);
                task2 = paymentsClient2.isReadyToPay(context, JSONObjectInstrumentation.toString(cardsIsReadyToPayRequest));
            } catch (NoSuchAlgorithmException e) {
                e = e;
                AnalyticsUtil.reportError(getClass().getName(), "error:exception", e.getMessage());
                Objects.requireNonNull(task2);
                task2.addOnCompleteListener(new OnCompleteListener<Boolean>() {
                    public void onComplete(@NonNull Task<Boolean> task3) {
                        BaseUtils.setIsGpayCardsUpiRegistered(((Boolean) task3.getResult()).booleanValue());
                    }
                });
                Objects.requireNonNull(task);
                task.addOnCompleteListener(new OnCompleteListener<Boolean>() {
                    public void onComplete(@NonNull Task<Boolean> task3) {
                        BaseUtils.setCompatibleWithGooglePay(((Boolean) task3.getResult()).booleanValue());
                    }
                });
            }
        } catch (NoSuchAlgorithmException e2) {
            e = e2;
            task = null;
        }
        Objects.requireNonNull(task2);
        task2.addOnCompleteListener(new OnCompleteListener<Boolean>() {
            public void onComplete(@NonNull Task<Boolean> task3) {
                BaseUtils.setIsGpayCardsUpiRegistered(((Boolean) task3.getResult()).booleanValue());
            }
        });
        Objects.requireNonNull(task);
        task.addOnCompleteListener(new OnCompleteListener<Boolean>() {
            public void onComplete(@NonNull Task<Boolean> task3) {
                BaseUtils.setCompatibleWithGooglePay(((Boolean) task3.getResult()).booleanValue());
            }
        });
    }
}