diff --git a/GME Remit/Modules/PowerCallModules/InternationalTopup/Application Logic/Service/InternationalTopupService.swift b/GME Remit/Modules/PowerCallModules/InternationalTopup/Application Logic/Service/InternationalTopupService.swift index 79dd87d7..2f8bb7ef 100644 --- a/GME Remit/Modules/PowerCallModules/InternationalTopup/Application Logic/Service/InternationalTopupService.swift +++ b/GME Remit/Modules/PowerCallModules/InternationalTopup/Application Logic/Service/InternationalTopupService.swift @@ -9,6 +9,18 @@ import Foundation class InternationalTopupService: InternationalTopupServiceType { + func fetchBalance( + type: String, + fintechUseNumber: String, + success: @escaping (BalanceModel) -> Void, + failure: @escaping (Error) -> Void + ) { + APIRouter.fetchBalace( + type: type, + fintechUseNumber: fintechUseNumber + ).json(success: success, failure: failure) + } + func fetchAutoDebitInformation( success: @escaping ([Account]) -> Void, failure: @escaping (Error) -> Void) { diff --git a/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Interactor/PhoneCardRechargeInteractor.swift b/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Interactor/PhoneCardRechargeInteractor.swift index 6895f46f..eb244313 100644 --- a/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Interactor/PhoneCardRechargeInteractor.swift +++ b/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Interactor/PhoneCardRechargeInteractor.swift @@ -62,6 +62,15 @@ class PhoneCardRechargeInteractor { // MARK: PhoneCardRecharge interactor input interface extension PhoneCardRechargeInteractor: PhoneCardRechargeInteractorInput { + func fetchBalanceForPowerCall(type: String, fintechUseNumber: String) { + service.fetchBalance( + type: type, + fintechUseNumber: fintechUseNumber, + success: {self.output?.setBalance(with: $0)}, + failure: {self.output?.setError(with: $0)} + ) + } + func fetchAutoDebitInformation() { service.fetchAutoDebitInformation( success: {self.output?.setModel(with: $0)}, diff --git a/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Interactor/PhoneCardRechargeInteractorIO.swift b/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Interactor/PhoneCardRechargeInteractorIO.swift index 57f487c4..983f34c5 100644 --- a/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Interactor/PhoneCardRechargeInteractorIO.swift +++ b/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Interactor/PhoneCardRechargeInteractorIO.swift @@ -9,6 +9,7 @@ protocol PhoneCardRechargeInteractorInput: class { func fetchCardList(type: RechargeType, mobile: String) func fetchAutoDebitInformation() + func fetchBalanceForPowerCall(type: String, fintechUseNumber: String) } protocol PhoneCardRechargeInteractorOutput: class { @@ -16,6 +17,7 @@ protocol PhoneCardRechargeInteractorOutput: class { func setFixedModel(with model: [MainCardInformation]) func setDataOnlyModel(with model: [MainCardInformation]) func setModel(with model: [Account]) + func setBalance(with model: BalanceModel) func setError(with error: Error) } diff --git a/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Model/RechargeModel.swift b/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Model/RechargeModel.swift index 076d089a..4c1055ac 100644 --- a/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Model/RechargeModel.swift +++ b/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Model/RechargeModel.swift @@ -7,6 +7,7 @@ // struct RechargeModel { + let paymentType: String let type: String let chargeType: String let cardName: String @@ -18,12 +19,14 @@ struct RechargeModel { var password: String? init( + paymentType: String, type: String, chargeType: String, cardName: String, mobile: String, price: String ) { + self.paymentType = paymentType self.type = type self.chargeType = chargeType self.cardName = cardName diff --git a/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Service/PhoneCardRechargeService.swift b/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Service/PhoneCardRechargeService.swift index f3a62ce4..63fb4563 100644 --- a/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Service/PhoneCardRechargeService.swift +++ b/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Service/PhoneCardRechargeService.swift @@ -9,6 +9,18 @@ import Foundation class PhoneCardRechargeService: PhoneCardRechargeServiceType { + func fetchBalance( + type: String, + fintechUseNumber: String, + success: @escaping (BalanceModel) -> Void, + failure: @escaping (Error) -> Void + ) { + APIRouter.fetchBalace( + type: type, + fintechUseNumber: fintechUseNumber + ).json(success: success, failure: failure) + } + func fetchAutoDebitInformation( success: @escaping ([Account]) -> Void, failure: @escaping (Error) -> Void diff --git a/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Service/PhoneCardRechargeServiceType.swift b/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Service/PhoneCardRechargeServiceType.swift index 291cb865..402e3abc 100644 --- a/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Service/PhoneCardRechargeServiceType.swift +++ b/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/Application Logic/Service/PhoneCardRechargeServiceType.swift @@ -17,4 +17,10 @@ protocol PhoneCardRechargeServiceType: class { success: @escaping ([Account]) -> Void, failure: @escaping (Error) -> Void ) + func fetchBalance( + type: String, + fintechUseNumber: String, + success: @escaping (BalanceModel) -> Void, + failure: @escaping (Error) -> Void + ) } diff --git a/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/User Interface/Presenter/PhoneCardRechargePresenter.swift b/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/User Interface/Presenter/PhoneCardRechargePresenter.swift index aa32bb7d..a197a4bb 100644 --- a/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/User Interface/Presenter/PhoneCardRechargePresenter.swift +++ b/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/User Interface/Presenter/PhoneCardRechargePresenter.swift @@ -51,6 +51,7 @@ class PhoneCardRechargePresenter: ViewModelType { struct Input { let viewWillAppear: Driver let selectAutodebit: Driver + let showBalanceTrigger: Driver let availableBalance: Driver let selectedMobile: Driver let contactOpenTap: Driver @@ -67,6 +68,7 @@ class PhoneCardRechargePresenter: ViewModelType { let isProgress: Driver let isEnableNext: Driver let isSuccessPayment: Driver + let getBalance: Driver let bankModel: Driver<[Account]> let regularModel: Driver<[PriceModel]> let fixedModel: Driver<[MainCardInformation]> @@ -82,12 +84,12 @@ class PhoneCardRechargePresenter: ViewModelType { private let errorLinker = PublishSubject() private let isSuccessPayment = PublishSubject() private let selectedPaymentMode = PublishSubject() - + private let getBalanceLinker = BehaviorSubject(value: nil) private let regularModel = BehaviorSubject<[PriceModel]>(value: []) private let bankModel = BehaviorSubject<[Account]>(value: []) private let fixedModel = BehaviorSubject<[MainCardInformation]>(value: []) private let dataOnlyModel = BehaviorSubject<[MainCardInformation]>(value: []) - private var accounts: [Account]? + private var accountType: String? func transform(input: Input) -> Output { Driver.combineLatest(input.viewWillAppear, input.selectedMobile, input.selectedRechargeType) @@ -104,6 +106,14 @@ class PhoneCardRechargePresenter: ViewModelType { }) .disposed(by: disposeBag) + input.showBalanceTrigger.withLatestFrom(selectedPaymentMode.asDriverOnErrorJustComplete()) { $1 } + .drive(onNext: { + let fintechUseNumber = $0?.fintechUseNumber ?? "" + let type = $0?.type ?? "autodebit" + self.progressLinker.onNext(true) + self.interactor?.fetchBalanceForPowerCall(type: type, fintechUseNumber: fintechUseNumber) + }).disposed(by: disposeBag) + input.selectAutodebit.drive(onNext: {[weak self] in let model = try? self?.bankModel.value() self?.wireframe?.showPaymentMode(with: model) @@ -123,7 +133,7 @@ class PhoneCardRechargePresenter: ViewModelType { input.selectedCarrierPlan.asObservable(), input.selectedDataOnlyType.asObservable() ) - + let carrierPlanModel = input.selectedCarrierType.map { $0?.subCardInfo ?? [] } let detailCarrierPlanModel = input.selectedCarrierPlan.map { $0?.planInfo } @@ -159,7 +169,9 @@ class PhoneCardRechargePresenter: ViewModelType { .map { ( _, mobile, type, priceModel, _, carrierPlan, dataOnlyType) -> RechargeModel? in switch type { case .regular: + return RechargeModel( + paymentType: self.accountType ?? "", type: type.value, chargeType: "", cardName: "", @@ -168,6 +180,7 @@ class PhoneCardRechargePresenter: ViewModelType { ) case .fixed: return RechargeModel( + paymentType: self.accountType ?? "", type: type.value, chargeType: carrierPlan?.cardType ?? "", cardName: carrierPlan?.cardName ?? "", @@ -176,6 +189,7 @@ class PhoneCardRechargePresenter: ViewModelType { ) case .dataOnly: return RechargeModel( + paymentType: self.accountType ?? "", type: type.value, chargeType: dataOnlyType?.cardCode ?? "", cardName: dataOnlyType?.cardName ?? "", @@ -193,6 +207,7 @@ class PhoneCardRechargePresenter: ViewModelType { isProgress: progressLinker.asDriverOnErrorJustComplete(), isEnableNext: isEnableNext.asDriverOnErrorJustComplete(), isSuccessPayment: isSuccessPayment.asDriverOnErrorJustComplete(), + getBalance: getBalanceLinker.asDriverOnErrorJustComplete(), bankModel: bankModel.asDriverOnErrorJustComplete(), regularModel: regularModel.asDriverOnErrorJustComplete(), fixedModel: fixedModel.asDriverOnErrorJustComplete(), @@ -206,6 +221,13 @@ class PhoneCardRechargePresenter: ViewModelType { // MARK: PhoneCardRecharge interactor output interface extension PhoneCardRechargePresenter: PhoneCardRechargeInteractorOutput { + + func setBalance(with model: BalanceModel) { + progressLinker.onNext(false) + getBalanceLinker.onNext(model) + + } + func setModel(with model: [Account]) { progressLinker.onNext(false) bankModel.onNext(model) diff --git a/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/User Interface/View/PhoneCardRecharge.storyboard b/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/User Interface/View/PhoneCardRecharge.storyboard index 48c7945f..1ad22e1d 100644 --- a/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/User Interface/View/PhoneCardRecharge.storyboard +++ b/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/User Interface/View/PhoneCardRecharge.storyboard @@ -1,6 +1,6 @@ - + @@ -83,57 +83,80 @@ - - - + + - - + + + + + + + + + + + + + + - - + + + + - + - - - - - - - - + + + + + - - + + + + + + + + - - - @@ -846,6 +869,8 @@ + + @@ -900,7 +925,7 @@ - + diff --git a/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/User Interface/View/PhoneCardRechargeViewController.swift b/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/User Interface/View/PhoneCardRechargeViewController.swift index 37270e76..10aa9679 100644 --- a/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/User Interface/View/PhoneCardRechargeViewController.swift +++ b/GME Remit/Modules/PowerCallModules/LocalTopup/PhoneCardRecharge/User Interface/View/PhoneCardRechargeViewController.swift @@ -23,6 +23,7 @@ class PhoneCardRechargeViewController: UIViewController { private let selectedMobile = PublishSubject() private let selectPaymentType = PublishSubject() private var amountButtons = [UIButton]() + // MARK: Computed Properties // MARK: IBOutlets @@ -37,6 +38,7 @@ class PhoneCardRechargeViewController: UIViewController { @IBOutlet private weak var typeSegment: UISegmentedControl! @IBOutlet private weak var mainContainerView: UIView! @IBOutlet private weak var menuContainerView: UIStackView! + @IBOutlet weak var balanceStackView: UIStackView! @IBOutlet weak var paymentTypeDropDownImageView: UIImageView! @IBOutlet var paymentTypeDropDownTap: UITapGestureRecognizer! @@ -49,6 +51,8 @@ class PhoneCardRechargeViewController: UIViewController { @IBOutlet private weak var amountButton4: UIButton! @IBOutlet private weak var amountButton5: UIButton! @IBOutlet private weak var amountButton6: UIButton! + @IBOutlet weak var balanceCheckButton: UIButton! + @IBOutlet private weak var regularTypeInfoContainerView: UIView! @IBOutlet private weak var regularInformationLabel1: UILabel! @IBOutlet private weak var regularInformationLabel2: UILabel! @@ -107,6 +111,10 @@ class PhoneCardRechargeViewController: UIViewController { @IBAction func touchAmountButton(_ sender: UIButton) { selectedAmountButton.onNext(sender.tag) } + @IBAction func checkBalanceButton(_ sender: UIButton) { + + } + } // MARK: Other Functions @@ -119,6 +127,7 @@ extension PhoneCardRechargeViewController { } private func setUI() { + balanceCheckButton.isHidden = true regularTypeContainerView.isHidden = true regularTypeInfoContainerView.isHidden = true fixedChargeTypeContainerView.isHidden = true @@ -133,6 +142,7 @@ extension PhoneCardRechargeViewController { ) nextButton.layer.cornerRadius = 5 + balanceCheckButton.layer.cornerRadius = 5 regularTypeButtonsStackView.travelSubView { (view, _) in if let button = view as? UIButton { @@ -194,6 +204,7 @@ extension PhoneCardRechargeViewController { let input = PhoneCardRechargePresenter.Input( viewWillAppear: viewWillAppear, selectAutodebit: selectPaymentType.asDriverOnErrorJustComplete(), + showBalanceTrigger: balanceCheckButton.rx.tap.asDriver(), availableBalance: availableBalance.asDriverOnErrorJustComplete(), selectedMobile: selectedMobile.asDriverOnErrorJustComplete(), contactOpenTap: contactButton.rx.tap.asDriverOnErrorJustComplete(), @@ -225,6 +236,14 @@ extension PhoneCardRechargeViewController { } ).disposed(by: disposeBag) + output.getBalance.map { $0?.balance?.decimalToCurrency() } + .drive(onNext: { [weak self] in + guard let balance = $0 else { return } + self?.balanceStackView.isHidden = false + self?.balanceCheckButton.isHidden = true + self?.mycashAmountLabel.text = balance + }).disposed(by: disposeBag) + output.isProgress .drive( onNext: { $0 ? self.showProgressHud() : self.hideProgressHud() } @@ -257,6 +276,27 @@ extension PhoneCardRechargeViewController { .drive(nextButton.rx.isEnabled) .disposed(by: disposeBag) + output.selectedPaymentMode.drive(onNext: {[weak self] in + guard + let model = $0 else { + return + } + if model.type == "wallet" { + self?.balanceCheckButton.isHidden = true + self?.balanceStackView.isHidden = false + self?.mycashAmountLabel.text = GMEDB.shared.user.string(.availableBalance) + } else { + self?.balanceCheckButton.isHidden = false + self?.balanceCheckButton.setTitle("account_balance_button_text".localized(), for: .normal) + self?.balanceCheckButton.backgroundColor = .themeBlue + self?.balanceCheckButton.setTitleColor(.white, for: .normal) + self?.balanceCheckButton.titleLabel?.minimumScaleFactor = 0.1 + self?.balanceCheckButton.titleLabel?.adjustsFontSizeToFitWidth = true + + self?.balanceStackView.isHidden = true + } + }).disposed(by: disposeBag) + output.regularModel.drive(onNext: { [weak self] model in guard let `self` = self, model.count == self.amountButtons.count else { return } self.amountButtons.enumerated().forEach { index, button in diff --git a/GME Remit/Modules/PowerCallModules/RechargePayment/User Interface/Presenter/RechargePaymentPresenter.swift b/GME Remit/Modules/PowerCallModules/RechargePayment/User Interface/Presenter/RechargePaymentPresenter.swift index e785dc34..99d932a9 100644 --- a/GME Remit/Modules/PowerCallModules/RechargePayment/User Interface/Presenter/RechargePaymentPresenter.swift +++ b/GME Remit/Modules/PowerCallModules/RechargePayment/User Interface/Presenter/RechargePaymentPresenter.swift @@ -80,6 +80,7 @@ class RechargePaymentPresenter: ViewModelType { // MARK: RechargePayment interactor output interface extension RechargePaymentPresenter: RechargePaymentInteractorOutput { + func setSubmitSuccess() { progressLinker.onNext(false) submitSuccess.onNext(()) diff --git a/GME Remit/Modules/PowerCallModules/RechargePayment/User Interface/View/RechargePayment.storyboard b/GME Remit/Modules/PowerCallModules/RechargePayment/User Interface/View/RechargePayment.storyboard index 614c692f..4dc310ad 100644 --- a/GME Remit/Modules/PowerCallModules/RechargePayment/User Interface/View/RechargePayment.storyboard +++ b/GME Remit/Modules/PowerCallModules/RechargePayment/User Interface/View/RechargePayment.storyboard @@ -46,7 +46,7 @@