正在查看: bbinstant v6.24.0 应用的 PaytmPGActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: bbinstant v6.24.0 应用的 PaytmPGActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.paytm.pgsdk;
import android.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.URLUtil;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.Iterator;
import java.util.Scanner;
import javax.net.ssl.HttpsURLConnection;
import org.json.JSONObject;
public class PaytmPGActivity extends Activity {
private static final String CHECKSUMHASH = "CHECKSUMHASH";
private static final String CLIENT_AUTHENTICATION_FAILED = "Client authentication failed. Please try again later.";
private static final String CLIENT_AUTHENTICATION_FAILED_DUE_TO_SERVER_ERROR = "Client authentication failed due to server error. Please try again later.";
private static final String PAYT_STATUS = "payt_STATUS";
private static final String SUCCESS = "1";
private static final String TRANSACTION_CANCELLED = "Transaction Cancelled.";
private static final String TRANSACTION_NOT_CANCELLED = "Transaction not Cancelled.";
private static final String UI_INITIALIZATION_ERROR_OCCURED = "Some error occured while initializing UI of Payment Gateway Activity";
private static final String UI_WEBVIEW_ERROR_OCCURED = "Some UI error occured in WebView of Payment Gateway Activity";
private static final String USER_CANCELED_TRANSACTION = "Transaction cancelled by user.";
private volatile e mAuthenticator;
private Dialog mDlg;
private volatile Bundle mParams;
protected volatile ProgressBar mProgress;
private volatile PaytmWebView mWV;
private boolean mbChecksumGenerated;
private boolean mbHideHeader;
private boolean mbIsCancellingRequest;
private boolean mbSendAllChecksumResponseParametersToPGServer;
class a implements View.OnClickListener {
a() {
}
@Override
public void onClick(View view) {
PaytmUtility.debugLog("User pressed back button which is present in Header Bar.");
PaytmPGActivity.this.cancelTransaction();
}
}
class b implements Runnable {
final String val$inMsg;
b(String str) {
this.val$inMsg = str;
}
@Override
public void run() {
try {
PaytmPGActivity.this.mbIsCancellingRequest = false;
PaytmUtility.debugLog(this.val$inMsg);
Toast.makeText(PaytmPGActivity.this, this.val$inMsg, 0).show();
PaytmUtility.debugLog("User cancelled " + PaytmPGActivity.this.mParams);
PaytmPGService.getService().mPaymentTransactionCallback.onTransactionCancel(PaytmPGActivity.USER_CANCELED_TRANSACTION, PaytmPGActivity.this.mParams);
PaytmUtility.debugLog("user cancellation");
PaytmPGActivity.this.finish();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
class c implements DialogInterface.OnClickListener {
c() {
}
@Override
public void onClick(DialogInterface dialogInterface, int i2) {
PaytmPGActivity.this.onBackPressed();
}
}
class d implements DialogInterface.OnClickListener {
d() {
}
@Override
public void onClick(DialogInterface dialogInterface, int i2) {
PaytmPGActivity.this.mDlg.dismiss();
}
}
private class e extends AsyncTask {
private e() {
}
e(PaytmPGActivity paytmPGActivity, a aVar) {
this();
}
@Override
public synchronized String doInBackground(String... strArr) {
String str;
str = "";
URLConnection uRLConnection = null;
try {
try {
URL url = new URL(strArr[0]);
PaytmUtility.debugLog("URL is " + url.toString());
uRLConnection = url.openConnection();
PaytmUtility.debugLog("New Connection is created.");
if (URLUtil.isHttpsUrl(url.toString())) {
PaytmUtility.debugLog("Https url");
PaytmUtility.debugLog("Setting SSLSocketFactory to connection...");
((HttpsURLConnection) uRLConnection).setSSLSocketFactory(new com.paytm.pgsdk.e(PaytmPGActivity.this, PaytmPGService.getService().mCertificate));
PaytmUtility.debugLog("SSLSocketFactory is set to connection.");
}
uRLConnection.setDoOutput(true);
((HttpURLConnection) uRLConnection).setRequestMethod("POST");
String stringFromBundle = PaytmUtility.getStringFromBundle(PaytmPGActivity.this.mParams);
if (stringFromBundle != null && stringFromBundle.length() > 0) {
PaytmUtility.debugLog("Getting the output stream to post");
PrintWriter printWriter = new PrintWriter(uRLConnection.getOutputStream());
PaytmUtility.debugLog("posting......");
printWriter.print(stringFromBundle);
printWriter.close();
PaytmUtility.debugLog("posted parameters and closing output stream");
int responseCode = ((HttpURLConnection) uRLConnection).getResponseCode();
String responseMessage = ((HttpURLConnection) uRLConnection).getResponseMessage();
PaytmUtility.debugLog("Response code is " + responseCode);
PaytmUtility.debugLog("Response Message is " + responseMessage);
if (responseCode == 200) {
PaytmUtility.debugLog("Getting the input stream to read response");
Scanner scanner = new Scanner(uRLConnection.getInputStream());
PaytmUtility.debugLog("reading......");
while (scanner.hasNextLine()) {
str = str + scanner.nextLine();
}
scanner.close();
PaytmUtility.debugLog("read response and closing input stream");
}
}
} catch (Exception e2) {
PaytmUtility.debugLog("Some exception occurred while making client authentication.");
PaytmUtility.printStackTrace(e2);
}
if (uRLConnection != null) {
try {
((HttpURLConnection) uRLConnection).disconnect();
} catch (Exception e3) {
PaytmUtility.printStackTrace(e3);
}
}
PaytmUtility.debugLog("connection is disconnected");
} catch (Throwable th) {
throw th;
}
return str;
}
@Override
public synchronized void onPostExecute(String str) {
try {
if (str != null) {
try {
} catch (Exception e2) {
PaytmPGActivity.this.finish();
com.paytm.pgsdk.c cVar = PaytmPGService.getService().mPaymentTransactionCallback;
if (cVar != null) {
cVar.someUIErrorOccurred(PaytmPGActivity.UI_WEBVIEW_ERROR_OCCURED);
}
PaytmUtility.debugLog("Some exception occurred while posting data to PG Server.");
PaytmUtility.printStackTrace(e2);
}
if (!str.equalsIgnoreCase("")) {
PaytmUtility.debugLog("Response is " + str);
if (PaytmPGActivity.this.extractJSON(str)) {
PaytmPGActivity.this.mbChecksumGenerated = true;
PaytmPGActivity.this.mWV.setVisibility(0);
PaytmPGActivity.this.mWV.postUrl(PaytmPGService.getService().mPGURL, PaytmUtility.getURLEncodedStringFromBundle(PaytmPGActivity.this.mParams).getBytes());
PaytmPGActivity.this.mWV.requestFocus(130);
} else {
PaytmPGActivity.this.finish();
com.paytm.pgsdk.c cVar2 = PaytmPGService.getService().mPaymentTransactionCallback;
if (cVar2 != null) {
cVar2.clientAuthenticationFailed(PaytmPGActivity.CLIENT_AUTHENTICATION_FAILED);
}
}
}
}
PaytmPGActivity.this.finish();
com.paytm.pgsdk.c cVar3 = PaytmPGService.getService().mPaymentTransactionCallback;
if (cVar3 != null) {
cVar3.clientAuthenticationFailed(PaytmPGActivity.CLIENT_AUTHENTICATION_FAILED_DUE_TO_SERVER_ERROR);
}
} catch (Throwable th) {
throw th;
}
}
}
public synchronized void cancelTransaction() {
if (!this.mbIsCancellingRequest) {
PaytmUtility.debugLog("Displaying Confirmation Dialog");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Cancel Transaction");
builder.setMessage("Are you sure you want to cancel transaction");
builder.setPositiveButton("Yes", new c());
builder.setNegativeButton("No", new d());
AlertDialog create = builder.create();
this.mDlg = create;
create.show();
}
}
private synchronized void displayToastNotification(String str) {
runOnUiThread(new b(str));
}
public synchronized boolean extractJSON(String str) {
boolean z;
z = false;
try {
try {
PaytmUtility.debugLog("Parsing JSON");
JSONObject jSONObject = new JSONObject(str);
Iterator<String> keys = jSONObject.keys();
PaytmUtility.debugLog("Appending Key Value pairs");
PaytmUtility.debugLog("Send All Checksum Response Parameters to PG " + this.mbSendAllChecksumResponseParametersToPGServer);
while (keys.hasNext()) {
String next = keys.next();
String string = jSONObject.getString(next);
String trim = next.trim();
PaytmUtility.debugLog(trim + " = " + string);
if (trim.equals(CHECKSUMHASH)) {
this.mParams.putString(trim, string);
} else if (this.mbSendAllChecksumResponseParametersToPGServer) {
this.mParams.putString(trim, string);
}
if (trim.equals(PAYT_STATUS) && string.equals(SUCCESS)) {
z = true;
}
}
} catch (Exception e2) {
PaytmUtility.debugLog("Some exception occurred while extracting the checksum from CAS Response.");
PaytmUtility.printStackTrace(e2);
}
} catch (Throwable th) {
throw th;
}
return z;
}
private synchronized boolean initUI() {
try {
try {
if (getIntent() != null) {
this.mbHideHeader = getIntent().getBooleanExtra("HIDE_HEADER", false);
this.mbSendAllChecksumResponseParametersToPGServer = getIntent().getBooleanExtra("SEND_ALL_CHECKSUM_RESPONSE_PARAMETERS_TO_PG_SERVER", false);
}
PaytmUtility.debugLog("Hide Header " + this.mbHideHeader);
PaytmUtility.debugLog("Initializing the UI of Transaction Page...");
RelativeLayout relativeLayout = new RelativeLayout(this);
RelativeLayout relativeLayout2 = new RelativeLayout(this);
relativeLayout2.setLayoutParams(new RelativeLayout.LayoutParams(-1, -2));
relativeLayout2.setId(1);
relativeLayout2.setBackgroundColor(Color.parseColor("#bdbdbd"));
Button button = new Button(this, null, R.attr.buttonStyleSmall);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-2, -2);
layoutParams.addRule(15);
layoutParams.leftMargin = (int) (getResources().getDisplayMetrics().density * 5.0f);
button.setOnClickListener(new a());
button.setLayoutParams(layoutParams);
button.setText("Cancel");
TextView textView = new TextView(this);
RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(-2, -2);
layoutParams2.addRule(13);
textView.setLayoutParams(layoutParams2);
textView.setTextColor(-16777216);
textView.setText("Paytm Payments");
relativeLayout2.addView(button);
relativeLayout2.addView(textView);
RelativeLayout relativeLayout3 = new RelativeLayout(this);
RelativeLayout.LayoutParams layoutParams3 = new RelativeLayout.LayoutParams(-1, -1);
layoutParams3.addRule(3, relativeLayout2.getId());
relativeLayout3.setLayoutParams(layoutParams3);
this.mWV = new PaytmWebView(this, this.mParams);
this.mWV.getSettings().setDomStorageEnabled(true);
this.mWV.setVisibility(8);
this.mWV.setLayoutParams(new RelativeLayout.LayoutParams(-1, -1));
this.mProgress = new ProgressBar(this, null, R.attr.progressBarStyleSmall);
RelativeLayout.LayoutParams layoutParams4 = new RelativeLayout.LayoutParams(-2, -2);
layoutParams4.addRule(13);
this.mProgress.setLayoutParams(layoutParams4);
relativeLayout3.addView(this.mWV);
relativeLayout3.addView(this.mProgress);
relativeLayout.addView(relativeLayout2);
relativeLayout.addView(relativeLayout3);
if (this.mbHideHeader) {
relativeLayout2.setVisibility(8);
}
requestWindowFeature(1);
setContentView(relativeLayout);
PaytmUtility.debugLog("Initialized UI of Transaction Page.");
} catch (Exception e2) {
PaytmUtility.debugLog("Some exception occurred while initializing UI.");
PaytmUtility.printStackTrace(e2);
return false;
}
} catch (Throwable th) {
throw th;
}
return true;
}
private synchronized void startTransaction() {
PaytmUtility.debugLog("Starting the Process...");
if (getIntent() != null && getIntent().getBundleExtra("Parameters") != null) {
this.mParams = getIntent().getBundleExtra("Parameters");
if (this.mParams != null && this.mParams.size() > 0) {
PaytmUtility.debugLog("Starting the Client Authentication...");
this.mAuthenticator = new e(this, null);
if (PaytmPGService.getService() != null) {
this.mWV.setVisibility(0);
this.mWV.postUrl(PaytmPGService.getService().mPGURL + "?ORDER_ID=" + PaytmPGService.getService().mOrder.getRequestParamMap().get("ORDER_ID").toString(), PaytmUtility.getURLEncodedStringFromBundle(this.mParams).getBytes());
this.mWV.requestFocus(130);
if (PaytmPGService.getService().mOrder.getRequestParamMap().get("prenotificationurl") != null) {
Intent intent = new Intent(getApplicationContext(), (Class<?>) IntentServicePreNotification.class);
intent.putExtra("url", PaytmPGService.getService().mOrder.getRequestParamMap().get("prenotificationurl"));
getApplicationContext().startService(intent);
}
}
}
}
}
@Override
public void onBackPressed() {
PaytmPGService.getService().mPaymentTransactionCallback.onBackPressedCancelTransaction();
super.onBackPressed();
}
@Override
protected synchronized void onCreate(Bundle bundle) {
try {
super.onCreate(bundle);
if (initUI()) {
startTransaction();
} else {
finish();
com.paytm.pgsdk.c cVar = PaytmPGService.getService().mPaymentTransactionCallback;
if (cVar != null) {
cVar.someUIErrorOccurred(UI_INITIALIZATION_ERROR_OCCURED);
}
}
} catch (Throwable th) {
throw th;
}
}
@Override
protected synchronized void onDestroy() {
try {
super.onDestroy();
try {
if (this.mAuthenticator != null) {
this.mAuthenticator.cancel(true);
}
PaytmPGService.getService().stopService();
} catch (Exception e2) {
PaytmPGService.getService().stopService();
PaytmUtility.debugLog("Some exception occurred while destroying the PaytmPGActivity.");
PaytmUtility.printStackTrace(e2);
}
} catch (Throwable th) {
throw th;
}
}
@Override
public synchronized boolean onKeyDown(int i2, KeyEvent keyEvent) {
try {
PaytmUtility.debugLog("User pressed key and key code is " + i2);
if (i2 == 4) {
PaytmUtility.debugLog("User pressed hard key back button");
cancelTransaction();
}
} catch (Throwable th) {
throw th;
}
return super.onKeyDown(i2, keyEvent);
}
}