Advertisement
vergepuppeter

IpayActivity

May 31st, 2019
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 20.39 KB | None | 0 0
  1. package my.app.trendcell.com.jayagrocer.Utils;
  2.  
  3. /**
  4.  * Created by Developer on 25/09/2017.
  5.  */
  6.  
  7. import android.app.Activity;
  8. import android.app.AlertDialog;
  9. import android.app.AlertDialog.Builder;
  10. import android.content.Context;
  11. import android.content.DialogInterface;
  12. import android.content.DialogInterface.OnClickListener;
  13. import android.content.Intent;
  14. import android.content.pm.PackageInfo;
  15. import android.content.pm.PackageManager;
  16. import android.content.pm.PackageManager.NameNotFoundException;
  17. import android.net.http.SslError;
  18. import android.net.wifi.WifiInfo;
  19. import android.net.wifi.WifiManager;
  20. import android.os.Bundle;
  21. import android.os.Message;
  22. import android.provider.Settings.Secure;
  23. import android.support.annotation.Keep;
  24. import android.telephony.TelephonyManager;
  25. import android.view.MotionEvent;
  26. import android.view.View;
  27. import android.view.View.OnTouchListener;
  28. import android.view.ViewGroup.LayoutParams;
  29. import android.webkit.CookieManager;
  30. import android.webkit.CookieSyncManager;
  31. import android.webkit.JavascriptInterface;
  32. import android.webkit.JsResult;
  33. import android.webkit.SslErrorHandler;
  34. import android.webkit.WebChromeClient;
  35. import android.webkit.WebSettings.PluginState;
  36. import android.webkit.WebView;
  37. import android.webkit.WebView.WebViewTransport;
  38. import android.webkit.WebViewClient;
  39. import android.widget.LinearLayout;
  40. import android.widget.Toast;
  41.  
  42. import com.ipay.DESProcessor;
  43. import com.ipay.IpayPayment;
  44. import com.ipay.IpayResultDelegate;
  45. import com.ipay.utils.IPaySDKAppUtils;
  46.  
  47. import org.apache.http.util.EncodingUtils;
  48.  
  49. import java.lang.reflect.Method;
  50.  
  51. public class IpayActivity extends Activity {
  52.     private static final String CLASSNAME_SYSTEM_PROPERTIES = "android.os.SystemProperties";
  53.     public static Ipay _ipay;
  54.     public static final String STATUS_CODE = "status_code";
  55.     public final static int STATUS_OK = 1;
  56.     public final static int STATUS_FAILED = 2;
  57.     public final static int STATUS_CANCELED = 0;
  58.     private IpayResultDelegate ipayResult;
  59.     private String RefNo = "";
  60.     private String Amount = "";
  61.     private String Remark = "";
  62.     private String TransId = "";
  63.     private String AuthCode = "";
  64.     private String Status = "";
  65.     private String ErrDesc = "";
  66.  
  67.     public IpayActivity() {}
  68.  
  69.     protected final void onCreate(Bundle savedInstanceState) {
  70.         super.onCreate(savedInstanceState);
  71.         CookieSyncManager.createInstance(this);
  72.         CookieManager cookieManager = CookieManager.getInstance();
  73.         cookieManager.removeAllCookie();
  74.         String installerStoreName = this.getPackageManager().getInstallerPackageName(this.getPackageName());
  75.         String imeistring = null;
  76.         String imsistring = null;
  77.         //TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
  78.         //imeistring = telephonyManager.getDeviceId();
  79.         // = telephonyManager.getSubscriberId();
  80.         String ANDROID_ID = Secure.getString(this.getContentResolver(), "android_id");
  81.         String serialnum = null;
  82.         String serialnum2 = null;
  83.         String macAddress = null;
  84.         String Line1 = null;
  85.         String SimSerial = null;
  86.  
  87.         try {
  88.             Class ll = Class.forName("android.os.SystemProperties");
  89.             Method webview = ll.getMethod("get", new Class[]{String.class, String.class});
  90.             serialnum = (String)((String)webview.invoke(ll, new Object[]{"ro.serialno", "unknown"}));
  91.             Class activity = Class.forName("android.os.SystemProperties");
  92.             Method[] postString = activity.getMethods();
  93.             Object[] ipaypayment = new Object[]{new String("ro.serialno"), new String("Unknown")};
  94.             serialnum2 = (String)((String)postString[2].invoke(activity, ipaypayment));
  95.             WifiManager pname = (WifiManager)this.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
  96.             WifiInfo pvcode = pname.getConnectionInfo();
  97.             macAddress = pvcode.getMacAddress();
  98. //            Line1 = telephonyManager.getLine1Number();
  99. //            SimSerial = telephonyManager.getSimSerialNumber();
  100.         } catch (Exception var29) {
  101.             var29.printStackTrace();
  102.         }
  103.  
  104.         LinearLayout ll1 = new LinearLayout(this);
  105.         ll1.setOrientation(LinearLayout.VERTICAL);
  106.         ll1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
  107.         final WebView webview1 = new WebView(this);
  108.         webview1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
  109.         webview1.setId(IPaySDKAppUtils.generateViewId());
  110.         webview1.setInitialScale(0);
  111.         webview1.getSettings().setPluginState(PluginState.ON);
  112.         webview1.getSettings().setJavaScriptEnabled(true);
  113.         webview1.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
  114.         webview1.getSettings().setSupportMultipleWindows(true);
  115.         webview1.setWebChromeClient(new WebChromeClient() {
  116.             public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, Message resultMsg) {
  117.                 final WebView childView = new WebView(IpayActivity.this);
  118.                 childView.setInitialScale(0);
  119.                 childView.setId(IPaySDKAppUtils.generateViewId());
  120.                 childView.getSettings().setJavaScriptEnabled(true);
  121.                 childView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
  122.                 childView.getSettings().setSupportMultipleWindows(true);
  123.                 childView.setWebChromeClient(new WebChromeClient() {
  124.                     WebView childView2 = null;
  125.  
  126.                     public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, Message resultMsg) {
  127.                         this.childView2 = new WebView(IpayActivity.this);
  128.                         this.childView2.setInitialScale(0);
  129.                         this.childView2.setId(IPaySDKAppUtils.generateViewId());
  130.                         this.childView2.getSettings().setJavaScriptEnabled(true);
  131.                         this.childView2.setWebChromeClient(this);
  132.                         this.childView2.setWebViewClient(new WebViewClient());
  133.                         this.childView2.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
  134.                         childView.addView(this.childView2);
  135.                         WebViewTransport transport = (WebViewTransport)resultMsg.obj;
  136.                         transport.setWebView(this.childView2);
  137.                         this.childView2.requestFocus(130);
  138.                         this.childView2.setOnTouchListener(new OnTouchListener() {
  139.                             public boolean onTouch(View v, MotionEvent event) {
  140.                                 switch(event.getAction()) {
  141.                                     case 0:
  142.                                     case 1:
  143.                                         if(!v.hasFocus()) {
  144.                                             v.requestFocus();
  145.                                         }
  146.                                     default:
  147.                                         return false;
  148.                                 }
  149.                             }
  150.                         });
  151.                         resultMsg.sendToTarget();
  152.                         return true;
  153.                     }
  154.  
  155.                     public void onCloseWindow(WebView window) {
  156.                         if(this.childView2 != null) {
  157.                             childView.removeView(this.childView2);
  158.                         } else {
  159.                             webview1.removeViewAt(webview1.getChildCount() - 1);
  160.                         }
  161.  
  162.                     }
  163.  
  164.                     public void onProgressChanged(WebView view, int progress) {
  165.                         IpayActivity.this.setProgress(progress * 100);
  166.                     }
  167.  
  168.                     public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
  169.                         (new Builder(view.getContext())).setMessage(message).setPositiveButton(android.R.string.ok, new OnClickListener() {
  170.                             public void onClick(DialogInterface dialog, int which) {
  171.                                 result.confirm();
  172.                             }
  173.                         }).setCancelable(false).create().show();
  174.                         return true;
  175.                     }
  176.                 });
  177.                 childView.setWebViewClient(new WebViewClient());
  178.                 childView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
  179.                 webview1.addView(childView);
  180.                 WebViewTransport transport = (WebViewTransport)resultMsg.obj;
  181.                 transport.setWebView(childView);
  182.                 childView.requestFocus(130);
  183.                 childView.setOnTouchListener(new OnTouchListener() {
  184.                     public boolean onTouch(View v, MotionEvent event) {
  185.                         switch(event.getAction()) {
  186.                             case 0:
  187.                             case 1:
  188.                                 if(!v.hasFocus()) {
  189.                                     v.requestFocus();
  190.                                 }
  191.                             default:
  192.                                 return false;
  193.                         }
  194.                     }
  195.                 });
  196.                 resultMsg.sendToTarget();
  197.                 return true;
  198.             }
  199.  
  200.             public void onCloseWindow(WebView window) {
  201.                 webview1.removeViewAt(webview1.getChildCount() - 1);
  202.             }
  203.  
  204.             public void onProgressChanged(WebView view, int progress) {
  205.                 IpayActivity.this.setProgress(progress * 100);
  206.             }
  207.  
  208.             public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
  209.                 (new Builder(view.getContext())).setMessage(message).setPositiveButton(android.R.string.ok, new OnClickListener() {
  210.                     public void onClick(DialogInterface dialog, int which) {
  211.                         result.confirm();
  212.                     }
  213.                 }).setCancelable(false).create().show();
  214.                 return true;
  215.             }
  216.         });
  217.         webview1.setWebViewClient(new WebViewClient() {
  218.             public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
  219.                 Toast.makeText(IpayActivity.this, "Oh no! " + description, Toast.LENGTH_SHORT).show();
  220.             }
  221.  
  222.             public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
  223.                 Builder builder = new Builder(IpayActivity.this);
  224.                 builder.setMessage("SSL Certificate verification failed, do you want continute open this page to process payment");
  225.                 builder.setPositiveButton("Keep getting the untrusted connection", new OnClickListener() {
  226.                     public void onClick(DialogInterface dialog, int which) {
  227.                         handler.proceed();
  228.                     }
  229.                 });
  230.                 builder.setNegativeButton("No", new OnClickListener() {
  231.                     public void onClick(DialogInterface dialog, int which) {
  232.                         handler.cancel();
  233.                         IpayActivity.this.closeWebPaymentUI();
  234.                     }
  235.                 });
  236.                 AlertDialog dialog = builder.create();
  237.                 dialog.show();
  238.             }
  239.         });
  240.         ll1.addView(webview1);
  241.         this.setContentView(ll1);
  242.         String postString1 = "";
  243.         IpayPayment ipaypayment1 = (IpayPayment)this.getIntent().getSerializableExtra("com.ipay.android.IPAY_PAYMENT");
  244.         if(ipaypayment1 != null) {
  245.             postString1 = postString1 + "MerchantCode=" + ipaypayment1.getMerchantCode();
  246.             postString1 = postString1 + "&MerchantKey=" + ipaypayment1.getMerchantKey();
  247.             postString1 = postString1 + "&PaymentId=" + ipaypayment1.getPaymentId();
  248.             postString1 = postString1 + "&RefNo=" + ipaypayment1.getRefNo();
  249.             postString1 = postString1 + "&Amount=" + ipaypayment1.getAmount();
  250.             postString1 = postString1 + "&Currency=" + ipaypayment1.getCurrency();
  251.             postString1 = postString1 + "&ProdDesc=" + ipaypayment1.getProdDesc();
  252.             postString1 = postString1 + "&UserName=" + ipaypayment1.getUserName();
  253.             postString1 = postString1 + "&UserEmail=" + ipaypayment1.getUserEmail();
  254.             postString1 = postString1 + "&UserContact=" + ipaypayment1.getUserContact();
  255.             postString1 = postString1 + "&Remark=" + ipaypayment1.getRemark();
  256.             postString1 = postString1 + "&Lang=" + ipaypayment1.getLang();
  257.             postString1 = postString1 + "&Country=" + ipaypayment1.getCountry();
  258.             postString1 = postString1 + "&BackendURL=" + ipaypayment1.getBackendPostURL();
  259.             if(installerStoreName == null) {
  260.                 installerStoreName = "na";
  261.             }
  262.  
  263.             if(imeistring == null) {
  264.                 imeistring = "na";
  265.             }
  266.  
  267.             if(imsistring == null) {
  268.                 imsistring = "na";
  269.             }
  270.  
  271.             if(ANDROID_ID == null) {
  272.                 ANDROID_ID = "na";
  273.             }
  274.  
  275.             if(serialnum == null) {
  276.                 serialnum = "na";
  277.             }
  278.  
  279.             if(serialnum2 == null) {
  280.                 serialnum2 = "na";
  281.             }
  282.  
  283.             if(macAddress == null) {
  284.                 macAddress = "na";
  285.             }
  286.  
  287.             if(Line1 == null) {
  288.                 Line1 = "na";
  289.             }
  290.  
  291.             if(SimSerial == null) {
  292.                 SimSerial = "na";
  293.             }
  294.  
  295.             if(installerStoreName.trim().equalsIgnoreCase("")) {
  296.                 installerStoreName = "na";
  297.             }
  298.  
  299.             if(imeistring.trim().equalsIgnoreCase("")) {
  300.                 imeistring = "na";
  301.             }
  302.  
  303.             if(imsistring.trim().equalsIgnoreCase("")) {
  304.                 imsistring = "na";
  305.             }
  306.  
  307.             if(ANDROID_ID.trim().equalsIgnoreCase("")) {
  308.                 ANDROID_ID = "na";
  309.             }
  310.  
  311.             if(serialnum.trim().equalsIgnoreCase("")) {
  312.                 serialnum = "na";
  313.             }
  314.  
  315.             if(serialnum2.trim().equalsIgnoreCase("")) {
  316.                 serialnum2 = "na";
  317.             }
  318.  
  319.             if(macAddress.trim().equalsIgnoreCase("")) {
  320.                 macAddress = "na";
  321.             }
  322.  
  323.             if(Line1.trim().equalsIgnoreCase("")) {
  324.                 Line1 = "na";
  325.             }
  326.  
  327.             if(SimSerial.trim().equalsIgnoreCase("")) {
  328.                 SimSerial = "na";
  329.             }
  330.  
  331.             postString1 = postString1 + "&StoreNameStr=" + installerStoreName;
  332.             postString1 = postString1 + "&IMEIStr=" + imeistring;
  333.             postString1 = postString1 + "&IMSIStr=" + imsistring;
  334.             postString1 = postString1 + "&ANDROIDIDStr=" + ANDROID_ID;
  335.             postString1 = postString1 + "&Serial1Str=" + serialnum;
  336.             postString1 = postString1 + "&Serial2Str=" + serialnum2;
  337.             postString1 = postString1 + "&MACStr=" + macAddress;
  338.             postString1 = postString1 + "&Line1Str=" + Line1;
  339.             postString1 = postString1 + "&SimSerialStr=" + SimSerial;
  340.             String pname1 = "";
  341.             String pvcode1 = "";
  342.             String pvname = "";
  343.             PackageManager manager = this.getPackageManager();
  344.  
  345.             try {
  346.                 PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
  347.                 pname1 = info.packageName;
  348.                 pvcode1 = "" + info.versionCode;
  349.                 pvname = info.versionName;
  350.             } catch (NameNotFoundException var28) {
  351.                 var28.printStackTrace();
  352.             }
  353.  
  354.             if(pname1 == null) {
  355.                 pname1 = "na";
  356.             }
  357.  
  358.             if(pvname == null) {
  359.                 pvname = "na";
  360.             }
  361.  
  362.             if(pname1.trim().equalsIgnoreCase("")) {
  363.                 pname1 = "na";
  364.             }
  365.  
  366.             if(pvcode1.trim().equalsIgnoreCase("")) {
  367.                 pvcode1 = "na";
  368.             }
  369.  
  370.             if(pvname.trim().equalsIgnoreCase("")) {
  371.                 pvname = "na";
  372.             }
  373.  
  374.             postString1 = postString1 + "&pname=" + pname1;
  375.             postString1 = postString1 + "&pvcode=" + pvcode1;
  376.             postString1 = postString1 + "&pvname=" + pvname;
  377.             DESProcessor desProcessor = new DESProcessor();
  378.             String en = "";
  379.  
  380.             try {
  381.                 en = DESProcessor.bytesToHex(desProcessor.encrypt(postString1));
  382.             } catch (Exception var27) {
  383.                 var27.printStackTrace();
  384.             }
  385.  
  386.             String platform = "";
  387.             platform = platform + "platform=android&key=" + en;
  388.             byte[] post = EncodingUtils.getBytes(platform, "BASE64");
  389.             webview1.addJavascriptInterface(new IpayActivity.IJavascriptHandler(), "cpjs");
  390.             webview1.clearSslPreferences();
  391.             webview1.postUrl("https://uat-mobile-payment.ipay88.com:8243/PaymentGateway/ipay_mobile_in.jsp", post);
  392.         }
  393.  
  394.     }
  395.  
  396.     private void closeWebPaymentUI() {
  397.         Intent data = new Intent();
  398.         this.setResult(RESULT_OK, data);
  399.         this.finish();
  400.     }
  401.  
  402.     public void setStatus(String text) {
  403.         this.cutText(text);
  404.         Intent data = new Intent();
  405.         data.putExtra("SOMETHING", "EXTRAS");
  406.         this.ipayResult = (IpayResultDelegate)this.getIntent().getSerializableExtra("com.paypal.android.RESULT_DELEGATE");
  407.         if(this.ErrDesc.toLowerCase().indexOf("customer cancel transaction") > -1) {
  408.             this.ipayResult.onPaymentCanceled(this.TransId, this.RefNo, this.Amount, this.Remark, this.ErrDesc);
  409.             data.putExtra(STATUS_CODE, STATUS_CANCELED);
  410.         } else if(this.Status.equalsIgnoreCase("1")) {
  411.             this.ipayResult.onPaymentSucceeded(this.TransId, this.RefNo, this.Amount, this.Remark, this.AuthCode);
  412.             data.putExtra(STATUS_CODE, STATUS_OK);
  413.         } else {
  414.             this.ipayResult.onPaymentFailed(this.TransId, this.RefNo, this.Amount, this.Remark, this.ErrDesc);
  415.             data.putExtra(STATUS_CODE, STATUS_FAILED);
  416.         }
  417.  
  418.         if(this.getParent() == null) {
  419.             this.setResult(RESULT_OK, data);
  420.         } else {
  421.             this.getParent().setResult(RESULT_OK, data);
  422.         }
  423.  
  424.         this.finish();
  425.     }
  426.  
  427.     private void cutText(String text) {
  428.         String[] arra = text.split(";");
  429.  
  430.         for(int i = 0; i < arra.length; ++i) {
  431.             String[] arrb = arra[i].split(":");
  432.             String value = "";
  433.             if(arrb.length > 1) {
  434.                 value = arrb[1];
  435.             }
  436.  
  437.             if(arrb[0].toString().equalsIgnoreCase("RefNo")) {
  438.                 this.RefNo = value;
  439.             } else if(arrb[0].toString().equalsIgnoreCase("Amount")) {
  440.                 this.Amount = value;
  441.             } else if(arrb[0].toString().equalsIgnoreCase("Remark")) {
  442.                 this.Remark = value;
  443.             } else if(arrb[0].toString().equalsIgnoreCase("TransId")) {
  444.                 this.TransId = value;
  445.             } else if(arrb[0].toString().equalsIgnoreCase("AuthCode")) {
  446.                 this.AuthCode = value;
  447.             } else if(arrb[0].toString().equalsIgnoreCase("Status")) {
  448.                 this.Status = value;
  449.             } else if(arrb[0].toString().equalsIgnoreCase("ErrDesc")) {
  450.                 this.ErrDesc = value;
  451.             }
  452.         }
  453.  
  454.     }
  455.  
  456.     public class IJavascriptHandler {
  457.         IJavascriptHandler() {
  458.         }
  459.  
  460.         @JavascriptInterface
  461.         @Keep
  462.         public void sendToAndroid(String text) {
  463.             Toast t = Toast.makeText(IpayActivity.this.getApplicationContext(), text, Toast.LENGTH_LONG);
  464.             t.show();
  465.         }
  466.  
  467.         @JavascriptInterface
  468.         @Keep
  469.         public void ActivateNextScreen(String text) {
  470.             IpayActivity.this.setStatus(text);
  471.         }
  472.     }
  473.  
  474.     @Override
  475.     public void onBackPressed() {
  476.         Intent data = new Intent();
  477.         data.putExtra("SOMETHING", "EXTRAS");
  478.         data.putExtra(STATUS_CODE, -2);
  479.  
  480.         if(this.getParent() == null) {
  481.             this.setResult(RESULT_OK, data);
  482.         } else {
  483.             this.getParent().setResult(RESULT_OK, data);
  484.         }
  485.         finish();
  486.     }
  487. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement