Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.unlitechsolutions.upsmobileapp.controller.remittance;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.support.design.widget.TextInputLayout;
- import android.support.v7.app.AlertDialog;
- import android.text.Html;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import com.unlitechsolutions.upsmobileapp.Mainmenu;
- import com.unlitechsolutions.upsmobileapp.R;
- import com.unlitechsolutions.upsmobileapp.data.AppInfo;
- import com.unlitechsolutions.upsmobileapp.data.JSONFlag;
- import com.unlitechsolutions.upsmobileapp.data.Message;
- import com.unlitechsolutions.upsmobileapp.data.Title;
- import com.unlitechsolutions.upsmobileapp.data.User;
- import com.unlitechsolutions.upsmobileapp.data.database.Data;
- import com.unlitechsolutions.upsmobileapp.model.RemittanceModel;
- import com.unlitechsolutions.upsmobileapp.model.UserModel;
- import com.unlitechsolutions.upsmobileapp.view.RemittanceView;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.io.UnsupportedEncodingException;
- import java.security.NoSuchAlgorithmException;
- import UnlitechDevFramework.src.ud.framework.data.Response;
- import UnlitechDevFramework.src.ud.framework.data.enums.Status;
- import UnlitechDevFramework.src.ud.framework.utilities.StringUtil;
- import UnlitechDevFramework.src.ud.framework.utilities.ViewUtil;
- import UnlitechDevFramework.src.ud.framework.webservice.data.WebServiceInfo;
- /**
- * Created by Em on 6/24/2016.
- */
- public class SmartMoneySendController extends RemittanceController {
- private View dialogView, verificationView;
- AlertDialog registrationDialog, verificationDialog;
- private int REQUEST_TYPE = 1;
- String transId;
- TextInputLayout tlCode;
- EditText code;
- private String TRACKINGNO = "";
- public SmartMoneySendController(RemittanceView view, RemittanceModel model) {
- super(view, model);
- }
- @Override
- protected boolean isValid(int type) {
- boolean result = true;
- String message = "This field is required.";
- RemittanceView.RemittanceHolder holder = mView.getCredentials(1);
- if (holder.sender_id.getText().toString().equals("")) {
- mView.showError(Title.ECASHPADALA, Message.SENDER_REQUIRED, null);
- result = false;
- } else if (holder.bene_id.getText().toString().equals("")) {
- mView.showError(Title.ECASHPADALA, Message.BENE_REQUIRED, null);
- result = false;
- } else if (holder.sender_id.getText().toString().equals(holder.bene_id.getText().toString())) {
- mView.showError(Title.ECASHPADALA, Message.SENDER_BENE_MUST_NOT_BE_THE_SAME, null);
- result = false;
- } else if (ViewUtil.isEmpty(holder.smartmoneyno)) {
- holder.tl_smartmoneyno.setError(message);
- result = false;
- } else if (holder.smartmoneyno.getText().toString().replaceAll("-", "").length() != 16) {
- holder.tl_smartmoneyno.setError("Invalid Smartmoney Number.");
- result = false;
- } else if (ViewUtil.isEmpty(holder.idtype)) {
- holder.tl_idtype.setError(message);
- result = false;
- } else if (ViewUtil.isEmpty(holder.idno)) {
- holder.tl_idno.setError(message);
- result = false;
- } else if (ViewUtil.isEmpty(holder.amount)) {
- holder.tl_amount.setError(message);
- result = false;
- } else if (ViewUtil.isEmpty(holder.tpass)) {
- holder.tl_tpass.setError(message);
- result = false;
- }
- return result;
- }
- public void submit() {
- User user = new UserModel().getCurrentUser(mView.getContext());
- if (user.getRemitSmartMoneySend().equals("0")) {
- mView.showError(Title.UPS, Message.MSG_UPGRADE_ACCOUNT, new DialogInterface.OnDismissListener() {
- @Override
- public void onDismiss(DialogInterface dialogInterface) {
- Intent intent = new Intent(mView.getActivity(), Mainmenu.class);
- mView.getActivity().startActivity(intent);
- mView.getActivity().finish();
- }
- });
- } else {
- RemittanceView.RemittanceHolder holder = mView.getCredentials(1);
- holder.tl_smartmoneyno.setError(null);
- holder.tl_idno.setError(null);
- holder.tl_idtype.setError(null);
- holder.tl_amount.setError(null);
- holder.tl_tpass.setError(null);
- if (isValid(1)) {
- requestRate();
- }
- }
- }
- private void requestRate() {
- try {
- User user = new UserModel().getCurrentUser(mView.getContext());
- WebServiceInfo wsInfo = new WebServiceInfo(AppInfo.getBaseUrl());
- wsInfo.addParam(AppInfo.ACTION_ID, new Data().getValue(AppInfo.ECASH_TO_SMARTMONEY_URL));
- wsInfo.addParam(AppInfo.DEVICE_ID, AppInfo.getDeviceID(mView.getActivity()));
- RemittanceView.RemittanceHolder holder = mView.getCredentials(1);
- String amount = holder.amount.getText().toString();
- String tpass = holder.tpass.getText().toString();
- wsInfo.addParam(RemittanceModel.BENEFICIARY_FULLNAME, holder.bene_fullanme.getText().toString());
- wsInfo.addParam(RemittanceModel.SMARTMONEYNO, holder.smartmoneyno.getText().toString().replaceAll("-", ""));
- wsInfo.addParam(RemittanceModel.AMOUNT, amount);
- wsInfo.addParam(RemittanceModel.TRANSPASS, tpass);
- wsInfo.addParam(RemittanceModel.REGCODE, user.getRegCode());
- wsInfo.addParam(user.getSkt(), StringUtil.md5(user.getRegCode() + user.getSkt() + StringUtil.md5(tpass)));
- if (user.getRegCode().equals("")) {
- mView.showError(Title.UNIFIED, Message.RELOGIN, null);
- } else {
- mModel.sendRequestWithProgressbar(mView.getContext(), wsInfo, Title.SMARTMONEYSEND, 3);
- }
- } catch (Exception e) {
- e.printStackTrace();
- mView.showError(Title.ECASHPADALA, e.getMessage(), null);
- }
- }
- public void processReponse(Response response, int type) {
- System.out.println("Response: " + response.getResponse());
- try {
- if (response.getStatus() == Status.SUCCESS) {
- JSONObject jo = new JSONObject(response.getResponse());
- if (jo.getInt(JSONFlag.STATUS) == JSONFlag.SUCCESS) {
- RemittanceView.RemittanceHolder holder3 = mView.getCredentials(1);
- holder3.mAlertDialog.dismiss();
- switch (type) {
- case 3:
- String charge = jo.getString(JSONFlag.CHARGE);
- showRate(charge);
- break;
- case 4:
- transId = jo.getString(JSONFlag.TRANS_NO);
- TRACKINGNO = transId;
- mView.showError(Title.ECASHPADALA, jo.getString(JSONFlag.MESSAGE) + " \nTRANSACTION NUMBER: " + transId, new DialogInterface.OnDismissListener() {
- @Override
- public void onDismiss(DialogInterface dialog) {
- mView.getActivity().onBackPressed();
- }
- });
- break;
- case 5:
- //check status
- String refno = jo.getString(JSONFlag.REF_NO);
- mView.showError(Title.ECASHPADALA, jo.getString(JSONFlag.MESSAGE) + " \nREFERENCE NUMBER: " + refno, new DialogInterface.OnDismissListener() {
- @Override
- public void onDismiss(DialogInterface dialog) {
- Intent intent = new Intent(mView.getActivity(), Mainmenu.class);
- mView.getActivity().startActivity(intent);
- verificationDialog.dismiss();
- }
- });
- break;
- case 6:
- //otp
- transId = jo.getString(JSONFlag.TRANS_NO);
- TRACKINGNO = transId;
- mView.showError(Title.ECASHPADALA, jo.getString(JSONFlag.MESSAGE) + " \nTRANSACTION NUMBER: " + transId, new DialogInterface.OnDismissListener() {
- @Override
- public void onDismiss(DialogInterface dialog) {
- verificationDialog.dismiss();
- Intent intent = new Intent(mView.getActivity(), Mainmenu.class);
- mView.getActivity().startActivity(intent);
- }
- });
- break;
- case 7:
- //resend otp
- mView.showError(Title.ECASHPADALA, jo.getString(JSONFlag.MESSAGE), null);
- break;
- }
- } else if (type == 4 && jo.getInt(JSONFlag.STATUS) == 25) {
- TRACKINGNO = jo.getString(JSONFlag.TRANS_NO);
- showVerification(jo.getString(JSONFlag.MESSAGE), 2);
- } else if (type == 5 && jo.getInt(JSONFlag.STATUS) == 25) {
- showVerification(jo.getString(JSONFlag.MESSAGE), 1);
- } else {
- // if(jo.getString(JSONFlag.MESSAGE).equals("NO MATCH FOUND")){
- // showRegistrationOption(jo.getString(JSONFlag.MESSAGE));
- // }
- // else
- mView.showError(Title.ECASHPADALA, jo.getString(JSONFlag.MESSAGE), null);
- }
- } else {
- mView.showError(Title.ECASHPADALA, Message.ERROR, null);
- }
- } catch (RuntimeException e) {
- mView.showError(Title.ECASHPADALA, Message.RUNTIME_ERROR, null);
- e.printStackTrace();
- } catch (JSONException e) {
- mView.showError(Title.ECASHPADALA, Message.JSON_ERROR, null);
- e.printStackTrace();
- }
- }
- private void showVerification(String message, int request_type) {
- REQUEST_TYPE = request_type;
- AlertDialog.Builder builder = new AlertDialog.Builder(mView.getActivity(), R.style.AppCompatAlertDialogStyle);
- LayoutInflater inflater = mView.getActivity().getLayoutInflater();
- verificationView = inflater.inflate(R.layout.remittance_smartmoney_verify, null);
- builder.setView(verificationView);
- builder.setPositiveButton("VERIFY", null);
- builder.setNegativeButton("CANCEL", null);
- TextView note = (TextView) verificationView.findViewById(R.id.tv_note);
- TextView trackno = (TextView) verificationView.findViewById(R.id.tv_tracking);
- TextView resend = (TextView) verificationView.findViewById(R.id.tv_resend);
- trackno.setText(Html.fromHtml("<b>*TRACKING NO:</b>" + TRACKINGNO));
- note.setText(Html.fromHtml("<b>*NOTE:</b>" + message));
- tlCode = (TextInputLayout) verificationView.findViewById(R.id.tl_code);
- code = (EditText) verificationView.findViewById(R.id.et_code);
- note.setText(message);
- resend.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- resendActivationCode();
- }
- });
- verificationDialog = builder.create();
- verificationDialog.setOnShowListener(new DialogInterface.OnShowListener() {
- @Override
- public void onShow(DialogInterface dialog) {
- Button b = verificationDialog.getButton(AlertDialog.BUTTON_POSITIVE);
- b.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- // TODO Do something
- tlCode.setError(null);
- if (ViewUtil.isEmpty(code)) {
- tlCode.setError("Please input verification code. ");
- } else
- sendVerification(code.getText().toString(), REQUEST_TYPE);
- }
- });
- }
- });
- verificationDialog.show();
- }
- protected void resendActivationCode() {
- // TODO Auto-generated method stub
- try {
- User user = new UserModel().getCurrentUser(mView.getContext());
- WebServiceInfo wsInfo = new WebServiceInfo(new Data().getValue(AppInfo.RESEND_CODE_URL));
- wsInfo.addParam(AppInfo.DEVICE_ID, AppInfo.getDeviceID(mView.getActivity()));
- wsInfo.addParam(RemittanceModel.REGCODE, user.getRegCode());
- mModel.sendRequestWithProgressbar(mView.getContext(), wsInfo, Title.SMARTMONEYSEND, 7);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- protected void sendVerification(String code, int type) {
- // TODO Auto-generated method stub
- try {
- User user = new UserModel().getCurrentUser(mView.getContext());
- WebServiceInfo wsInfo = new WebServiceInfo(AppInfo.getBaseUrl());
- wsInfo.addParam(AppInfo.ACTION_ID, new Data().getValue(AppInfo.SMARTMONEY_VERIFICATION));
- wsInfo.addParam(AppInfo.DEVICE_ID, AppInfo.getDeviceID(mView.getActivity()));
- wsInfo.addParam(RemittanceModel.REGCODE, user.getRegCode());
- wsInfo.addParam("vericode", code);
- wsInfo.addParam("trackno", TRACKINGNO);
- wsInfo.addParam(user.getSkt(), StringUtil.md5(user.getRegCode().concat(user.getSkt())));
- mModel.sendRequestWithProgressbar(mView.getContext(), wsInfo, Title.SMARTMONEYSEND, 6);
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- }
- }
- private void showRate(String charge) {
- AlertDialog.Builder builder = new AlertDialog.Builder(mView.getActivity(), R.style.AppCompatAlertDialogStyle);
- LayoutInflater inflater = mView.getActivity().getLayoutInflater();
- dialogView = inflater.inflate(R.layout.remittance_smartmoneysend_confirm, null);
- builder.setView(dialogView);
- builder.setPositiveButton("CONFIRM", null);
- builder.setNegativeButton("CANCEL", null);
- TextView sendername = (TextView) dialogView.findViewById(R.id.tv_sender_name);
- TextView sendermobile = (TextView) dialogView.findViewById(R.id.tv_sender_mobile);
- TextView benename = (TextView) dialogView.findViewById(R.id.tv_bene_name);
- TextView benemobile = (TextView) dialogView.findViewById(R.id.tv_bene_mobile);
- TextView amount = (TextView) dialogView.findViewById(R.id.tv_amount);
- TextView smartmoneyno = (TextView) dialogView.findViewById(R.id.tv_smartmoneyno);
- TextView tv_charge = (TextView) dialogView.findViewById(R.id.tv_charge);
- TextView tv_total = (TextView) dialogView.findViewById(R.id.tv_total);
- RemittanceView.RemittanceHolder holder = mView.getCredentials(1);
- sendername.setText(holder.sender_fullanme.getText().toString());
- sendermobile.setText(holder.sender_mobile.getText().toString());
- benename.setText(holder.bene_fullanme.getText().toString());
- benemobile.setText(holder.bene_mobile.getText().toString());
- smartmoneyno.setText(holder.smartmoneyno.getText().toString());
- amount.setText("P" + holder.amount.getText().toString());
- Double total = Double.valueOf(holder.amount.getText().toString()) + Double.valueOf(charge);
- tv_charge.setText("P" + charge);
- tv_total.setText("P" + total);
- registrationDialog = builder.create();
- registrationDialog.setOnShowListener(new DialogInterface.OnShowListener() {
- @Override
- public void onShow(DialogInterface dialog) {
- Button b = registrationDialog.getButton(AlertDialog.BUTTON_POSITIVE);
- b.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- // TODO Do something
- sendRequest();
- }
- });
- }
- });
- registrationDialog.show();
- }
- private void sendRequest() {
- try {
- RemittanceView.RemittanceHolder holder = mView.getCredentials(1);
- User user = new UserModel().getCurrentUser(mView.getContext());
- // send data to smartmoney URL
- WebServiceInfo wsInfo = new WebServiceInfo(AppInfo.getBaseUrl());
- wsInfo.addParam(AppInfo.ACTION_ID, new Data().getValue(AppInfo.ECASH_TO_SMARTMONEY_URL2));
- wsInfo.addParam(AppInfo.DEVICE_ID, AppInfo.getDeviceID(mView.getActivity()));
- String sender_loyalty = holder.sender_id.getText().toString();
- String beneficiary_loyalty = holder.bene_id.getText().toString();
- String smartmoneyNo = holder.smartmoneyno.getText().toString();
- smartmoneyNo.replaceAll("-", "");
- String idtype = holder.idtype.getText().toString();
- String idno = holder.idno.getText().toString();
- String amount = holder.amount.getText().toString();
- String tpass = holder.tpass.getText().toString();
- wsInfo.addParam(RemittanceModel.REGCODE, user.getRegCode());
- wsInfo.addParam(RemittanceModel.SMARTMONEYNO, smartmoneyNo.replaceAll("-", ""));
- wsInfo.addParam(RemittanceModel.SENDER_LOYALTYID, sender_loyalty);
- wsInfo.addParam(RemittanceModel.BENEFICIARY_LOYALTYID, beneficiary_loyalty);
- wsInfo.addParam(RemittanceModel.IDTYPE, idtype);
- wsInfo.addParam(RemittanceModel.IDNO, idno);
- wsInfo.addParam(RemittanceModel.AMOUNT, amount);
- wsInfo.addParam(RemittanceModel.TRANSPASS, tpass);
- wsInfo.addParam(user.getSkt(), StringUtil.md5(user.getRegCode() + user.getSkt() + StringUtil.md5(tpass)));
- if (user.getRegCode().equals("")) {
- mView.showError(Title.UNIFIED, Message.RELOGIN, null);
- } else {
- mModel.sendRequestWithProgressbar(mView.getContext(), wsInfo, Title.SMARTMONEYSEND, 4);
- }
- } catch (Exception e) {
- e.printStackTrace();
- mView.showError(Title.SMARTMONEYSEND, Message.REQUEST_ERROR, null);
- }
- }
- public void checkReference(String trackno) {
- TRACKINGNO = trackno;
- try {
- User user = new UserModel().getCurrentUser(mView.getContext());
- WebServiceInfo wsInfo = new WebServiceInfo(AppInfo.getBaseUrl());
- wsInfo.addParam(AppInfo.ACTION_ID, new Data().getValue(AppInfo.CHECKREF_URL));
- wsInfo.addParam(AppInfo.DEVICE_ID, AppInfo.getDeviceID(mView.getActivity()));
- wsInfo.addParam(RemittanceModel.REGCODE, user.getRegCode());
- wsInfo.addParam(RemittanceModel.TRACKING_NO, trackno);
- if (user.getRegCode().equals("")) {
- mView.showError(Title.UNIFIED, Message.RELOGIN, null);
- } else {
- mModel.sendRequestWithProgressbar(mView.getContext(), wsInfo, Title.SMARTMONEYSEND, 5);
- }
- } catch (Exception e) {
- e.printStackTrace();
- mView.showError(Title.SMARTMONEYSEND, Message.REQUEST_ERROR, null);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement