导航菜单

页面标题

页面副标题

Housing v14.7.8 - RazorpayUtils.java 源代码

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

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


package com.razorpay;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import androidx.compose.foundation.text.selection.v0;
import com.newrelic.agent.android.instrumentation.Instrumented;
import com.newrelic.agent.android.instrumentation.JSONObjectInstrumentation;
import com.razorpay.RazorpayUtils;
import com.razorpay.rn.RazorpayModule;
import io.sentry.h4;
import java.util.Iterator;
import java.util.Timer;
import java.util.TimerTask;
import org.json.JSONException;
import org.json.JSONObject;

class RazorpayUtils {

    @Instrumented
    class AnonymousClass2 implements Callback {
        final String val$apiKey;
        final JSONObject val$appResponse;
        final PaymentCompleteInternalCallback val$callback;
        final String val$paymentId;
        final int val$pollCount;

        public AnonymousClass2(PaymentCompleteInternalCallback paymentCompleteInternalCallback, int i, String str, String str2, JSONObject jSONObject) {
            this.val$callback = paymentCompleteInternalCallback;
            this.val$pollCount = i;
            this.val$paymentId = str;
            this.val$apiKey = str2;
            this.val$appResponse = jSONObject;
        }

        public static void lambda$run$0(String str, String str2, int i, PaymentCompleteInternalCallback paymentCompleteInternalCallback, JSONObject jSONObject) {
            RazorpayUtils.pollForPaymentStatus(str, str2, i + 1, paymentCompleteInternalCallback, jSONObject);
        }

        @Override
        public void run(ResponseObject responseObject) {
            String responseResult = responseObject.getResponseResult();
            if (responseResult != null && (responseResult.contains(RazorpayModule.MAP_KEY_RZP_PAYMENT_ID) || responseResult.contains("error"))) {
                this.val$callback.oncomplete(responseObject.getResponseResult());
                return;
            }
            final int i = this.val$pollCount;
            if (i < 12) {
                final String str = this.val$paymentId;
                final String str2 = this.val$apiKey;
                final PaymentCompleteInternalCallback paymentCompleteInternalCallback = this.val$callback;
                final JSONObject jSONObject = this.val$appResponse;
                RazorpayUtils.onTimer(new TimerCallback() {
                    @Override
                    public final void onTimerFinished() {
                        RazorpayUtils.AnonymousClass2.lambda$run$0(str, str2, i, paymentCompleteInternalCallback, jSONObject);
                    }
                });
                return;
            }
            if (this.val$appResponse.has("recurring")) {
                this.val$callback.oncomplete("{\"error\": {\"code\": 0,\"description\": \"The status of your payment is pending. You can either wait or retry to pay successfully\"}}");
                return;
            }
            try {
                String string = this.val$appResponse.getJSONObject("data").getJSONObject("apiResponse").getString(RazorpayModule.MAP_KEY_ERROR_DESC);
                this.val$callback.oncomplete("{\"error\":{\"code\": \"" + this.val$appResponse.getInt("resultCode") + "\", \"description\": \"" + string + "\"}}");
            } catch (JSONException unused) {
                PaymentCompleteInternalCallback paymentCompleteInternalCallback2 = this.val$callback;
                JSONObject jSONObject2 = this.val$appResponse;
                paymentCompleteInternalCallback2.oncomplete(jSONObject2 == null ? jSONObject2.toString() : JSONObjectInstrumentation.toString(jSONObject2));
            }
        }
    }

    interface TimerCallback {
        void onTimerFinished();
    }

    public static String getBankLogoUrl(String str) {
        if (GlobalUrlConfig.instance().getCdnUrl().isEmpty()) {
            StringBuilder sb = new StringBuilder();
            v0.C(Config.getInstance().getBankLogoBaseUrl(), str, ".", sb);
            sb.append(Config.getInstance().getBankLogoExtension());
            return sb.toString();
        }
        return GlobalUrlConfig.instance().getCdnUrl() + "/bank/" + str + "." + Config.getInstance().getBankLogoExtension();
    }

    public static String getCardNetwork(String str) {
        JSONObject cardNetworkTypeRegexJson = Config.getInstance().getCardNetworkTypeRegexJson();
        if (str == null || str.length() < 6) {
            return "unknown";
        }
        Iterator<String> keys = cardNetworkTypeRegexJson.keys();
        while (keys.hasNext()) {
            String next = keys.next();
            try {
            } catch (Exception e) {
                AnalyticsUtil.reportError("RazorpayUtils", "S0", e.getLocalizedMessage());
            }
            if (str.matches(cardNetworkTypeRegexJson.getString(next) + h4.DEFAULT_PROPAGATION_TARGETS)) {
                return next;
            }
        }
        return "unknown";
    }

    public static int getCardNetworkLength(String str) {
        if (!Config.getInstance().getNetworkCardLengthJson().has(str.toLowerCase())) {
            return -1;
        }
        try {
            return Config.getInstance().getNetworkCardLengthJson().getInt(str.toLowerCase());
        } catch (Exception e) {
            AnalyticsUtil.reportError("RazorpayUtils", "error:exception", e.getLocalizedMessage());
            return -1;
        }
    }

    public static String getLastPaymentAmount(Context context) {
        return SharedPreferenceUtil.getPrivatePrefs(context).getString("rzp_last_payment_amount", null);
    }

    public static String getLastPaymentLocalOrderId(Context context) {
        return SharedPreferenceUtil.getPrivatePrefs(context).getString("rzp_last_payment_session_id", null);
    }

    public static long getLastPaymentTimestamp(Context context) {
        return SharedPreferenceUtil.getPrivatePrefs(context).getLong("rzp_last_payment_timestamp", 0L);
    }

    private static String getPaymentCancelUrl(String str, String str2) {
        return a.m("https://api.razorpay.com/v1/payments/", str, "/cancel?key_id=", str2);
    }

    private static String getPaymentStatusUrl(String str, String str2) {
        return a.m("https://api.razorpay.com/v1/payments/", str, "/status?key_id=", str2);
    }

    public static String getWalletLogoUrl(String str) {
        if (GlobalUrlConfig.instance().getCdnUrl().isEmpty()) {
            StringBuilder sb = new StringBuilder();
            v0.C(Config.getInstance().getBankLogoBaseUrl(), str, ".", sb);
            sb.append(Config.getInstance().getBankLogoExtension());
            return sb.toString();
        }
        return GlobalUrlConfig.instance().getCdnUrl() + "/wallet/" + str + "." + Config.getInstance().getBankLogoExtension();
    }

    public static String getWalletSqLogoUrl(String str) {
        if (GlobalUrlConfig.instance().getCdnUrl().isEmpty()) {
            StringBuilder sb = new StringBuilder();
            v0.C(Config.getInstance().getBankLogoBaseUrl(), str, ".", sb);
            sb.append(Config.getInstance().getBankLogoExtension());
            return sb.toString();
        }
        return GlobalUrlConfig.instance().getCdnUrl() + "/wallet-sq/" + str + "." + Config.getInstance().getBankLogoExtension();
    }

    public static void handleCredIntentPaymentResponse(Activity activity, String str, PaymentCompleteInternalCallback paymentCompleteInternalCallback) {
        String value = SharedPreferenceUtil.getValue(activity, RazorpayModule.MAP_KEY_RZP_PAYMENT_ID);
        if (value == null || TextUtils.isEmpty(value)) {
            return;
        }
        pollForPaymentStatus(value, str, 0, paymentCompleteInternalCallback);
    }

    public static void handleGpayFeaturePaymentResponse(JSONObject jSONObject, Activity activity, String str, PaymentCompleteInternalCallback paymentCompleteInternalCallback) {
        String value = SharedPreferenceUtil.getValue(activity, RazorpayModule.MAP_KEY_RZP_PAYMENT_ID);
        if (value == null || TextUtils.isEmpty(value)) {
            return;
        }
        pollForPaymentStatus(value, str, 0, paymentCompleteInternalCallback, jSONObject);
    }

    public static void handleUpiIntentAutoPayPayment(Activity activity, String str, PaymentCompleteInternalCallback paymentCompleteInternalCallback) {
        String value = SharedPreferenceUtil.getValue(activity, RazorpayModule.MAP_KEY_RZP_PAYMENT_ID);
        if (value == null || TextUtils.isEmpty(value)) {
            return;
        }
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("recurring", "1");
            pollForPaymentStatus(value, str, 0, paymentCompleteInternalCallback, jSONObject);
        } catch (JSONException unused) {
            pollForPaymentStatus(value, str, 0, paymentCompleteInternalCallback);
        }
    }

    public static void handleUpiIntentPaymentWhenActivityDestroyed(JSONObject jSONObject, Activity activity, String str, PaymentCompleteInternalCallback paymentCompleteInternalCallback) {
        JSONObject jSONObject2;
        String value = SharedPreferenceUtil.getValue(activity, RazorpayModule.MAP_KEY_RZP_PAYMENT_ID);
        if (value == null || TextUtils.isEmpty(value)) {
            return;
        }
        String optString = jSONObject.optString("txnId");
        try {
            jSONObject2 = jSONObject.getJSONObject("data").getJSONObject("apiResponse").getJSONObject("request");
        } catch (JSONException unused) {
            jSONObject2 = null;
        }
        if (!TextUtils.isEmpty(optString)) {
            pollForPaymentStatus(value, str, 0, paymentCompleteInternalCallback);
        } else if (jSONObject2 == null || !jSONObject2.has("url")) {
            markPaymentCancelAndPollForPaymentStatus(value, str, paymentCompleteInternalCallback);
        } else {
            pollForPaymentStatus(value, str, 0, paymentCompleteInternalCallback, jSONObject);
        }
    }

    public static boolean isValidCardNumber(String str) {
        int length = str.length();
        int[] iArr = new int[length];
        for (int i = 0; i < str.length(); i++) {
            Character valueOf = Character.valueOf(str.charAt(i));
            StringBuilder sb = new StringBuilder();
            sb.append(valueOf);
            iArr[i] = Integer.parseInt(sb.toString());
        }
        int i2 = 0;
        for (int i3 = 0; i3 < length; i3++) {
            int i4 = iArr[(length - i3) - 1];
            if (i3 % 2 == 1) {
                i4 <<= 1;
            }
            if (i4 > 9) {
                i4 -= 9;
            }
            i2 += i4;
        }
        return i2 % 10 == 0;
    }

    private static void markPaymentCancelAndPollForPaymentStatus(final String str, final String str2, final PaymentCompleteInternalCallback paymentCompleteInternalCallback) {
        Owl.get(getPaymentCancelUrl(str, str2), new Callback() {
            @Override
            public void run(ResponseObject responseObject) {
                RazorpayUtils.pollForPaymentStatus(str, str2, 0, paymentCompleteInternalCallback);
            }
        });
    }

    public static void onTimer(final TimerCallback timerCallback) {
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                TimerCallback.this.onTimerFinished();
            }
        }, 500L);
    }

    public static void pollForPaymentStatus(String str, String str2, int i, PaymentCompleteInternalCallback paymentCompleteInternalCallback, JSONObject jSONObject) {
        Owl.get(getPaymentStatusUrl(str, str2), new AnonymousClass2(paymentCompleteInternalCallback, i, str, str2, jSONObject));
    }

    public static String sanitize(String str) {
        StringBuilder sb = new StringBuilder();
        int length = str.length();
        for (int i = 0; i < length; i++) {
            char charAt = str.charAt(i);
            if (charAt == '\f') {
                sb.append("\\f");
            } else if (charAt == '\r') {
                sb.append("\\r");
            } else if (charAt != '\"' && charAt != '\\') {
                switch (charAt) {
                    case '\b':
                        sb.append("\\b");
                        break;
                    case '\t':
                        sb.append("\\t");
                        break;
                    case '\n':
                        sb.append("\\n");
                        break;
                    default:
                        if (charAt <= 31) {
                            sb.append(String.format("\\u%04x", Integer.valueOf(charAt)));
                            break;
                        } else {
                            sb.append(charAt);
                            break;
                        }
                }
            } else {
                sb.append('\\');
                sb.append(charAt);
            }
        }
        return sb.toString();
    }

    public static void setLastPaymentAmount(Context context, String str) {
        SharedPreferenceUtil.getPrivateEditor(context).putString("rzp_last_payment_amount", str).apply();
    }

    public static void setLastPaymentLocalOrderId(Context context, String str) {
        SharedPreferenceUtil.getPrivateEditor(context).putString("rzp_last_payment_session_id", str).apply();
    }

    public static void setLastPaymentSuccessful(Context context, boolean z) {
        SharedPreferenceUtil.getPrivateEditor(context).putBoolean("rzp_last_payment_status", z).apply();
    }

    public static void setLastPaymentTimestamp(Context context, long j) {
        SharedPreferenceUtil.getPrivateEditor(context).putLong("rzp_last_payment_timestamp", j).apply();
    }

    public static boolean wasLastPaymentSuccessful(Context context) {
        return SharedPreferenceUtil.getPrivatePrefs(context).getBoolean("rzp_last_payment_status", false);
    }

    public static void pollForPaymentStatus(final String str, final String str2, final int i, final PaymentCompleteInternalCallback paymentCompleteInternalCallback) {
        Owl.get(getPaymentStatusUrl(str, str2), new Callback() {
            @Override
            public void run(ResponseObject responseObject) {
                String responseResult = responseObject.getResponseResult();
                if (responseResult != null && (responseResult.contains(RazorpayModule.MAP_KEY_RZP_PAYMENT_ID) || responseResult.contains("error"))) {
                    PaymentCompleteInternalCallback.this.oncomplete(responseObject.getResponseResult());
                } else if (i < 12) {
                    new Timer().schedule(new TimerTask() {
                        @Override
                        public void run() {
                            AnonymousClass3 anonymousClass3 = AnonymousClass3.this;
                            RazorpayUtils.pollForPaymentStatus(str, str2, i + 1, PaymentCompleteInternalCallback.this);
                        }
                    }, 500L);
                } else {
                    PaymentCompleteInternalCallback.this.oncomplete(responseResult);
                }
            }
        });
    }
}