Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package my.app.trendcell.com.jayagrocer.Utils;
- /**
- * Created by Developer on 25/09/2017.
- */
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.app.AlertDialog.Builder;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.DialogInterface.OnClickListener;
- import android.content.Intent;
- import android.content.pm.PackageInfo;
- import android.content.pm.PackageManager;
- import android.content.pm.PackageManager.NameNotFoundException;
- import android.net.http.SslError;
- import android.net.wifi.WifiInfo;
- import android.net.wifi.WifiManager;
- import android.os.Bundle;
- import android.os.Message;
- import android.provider.Settings.Secure;
- import android.support.annotation.Keep;
- import android.telephony.TelephonyManager;
- import android.view.MotionEvent;
- import android.view.View;
- import android.view.View.OnTouchListener;
- import android.view.ViewGroup.LayoutParams;
- import android.webkit.CookieManager;
- import android.webkit.CookieSyncManager;
- import android.webkit.JavascriptInterface;
- import android.webkit.JsResult;
- import android.webkit.SslErrorHandler;
- import android.webkit.WebChromeClient;
- import android.webkit.WebSettings.PluginState;
- import android.webkit.WebView;
- import android.webkit.WebView.WebViewTransport;
- import android.webkit.WebViewClient;
- import android.widget.LinearLayout;
- import android.widget.Toast;
- import com.ipay.DESProcessor;
- import com.ipay.IpayPayment;
- import com.ipay.IpayResultDelegate;
- import com.ipay.utils.IPaySDKAppUtils;
- import org.apache.http.util.EncodingUtils;
- import java.lang.reflect.Method;
- public class IpayActivity extends Activity {
- private static final String CLASSNAME_SYSTEM_PROPERTIES = "android.os.SystemProperties";
- public static Ipay _ipay;
- public static final String STATUS_CODE = "status_code";
- public final static int STATUS_OK = 1;
- public final static int STATUS_FAILED = 2;
- public final static int STATUS_CANCELED = 0;
- private IpayResultDelegate ipayResult;
- private String RefNo = "";
- private String Amount = "";
- private String Remark = "";
- private String TransId = "";
- private String AuthCode = "";
- private String Status = "";
- private String ErrDesc = "";
- public IpayActivity() {}
- protected final void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- CookieSyncManager.createInstance(this);
- CookieManager cookieManager = CookieManager.getInstance();
- cookieManager.removeAllCookie();
- String installerStoreName = this.getPackageManager().getInstallerPackageName(this.getPackageName());
- String imeistring = null;
- String imsistring = null;
- //TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
- //imeistring = telephonyManager.getDeviceId();
- // = telephonyManager.getSubscriberId();
- String ANDROID_ID = Secure.getString(this.getContentResolver(), "android_id");
- String serialnum = null;
- String serialnum2 = null;
- String macAddress = null;
- String Line1 = null;
- String SimSerial = null;
- try {
- Class ll = Class.forName("android.os.SystemProperties");
- Method webview = ll.getMethod("get", new Class[]{String.class, String.class});
- serialnum = (String)((String)webview.invoke(ll, new Object[]{"ro.serialno", "unknown"}));
- Class activity = Class.forName("android.os.SystemProperties");
- Method[] postString = activity.getMethods();
- Object[] ipaypayment = new Object[]{new String("ro.serialno"), new String("Unknown")};
- serialnum2 = (String)((String)postString[2].invoke(activity, ipaypayment));
- WifiManager pname = (WifiManager)this.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
- WifiInfo pvcode = pname.getConnectionInfo();
- macAddress = pvcode.getMacAddress();
- // Line1 = telephonyManager.getLine1Number();
- // SimSerial = telephonyManager.getSimSerialNumber();
- } catch (Exception var29) {
- var29.printStackTrace();
- }
- LinearLayout ll1 = new LinearLayout(this);
- ll1.setOrientation(LinearLayout.VERTICAL);
- ll1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
- final WebView webview1 = new WebView(this);
- webview1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
- webview1.setId(IPaySDKAppUtils.generateViewId());
- webview1.setInitialScale(0);
- webview1.getSettings().setPluginState(PluginState.ON);
- webview1.getSettings().setJavaScriptEnabled(true);
- webview1.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
- webview1.getSettings().setSupportMultipleWindows(true);
- webview1.setWebChromeClient(new WebChromeClient() {
- public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, Message resultMsg) {
- final WebView childView = new WebView(IpayActivity.this);
- childView.setInitialScale(0);
- childView.setId(IPaySDKAppUtils.generateViewId());
- childView.getSettings().setJavaScriptEnabled(true);
- childView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
- childView.getSettings().setSupportMultipleWindows(true);
- childView.setWebChromeClient(new WebChromeClient() {
- WebView childView2 = null;
- public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, Message resultMsg) {
- this.childView2 = new WebView(IpayActivity.this);
- this.childView2.setInitialScale(0);
- this.childView2.setId(IPaySDKAppUtils.generateViewId());
- this.childView2.getSettings().setJavaScriptEnabled(true);
- this.childView2.setWebChromeClient(this);
- this.childView2.setWebViewClient(new WebViewClient());
- this.childView2.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
- childView.addView(this.childView2);
- WebViewTransport transport = (WebViewTransport)resultMsg.obj;
- transport.setWebView(this.childView2);
- this.childView2.requestFocus(130);
- this.childView2.setOnTouchListener(new OnTouchListener() {
- public boolean onTouch(View v, MotionEvent event) {
- switch(event.getAction()) {
- case 0:
- case 1:
- if(!v.hasFocus()) {
- v.requestFocus();
- }
- default:
- return false;
- }
- }
- });
- resultMsg.sendToTarget();
- return true;
- }
- public void onCloseWindow(WebView window) {
- if(this.childView2 != null) {
- childView.removeView(this.childView2);
- } else {
- webview1.removeViewAt(webview1.getChildCount() - 1);
- }
- }
- public void onProgressChanged(WebView view, int progress) {
- IpayActivity.this.setProgress(progress * 100);
- }
- public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
- (new Builder(view.getContext())).setMessage(message).setPositiveButton(android.R.string.ok, new OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- result.confirm();
- }
- }).setCancelable(false).create().show();
- return true;
- }
- });
- childView.setWebViewClient(new WebViewClient());
- childView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
- webview1.addView(childView);
- WebViewTransport transport = (WebViewTransport)resultMsg.obj;
- transport.setWebView(childView);
- childView.requestFocus(130);
- childView.setOnTouchListener(new OnTouchListener() {
- public boolean onTouch(View v, MotionEvent event) {
- switch(event.getAction()) {
- case 0:
- case 1:
- if(!v.hasFocus()) {
- v.requestFocus();
- }
- default:
- return false;
- }
- }
- });
- resultMsg.sendToTarget();
- return true;
- }
- public void onCloseWindow(WebView window) {
- webview1.removeViewAt(webview1.getChildCount() - 1);
- }
- public void onProgressChanged(WebView view, int progress) {
- IpayActivity.this.setProgress(progress * 100);
- }
- public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
- (new Builder(view.getContext())).setMessage(message).setPositiveButton(android.R.string.ok, new OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- result.confirm();
- }
- }).setCancelable(false).create().show();
- return true;
- }
- });
- webview1.setWebViewClient(new WebViewClient() {
- public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
- Toast.makeText(IpayActivity.this, "Oh no! " + description, Toast.LENGTH_SHORT).show();
- }
- public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
- Builder builder = new Builder(IpayActivity.this);
- builder.setMessage("SSL Certificate verification failed, do you want continute open this page to process payment");
- builder.setPositiveButton("Keep getting the untrusted connection", new OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- handler.proceed();
- }
- });
- builder.setNegativeButton("No", new OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- handler.cancel();
- IpayActivity.this.closeWebPaymentUI();
- }
- });
- AlertDialog dialog = builder.create();
- dialog.show();
- }
- });
- ll1.addView(webview1);
- this.setContentView(ll1);
- String postString1 = "";
- IpayPayment ipaypayment1 = (IpayPayment)this.getIntent().getSerializableExtra("com.ipay.android.IPAY_PAYMENT");
- if(ipaypayment1 != null) {
- postString1 = postString1 + "MerchantCode=" + ipaypayment1.getMerchantCode();
- postString1 = postString1 + "&MerchantKey=" + ipaypayment1.getMerchantKey();
- postString1 = postString1 + "&PaymentId=" + ipaypayment1.getPaymentId();
- postString1 = postString1 + "&RefNo=" + ipaypayment1.getRefNo();
- postString1 = postString1 + "&Amount=" + ipaypayment1.getAmount();
- postString1 = postString1 + "&Currency=" + ipaypayment1.getCurrency();
- postString1 = postString1 + "&ProdDesc=" + ipaypayment1.getProdDesc();
- postString1 = postString1 + "&UserName=" + ipaypayment1.getUserName();
- postString1 = postString1 + "&UserEmail=" + ipaypayment1.getUserEmail();
- postString1 = postString1 + "&UserContact=" + ipaypayment1.getUserContact();
- postString1 = postString1 + "&Remark=" + ipaypayment1.getRemark();
- postString1 = postString1 + "&Lang=" + ipaypayment1.getLang();
- postString1 = postString1 + "&Country=" + ipaypayment1.getCountry();
- postString1 = postString1 + "&BackendURL=" + ipaypayment1.getBackendPostURL();
- if(installerStoreName == null) {
- installerStoreName = "na";
- }
- if(imeistring == null) {
- imeistring = "na";
- }
- if(imsistring == null) {
- imsistring = "na";
- }
- if(ANDROID_ID == null) {
- ANDROID_ID = "na";
- }
- if(serialnum == null) {
- serialnum = "na";
- }
- if(serialnum2 == null) {
- serialnum2 = "na";
- }
- if(macAddress == null) {
- macAddress = "na";
- }
- if(Line1 == null) {
- Line1 = "na";
- }
- if(SimSerial == null) {
- SimSerial = "na";
- }
- if(installerStoreName.trim().equalsIgnoreCase("")) {
- installerStoreName = "na";
- }
- if(imeistring.trim().equalsIgnoreCase("")) {
- imeistring = "na";
- }
- if(imsistring.trim().equalsIgnoreCase("")) {
- imsistring = "na";
- }
- if(ANDROID_ID.trim().equalsIgnoreCase("")) {
- ANDROID_ID = "na";
- }
- if(serialnum.trim().equalsIgnoreCase("")) {
- serialnum = "na";
- }
- if(serialnum2.trim().equalsIgnoreCase("")) {
- serialnum2 = "na";
- }
- if(macAddress.trim().equalsIgnoreCase("")) {
- macAddress = "na";
- }
- if(Line1.trim().equalsIgnoreCase("")) {
- Line1 = "na";
- }
- if(SimSerial.trim().equalsIgnoreCase("")) {
- SimSerial = "na";
- }
- postString1 = postString1 + "&StoreNameStr=" + installerStoreName;
- postString1 = postString1 + "&IMEIStr=" + imeistring;
- postString1 = postString1 + "&IMSIStr=" + imsistring;
- postString1 = postString1 + "&ANDROIDIDStr=" + ANDROID_ID;
- postString1 = postString1 + "&Serial1Str=" + serialnum;
- postString1 = postString1 + "&Serial2Str=" + serialnum2;
- postString1 = postString1 + "&MACStr=" + macAddress;
- postString1 = postString1 + "&Line1Str=" + Line1;
- postString1 = postString1 + "&SimSerialStr=" + SimSerial;
- String pname1 = "";
- String pvcode1 = "";
- String pvname = "";
- PackageManager manager = this.getPackageManager();
- try {
- PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
- pname1 = info.packageName;
- pvcode1 = "" + info.versionCode;
- pvname = info.versionName;
- } catch (NameNotFoundException var28) {
- var28.printStackTrace();
- }
- if(pname1 == null) {
- pname1 = "na";
- }
- if(pvname == null) {
- pvname = "na";
- }
- if(pname1.trim().equalsIgnoreCase("")) {
- pname1 = "na";
- }
- if(pvcode1.trim().equalsIgnoreCase("")) {
- pvcode1 = "na";
- }
- if(pvname.trim().equalsIgnoreCase("")) {
- pvname = "na";
- }
- postString1 = postString1 + "&pname=" + pname1;
- postString1 = postString1 + "&pvcode=" + pvcode1;
- postString1 = postString1 + "&pvname=" + pvname;
- DESProcessor desProcessor = new DESProcessor();
- String en = "";
- try {
- en = DESProcessor.bytesToHex(desProcessor.encrypt(postString1));
- } catch (Exception var27) {
- var27.printStackTrace();
- }
- String platform = "";
- platform = platform + "platform=android&key=" + en;
- byte[] post = EncodingUtils.getBytes(platform, "BASE64");
- webview1.addJavascriptInterface(new IpayActivity.IJavascriptHandler(), "cpjs");
- webview1.clearSslPreferences();
- webview1.postUrl("https://uat-mobile-payment.ipay88.com:8243/PaymentGateway/ipay_mobile_in.jsp", post);
- }
- }
- private void closeWebPaymentUI() {
- Intent data = new Intent();
- this.setResult(RESULT_OK, data);
- this.finish();
- }
- public void setStatus(String text) {
- this.cutText(text);
- Intent data = new Intent();
- data.putExtra("SOMETHING", "EXTRAS");
- this.ipayResult = (IpayResultDelegate)this.getIntent().getSerializableExtra("com.paypal.android.RESULT_DELEGATE");
- if(this.ErrDesc.toLowerCase().indexOf("customer cancel transaction") > -1) {
- this.ipayResult.onPaymentCanceled(this.TransId, this.RefNo, this.Amount, this.Remark, this.ErrDesc);
- data.putExtra(STATUS_CODE, STATUS_CANCELED);
- } else if(this.Status.equalsIgnoreCase("1")) {
- this.ipayResult.onPaymentSucceeded(this.TransId, this.RefNo, this.Amount, this.Remark, this.AuthCode);
- data.putExtra(STATUS_CODE, STATUS_OK);
- } else {
- this.ipayResult.onPaymentFailed(this.TransId, this.RefNo, this.Amount, this.Remark, this.ErrDesc);
- data.putExtra(STATUS_CODE, STATUS_FAILED);
- }
- if(this.getParent() == null) {
- this.setResult(RESULT_OK, data);
- } else {
- this.getParent().setResult(RESULT_OK, data);
- }
- this.finish();
- }
- private void cutText(String text) {
- String[] arra = text.split(";");
- for(int i = 0; i < arra.length; ++i) {
- String[] arrb = arra[i].split(":");
- String value = "";
- if(arrb.length > 1) {
- value = arrb[1];
- }
- if(arrb[0].toString().equalsIgnoreCase("RefNo")) {
- this.RefNo = value;
- } else if(arrb[0].toString().equalsIgnoreCase("Amount")) {
- this.Amount = value;
- } else if(arrb[0].toString().equalsIgnoreCase("Remark")) {
- this.Remark = value;
- } else if(arrb[0].toString().equalsIgnoreCase("TransId")) {
- this.TransId = value;
- } else if(arrb[0].toString().equalsIgnoreCase("AuthCode")) {
- this.AuthCode = value;
- } else if(arrb[0].toString().equalsIgnoreCase("Status")) {
- this.Status = value;
- } else if(arrb[0].toString().equalsIgnoreCase("ErrDesc")) {
- this.ErrDesc = value;
- }
- }
- }
- public class IJavascriptHandler {
- IJavascriptHandler() {
- }
- @JavascriptInterface
- @Keep
- public void sendToAndroid(String text) {
- Toast t = Toast.makeText(IpayActivity.this.getApplicationContext(), text, Toast.LENGTH_LONG);
- t.show();
- }
- @JavascriptInterface
- @Keep
- public void ActivateNextScreen(String text) {
- IpayActivity.this.setStatus(text);
- }
- }
- @Override
- public void onBackPressed() {
- Intent data = new Intent();
- data.putExtra("SOMETHING", "EXTRAS");
- data.putExtra(STATUS_CODE, -2);
- if(this.getParent() == null) {
- this.setResult(RESULT_OK, data);
- } else {
- this.getParent().setResult(RESULT_OK, data);
- }
- finish();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement