|
|
@ -63,6 +63,7 @@ class AutoRefundsViewController: UIViewController { |
|
|
|
let amount = self.amountTextfield.text! |
|
|
|
let minAmnt = self.autorefund?.minAmount ?? "0" |
|
|
|
if amount.isEmpty {self.show(error: "add refund amount"); return} |
|
|
|
|
|
|
|
if !isValidRefundable(amount: amount) { |
|
|
|
self.show(error: "Amount cannot be minimum than \(Utility.getCommaSeperatedString(numberString: minAmnt) ?? "")") |
|
|
|
return |
|
|
@ -73,20 +74,37 @@ class AutoRefundsViewController: UIViewController { |
|
|
|
let id = Utility.getMyId() |
|
|
|
|
|
|
|
self.showProgressHud() |
|
|
|
self.refund(amount: amount, userName: userName, chargeAmount: chargeAmt, userId: id, success: { (message) in |
|
|
|
self.refund(amount: amount, userName: userName, chargeAmount: chargeAmt, userId: id, success: { (successMessage) in |
|
|
|
self.hideProgressHud() |
|
|
|
self.alertWithOk(message: message, title: "Success", okTitle: "Ok", style: UIAlertControllerStyle.alert, OkStyle: UIAlertActionStyle.default, okAction: { |
|
|
|
self.alertWithOk(message: successMessage?.message, title: "Success", okTitle: "Ok", style: UIAlertControllerStyle.alert, OkStyle: UIAlertActionStyle.default, okAction: { |
|
|
|
self.navigationController?.popViewController(animated: true) |
|
|
|
self.updateBalance(value: successMessage) |
|
|
|
|
|
|
|
}) |
|
|
|
}) { (error) in |
|
|
|
self.hideProgressHud() |
|
|
|
self.show(error: error.localizedDescription) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private func updateBalance(value: SuccessMessage?) { |
|
|
|
let balance = value?.extra ?? "" |
|
|
|
let yearlyLimits = value?.yearlyLimit ?? "" |
|
|
|
UserDefaults.standard.set(yearlyLimits, forKey: UserKeys.yearlyLimit) |
|
|
|
UserDefaults.standard.set(balance, forKey: UserKeys.availableBalance) |
|
|
|
let userInfo = [SideMenuNavigationNotifications.availableBalance : balance] |
|
|
|
NotificationCenter.default.post(name: self.getAvailableBalanceNotificationName(), object: nil, userInfo: userInfo) |
|
|
|
} |
|
|
|
|
|
|
|
func getAvailableBalanceNotificationName() -> Notification.Name { |
|
|
|
return Notification.Name.init(rawValue: SideMenuNavigationNotifications.availableBalance) |
|
|
|
} |
|
|
|
|
|
|
|
private func isValidRefundable(amount: String) -> Bool { |
|
|
|
let minRefundAmount = self.autorefund?.minAmount ?? "0" |
|
|
|
let _minRefundAmount = self.autorefund?.minAmount ?? "0" |
|
|
|
let minRefundAmount = _minRefundAmount.replacingOccurrences(of: ",", with: "") |
|
|
|
print(minRefundAmount) |
|
|
|
|
|
|
|
guard let amt = Double(amount), let minRefundAmt = Double(minRefundAmount) else {return false} |
|
|
|
let result = amt > minRefundAmt |
|
|
|
return result |
|
|
|