diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 31e1daf3..7d68790c 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/LocalTopUpThrowable.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/LocalTopUpThrowable.java new file mode 100644 index 00000000..08fd10bb --- /dev/null +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/LocalTopUpThrowable.java @@ -0,0 +1,7 @@ +package com.gmeremit.online.gmeremittance_native.topup.local; + +public class LocalTopUpThrowable extends Throwable { + public LocalTopUpThrowable(String message) { + super(message); + } +} diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/model/LocalTopUpTxnRequestBodyDTO.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/model/LocalTopUpTxnRequestBodyDTO.java index 64535503..a9218a83 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/model/LocalTopUpTxnRequestBodyDTO.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/model/LocalTopUpTxnRequestBodyDTO.java @@ -11,9 +11,7 @@ public class LocalTopUpTxnRequestBodyDTO { @SerializedName("CustomerId") @Expose private String customerId; - @SerializedName("OrderNo") - @Expose - private String orderNo; + @SerializedName("ChargeType") @Expose private String chargeType; @@ -46,13 +44,7 @@ public class LocalTopUpTxnRequestBodyDTO { this.customerId = customerId; } - public String getOrderNo() { - return orderNo; - } - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } public String getChargeType() { return chargeType; diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/model/PlanInfo.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/model/PlanInfo.java index bffa7b51..4482079d 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/model/PlanInfo.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/model/PlanInfo.java @@ -11,9 +11,9 @@ public class PlanInfo { @SerializedName("Voice") @Expose private String voice; - @SerializedName("Unlimited") + @SerializedName("SMS") @Expose - private String unlimited; + private String sms; public String getData() { return data; @@ -31,11 +31,11 @@ public class PlanInfo { this.voice = voice; } - public String getUnlimited() { - return unlimited; + public String getSms() { + return sms; } - public void setUnlimited(String unlimited) { - this.unlimited = unlimited; + public void setSms(String sms) { + this.sms = sms; } } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/presenter/LocalTopUpPresenter.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/presenter/LocalTopUpPresenter.java index eaefa372..87b714fb 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/presenter/LocalTopUpPresenter.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/presenter/LocalTopUpPresenter.java @@ -5,6 +5,7 @@ import android.util.Log; import com.gmeremit.online.gmeremittance_native.R; import com.gmeremit.online.gmeremittance_native.base.BasePresenter; import com.gmeremit.online.gmeremittance_native.customwidgets.CustomAlertDialog; +import com.gmeremit.online.gmeremittance_native.topup.local.LocalTopUpThrowable; import com.gmeremit.online.gmeremittance_native.topup.local.model.ButtonsGrid; import com.gmeremit.online.gmeremittance_native.topup.local.model.CardInfoDTO; import com.gmeremit.online.gmeremittance_native.topup.local.model.LocalTopUpDetailDTO; @@ -18,24 +19,32 @@ import com.gmeremit.online.gmeremittance_native.utils.Constants; import com.gmeremit.online.gmeremittance_native.utils.Utils; import com.gmeremit.online.gmeremittance_native.utils.https.GenericApiObserverResponseV2; import com.gmeremit.online.gmeremittance_native.utils.https.GenericResponseDataModel; +import com.gmeremit.online.gmeremittance_native.utils.https.HTTPConstants; import com.gmeremit.online.gmeremittance_native.utils.https.HttpClientV2; import com.gmeremit.online.gmeremittance_native.utils.security.SecurityUtils; import com.google.gson.reflect.TypeToken; +import java.io.IOException; import java.lang.reflect.Type; +import java.net.SocketTimeoutException; +import java.net.UnknownHostException; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; +import io.reactivex.functions.BiFunction; import io.reactivex.observers.DisposableObserver; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.BehaviorSubject; +import retrofit2.HttpException; public class LocalTopUpPresenter extends BasePresenter implements LocalTopUpPresenterInterface { + private static final int RETRIES_LIMIT = 3; private final LocalTopUpContractInterface view; private final LocalTopUpInteractorInterface.LocalTopupGateway gateway; private final CompositeDisposable compositeDisposable; @@ -67,7 +76,7 @@ public class LocalTopUpPresenter extends BasePresenter implements LocalTopUpPres fetchUserBalance(); this.userMsisdn = gateway.getUserMsisdn(); if (userMsisdn != null && userMsisdn.length() > 0) - view.showUserMsisdn(userMsisdn.replaceAll("010","")); + view.showUserMsisdn(userMsisdn.replaceAll("010", "")); } private void fetchUserBalance() { @@ -95,13 +104,28 @@ public class LocalTopUpPresenter extends BasePresenter implements LocalTopUpPres private void fetchLocalTopUpData() { this.compositeDisposable.add( Observable.zip( - getLocalTopUpOnBasisCardType(REGULAR_CARD_TYPE, userMsisdn) - .onErrorReturnItem(new LocalTopUpResponseDTO()), - getLocalTopUpOnBasisCardType(FIXED_CARD_TYPE, userMsisdn) - .onErrorReturnItem(new LocalTopUpResponseDTO()), - getLocalTopUpOnBasisCardType(DATA_PACK_CARD_TYPE, userMsisdn) - .onErrorReturnItem(new LocalTopUpResponseDTO()), + getLocalTopUpOnBasisCardType(REGULAR_CARD_TYPE, userMsisdn), + getLocalTopUpOnBasisCardType(FIXED_CARD_TYPE, userMsisdn), + getLocalTopUpOnBasisCardType(DATA_PACK_CARD_TYPE, userMsisdn), LocalTopUpRelatedData::new) +// .retryWhen(errors -> errors.zipWith( +// Observable.range(1, RETRIES_LIMIT + 1), +// (BiFunction>) (error, retryCount) -> { +// if (retryCount > RETRIES_LIMIT) +// return Observable.error(error); +// else if (error instanceof IOException) { +// return Observable.just(retryCount); +//// return Observable.error(new LocalTopUpThrowable(HTTPConstants.HTTP_RESPONSE_NO_INTERNET)); +// +// } +// else if (error instanceof HttpException || error instanceof LocalTopUpThrowable) +// { +// return Observable.error(error); +// } +// else { +// return Observable.just(retryCount); +// } +// }).flatMap(retryCount -> Observable.timer(200, TimeUnit.SECONDS))) .subscribeOn(Schedulers.io()) .doOnSubscribe(d -> { view.hideKeyBoard(); @@ -170,38 +194,30 @@ public class LocalTopUpPresenter extends BasePresenter implements LocalTopUpPres @Override public void updatePhoneNumber(String phoneNo) { view.showUserMsisdnError(null); - if(phoneNo==null||phoneNo.length()<1) + if (phoneNo == null || phoneNo.length() < 1) return; - String formattedPhoneNo=phoneNo.replaceAll("[^\\d]",""); - if(formattedPhoneNo.length()<11) - { - userMsisdn=null; + String formattedPhoneNo = phoneNo.replaceAll("[^\\d]", ""); + if (formattedPhoneNo.length() < 11) { + userMsisdn = null; view.showUserMsisdn("010"); view.showUserMsisdnError(getStringfromStringId(R.string.kyc_mobile_invalid_number_error)); view.showTopUpScreens(false); - } - else - { - formattedPhoneNo=formattedPhoneNo.substring(formattedPhoneNo.length()-11); - boolean b2= Pattern.compile("010[0-9]{8}").matcher(formattedPhoneNo).matches(); + } else { + formattedPhoneNo = formattedPhoneNo.substring(formattedPhoneNo.length() - 11); + boolean b2 = Pattern.compile("010[0-9]{8}").matcher(formattedPhoneNo).matches(); - if(b2) { - userMsisdn=formattedPhoneNo; - view.showUserMsisdn(formattedPhoneNo.replaceAll("010","")); - } - else - { + if (b2) { + userMsisdn = formattedPhoneNo; + view.showUserMsisdn(formattedPhoneNo.replaceAll("010", "")); + } else { view.showUserMsisdn("010"); - userMsisdn=null; + userMsisdn = null; view.showUserMsisdnError(getStringfromStringId(R.string.kyc_mobile_invalid_number_error)); view.showTopUpScreens(false); } } - - - } @Override @@ -286,7 +302,6 @@ public class LocalTopUpPresenter extends BasePresenter implements LocalTopUpPres LocalTopUpTxnRequestBodyDTO localTopUpTxnRequestBodyDTO = new LocalTopUpTxnRequestBodyDTO(); localTopUpTxnRequestBodyDTO.setBuyType(REGULAR_CARD_TYPE); localTopUpTxnRequestBodyDTO.setCustomerId(this.gateway.getUserIDNumber()); - localTopUpTxnRequestBodyDTO.setOrderNo("gmesub_000000002"); localTopUpTxnRequestBodyDTO.setChargeType(""); localTopUpTxnRequestBodyDTO.setPhoneNo(userMsisdn); localTopUpTxnRequestBodyDTO.setPrice(regularTopUpValidator.selectedDeno.getPrice()); @@ -300,14 +315,11 @@ public class LocalTopUpPresenter extends BasePresenter implements LocalTopUpPres localTopUpTxnRequestBodyDTO.setBuyType(FIXED_CARD_TYPE); localTopUpTxnRequestBodyDTO.setCustomerId(this.gateway.getUserIDNumber()); - localTopUpTxnRequestBodyDTO.setOrderNo("gmesub_000000006"); localTopUpTxnRequestBodyDTO.setPhoneNo(userMsisdn); - if(fixedTopUpValidator.selectedCarrierPlan!=null) { + if (fixedTopUpValidator.selectedCarrierPlan != null) { localTopUpTxnRequestBodyDTO.setChargeType(fixedTopUpValidator.selectedCarrierPlan.getCardType()); localTopUpTxnRequestBodyDTO.setPrice(fixedTopUpValidator.selectedCarrierPlan.getFacePrice()); - } - else - { + } else { localTopUpTxnRequestBodyDTO.setChargeType(fixedTopUpValidator.selectedCarrierType.getCardCode()); localTopUpTxnRequestBodyDTO.setPrice(fixedTopUpValidator.selectedCarrierType.getFacePrice()); } @@ -322,7 +334,6 @@ public class LocalTopUpPresenter extends BasePresenter implements LocalTopUpPres localTopUpTxnRequestBodyDTO.setBuyType(DATA_PACK_CARD_TYPE); localTopUpTxnRequestBodyDTO.setCustomerId(this.gateway.getUserIDNumber()); - localTopUpTxnRequestBodyDTO.setOrderNo("gmesub_000000013"); localTopUpTxnRequestBodyDTO.setChargeType(dataTopUpValidator.selectedCarrierPlan.getCardCode()); localTopUpTxnRequestBodyDTO.setPhoneNo(userMsisdn); localTopUpTxnRequestBodyDTO.setPrice(dataTopUpValidator.selectedCarrierPlan.getFacePrice()); @@ -360,9 +371,12 @@ public class LocalTopUpPresenter extends BasePresenter implements LocalTopUpPres GenericResponseDataModel data = HttpClientV2.getDeserializer().fromJson(response.string(), productType); if (data.getErrorCode().equalsIgnoreCase(Constants.SUCCESS_CODE_V2)) return Observable.just(data.getData()); + else if(data.getErrorCode().equalsIgnoreCase("5")) + return Observable.error(new LocalTopUpThrowable("You have a recent request for recharging.\\nWait for the results of this request.\" and then move Dashboard")); else - return Observable.error(new Throwable(data.getMsg())); + return Observable.error(new LocalTopUpThrowable(data.getMsg())); }); + } @@ -441,14 +455,13 @@ public class LocalTopUpPresenter extends BasePresenter implements LocalTopUpPres if (result) { this.selectedCarrierPlan = selectedCarrierPlan; view.enableFixedTopUpButton(result, getStringfromStringId(R.string.continue_text)); - String data=null,voice=null,sms=null; - if(selectedCarrierPlan.getPlanInfo()!=null) - { - data=selectedCarrierPlan.getPlanInfo().getData()!=null&&selectedCarrierPlan.getPlanInfo().getData().length()>0?selectedCarrierPlan.getPlanInfo().getData():Constants.UNLIMITED_TEXT; - voice=selectedCarrierPlan.getPlanInfo().getVoice()!=null&&selectedCarrierPlan.getPlanInfo().getVoice().length()>0?selectedCarrierPlan.getPlanInfo().getVoice():Constants.UNLIMITED_TEXT; - sms=selectedCarrierPlan.getPlanInfo().getUnlimited()!=null&&selectedCarrierPlan.getPlanInfo().getUnlimited().length()>0?selectedCarrierPlan.getPlanInfo().getUnlimited():Constants.UNLIMITED_TEXT; + String data = null, voice = null, sms = null; + if (selectedCarrierPlan.getPlanInfo() != null) { + data = selectedCarrierPlan.getPlanInfo().getData(); + voice = selectedCarrierPlan.getPlanInfo().getVoice(); + sms = selectedCarrierPlan.getPlanInfo().getSms(); } - LocalTopUpDetailDTO localTopUpDetailDTO=new LocalTopUpDetailDTO(userMsisdn,selectedCarrierPlan.getCardName(),data,voice,sms,Constants.KOREAN_WON+" "+ Utils.formatCurrencyWithoutTruncatingDecimal(selectedCarrierPlan.getFacePrice())); + LocalTopUpDetailDTO localTopUpDetailDTO = new LocalTopUpDetailDTO(userMsisdn, selectedCarrierPlan.getCardName(), data, voice, sms, Constants.KOREAN_WON + " " + Utils.formatCurrencyWithoutTruncatingDecimal(selectedCarrierPlan.getFacePrice())); view.showPlanToFixedLocalTopUp(localTopUpDetailDTO); } else { this.selectedCarrierPlan = null; @@ -496,7 +509,16 @@ public class LocalTopUpPresenter extends BasePresenter implements LocalTopUpPres @Override public void onError(Throwable e) { - Log.d("LocalTopUpError", e.getMessage()); + String message =e.getMessage(); + if(e instanceof HttpException) + { + message=HTTPConstants.getErrorMessageFromCode(((HttpException)e).code()); + } + else if(e instanceof IOException) + { + message=HTTPConstants.HTTP_RESPONSE_NO_INTERNET; + } + view.showPopUpMessage(message, CustomAlertDialog.AlertType.FAILED, alertType -> view.exitView()); } @Override diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/view/services/FixedChargeLocalTopupFragment.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/view/services/FixedChargeLocalTopupFragment.java index 72274f9f..9789f451 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/view/services/FixedChargeLocalTopupFragment.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/topup/local/view/services/FixedChargeLocalTopupFragment.java @@ -68,6 +68,15 @@ public class FixedChargeLocalTopupFragment extends BaseFragment { @BindView(R.id.amountTxtView) TextView amountTxtView; + @BindView(R.id.dataTitleTxtView) + TextView dataTitleTxtView; + + @BindView(R.id.voiceTitleTxtView) + TextView voiceTitleTxtView; + + @BindView(R.id.smsTitleTxtView) + TextView smsTitleTxtView; + private LocalTopUpResponseDTO fixedTopUpData; private GenericTextListingDialog carrierTypeListingDialog; private GenericTextListingDialog carrierPlanListingDialog; @@ -178,7 +187,41 @@ public class FixedChargeLocalTopupFragment extends BaseFragment { TransitionManager.beginDelayedTransition(infoViewContainer); cellPhoneTxtView.setText(localTopUpDetailDTO.getPhoneNumber()); chargeTypeTxtView.setText(localTopUpDetailDTO.getChargeType()); - dataTxtView.setText(localTopUpDetailDTO.getData()); + if(localTopUpDetailDTO.getData()!=null&&localTopUpDetailDTO.getData().length()>0) { + dataTxtView.setText(localTopUpDetailDTO.getData()); + dataTxtView.setVisibility(View.VISIBLE); + dataTitleTxtView.setVisibility(View.VISIBLE); + + } + else + { + dataTxtView.setText(""); + dataTxtView.setVisibility(View.GONE); + dataTitleTxtView.setVisibility(View.GONE); + } + if(localTopUpDetailDTO.getVoice()!=null&&localTopUpDetailDTO.getVoice().length()>0) { + voiceTxtView.setText(localTopUpDetailDTO.getVoice()); + voiceTxtView.setVisibility(View.VISIBLE); + voiceTitleTxtView.setVisibility(View.VISIBLE); + } + else + { + voiceTxtView.setText(""); + voiceTxtView.setVisibility(View.GONE); + voiceTitleTxtView.setVisibility(View.GONE); + } + if(localTopUpDetailDTO.getSms()!=null&&localTopUpDetailDTO.getSms().length()>0) { + smsTxtView.setText(localTopUpDetailDTO.getSms()); + smsTxtView.setVisibility(View.VISIBLE); + smsTitleTxtView.setVisibility(View.VISIBLE); + } + else + { + smsTxtView.setText(""); + smsTxtView.setVisibility(View.GONE); + smsTitleTxtView.setVisibility(View.GONE); + } + voiceTxtView.setText(localTopUpDetailDTO.getVoice()); smsTxtView.setText(localTopUpDetailDTO.getSms()); amountTxtView.setText(localTopUpDetailDTO.getAmount()); diff --git a/app/src/main/res/layout/fragment_fixed_local_topup.xml b/app/src/main/res/layout/fragment_fixed_local_topup.xml index 2353b88e..0362ccac 100644 --- a/app/src/main/res/layout/fragment_fixed_local_topup.xml +++ b/app/src/main/res/layout/fragment_fixed_local_topup.xml @@ -83,7 +83,7 @@ + android:visibility="visible"/>