Advertisement
Guest User

Untitled

a guest
May 24th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.94 KB | None | 0 0
  1. package com.unlitechsolutions.upsmobileapp.controller.remittance;
  2.  
  3. import android.content.DialogInterface;
  4. import android.content.Intent;
  5. import android.support.design.widget.TextInputLayout;
  6. import android.support.v7.app.AlertDialog;
  7. import android.text.Html;
  8. import android.view.LayoutInflater;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.EditText;
  12. import android.widget.TextView;
  13.  
  14. import com.unlitechsolutions.upsmobileapp.Mainmenu;
  15. import com.unlitechsolutions.upsmobileapp.R;
  16. import com.unlitechsolutions.upsmobileapp.data.AppInfo;
  17. import com.unlitechsolutions.upsmobileapp.data.JSONFlag;
  18. import com.unlitechsolutions.upsmobileapp.data.Message;
  19. import com.unlitechsolutions.upsmobileapp.data.Title;
  20. import com.unlitechsolutions.upsmobileapp.data.User;
  21. import com.unlitechsolutions.upsmobileapp.data.database.Data;
  22. import com.unlitechsolutions.upsmobileapp.model.RemittanceModel;
  23. import com.unlitechsolutions.upsmobileapp.model.UserModel;
  24. import com.unlitechsolutions.upsmobileapp.view.RemittanceView;
  25.  
  26. import org.json.JSONException;
  27. import org.json.JSONObject;
  28.  
  29. import java.io.UnsupportedEncodingException;
  30. import java.security.NoSuchAlgorithmException;
  31.  
  32. import UnlitechDevFramework.src.ud.framework.data.Response;
  33. import UnlitechDevFramework.src.ud.framework.data.enums.Status;
  34. import UnlitechDevFramework.src.ud.framework.utilities.StringUtil;
  35. import UnlitechDevFramework.src.ud.framework.utilities.ViewUtil;
  36. import UnlitechDevFramework.src.ud.framework.webservice.data.WebServiceInfo;
  37.  
  38. /**
  39. * Created by Em on 6/24/2016.
  40. */
  41. public class SmartMoneySendController extends RemittanceController {
  42. private View dialogView, verificationView;
  43. AlertDialog registrationDialog, verificationDialog;
  44. private int REQUEST_TYPE = 1;
  45. String transId;
  46. TextInputLayout tlCode;
  47. EditText code;
  48. private String TRACKINGNO = "";
  49.  
  50. public SmartMoneySendController(RemittanceView view, RemittanceModel model) {
  51. super(view, model);
  52. }
  53.  
  54. @Override
  55. protected boolean isValid(int type) {
  56. boolean result = true;
  57. String message = "This field is required.";
  58. RemittanceView.RemittanceHolder holder = mView.getCredentials(1);
  59. if (holder.sender_id.getText().toString().equals("")) {
  60. mView.showError(Title.ECASHPADALA, Message.SENDER_REQUIRED, null);
  61. result = false;
  62. } else if (holder.bene_id.getText().toString().equals("")) {
  63. mView.showError(Title.ECASHPADALA, Message.BENE_REQUIRED, null);
  64. result = false;
  65. } else if (holder.sender_id.getText().toString().equals(holder.bene_id.getText().toString())) {
  66. mView.showError(Title.ECASHPADALA, Message.SENDER_BENE_MUST_NOT_BE_THE_SAME, null);
  67. result = false;
  68. } else if (ViewUtil.isEmpty(holder.smartmoneyno)) {
  69. holder.tl_smartmoneyno.setError(message);
  70. result = false;
  71. } else if (holder.smartmoneyno.getText().toString().replaceAll("-", "").length() != 16) {
  72. holder.tl_smartmoneyno.setError("Invalid Smartmoney Number.");
  73. result = false;
  74. } else if (ViewUtil.isEmpty(holder.idtype)) {
  75. holder.tl_idtype.setError(message);
  76. result = false;
  77. } else if (ViewUtil.isEmpty(holder.idno)) {
  78. holder.tl_idno.setError(message);
  79. result = false;
  80. } else if (ViewUtil.isEmpty(holder.amount)) {
  81. holder.tl_amount.setError(message);
  82. result = false;
  83. } else if (ViewUtil.isEmpty(holder.tpass)) {
  84. holder.tl_tpass.setError(message);
  85. result = false;
  86. }
  87. return result;
  88. }
  89.  
  90. public void submit() {
  91. User user = new UserModel().getCurrentUser(mView.getContext());
  92. if (user.getRemitSmartMoneySend().equals("0")) {
  93. mView.showError(Title.UPS, Message.MSG_UPGRADE_ACCOUNT, new DialogInterface.OnDismissListener() {
  94. @Override
  95. public void onDismiss(DialogInterface dialogInterface) {
  96. Intent intent = new Intent(mView.getActivity(), Mainmenu.class);
  97. mView.getActivity().startActivity(intent);
  98. mView.getActivity().finish();
  99. }
  100. });
  101. } else {
  102. RemittanceView.RemittanceHolder holder = mView.getCredentials(1);
  103. holder.tl_smartmoneyno.setError(null);
  104. holder.tl_idno.setError(null);
  105. holder.tl_idtype.setError(null);
  106. holder.tl_amount.setError(null);
  107. holder.tl_tpass.setError(null);
  108. if (isValid(1)) {
  109. requestRate();
  110. }
  111. }
  112. }
  113.  
  114. private void requestRate() {
  115. try {
  116. User user = new UserModel().getCurrentUser(mView.getContext());
  117. WebServiceInfo wsInfo = new WebServiceInfo(AppInfo.getBaseUrl());
  118. wsInfo.addParam(AppInfo.ACTION_ID, new Data().getValue(AppInfo.ECASH_TO_SMARTMONEY_URL));
  119. wsInfo.addParam(AppInfo.DEVICE_ID, AppInfo.getDeviceID(mView.getActivity()));
  120. RemittanceView.RemittanceHolder holder = mView.getCredentials(1);
  121. String amount = holder.amount.getText().toString();
  122. String tpass = holder.tpass.getText().toString();
  123. wsInfo.addParam(RemittanceModel.BENEFICIARY_FULLNAME, holder.bene_fullanme.getText().toString());
  124. wsInfo.addParam(RemittanceModel.SMARTMONEYNO, holder.smartmoneyno.getText().toString().replaceAll("-", ""));
  125. wsInfo.addParam(RemittanceModel.AMOUNT, amount);
  126. wsInfo.addParam(RemittanceModel.TRANSPASS, tpass);
  127. wsInfo.addParam(RemittanceModel.REGCODE, user.getRegCode());
  128. wsInfo.addParam(user.getSkt(), StringUtil.md5(user.getRegCode() + user.getSkt() + StringUtil.md5(tpass)));
  129.  
  130. if (user.getRegCode().equals("")) {
  131. mView.showError(Title.UNIFIED, Message.RELOGIN, null);
  132. } else {
  133. mModel.sendRequestWithProgressbar(mView.getContext(), wsInfo, Title.SMARTMONEYSEND, 3);
  134. }
  135.  
  136. } catch (Exception e) {
  137. e.printStackTrace();
  138. mView.showError(Title.ECASHPADALA, e.getMessage(), null);
  139.  
  140. }
  141. }
  142.  
  143. public void processReponse(Response response, int type) {
  144. System.out.println("Response: " + response.getResponse());
  145. try {
  146. if (response.getStatus() == Status.SUCCESS) {
  147. JSONObject jo = new JSONObject(response.getResponse());
  148. if (jo.getInt(JSONFlag.STATUS) == JSONFlag.SUCCESS) {
  149. RemittanceView.RemittanceHolder holder3 = mView.getCredentials(1);
  150. holder3.mAlertDialog.dismiss();
  151. switch (type) {
  152. case 3:
  153. String charge = jo.getString(JSONFlag.CHARGE);
  154. showRate(charge);
  155. break;
  156. case 4:
  157. transId = jo.getString(JSONFlag.TRANS_NO);
  158. TRACKINGNO = transId;
  159. mView.showError(Title.ECASHPADALA, jo.getString(JSONFlag.MESSAGE) + " \nTRANSACTION NUMBER: " + transId, new DialogInterface.OnDismissListener() {
  160. @Override
  161. public void onDismiss(DialogInterface dialog) {
  162. mView.getActivity().onBackPressed();
  163. }
  164. });
  165. break;
  166. case 5:
  167. //check status
  168. String refno = jo.getString(JSONFlag.REF_NO);
  169. mView.showError(Title.ECASHPADALA, jo.getString(JSONFlag.MESSAGE) + " \nREFERENCE NUMBER: " + refno, new DialogInterface.OnDismissListener() {
  170. @Override
  171. public void onDismiss(DialogInterface dialog) {
  172. Intent intent = new Intent(mView.getActivity(), Mainmenu.class);
  173. mView.getActivity().startActivity(intent);
  174. verificationDialog.dismiss();
  175. }
  176. });
  177. break;
  178. case 6:
  179. //otp
  180. transId = jo.getString(JSONFlag.TRANS_NO);
  181. TRACKINGNO = transId;
  182. mView.showError(Title.ECASHPADALA, jo.getString(JSONFlag.MESSAGE) + " \nTRANSACTION NUMBER: " + transId, new DialogInterface.OnDismissListener() {
  183. @Override
  184. public void onDismiss(DialogInterface dialog) {
  185. verificationDialog.dismiss();
  186. Intent intent = new Intent(mView.getActivity(), Mainmenu.class);
  187. mView.getActivity().startActivity(intent);
  188.  
  189. }
  190. });
  191. break;
  192. case 7:
  193. //resend otp
  194. mView.showError(Title.ECASHPADALA, jo.getString(JSONFlag.MESSAGE), null);
  195. break;
  196. }
  197. } else if (type == 4 && jo.getInt(JSONFlag.STATUS) == 25) {
  198. TRACKINGNO = jo.getString(JSONFlag.TRANS_NO);
  199. showVerification(jo.getString(JSONFlag.MESSAGE), 2);
  200. } else if (type == 5 && jo.getInt(JSONFlag.STATUS) == 25) {
  201. showVerification(jo.getString(JSONFlag.MESSAGE), 1);
  202. } else {
  203. // if(jo.getString(JSONFlag.MESSAGE).equals("NO MATCH FOUND")){
  204. // showRegistrationOption(jo.getString(JSONFlag.MESSAGE));
  205. // }
  206. // else
  207. mView.showError(Title.ECASHPADALA, jo.getString(JSONFlag.MESSAGE), null);
  208. }
  209. } else {
  210. mView.showError(Title.ECASHPADALA, Message.ERROR, null);
  211. }
  212. } catch (RuntimeException e) {
  213. mView.showError(Title.ECASHPADALA, Message.RUNTIME_ERROR, null);
  214. e.printStackTrace();
  215. } catch (JSONException e) {
  216. mView.showError(Title.ECASHPADALA, Message.JSON_ERROR, null);
  217. e.printStackTrace();
  218. }
  219. }
  220.  
  221. private void showVerification(String message, int request_type) {
  222. REQUEST_TYPE = request_type;
  223. AlertDialog.Builder builder = new AlertDialog.Builder(mView.getActivity(), R.style.AppCompatAlertDialogStyle);
  224. LayoutInflater inflater = mView.getActivity().getLayoutInflater();
  225. verificationView = inflater.inflate(R.layout.remittance_smartmoney_verify, null);
  226. builder.setView(verificationView);
  227. builder.setPositiveButton("VERIFY", null);
  228. builder.setNegativeButton("CANCEL", null);
  229. TextView note = (TextView) verificationView.findViewById(R.id.tv_note);
  230. TextView trackno = (TextView) verificationView.findViewById(R.id.tv_tracking);
  231. TextView resend = (TextView) verificationView.findViewById(R.id.tv_resend);
  232. trackno.setText(Html.fromHtml("<b>*TRACKING NO:</b>" + TRACKINGNO));
  233. note.setText(Html.fromHtml("<b>*NOTE:</b>" + message));
  234. tlCode = (TextInputLayout) verificationView.findViewById(R.id.tl_code);
  235. code = (EditText) verificationView.findViewById(R.id.et_code);
  236. note.setText(message);
  237. resend.setOnClickListener(new View.OnClickListener() {
  238. @Override
  239. public void onClick(View v) {
  240. resendActivationCode();
  241. }
  242. });
  243. verificationDialog = builder.create();
  244. verificationDialog.setOnShowListener(new DialogInterface.OnShowListener() {
  245.  
  246. @Override
  247. public void onShow(DialogInterface dialog) {
  248.  
  249. Button b = verificationDialog.getButton(AlertDialog.BUTTON_POSITIVE);
  250. b.setOnClickListener(new View.OnClickListener() {
  251.  
  252. @Override
  253. public void onClick(View view) {
  254. // TODO Do something
  255. tlCode.setError(null);
  256. if (ViewUtil.isEmpty(code)) {
  257. tlCode.setError("Please input verification code. ");
  258. } else
  259. sendVerification(code.getText().toString(), REQUEST_TYPE);
  260. }
  261. });
  262. }
  263. });
  264. verificationDialog.show();
  265. }
  266.  
  267. protected void resendActivationCode() {
  268. // TODO Auto-generated method stub
  269. try {
  270. User user = new UserModel().getCurrentUser(mView.getContext());
  271. WebServiceInfo wsInfo = new WebServiceInfo(new Data().getValue(AppInfo.RESEND_CODE_URL));
  272. wsInfo.addParam(AppInfo.DEVICE_ID, AppInfo.getDeviceID(mView.getActivity()));
  273. wsInfo.addParam(RemittanceModel.REGCODE, user.getRegCode());
  274. mModel.sendRequestWithProgressbar(mView.getContext(), wsInfo, Title.SMARTMONEYSEND, 7);
  275. } catch (Exception e) {
  276. e.printStackTrace();
  277. }
  278. }
  279.  
  280. protected void sendVerification(String code, int type) {
  281. // TODO Auto-generated method stub
  282. try {
  283. User user = new UserModel().getCurrentUser(mView.getContext());
  284. WebServiceInfo wsInfo = new WebServiceInfo(AppInfo.getBaseUrl());
  285. wsInfo.addParam(AppInfo.ACTION_ID, new Data().getValue(AppInfo.SMARTMONEY_VERIFICATION));
  286. wsInfo.addParam(AppInfo.DEVICE_ID, AppInfo.getDeviceID(mView.getActivity()));
  287. wsInfo.addParam(RemittanceModel.REGCODE, user.getRegCode());
  288. wsInfo.addParam("vericode", code);
  289. wsInfo.addParam("trackno", TRACKINGNO);
  290. wsInfo.addParam(user.getSkt(), StringUtil.md5(user.getRegCode().concat(user.getSkt())));
  291. mModel.sendRequestWithProgressbar(mView.getContext(), wsInfo, Title.SMARTMONEYSEND, 6);
  292. } catch (UnsupportedEncodingException e) {
  293. e.printStackTrace();
  294. } catch (NoSuchAlgorithmException e) {
  295. e.printStackTrace();
  296. }
  297. }
  298.  
  299. private void showRate(String charge) {
  300. AlertDialog.Builder builder = new AlertDialog.Builder(mView.getActivity(), R.style.AppCompatAlertDialogStyle);
  301. LayoutInflater inflater = mView.getActivity().getLayoutInflater();
  302. dialogView = inflater.inflate(R.layout.remittance_smartmoneysend_confirm, null);
  303. builder.setView(dialogView);
  304. builder.setPositiveButton("CONFIRM", null);
  305. builder.setNegativeButton("CANCEL", null);
  306. TextView sendername = (TextView) dialogView.findViewById(R.id.tv_sender_name);
  307. TextView sendermobile = (TextView) dialogView.findViewById(R.id.tv_sender_mobile);
  308. TextView benename = (TextView) dialogView.findViewById(R.id.tv_bene_name);
  309. TextView benemobile = (TextView) dialogView.findViewById(R.id.tv_bene_mobile);
  310. TextView amount = (TextView) dialogView.findViewById(R.id.tv_amount);
  311. TextView smartmoneyno = (TextView) dialogView.findViewById(R.id.tv_smartmoneyno);
  312. TextView tv_charge = (TextView) dialogView.findViewById(R.id.tv_charge);
  313. TextView tv_total = (TextView) dialogView.findViewById(R.id.tv_total);
  314. RemittanceView.RemittanceHolder holder = mView.getCredentials(1);
  315. sendername.setText(holder.sender_fullanme.getText().toString());
  316. sendermobile.setText(holder.sender_mobile.getText().toString());
  317. benename.setText(holder.bene_fullanme.getText().toString());
  318. benemobile.setText(holder.bene_mobile.getText().toString());
  319. smartmoneyno.setText(holder.smartmoneyno.getText().toString());
  320. amount.setText("P" + holder.amount.getText().toString());
  321. Double total = Double.valueOf(holder.amount.getText().toString()) + Double.valueOf(charge);
  322. tv_charge.setText("P" + charge);
  323. tv_total.setText("P" + total);
  324. registrationDialog = builder.create();
  325. registrationDialog.setOnShowListener(new DialogInterface.OnShowListener() {
  326.  
  327. @Override
  328. public void onShow(DialogInterface dialog) {
  329.  
  330. Button b = registrationDialog.getButton(AlertDialog.BUTTON_POSITIVE);
  331. b.setOnClickListener(new View.OnClickListener() {
  332.  
  333. @Override
  334. public void onClick(View view) {
  335. // TODO Do something
  336. sendRequest();
  337. }
  338. });
  339. }
  340. });
  341. registrationDialog.show();
  342. }
  343.  
  344. private void sendRequest() {
  345. try {
  346. RemittanceView.RemittanceHolder holder = mView.getCredentials(1);
  347.  
  348. User user = new UserModel().getCurrentUser(mView.getContext());
  349. // send data to smartmoney URL
  350. WebServiceInfo wsInfo = new WebServiceInfo(AppInfo.getBaseUrl());
  351. wsInfo.addParam(AppInfo.ACTION_ID, new Data().getValue(AppInfo.ECASH_TO_SMARTMONEY_URL2));
  352. wsInfo.addParam(AppInfo.DEVICE_ID, AppInfo.getDeviceID(mView.getActivity()));
  353. String sender_loyalty = holder.sender_id.getText().toString();
  354. String beneficiary_loyalty = holder.bene_id.getText().toString();
  355. String smartmoneyNo = holder.smartmoneyno.getText().toString();
  356. smartmoneyNo.replaceAll("-", "");
  357. String idtype = holder.idtype.getText().toString();
  358. String idno = holder.idno.getText().toString();
  359. String amount = holder.amount.getText().toString();
  360. String tpass = holder.tpass.getText().toString();
  361.  
  362. wsInfo.addParam(RemittanceModel.REGCODE, user.getRegCode());
  363. wsInfo.addParam(RemittanceModel.SMARTMONEYNO, smartmoneyNo.replaceAll("-", ""));
  364. wsInfo.addParam(RemittanceModel.SENDER_LOYALTYID, sender_loyalty);
  365. wsInfo.addParam(RemittanceModel.BENEFICIARY_LOYALTYID, beneficiary_loyalty);
  366. wsInfo.addParam(RemittanceModel.IDTYPE, idtype);
  367. wsInfo.addParam(RemittanceModel.IDNO, idno);
  368. wsInfo.addParam(RemittanceModel.AMOUNT, amount);
  369. wsInfo.addParam(RemittanceModel.TRANSPASS, tpass);
  370. wsInfo.addParam(user.getSkt(), StringUtil.md5(user.getRegCode() + user.getSkt() + StringUtil.md5(tpass)));
  371.  
  372. if (user.getRegCode().equals("")) {
  373. mView.showError(Title.UNIFIED, Message.RELOGIN, null);
  374. } else {
  375. mModel.sendRequestWithProgressbar(mView.getContext(), wsInfo, Title.SMARTMONEYSEND, 4);
  376. }
  377. } catch (Exception e) {
  378. e.printStackTrace();
  379. mView.showError(Title.SMARTMONEYSEND, Message.REQUEST_ERROR, null);
  380. }
  381. }
  382.  
  383. public void checkReference(String trackno) {
  384. TRACKINGNO = trackno;
  385. try {
  386. User user = new UserModel().getCurrentUser(mView.getContext());
  387. WebServiceInfo wsInfo = new WebServiceInfo(AppInfo.getBaseUrl());
  388. wsInfo.addParam(AppInfo.ACTION_ID, new Data().getValue(AppInfo.CHECKREF_URL));
  389. wsInfo.addParam(AppInfo.DEVICE_ID, AppInfo.getDeviceID(mView.getActivity()));
  390. wsInfo.addParam(RemittanceModel.REGCODE, user.getRegCode());
  391. wsInfo.addParam(RemittanceModel.TRACKING_NO, trackno);
  392. if (user.getRegCode().equals("")) {
  393. mView.showError(Title.UNIFIED, Message.RELOGIN, null);
  394. } else {
  395. mModel.sendRequestWithProgressbar(mView.getContext(), wsInfo, Title.SMARTMONEYSEND, 5);
  396. }
  397.  
  398. } catch (Exception e) {
  399. e.printStackTrace();
  400. mView.showError(Title.SMARTMONEYSEND, Message.REQUEST_ERROR, null);
  401. }
  402. }
  403. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement