正在查看: Clash Legends v0.0.1 应用的 CheckoutPresenterImpl.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Clash Legends v0.0.1 应用的 CheckoutPresenterImpl.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.razorpay;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.TextUtils;
import android.util.Log;
import android.view.WindowManager;
import android.webkit.WebView;
import androidx.core.app.ActivityCompat;
import com.google.android.gms.auth.api.phone.SmsRetriever;
import com.google.android.gms.auth.api.phone.SmsRetrieverClient;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.tasks.Task;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.payu.custombrowser.util.b;
import com.payu.india.Payu.PayuConstants;
import com.payu.otpassist.utils.Constants;
import com.razorpay.AnalyticsProperty;
import com.razorpay.CheckoutBridge;
import com.razorpay.CheckoutUtils;
import io.card.payment.CreditCard;
import java.net.URL;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import org.json.JSONException;
import org.json.JSONObject;
class CheckoutPresenterImpl implements CheckoutPresenter, CheckoutInteractor {
protected Activity activity;
private AutoReadOtpHelper autoReadOtpHelper;
private String checkoutBody;
private long checkoutLoadStartAt;
CheckoutOptions checkoutOptions;
private String checkoutUrl;
private boolean clearHistory;
private String dashOptions;
private JSONObject dashOptionsJSON;
private Task<Void> loginOtpSmsTask;
String merchantKey;
private long preloadAbortDuration;
private long preloadCompleteDuration;
protected CheckoutView view;
private String checkoutContent = "{}";
private int paymentAttempts = 0;
private boolean isPaymentSuccessful = false;
private boolean isTwoWebViewFlow = false;
private boolean isMagic = false;
private int merchantLogoResourceId = 0;
private boolean isActivityCreated = false;
private boolean sendSmsHash = false;
private String payment_id = null;
private MagicBase magicBase = null;
private BroadcastReceiver otpAutoReadBroadcast = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if ("com.google.android.gms.auth.api.phone.SMS_RETRIEVED".equals(intent.getAction())) {
Bundle extras = intent.getExtras();
Status status = (Status) extras.get("com.google.android.gms.auth.api.phone.EXTRA_STATUS");
switch (status.getStatusCode()) {
case 0:
String message = (String) extras.get("com.google.android.gms.auth.api.phone.EXTRA_SMS_MESSAGE");
Intent smsIntent = new Intent();
smsIntent.putExtra("com.google.android.gms.auth.api.phone.EXTRA_SMS_MESSAGE", message);
CheckoutPresenterImpl.this.onActivityResultReceived(1001, -1, smsIntent);
break;
case CreditCard.EXPIRY_MAX_FUTURE_YEARS:
AnalyticsUtil.trackEvent(AnalyticsEvent.AUTO_READ_OTP_SMS_RETRIEVER_API_TIMEOUT);
break;
}
}
}
};
Queue<String> checkoutMessageQueue = new LinkedList();
private boolean isCheckoutLoaded = false;
interface CheckoutView {
void addJavascriptInterfaceToPrimaryWebview(Object obj, String str);
void checkSmsPermission();
void clearWebViewHistory(int i);
void destroy(int i, String str);
WebView getWebView(int i);
void hideProgressBar();
boolean isWebViewVisible(int i);
void loadData(int i, String str, String str2, String str3);
void loadDataWithBaseURL(int i, String str, String str2, String str3, String str4, String str5);
void loadUrl(int i, String str);
void makeWebViewVisible(int i);
void showProgressBar(int i);
void showToast(String str, int i);
}
public CheckoutPresenterImpl(Activity activity, CheckoutView view) {
this.activity = activity;
this.view = view;
}
@Override
public boolean setOptions(Bundle data, boolean activityRestored) {
this.isActivityCreated = activityRestored;
if (data == null) {
destroyActivity(0, this.activity.getResources().getString(R.string.activity_result_invalid_parameters));
return false;
}
CheckoutOptions checkoutOptions = new CheckoutOptions(data.getString(CheckoutConstants.OPTIONS));
this.checkoutOptions = checkoutOptions;
this.merchantKey = checkoutOptions.getMerchantKey();
this.sendSmsHash = this.checkoutOptions.shouldSendHashForSms();
int i = data.getInt(CheckoutConstants.IMAGE, 0);
this.merchantLogoResourceId = i;
this.checkoutOptions.modifyMerchantOptions(this.activity, i);
this.checkoutBody = data.getString(CheckoutConstants.BODY);
CheckoutUtils.addAddons(this.activity, this.merchantKey);
String checkoutUrlWithOptions = CheckoutUtils.getCheckoutUrlWithOptions(this.checkoutOptions);
this.checkoutUrl = checkoutUrlWithOptions;
if (checkoutUrlWithOptions == null) {
destroyActivity(3, this.activity.getResources().getString(R.string.activity_result_invalid_url));
}
try {
this.dashOptionsJSON = new JSONObject(this.dashOptions);
} catch (Exception e) {
AnalyticsUtil.reportError(e, "critical", e.getLocalizedMessage());
}
if (!activityRestored) {
this.checkoutOptions.logMerchantOptions();
this.dashOptions = CheckoutUtils.getMerchantOptions(this.activity, this.merchantKey);
String framework = data.getString(CheckoutConstants.FRAMEWORK);
if (framework != null) {
AnalyticsUtil.addProperty("framework", new AnalyticsProperty(framework, AnalyticsProperty.Scope.ORDER));
}
String frameworkVersion = data.getString(CheckoutConstants.FRAMEWORK_VERSION);
if (frameworkVersion != null) {
AnalyticsUtil.addProperty("frameworkVersion", new AnalyticsProperty(frameworkVersion, AnalyticsProperty.Scope.ORDER));
}
if (data.getBoolean(CheckoutConstants.DISABLE_FULL_SCREEN, false)) {
CheckoutUtils.disableFullScreenMode(this.activity);
}
if (data.containsKey("PRELOAD_COMPLETE_DURATION")) {
this.preloadCompleteDuration = data.getLong("PRELOAD_COMPLETE_DURATION");
}
if (data.containsKey("PRELOAD_ABORT_DURATION")) {
this.preloadAbortDuration = data.getLong("PRELOAD_ABORT_DURATION");
}
} else {
this.dashOptions = data.getString("DASH_OPTIONS");
if (data.getBoolean(CheckoutConstants.DISABLE_FULL_SCREEN, false)) {
CheckoutUtils.disableFullScreenMode(this.activity);
}
}
return true;
}
@Override
public void onActivityResultReceived(int requestCode, int resultCode, Intent data) {
if (requestCode == 1001) {
if (resultCode == -1) {
AnalyticsUtil.trackEvent(AnalyticsEvent.AUTO_READ_OTP_SMS_RETRIEVER_API_RECEIVED_SMS);
String message = data.getStringExtra("com.google.android.gms.auth.api.phone.EXTRA_SMS_MESSAGE");
if (this.isCheckoutLoaded) {
try {
JSONObject sms = new JSONObject();
sms.put(b.SENDER, "razorpay");
sms.put("message", message);
String lastSms = sms.toString();
String otpMessage = String.format("javascript: OTPElf.elfBridge.setSms(%s)", lastSms);
this.view.loadUrl(1, otpMessage);
AnalyticsUtil.trackEvent(AnalyticsEvent.AUTO_READ_OTP_SMS_RETRIEVER_API_OTP_POPULATION_JS);
return;
} catch (JSONException e) {
AnalyticsUtil.reportError(e, "critical", e.getLocalizedMessage());
e.printStackTrace();
return;
}
}
return;
}
AnalyticsUtil.trackEvent(AnalyticsEvent.AUTO_READ_OTP_SMS_RETRIEVER_API_CONSENT_DECLINED);
return;
}
if (requestCode == 99) {
JSONObject jsonObject = BaseUtils.getJSONFromIntentData(data);
String message2 = String.format("javascript: upiIntentResponse(%s)", jsonObject.toString());
loadResultToWebView(jsonObject, message2);
} else if (requestCode == 20) {
try {
JSONObject jsonObject2 = new JSONObject("{'data':" + resultCode + "}");
jsonObject2.put("provider", "CRED");
String message3 = String.format("javascript:externalAppResponse(%s)", jsonObject2.toString());
loadResultToWebView(jsonObject2, message3);
} catch (JSONException e2) {
AnalyticsUtil.reportError(e2, "critical", e2.getMessage());
}
}
}
private void loadResultToWebView(JSONObject jsonObject, String message) {
Map<String, Object> prop = new HashMap<>();
prop.put("result", jsonObject);
AnalyticsUtil.trackEvent(AnalyticsEvent.NATIVE_INTENT_ONACTIVITY_RESULT, prop);
if (this.isCheckoutLoaded) {
this.view.loadUrl(1, message);
return;
}
if (this.checkoutMessageQueue == null) {
this.checkoutMessageQueue = new LinkedList();
}
this.checkoutMessageQueue.add(message);
}
@Override
public void verifyGPaySdkResponse(String response) {
String str = String.format("javascript: window.externalSDKResponse(%s)", response);
if (this.isCheckoutLoaded) {
this.view.loadUrl(1, str);
return;
}
if (this.checkoutMessageQueue == null) {
this.checkoutMessageQueue = new LinkedList();
}
this.checkoutMessageQueue.add(str);
}
@Override
public CheckoutOptions getCheckoutOptions() {
return this.checkoutOptions;
}
@Override
public void setUpAddOn() {
this.magicBase = new MagicBase(this.activity, this.view.getWebView(2));
}
@Override
public void loadForm(String query) {
if (this.paymentAttempts != 0) {
AnalyticsUtil.postData();
}
int i = this.paymentAttempts + 1;
this.paymentAttempts = i;
AnalyticsUtil.addProperty("payment_attempt", new AnalyticsProperty(i, AnalyticsProperty.Scope.ORDER));
this.clearHistory = true;
String url = (this.checkoutUrl + query).replace(" ", "%20");
String str = this.checkoutBody;
if (str == null || str.isEmpty()) {
this.view.loadUrl(1, url);
} else {
this.view.loadDataWithBaseURL(1, url, this.checkoutBody, "text/html", "UTF-8", null);
}
}
@Override
public void passPrefillToSegment() {
String email = this.checkoutOptions.getPrefilledEmail();
if (!TextUtils.isEmpty(email)) {
AnalyticsUtil.addProperty("email", new AnalyticsProperty(email, AnalyticsProperty.Scope.ORDER));
}
String contact = this.checkoutOptions.getPrefilledContact();
if (!TextUtils.isEmpty(contact)) {
AnalyticsUtil.addProperty(PayuConstants.IFSC_CONTACT, new AnalyticsProperty(contact, AnalyticsProperty.Scope.ORDER));
}
}
@Override
public void handleCardSaving() {
AnalyticsUtil.trackEvent(AnalyticsEvent.CARD_SAVING_START);
CardSaving.fetchDeviceTokenFromOtherAppsIfRequired(this.activity.getApplicationContext());
}
@Override
public void saveInstanceState(Bundle data) {
if (this.merchantLogoResourceId != 0) {
data.putString(CheckoutConstants.OPTIONS, this.checkoutOptions.getOptionsWithoutImage());
data.putInt(CheckoutConstants.IMAGE, this.merchantLogoResourceId);
} else {
data.putString(CheckoutConstants.OPTIONS, this.checkoutOptions.getAsString());
}
data.putString("DASH_OPTIONS", this.dashOptions);
if (this.activity.getIntent() != null) {
data.putBoolean(CheckoutConstants.DISABLE_FULL_SCREEN, this.activity.getIntent().getBooleanExtra(CheckoutConstants.DISABLE_FULL_SCREEN, false));
}
}
@Override
public void setCheckoutLoadStartAt() {
this.checkoutLoadStartAt = System.nanoTime();
}
@Override
public void destroyActivity(int resultCode, String result) {
AnalyticsUtil.addProperty("destroy_resultCode", new AnalyticsProperty(String.valueOf(resultCode), AnalyticsProperty.Scope.ORDER));
AnalyticsUtil.addProperty("destroy_result", new AnalyticsProperty(result, AnalyticsProperty.Scope.ORDER));
AnalyticsUtil.trackEvent(AnalyticsEvent.INTERNAL_DESTROY_METHOD_CALLED);
this.view.destroy(resultCode, result);
}
@Override
public void onCheckoutBackPress() {
AnalyticsUtil.trackEvent(AnalyticsEvent.CHECKOUT_SOFT_BACK_PRESSED);
destroyActivity(0, "" + BaseUtils.getPaymentCancelledResponse(this.payment_id));
}
protected void enableAddon(JSONObject jsonObject) {
try {
if (jsonObject.has("magic")) {
boolean z = jsonObject.getBoolean("magic");
this.isMagic = z;
MagicBase magicBase = this.magicBase;
if (magicBase != null) {
magicBase.setMagicEnabled(z);
}
AnalyticsUtil.addProperty("is_magic", new AnalyticsProperty(this.isMagic, AnalyticsProperty.Scope.PAYMENT));
}
} catch (JSONException e) {
AnalyticsUtil.reportError(e, "critical", e.getLocalizedMessage());
e.printStackTrace();
}
}
@Override
public void invokePopup(final String data) {
this.isTwoWebViewFlow = true;
try {
this.activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
JSONObject jsonObject = new JSONObject(data);
CheckoutPresenterImpl.this.enableAddon(jsonObject);
if (jsonObject.has(FirebaseAnalytics.Param.CONTENT)) {
String content = jsonObject.getString(FirebaseAnalytics.Param.CONTENT);
CheckoutPresenterImpl.this.view.loadDataWithBaseURL(2, "about:blank", content, "text/html", "UTF-8", null);
}
if (jsonObject.has("url")) {
String url = jsonObject.getString("url");
CheckoutPresenterImpl.this.view.loadUrl(2, url);
}
if (jsonObject.has("focus") && !jsonObject.getBoolean("focus")) {
CheckoutPresenterImpl.this.view.makeWebViewVisible(1);
} else {
CheckoutPresenterImpl.this.view.makeWebViewVisible(2);
}
} catch (Exception e) {
AnalyticsUtil.reportError(e, "critical", e.getLocalizedMessage());
e.printStackTrace();
}
AnalyticsUtil.addProperty("two_webview_flow", new AnalyticsProperty(true, AnalyticsProperty.Scope.PAYMENT));
}
});
} catch (Exception e) {
AnalyticsUtil.reportError(e, "critical", e.getLocalizedMessage());
e.printStackTrace();
}
}
@Override
public void fetchCondfig() {
Config.IS_MAGIC_ENABLED = isMagicPresent();
Config.fetchConfig(this.activity, this.merchantKey);
}
@Override
public boolean isMagicPresent() {
return false;
}
@Override
public void onProgressChanges(int webViewType, int progress) {
switch (webViewType) {
case 1:
this.view.showProgressBar(progress);
break;
case 2:
MagicBase magicBase = this.magicBase;
if (magicBase != null && this.isMagic) {
magicBase.onProgressChanged(progress);
break;
}
break;
}
}
@Override
public void onPageStarted(int webViewType, WebView webView, String url) {
switch (webViewType) {
case 1:
CheckoutUtils.showLoader(this.activity);
break;
case 2:
MagicBase magicBase = this.magicBase;
if (magicBase != null && this.isMagic) {
magicBase.onPageStarted(webView, url);
break;
}
break;
}
}
@Override
public void onPageFinished(int webViewType, WebView webView, String url) {
switch (webViewType) {
case 1:
primaryWebviewPageFinished(url, webView);
break;
case 2:
MagicBase magicBase = this.magicBase;
if (magicBase != null && this.isMagic) {
magicBase.onPageFinished(webView, url);
break;
}
break;
}
}
private void sendQueuedMessagesToCheckout() {
Queue<String> queue = this.checkoutMessageQueue;
if (queue != null && !queue.isEmpty()) {
for (String message : this.checkoutMessageQueue) {
this.view.loadUrl(1, message);
}
this.checkoutMessageQueue.clear();
}
}
protected void primaryWebviewPageFinished(String url, WebView webview) {
long pageFinishedAt = System.nanoTime();
CheckoutUtils.dismissLoader();
this.view.hideProgressBar();
BaseUtils.getDeviceParamValues(this.activity, new RzpJSONCallback() {
@Override
public void onResponse(JSONObject response) {
CheckoutPresenterImpl.this.view.loadUrl(1, String.format("javascript: window.getDeviceDetails(%s)", response.toString()));
}
});
if (url.indexOf(this.checkoutUrl) == 0) {
if (this.paymentAttempts == 1) {
this.isCheckoutLoaded = true;
sendQueuedMessagesToCheckout();
Map<String, Object> props = new HashMap<>();
long checkoutLoadDuration = pageFinishedAt - this.checkoutLoadStartAt;
props.put("checkout_load_duration", Long.valueOf(checkoutLoadDuration));
Logger.d("Checkout loaded in " + BaseUtils.nanoTimeToSecondsString(checkoutLoadDuration, 2) + " sec.");
long j = this.preloadCompleteDuration;
if (j > 0) {
props.put("preload_finish_duration", Long.valueOf(j));
Logger.d("Preload was completed in " + BaseUtils.nanoTimeToSecondsString(this.preloadCompleteDuration, 2) + " sec.");
} else {
long j2 = this.preloadAbortDuration;
if (j2 > 0) {
props.put("preload_abort_duration", Long.valueOf(j2));
Logger.d("Preload was aborted in " + BaseUtils.nanoTimeToSecondsString(this.preloadAbortDuration, 2) + " sec.");
}
}
long loadTimeShaved = this.preloadCompleteDuration - checkoutLoadDuration;
if (loadTimeShaved > 0) {
props.put("time_shaved_off", Long.valueOf(loadTimeShaved));
Logger.d("Load time shaved is " + BaseUtils.nanoTimeToSecondsString(loadTimeShaved, 2) + " sec.");
}
AnalyticsUtil.trackEvent(AnalyticsEvent.CHECKOUT_LOADED, props);
}
if (this.clearHistory) {
this.view.clearWebViewHistory(1);
this.clearHistory = false;
}
}
}
@Override
public String getProgressBarColor() {
JSONObject jSONObject;
String color = null;
try {
if (this.checkoutOptions.getAsJson() != null) {
JSONObject optionsJson = this.checkoutOptions.getAsJson();
JSONObject theme = optionsJson.getJSONObject("theme");
String color2 = theme.getString("color");
Color.parseColor(color2);
return color2;
}
throw new Exception("No options defined");
} catch (Exception e) {
try {
jSONObject = this.dashOptionsJSON;
} catch (Exception e2) {
AnalyticsUtil.reportError(e2, "error", e2.getMessage());
}
if (jSONObject != null) {
JSONObject theme2 = jSONObject.getJSONObject("theme");
color = theme2.getString("color");
Color.parseColor(color);
AnalyticsUtil.reportError(e, "error", e.getMessage());
return color;
}
throw new Exception("No dash options defined");
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
}
@Override
public void sendOtpPermissionCallback(final boolean granted) {
this.activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("granted", granted);
CheckoutPresenterImpl.this.view.loadUrl(1, String.format("javascript: otpPermissionCallback(%s)", jsonObject.toString()));
} catch (Exception e) {
AnalyticsUtil.reportError(e, "warning", e.getLocalizedMessage());
}
}
});
}
protected void addOnFlowEnd() {
MagicBase magicBase = this.magicBase;
if (magicBase != null) {
magicBase.paymentFlowEnd();
}
}
@Override
public void cleanUpOnDestroy() {
markPaymentCancelled();
addOnFlowEnd();
RazorpayExceptionHandler.unregister();
}
public void markPaymentCancelled() {
if (this.payment_id == null || this.isPaymentSuccessful) {
return;
}
try {
String auth = BaseUtils.constructBasicAuth(this.merchantKey);
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", "Basic " + auth);
String url = "https://api.razorpay.com/v1/payments/" + this.payment_id + "/cancel?platform=android_sdk";
Logger.d("Sending cancel request");
Owl.get(url, headers, new Callback() {
@Override
public void run(ResponseObject response) {
Logger.d("API Cancel hit: " + response.getResponseResult());
}
});
this.payment_id = null;
} catch (Exception e) {
AnalyticsUtil.reportError(e, "critical", e.getLocalizedMessage());
Logger.d("Exception in cancel req", e);
}
}
@Override
public void backPressed(final Map<String, Object> props) {
AnalyticsUtil.trackEvent(AnalyticsEvent.CHECKOUT_HARD_BACK_PRESSED, props);
if (CheckoutUtils.isCheckoutUrl(this.view.getWebView(1)) && !this.view.isWebViewVisible(2)) {
this.view.loadUrl(1, "javascript: window.backPressed ? window.backPressed('onCheckoutBackPress') : CheckoutBridge.onCheckoutBackPress();");
props.put("in_checkout", "true");
} else if (!Config.getInstance().isBackButtonAlertEnabled()) {
destroyActivity(0, "BackPressed");
} else {
CheckoutUtils.showDialog(this.activity, Config.getInstance().getBackButtonAlertMessage(), Config.getInstance().getBackButtonPositiveText(), Config.getInstance().getBackButtonNegativeText(), new CheckoutUtils.BackButtonDialogCallback() {
@Override
public void onPositiveButtonClick() {
Logger.d("ALERT Don't cancel");
AnalyticsUtil.trackEvent(AnalyticsEvent.ALERT_PAYMENT_CONTINUE, (Map<String, Object>) props);
}
@Override
public void onNegativeButtonClick() {
Logger.d("ALERT Cancel");
AnalyticsUtil.trackEvent(AnalyticsEvent.ALERT_PAYMENT_CANCELLED, (Map<String, Object>) props);
if (!CheckoutPresenterImpl.this.isTwoWebViewFlow) {
CheckoutPresenterImpl.this.handleRetry("");
CheckoutPresenterImpl.this.markPaymentCancelled();
} else {
CheckoutPresenterImpl.this.view.makeWebViewVisible(1);
CheckoutPresenterImpl.this.view.loadUrl(2, "about:blank");
CheckoutPresenterImpl.this.view.loadUrl(1, "javascript: window.onpaymentcancel()");
}
CheckoutPresenterImpl.this.isTwoWebViewFlow = false;
}
});
}
}
@Override
public void onLoad() {
this.activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (CheckoutPresenterImpl.this.checkoutBody == null || CheckoutPresenterImpl.this.checkoutBody.isEmpty()) {
CheckoutPresenterImpl.this.view.loadUrl(1, "javascript: CheckoutBridge.setCheckoutBody(document.documentElement.outerHTML)");
}
CheckoutPresenterImpl.this.view.loadUrl(1, CheckoutPresenterImpl.this.getHandleMessageFormattedString());
CheckoutPresenterImpl.this.view.loadUrl(1, String.format("javascript: CheckoutBridge.sendAnalyticsData({data: %s})", AnalyticsUtil.getAnalyticsDataForCheckout(CheckoutPresenterImpl.this.activity).toString()));
}
});
if (Build.VERSION.SDK_INT >= 29 || ActivityCompat.checkSelfPermission(this.activity, "android.permission.RECEIVE_SMS") != 0) {
if (this.sendSmsHash) {
SmsRetrieverClient smsRetrieverClient = SmsRetriever.getClient(this.activity);
this.loginOtpSmsTask = smsRetrieverClient.startSmsRetriever();
try {
new CountDownTimer(2000L, 1000L) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
try {
if (!CheckoutPresenterImpl.this.loginOtpSmsTask.isSuccessful()) {
CheckoutPresenterImpl.this.startSmsRetrieverForSavedCardsOTP();
} else {
IntentFilter intentFilter = new IntentFilter("com.google.android.gms.auth.api.phone.SMS_RETRIEVED");
CheckoutPresenterImpl.this.activity.registerReceiver(CheckoutPresenterImpl.this.otpAutoReadBroadcast, intentFilter, "com.google.android.gms.auth.api.phone.permission.SEND", null);
}
} catch (AbstractMethodError eab) {
AnalyticsUtil.reportError(eab, "error", eab.getMessage());
CheckoutPresenterImpl.this.startSmsRetrieverForSavedCardsOTP();
} catch (Exception e) {
AnalyticsUtil.reportError(e, "error", e.getMessage());
CheckoutPresenterImpl.this.startSmsRetrieverForSavedCardsOTP();
}
}
}.start();
return;
} catch (Exception e) {
AnalyticsUtil.reportError(e, "error", e.getMessage());
startSmsRetrieverForSavedCardsOTP();
return;
}
}
startSmsRetrieverForSavedCardsOTP();
}
}
public void startSmsRetrieverForSavedCardsOTP() {
this.loginOtpSmsTask = SmsRetriever.getClient(this.activity).startSmsUserConsent((String) null);
this.autoReadOtpHelper = new AutoReadOtpHelper(this.activity);
IntentFilter intentFilter = new IntentFilter("com.google.android.gms.auth.api.phone.SMS_RETRIEVED");
this.activity.registerReceiver(this.autoReadOtpHelper, intentFilter);
}
protected JSONObject getOptionsForHandleMessage() {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("options", this.checkoutOptions.getAsJson());
jsonObject.put("data", this.checkoutContent);
jsonObject.put("id", AnalyticsUtil.getLocalOrderId());
jsonObject.put("key_id", this.merchantKey);
jsonObject.put("externalSDKs", new JSONObject());
if (this.checkoutOptions.shouldSendHashForSms()) {
AppSignatureHelper appSignatureHelper = new AppSignatureHelper(this.activity);
jsonObject.put("sms_hash", appSignatureHelper.getAppSignatures().get(0));
}
jsonObject.put("upi_intents_data", CheckoutUtils.getUpiIntentsDataInJsonArray(this.activity));
jsonObject.put("uri_data", CheckoutUtils.getAppIntentDataInJsonArray(this.activity));
JSONObject metaDataObj = new JSONObject();
metaDataObj.put("openedAt", System.currentTimeMillis());
jsonObject.put("metadata", metaDataObj);
String deviceToken = CardSaving.getDeviceToken(this.activity.getApplicationContext());
if (!TextUtils.isEmpty(deviceToken)) {
jsonObject.put("device_token", deviceToken);
}
jsonObject.put("sdk_popup", true);
jsonObject.put("magic", true);
jsonObject.put("network_type", BaseUtils.getNetworkType(this.activity));
jsonObject.put("activity_recreated", this.isActivityCreated);
} catch (JSONException e) {
AnalyticsUtil.reportError(e, "warning", e.getLocalizedMessage());
}
return jsonObject;
}
public String getHandleMessageFormattedString() {
return String.format("javascript: handleMessage(%s)", getOptionsForHandleMessage().toString());
}
@Override
public void setAppToken(String appToken) {
CardSaving.setAppToken(this.activity, appToken);
}
@Override
public void setDeviceToken(String deviceToken) {
CardSaving.setDeviceToken(this.activity, deviceToken);
}
@Override
public void callNativeIntent(String url, String packageName) {
BaseUtils.startActivityForResult(url, packageName, this.activity);
Map<String, Object> prop = new HashMap<>();
prop.put("url", url == null ? "null" : url);
prop.put(Constants.PACKAGE_NAME, packageName != null ? packageName : "null");
AnalyticsUtil.trackEvent(AnalyticsEvent.NATIVE_INTENT_CALLED, prop);
}
@Override
public void setPaymentID(String id) {
Logger.d("setPaymentID called: " + id);
this.payment_id = id;
AnalyticsUtil.addProperty("payment_id", new AnalyticsProperty(id, AnalyticsProperty.Scope.PAYMENT));
AnalyticsUtil.trackEvent(AnalyticsEvent.PAYMENT_ID_ATTACHED);
}
@Override
public void setCheckoutBody(String body) {
this.checkoutBody = body;
}
@Override
public void setMerchantOptions(String dashOptions) {
this.dashOptions = dashOptions;
try {
this.dashOptionsJSON = new JSONObject(dashOptions);
} catch (Exception e) {
Logger.e("Error parsing merchant dash options JSON", e);
this.dashOptionsJSON = null;
AnalyticsUtil.reportError(e, "critical", e.getMessage());
}
if (this.dashOptionsJSON == null) {
CheckoutUtils.setMerchantOptions(this.activity, this.merchantKey, null);
} else {
CheckoutUtils.setMerchantOptions(this.activity, this.merchantKey, dashOptions);
}
}
protected void addAnalyticsData(JSONObject jsonData) {
AnalyticsUtil.addFilteredPropertiesFromPayload(jsonData);
}
@Override
public void onSubmit(String data) {
if (this.paymentAttempts > 1) {
AnalyticsUtil.refreshPaymentSession();
}
if (this.autoReadOtpHelper != null && this.loginOtpSmsTask.isComplete()) {
try {
this.activity.unregisterReceiver(this.autoReadOtpHelper);
} catch (IllegalArgumentException e) {
AnalyticsUtil.reportError(e, "error", e.getMessage());
}
}
try {
JSONObject jsonData = new JSONObject(data);
this.checkoutContent = data;
addAnalyticsData(jsonData);
savePrefillData(jsonData);
String method = jsonData.getString(FirebaseAnalytics.Param.METHOD);
if (Build.VERSION.SDK_INT < 29 && ActivityCompat.checkSelfPermission(this.activity, "android.permission.RECEIVE_SMS") == 0) {
if (!method.equals("card") && method.equals("wallet")) {
String wallet = jsonData.getString("wallet");
if (this.checkoutOptions.hasExternalWallet(wallet)) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("external_wallet", wallet);
AnalyticsUtil.addProperty("external_wallet", new AnalyticsProperty(wallet, AnalyticsProperty.Scope.ORDER));
AnalyticsUtil.trackEvent(AnalyticsEvent.EXTERNAL_WALLET_SELECTED);
onComplete(jsonObject);
}
}
AnalyticsUtil.trackEvent(AnalyticsEvent.CHECKOUT_SUBMIT);
AnalyticsUtil.postData();
}
if (method.equalsIgnoreCase(PayuConstants.NETBANKING) || method.equalsIgnoreCase("card")) {
Log.d("SMS", "received method as netbanking");
SmsRetriever.getClient(this.activity).startSmsUserConsent((String) null);
Log.d("SMS", "task started successfully");
AutoReadOtpHelper autoReadOtpHelper = new AutoReadOtpHelper(this.activity);
IntentFilter intentFilter = new IntentFilter("com.google.android.gms.auth.api.phone.SMS_RETRIEVED");
this.activity.registerReceiver(autoReadOtpHelper, intentFilter);
AnalyticsUtil.trackEvent(AnalyticsEvent.AUTO_READ_OTP_SMS_RETRIEVER_API_TASK);
}
AnalyticsUtil.trackEvent(AnalyticsEvent.CHECKOUT_SUBMIT);
AnalyticsUtil.postData();
} catch (Exception e2) {
AnalyticsUtil.reportError(e2, "critical", e2.getMessage());
Logger.e("Error in submit", e2);
}
}
protected void onComplete(JSONObject o) {
try {
if (o.has("error")) {
AnalyticsUtil.addProperty("payment_status", new AnalyticsProperty(b.FAIL, AnalyticsProperty.Scope.PAYMENT));
AnalyticsUtil.addProperty("payload", new AnalyticsProperty(o.toString(), AnalyticsProperty.Scope.PAYMENT));
AnalyticsUtil.trackEvent(AnalyticsEvent.CHECKOUT_PAYMENT_COMPLETE);
if (this.isTwoWebViewFlow) {
this.view.makeWebViewVisible(1);
}
onError(o);
} else if (o.has("razorpay_fund_account_id")) {
destroyActivity(1, o.toString());
} else if (o.has("razorpay_payment_id")) {
String payment_id = o.getString("razorpay_payment_id");
this.payment_id = payment_id;
AnalyticsUtil.addProperty("payment_id", new AnalyticsProperty(payment_id, AnalyticsProperty.Scope.PAYMENT));
AnalyticsUtil.addProperty("payment_status", new AnalyticsProperty("success", AnalyticsProperty.Scope.PAYMENT));
AnalyticsUtil.addProperty("payload", new AnalyticsProperty(o.toString(), AnalyticsProperty.Scope.PAYMENT));
AnalyticsUtil.trackEvent(AnalyticsEvent.CHECKOUT_PAYMENT_COMPLETE);
this.isPaymentSuccessful = true;
destroyActivity(1, o.toString());
} else if (o.has("external_wallet")) {
destroyActivity(4, o.toString());
} else {
destroyActivity(0, "Post payment parsing error");
}
} catch (Exception e) {
AnalyticsUtil.reportError(e, "critical", e.getMessage());
destroyActivity(0, e.getMessage());
}
this.isTwoWebViewFlow = false;
}
protected void onError(JSONObject o) {
Activity activity;
Runnable runnable;
if (this.isTwoWebViewFlow) {
String str = String.format("javascript: window.onComplete(%s)", o.toString());
this.view.loadUrl(1, str);
return;
}
String qp = "";
try {
try {
if (o.has("error")) {
qp = "" + (this.checkoutUrl.contains("?") ? "&" : "?");
if (o.get("error") instanceof JSONObject) {
JSONObject error = (JSONObject) o.get("error");
qp = qp + "error=" + error.toString();
}
}
final String errorParam = qp;
activity = this.activity;
runnable = new Runnable() {
@Override
public void run() {
CheckoutPresenterImpl.this.handleRetry(errorParam);
}
};
} catch (Exception e) {
AnalyticsUtil.reportError(e, "critical", e.getMessage());
final String errorParam2 = qp;
activity = this.activity;
runnable = new Runnable() {
@Override
public void run() {
CheckoutPresenterImpl.this.handleRetry(errorParam2);
}
};
}
activity.runOnUiThread(runnable);
} catch (Throwable th) {
final String errorParam3 = qp;
this.activity.runOnUiThread(new Runnable() {
@Override
public void run() {
CheckoutPresenterImpl.this.handleRetry(errorParam3);
}
});
throw th;
}
}
public void handleRetry(String errorParam) {
if (CheckoutUtils.shouldRetryPayment(this.paymentAttempts)) {
helpersReset();
loadForm(errorParam);
} else {
destroyActivity(0, errorParam);
}
}
protected void helpersReset() {
Logger.d("helpersReset called");
}
private void savePrefillData(JSONObject jsonData) {
try {
if (jsonData.has(PayuConstants.IFSC_CONTACT)) {
CheckoutUtils.setUserContact(this.activity, jsonData.getString(PayuConstants.IFSC_CONTACT));
this.checkoutOptions.putPrefill(PayuConstants.IFSC_CONTACT, jsonData.getString(PayuConstants.IFSC_CONTACT));
}
if (jsonData.has("email")) {
CheckoutUtils.setUserEmail(this.activity, jsonData.getString("email"));
this.checkoutOptions.putPrefill("email", jsonData.getString("email"));
}
} catch (JSONException e) {
Logger.e("Error parsing JSON", e);
}
}
@Override
public void onFault(String response) {
destroyActivity(3, response);
}
@Override
public void onComplete(final String response) {
this.activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
JSONObject o = new JSONObject(response);
Logger.d("oncomplete JavascriptInterface");
CheckoutPresenterImpl.this.onComplete(o);
} catch (Exception e) {
AnalyticsUtil.reportError(e, "critical", e.getMessage());
CheckoutPresenterImpl.this.destroyActivity(0, e.getMessage());
}
}
});
}
@Override
public void setDimensions(final int width, final int height) {
if (ResourceUtils.isTablet(this.activity)) {
this.activity.runOnUiThread(new Runnable() {
@Override
public void run() {
WindowManager.LayoutParams params = CheckoutPresenterImpl.this.activity.getWindow().getAttributes();
Logger.d("SetDimensions called");
Logger.d("Height:" + height);
Logger.d("Width:" + width);
params.height = ResourceUtils.dpToPx(CheckoutPresenterImpl.this.activity, height);
params.width = ResourceUtils.dpToPx(CheckoutPresenterImpl.this.activity, width);
CheckoutPresenterImpl.this.activity.getWindow().setAttributes(params);
}
});
}
}
@Override
public void onDismiss() {
destroyActivity(0, BaseUtils.getPaymentCancelledResponse(this.payment_id));
}
@Override
public void onDismiss(String response) {
destroyActivity(0, response);
}
@Override
public void requestExtraAnalyticsData() {
final JSONObject jsonObject = AnalyticsUtil.getExtraAnalyticsPayload();
this.activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
CheckoutPresenterImpl.this.view.loadUrl(1, String.format("javascript: CheckoutBridge.sendExtraAnalyticsData(%s)", jsonObject.toString()));
} catch (Exception e) {
AnalyticsUtil.reportError(e, "warning", e.getLocalizedMessage());
}
}
});
}
@Override
public void onError(String message) {
try {
onError(new JSONObject(message));
} catch (Exception e) {
AnalyticsUtil.reportError(e, "critical", e.getMessage());
this.activity.runOnUiThread(new Runnable() {
@Override
public void run() {
CheckoutPresenterImpl.this.helpersReset();
CheckoutPresenterImpl.this.loadForm("");
}
});
}
}
@Override
public void relay(String data) {
}
@Override
public void requestOtpPermission() {
}
@Override
public void toast(final String message, final int duration) {
this.activity.runOnUiThread(new Runnable() {
@Override
public void run() {
CheckoutPresenterImpl.this.view.showToast(message, duration);
}
});
}
@Override
public void showAlertDialog(final String message, final String negativeButtonText, final String positiveButtonText) {
this.activity.runOnUiThread(new Runnable() {
@Override
public void run() {
CheckoutUtils.showDialog(CheckoutPresenterImpl.this.activity, message, positiveButtonText, negativeButtonText, new CheckoutUtils.BackButtonDialogCallback() {
@Override
public void onPositiveButtonClick() {
CheckoutPresenterImpl.this.view.loadUrl(1, String.format("javascript: CheckoutBridge.isPositiveButtonClicked({isClicked: %s})", true));
}
@Override
public void onNegativeButtonClick() {
CheckoutPresenterImpl.this.view.loadUrl(1, String.format("javascript: CheckoutBridge.isPositiveButtonClicked({isClicked: %s})", false));
}
});
}
});
}
@Override
public void sendDataToWebView(final int webViewType, final String data) {
this.activity.runOnUiThread(new Runnable() {
@Override
public void run() {
switch (webViewType) {
case 1:
CheckoutPresenterImpl.this.view.loadUrl(1, String.format("javascript: handleRelay(%s)", data));
break;
case 2:
String url = String.format("javascript: Magic.handleRelay(%s)", data);
CheckoutPresenterImpl.this.view.loadUrl(2, url);
break;
}
}
});
}
@Override
public void checkSmsPermission() {
this.view.checkSmsPermission();
}
@Override
public void isWebViewSafeOnUI(final int webViewType, final CheckoutBridge.WebViewSafeCheckCallback callback) {
this.activity.runOnUiThread(new Runnable() {
@Override
public void run() {
CheckoutPresenterImpl.this.executeWebViewCallback(webViewType, callback);
}
});
}
public void executeWebViewCallback(int webViewType, CheckoutBridge.WebViewSafeCheckCallback callback) {
WebView webView = webViewType == 1 ? this.view.getWebView(1) : this.view.getWebView(2);
String url = webView.getTag().toString();
try {
URL urlObject = new URL(url);
String host = urlObject.getHost();
if (host != null && host.endsWith("razorpay.com")) {
callback.secure();
} else {
callback.unSecure();
}
} catch (Exception e) {
AnalyticsUtil.reportError(e, "critical", e.getLocalizedMessage());
callback.unSecure();
}
}
@Override
public void isWebViewSafe(int webViewType, CheckoutBridge.WebViewSafeCheckCallback callback) {
executeWebViewCallback(webViewType, callback);
}
@Override
public boolean isUserRegisteredOnUPI(String packageName) {
return BaseUtils.checkUpiRegisteredApp(this.activity, packageName);
}
}