Commit d0bd26e8 by Olzhas Aldabergenov

быстрая оплата решена

parent efbec3b2
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildLocationStyle</key>
<string>UseAppPreferences</string>
<key>CustomBuildLocationType</key>
<string>RelativeToDerivedData</string>
<key>DerivedDataLocationStyle</key>
<string>Default</string>
<key>IssueFilterStyle</key>
<string>ShowActiveSchemeOnly</string>
<key>LiveSourceIssuesEnabled</key>
<true/>
</dict>
</plist>
...@@ -259,5 +259,21 @@ ...@@ -259,5 +259,21 @@
landmarkType = "7"> landmarkType = "7">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "kt/ViewControllers/FastPay/UIFastPayViewController.swift"
timestampString = "530168698.751804"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "89"
endingLineNumber = "89"
landmarkName = "createCellsData()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints> </Breakpoints>
</Bucket> </Bucket>
...@@ -31,7 +31,6 @@ extension Facade { ...@@ -31,7 +31,6 @@ extension Facade {
} }
} }
func getBalance(phoneNumber: String, onSuccess: ((Int) -> Void)? = nil, onError: ((NSError) -> Void)? = nil) { func getBalance(phoneNumber: String, onSuccess: ((Int) -> Void)? = nil, onError: ((NSError) -> Void)? = nil) {
if Facade.accessToken == nil || Facade.clientId == nil { if Facade.accessToken == nil || Facade.clientId == nil {
notificationCenter.postNotification(UserNeedAuthNotification) notificationCenter.postNotification(UserNeedAuthNotification)
......
...@@ -43,7 +43,7 @@ extension FastPayManager { ...@@ -43,7 +43,7 @@ extension FastPayManager {
func getStoredFastPays() -> [FastPayItem] { func getStoredFastPays() -> [FastPayItem] {
var result : [FastPayItem] = [] var result : [FastPayItem] = []
createInternalFastPay() //createInternalFastPay()
let storeresult = retrieveFastPays() let storeresult = retrieveFastPays()
if (storeresult != nil) { if (storeresult != nil) {
result = storeresult! result = storeresult!
...@@ -84,6 +84,7 @@ extension FastPayManager { ...@@ -84,6 +84,7 @@ extension FastPayManager {
if (items == nil) { if (items == nil) {
items = [] items = []
} }
//removeFromStoreFastPay(fastPay)
items!.append(fastPay) items!.append(fastPay)
saveStoreFastPay(items!) saveStoreFastPay(items!)
} }
...@@ -92,8 +93,8 @@ extension FastPayManager { ...@@ -92,8 +93,8 @@ extension FastPayManager {
let items = getStoredFastPays() let items = getStoredFastPays()
let mutableItems : NSMutableArray = NSMutableArray(array: items) let mutableItems : NSMutableArray = NSMutableArray(array: items)
for item in mutableItems { for item in mutableItems {
let fastPay = item as! FastPayItem let fastPay2 = item as! FastPayItem
if fastPay.compare(fastPay) { if fastPay2.compare(fastPay) {
mutableItems.removeObject(item) mutableItems.removeObject(item)
break break
} }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -612,3 +612,10 @@ ...@@ -612,3 +612,10 @@
"callback_request" = "Заявка на обратный звонок"; "callback_request" = "Заявка на обратный звонок";
"payment_last_format" = "Последний платеж: "; "payment_last_format" = "Последний платеж: ";
"fastPay_create_cellAccountNumber_placeholder" = "мой счет";
"select_your_region" = "Выберите ваш регион";
"fastPay_create_validationFail_accountNumber" = "Номер лицевого счета указан не верно";
"fastPayCell_accountNumber_title" = "Номер лицевого счета:";
"fastPay_positive_balance" = "Оплата не требуется";
"fastPay_error_during_request" = "Ошибка получения данных";
...@@ -611,3 +611,10 @@ ...@@ -611,3 +611,10 @@
"callback_request" = "Заявка на обратный звонок"; "callback_request" = "Заявка на обратный звонок";
"payment_last_format" = "Последний платеж: "; "payment_last_format" = "Последний платеж: ";
"fastPay_create_cellAccountNumber_placeholder" = "мой счет";
"select_your_region" = "Выберите ваш регион";
"fastPay_create_validationFail_accountNumber" = "Номер лицевого счета указан не верно";
"fastPayCell_accountNumber_title" = "Номер лицевого счета:";
"fastPay_positive_balance" = "Оплата не требуется";
"fastPay_error_during_request" = "Ошибка получения данных";
...@@ -614,3 +614,9 @@ ...@@ -614,3 +614,9 @@
"callback_request" = "Заявка на обратный звонок"; "callback_request" = "Заявка на обратный звонок";
"payment_last_format" = "Последний платеж: "; "payment_last_format" = "Последний платеж: ";
"fastPay_create_cellAccountNumber_placeholder" = "мой счет";
"select_your_region" = "Выберите ваш регион";
"fastPay_create_validationFail_accountNumber" = "Номер лицевого счета указан не верно";
"fastPayCell_accountNumber_title" = "Номер лицевого счета:";
"fastPay_positive_balance" = "Оплата не требуется";
"fastPay_error_during_request" = "Ошибка получения данных";
...@@ -8,26 +8,42 @@ ...@@ -8,26 +8,42 @@
import Foundation import Foundation
class UICreateFastPayViewController : UIViewController, UITableViewDelegate, UITableViewDataSource { class UICreateFastPayViewController : UIViewController, UITableViewDelegate, UITableViewDataSource,
UIPickerViewDelegate, UIPickerViewDataSource {
//MARK: - IBOutlest //MARK: - IBOutlets
@IBOutlet weak var tableView : UITableView! @IBOutlet weak var tableView : UITableView!
@IBOutlet weak var lblDescription : UILabel! @IBOutlet weak var lblDescription : UILabel!
@IBOutlet weak var btnDelete : UIButton! @IBOutlet weak var btnDelete : UIButton!
@IBOutlet weak var btnCreate : UIButton! @IBOutlet weak var btnCreate : UIButton!
var cellsData : [TextBoxCellData] = [] @IBOutlet weak var toggle: UISegmentedControl!
@IBOutlet weak var labelPickRegion: UILabel!
@IBOutlet weak var regionPicker: UIPickerView!
var cellsDataPhone : [TextBoxCellData] = []
var cells : [UIBaseTableViewCell] = [] var cells : [UIBaseTableViewCell] = []
var cellsDataAccount : [TextBoxCellData] = []
var cellsAccount : [UIBaseTableViewCell] = []
var cellDataName : TextBoxCellData? var cellDataName : TextBoxCellData?
var cellDataAccountNumber : TextBoxCellData?
var cellDataPhoneNumber : TextBoxCellData? var cellDataPhoneNumber : TextBoxCellData?
var fastPayForEditing : FastPayItem? var fastPayForEditing : FastPayItem?
var regions : [CallbackRegion] = []
var selectedRegion : CallbackRegion?
//MARK: - System functions //MARK: - System functions
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
createCells() createCells()
self.regionPicker.delegate = self
self.regionPicker.dataSource = self
tableView.reloadData() tableView.reloadData()
self.title = isEditableMode() ? LS("fastPay_create_editingTitle") : LS("fastPay_create_createTitle") self.title = isEditableMode() ? LS("fastPay_create_editingTitle") : LS("fastPay_create_createTitle")
if (!isEditableMode()) { if (!isEditableMode()) {
...@@ -37,14 +53,54 @@ class UICreateFastPayViewController : UIViewController, UITableViewDelegate, UIT ...@@ -37,14 +53,54 @@ class UICreateFastPayViewController : UIViewController, UITableViewDelegate, UIT
btnCreate.setTitle(LS("fastPay_create_button_saveChangesTitle"), forState: UIControlState.Normal) btnCreate.setTitle(LS("fastPay_create_button_saveChangesTitle"), forState: UIControlState.Normal)
btnDelete.setTitle(LS("fastPay_create_button_deleteTitle"), forState: UIControlState.Normal) btnDelete.setTitle(LS("fastPay_create_button_deleteTitle"), forState: UIControlState.Normal)
} }
toggle.setTitle(LS("createGUID_PhoneNumber_Title"), forSegmentAtIndex: 0)
toggle.setTitle(LS("createGUID_PersonalAccount_Title"), forSegmentAtIndex: 1)
labelPickRegion.text = LS("select_your_region").uppercaseString
labelPickRegion.hidden = true
regionPicker.hidden = true
self.regionPicker.delegate = self
self.regionPicker.dataSource = self
if (isEditableMode() ) {
if ( !self.fastPayForEditing!.isPhoneNumber() ) {
loadAccountView()
}
}
} }
//MARK: - Functions @IBAction func onItemSelected(sender: UISegmentedControl) {
tableView.reloadData()
if ( toggle.selectedSegmentIndex == 0 ) {
loadPhoneView()
} else {
loadAccountView()
}
}
func loadPhoneView() {
toggle.selectedSegmentIndex = 0
labelPickRegion.hidden = true
regionPicker.hidden = true
}
func loadAccountView() {
toggle.selectedSegmentIndex = 1
labelPickRegion.hidden = false
regionPicker.hidden = false
}
//MARK: - Functions
func createCells() { func createCells() {
cells = [] cells = []
cellsAccount = []
createCellsData() createCellsData()
for var cellData in cellsData {
for var cellData in cellsDataPhone {
let cell = tableView.dequeueReusableCellWithIdentifier(cellData.cellType.reuseIdentifier) as! UIBaseTableViewCell let cell = tableView.dequeueReusableCellWithIdentifier(cellData.cellType.reuseIdentifier) as! UIBaseTableViewCell
cell.fillWithCellData(cellData) cell.fillWithCellData(cellData)
cell.selectionStyle = .None cell.selectionStyle = .None
...@@ -53,10 +109,21 @@ class UICreateFastPayViewController : UIViewController, UITableViewDelegate, UIT ...@@ -53,10 +109,21 @@ class UICreateFastPayViewController : UIViewController, UITableViewDelegate, UIT
cell.selectionStyle = .None cell.selectionStyle = .None
} }
} }
for var cellData in cellsDataAccount {
let cell = tableView.dequeueReusableCellWithIdentifier(cellData.cellType.reuseIdentifier) as! UIBaseTableViewCell
cell.fillWithCellData(cellData)
cell.selectionStyle = .None
cellsAccount.append(cell)
if (cellData.cellType != .TitleValueCell) {
cell.selectionStyle = .None
}
}
} }
func createCellsData() { func createCellsData() {
cellsData = [] cellsDataPhone = []
cellsDataAccount = []
let valueName = fastPayForEditing != nil ? fastPayForEditing!.title : "" let valueName = fastPayForEditing != nil ? fastPayForEditing!.title : ""
cellDataName = TextBoxCellData(title: LS("fastPay_create_cardName").uppercaseString, value: valueName, placeholder: LS("fastPay_create_cellName_placeholder")) { (object) -> Bool in cellDataName = TextBoxCellData(title: LS("fastPay_create_cardName").uppercaseString, value: valueName, placeholder: LS("fastPay_create_cellName_placeholder")) { (object) -> Bool in
var result = false var result = false
...@@ -69,6 +136,19 @@ class UICreateFastPayViewController : UIViewController, UITableViewDelegate, UIT ...@@ -69,6 +136,19 @@ class UICreateFastPayViewController : UIViewController, UITableViewDelegate, UIT
return result return result
} }
var accountNumber = fastPayForEditing != nil ? fastPayForEditing!.guid : ""
accountNumber = getGuidWithoutDash(accountNumber)
cellDataAccountNumber = TextBoxCellData(title: LS("createGUID_PersonalAccount_Title").uppercaseString, value: accountNumber, placeholder: LS("fastPay_create_cellAccountNumber_placeholder")) { (object) -> Bool in
var result = false
if (object != nil) {
let st = object as! String
if (st.characters.count > 0) {
result = true;
}
}
return result
}
let valuePhone = fastPayForEditing != nil ? fastPayForEditing?.phoneNumber : "" let valuePhone = fastPayForEditing != nil ? fastPayForEditing?.phoneNumber : ""
cellDataPhoneNumber = TextBoxCellData(title: LS("fastPay_create_phoneNumber").uppercaseString, value: valuePhone!, placeholder: LS("fastPay_create_cellPhone_placeholder")) { (object) -> Bool in cellDataPhoneNumber = TextBoxCellData(title: LS("fastPay_create_phoneNumber").uppercaseString, value: valuePhone!, placeholder: LS("fastPay_create_cellPhone_placeholder")) { (object) -> Bool in
var result = false var result = false
...@@ -82,8 +162,49 @@ class UICreateFastPayViewController : UIViewController, UITableViewDelegate, UIT ...@@ -82,8 +162,49 @@ class UICreateFastPayViewController : UIViewController, UITableViewDelegate, UIT
} }
cellDataPhoneNumber?.keyboardType = .PhonePad cellDataPhoneNumber?.keyboardType = .PhonePad
cellsData.append(cellDataName!) cellsDataPhone.append(cellDataName!)
cellsData.append(cellDataPhoneNumber!) cellsDataPhone.append(cellDataPhoneNumber!)
cellsDataAccount.append(cellDataName!)
cellsDataAccount.append(cellDataAccountNumber!)
Facade.sharedInstance().getOfferRegions({ (regions) in
self.regions = regions
if (self.fastPayForEditing != nil) {
self.scrollToUsersRegion()
}
self.regionPicker.reloadAllComponents()
}, onError: { (error) in
print(error)
}) {
}
}
func scrollToUsersRegion() {
let regionId = getRegionFromGuid(self.fastPayForEditing!.guid);
var index : Int = 0
for var region in self.regions {
if ( regionId == region.guid_server_id! ) {
break
}
index += 1
}
if ( index >= self.regions.count ) {
index = 0;
}
dispatch_async(dispatch_get_main_queue()) {
self.regionPicker.selectRow(index, inComponent: 0, animated: true)
self.pickerView(self.regionPicker, didSelectRow: index, inComponent: 0)
}
}
func getRegionFromGuid(guid: String) -> String {
var region = guid
if let range = region.rangeOfString("-") {
region = region.substringToIndex(range.startIndex)
}
return region
} }
func showAlert(title : String, message: String) { func showAlert(title : String, message: String) {
...@@ -95,6 +216,7 @@ class UICreateFastPayViewController : UIViewController, UITableViewDelegate, UIT ...@@ -95,6 +216,7 @@ class UICreateFastPayViewController : UIViewController, UITableViewDelegate, UIT
func checkForm() -> Bool { func checkForm() -> Bool {
if ( isPhoneNumberMode() ) {
for var cell in cells { for var cell in cells {
cell.updateCellData() cell.updateCellData()
} }
...@@ -116,6 +238,38 @@ class UICreateFastPayViewController : UIViewController, UITableViewDelegate, UIT ...@@ -116,6 +238,38 @@ class UICreateFastPayViewController : UIViewController, UITableViewDelegate, UIT
} }
return result return result
} else {
for var cell in cellsAccount {
cell.updateCellData()
}
var result = true
var message = ""
if (!(cellDataName!.checkValues())) {
message.appendContentsOf("\(LS("fastPay_create_validationFail_cellName")) \n")
}
if (!(cellDataAccountNumber!.checkValues())) {
message.appendContentsOf("\(LS("fastPay_create_validationFail_accountNumber")) \n")
}
if ( selectedRegion == nil ) {
message.appendContentsOf("\(LS("select_your_region")) \n")
}
if message.characters.count > 0 {
result = false
showAlert(LS("fastPay_create_alertTitle_error"), message: message)
}
if message.characters.count > 0 {
result = false
showAlert(LS("fastPay_create_alertTitle_error"), message: message)
}
return result
}
} }
...@@ -128,14 +282,35 @@ class UICreateFastPayViewController : UIViewController, UITableViewDelegate, UIT ...@@ -128,14 +282,35 @@ class UICreateFastPayViewController : UIViewController, UITableViewDelegate, UIT
} }
func sendRequestBalanceByGuid(onSuccess:() -> Void, onFailure : () -> Void ) {
var guid = getGuid()
Facade.sharedInstance().getBalanceByGuid( guid, onSuccess: { (balance) in
onSuccess()
}) { (nsError) in
onFailure()
}
}
func getGuid() -> String {
return (self.selectedRegion!.guid_server_id)! + "-" + (cellDataAccountNumber?.value)!
}
func isEditableMode() -> Bool { func isEditableMode() -> Bool {
return fastPayForEditing != nil return fastPayForEditing != nil
} }
func isPhoneNumberMode() -> Bool {
return toggle.selectedSegmentIndex == 0
}
//MARK: - IBActions //MARK: - IBActions
@IBAction func btnCreateFastPay_action(sender: AnyObject) { @IBAction func btnCreateFastPay_action(sender: AnyObject) {
if (checkForm()) { if (checkForm()) {
if ( isPhoneNumberMode() ) {
sendRequestBalance({ sendRequestBalance({
let name = self.cellDataName?.value let name = self.cellDataName?.value
let phoneNumber = self.cellDataPhoneNumber?.value let phoneNumber = self.cellDataPhoneNumber?.value
...@@ -148,7 +323,38 @@ class UICreateFastPayViewController : UIViewController, UITableViewDelegate, UIT ...@@ -148,7 +323,38 @@ class UICreateFastPayViewController : UIViewController, UITableViewDelegate, UIT
self.back() self.back()
}, onFailure: { }, onFailure: {
self.showAlert(LS("fastPay_create_alertTitle_error"), message: LS("fastPay_create_validationFail_cellPhone")) self.showAlert(LS("fastPay_create_alertTitle_error"), message: LS("fastPay_create_validationFail_cellPhone"))
}) } })
} else {
sendRequestBalanceByGuid(
{
print("success")
let name = self.cellDataName?.value
let guid = self.getGuid()
if (self.fastPayForEditing != nil) {
FastPayManager.sharedInstance().removeFromStoreFastPay(self.fastPayForEditing!)
}
let fastPayItem = FastPayItem(title: name!, guid : guid)
FastPayManager.sharedInstance().addInStoreFastPay(fastPayItem)
self.back()
},
onFailure: {
self.showAlert(LS("fastPay_create_alertTitle_error"), message: LS("fastPay_create_validationFail_accountNumber"))
}
)
}
}
}
func getGuidWithoutDash(input: String ) -> String {
var guid = input
if let range = guid.rangeOfString("-") {
guid = guid.substringFromIndex(range.endIndex)
}
return guid
} }
@IBAction func btnDeleteFastPay_action(sender: AnyObject) { @IBAction func btnDeleteFastPay_action(sender: AnyObject) {
...@@ -165,13 +371,25 @@ extension UICreateFastPayViewController { ...@@ -165,13 +371,25 @@ extension UICreateFastPayViewController {
} }
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if ( isPhoneNumberMode() ) {
let cell = cells[indexPath.row] let cell = cells[indexPath.row]
cell.hideSeparatorLine() cell.hideSeparatorLine()
return cell return cell
} }
else {
let cell = cellsAccount[indexPath.row]
cell.hideSeparatorLine()
return cell
}
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return cellsData.count if ( isPhoneNumberMode() ) {
return cells.count
}
else {
return cellsAccount.count
}
} }
} }
...@@ -179,7 +397,31 @@ extension UICreateFastPayViewController { ...@@ -179,7 +397,31 @@ extension UICreateFastPayViewController {
extension UICreateFastPayViewController { extension UICreateFastPayViewController {
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print(indexPath)
}
}
// UIPickerViewDelegate
extension UICreateFastPayViewController {
// The number of columns of data
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
// The number of rows of data
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return self.regions.count
}
// The data to return for the row and component (column) that's being passed in
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return self.regions[row].name
}
// item has been picked
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
self.selectedRegion = regions[row]
} }
} }
...@@ -85,7 +85,8 @@ class UIFastPayViewController : ViewControllerWithMenu, UITableViewDelegate { ...@@ -85,7 +85,8 @@ class UIFastPayViewController : ViewControllerWithMenu, UITableViewDelegate {
cellsData = [] cellsData = []
let items = FastPayManager.sharedInstance().getStoredFastPays() let items = FastPayManager.sharedInstance().getStoredFastPays()
for fastPay in items { for fastPay in items {
let cellData = FastPayCellData(name: fastPay.title, phoneNumber: fastPay.phoneNumber, credit: "")
let cellData = getFastPayCellData(fastPay)
cellData.fastPayItem = fastPay cellData.fastPayItem = fastPay
cellData.onClick = { cellData.onClick = {
self.showEditForm(cellData.fastPayItem!) self.showEditForm(cellData.fastPayItem!)
...@@ -97,17 +98,40 @@ class UIFastPayViewController : ViewControllerWithMenu, UITableViewDelegate { ...@@ -97,17 +98,40 @@ class UIFastPayViewController : ViewControllerWithMenu, UITableViewDelegate {
} }
} }
private func getFastPayCellData(fastPay: FastPayItem) -> FastPayCellData {
if ( fastPay.isPhoneNumber() ) {
return FastPayCellData(name: fastPay.title, phoneNumber: fastPay.phoneNumber, credit: "")
}
else {
return FastPayCellData(name: fastPay.title, guid: fastPay.guid, credit: "")
}
}
private func showEditForm(fastPay : FastPayItem) { private func showEditForm(fastPay : FastPayItem) {
performSegueWithIdentifier("createPayIdentifier", sender: fastPay) performSegueWithIdentifier("createPayIdentifier", sender: fastPay)
} }
private func showPayForm(cellData : FastPayCellData) { private func showPayForm(cellData : FastPayCellData) {
//print(cellData.phoneNumberValue)
sendOnlinePaymentRequest(cellData.phoneNumberValue, summ: cellData.summ) if ( cellData.fastPayItem!.isPhoneNumber() ) {
sendOnlinePaymentRequestPhoneNumber(cellData.phoneNumberValue, summ: cellData.summ)
} else {
sendOnlinePaymentRequestAccountNumber(cellData.accountNumberValue, summ: cellData.summ)
}
} }
func sendOnlinePaymentRequest(phoneNumber : String, summ: String) { private func sendOnlinePaymentRequestPhoneNumber(phoneNumber : String, summ: String) {
let request = PaymentCreateOrderRequest(payType: "phone", email: AbonentInfoManager.sharedInstance.abonentInfo?.email, guidOrPhone: phoneNumber, amount: summ, lang: AppLocalization.language().forTelecom) let request = PaymentCreateOrderRequest(payType: "phone", email: AbonentInfoManager.sharedInstance.abonentInfo?.email, guidOrPhone: phoneNumber, amount: summ, lang: AppLocalization.language().forTelecom)
requestExecute(request)
}
private func sendOnlinePaymentRequestAccountNumber(accountNumber : String, summ: String) {
let request = PaymentCreateOrderRequest(payType: "guid", email: AbonentInfoManager.sharedInstance.abonentInfo?.email, guidOrPhone: accountNumber, amount: summ, lang: AppLocalization.language().forTelecom)
requestExecute(request)
}
func requestExecute(request : PaymentCreateOrderRequest ) {
guard request.validateFields() else { AlertViewUtil.showAlert(request.validationMessage); return } guard request.validateFields() else { AlertViewUtil.showAlert(request.validationMessage); return }
self.processRequest(true) self.processRequest(true)
Facade.sharedInstance().createOrder(request.params, onSuccess: { (data) in Facade.sharedInstance().createOrder(request.params, onSuccess: { (data) in
...@@ -120,7 +144,6 @@ class UIFastPayViewController : ViewControllerWithMenu, UITableViewDelegate { ...@@ -120,7 +144,6 @@ class UIFastPayViewController : ViewControllerWithMenu, UITableViewDelegate {
}, onFinish: { }, onFinish: {
self.processRequest(false) self.processRequest(false)
}) })
} }
//MARK: - IBOutlets //MARK: - IBOutlets
......
...@@ -13,11 +13,21 @@ class FastPayItem : NSObject, NSCoding { ...@@ -13,11 +13,21 @@ class FastPayItem : NSObject, NSCoding {
internal var title : String = "" internal var title : String = ""
internal var phoneNumber : String = "" internal var phoneNumber : String = ""
internal var uuid : String = "" internal var uuid : String = ""
internal var guid : String = ""
init(title: String, phoneNumber : String) { init(title: String, phoneNumber : String) {
self.title = title self.title = title
self.phoneNumber = phoneNumber self.phoneNumber = phoneNumber
self.uuid = NSUUID().UUIDString self.uuid = NSUUID().UUIDString
self.guid = ""
super.init()
}
init(title: String, guid : String) {
self.title = title
self.guid = guid
self.uuid = NSUUID().UUIDString
self.phoneNumber = ""
super.init() super.init()
} }
...@@ -32,12 +42,23 @@ class FastPayItem : NSObject, NSCoding { ...@@ -32,12 +42,23 @@ class FastPayItem : NSObject, NSCoding {
title = aDecoder.decodeObjectForKey("title") as! String title = aDecoder.decodeObjectForKey("title") as! String
phoneNumber = aDecoder.decodeObjectForKey("phoneNumber") as! String phoneNumber = aDecoder.decodeObjectForKey("phoneNumber") as! String
uuid = aDecoder.decodeObjectForKey("uuid") as! String uuid = aDecoder.decodeObjectForKey("uuid") as! String
if ( aDecoder.containsValueForKey("guid")) {
guid = aDecoder.decodeObjectForKey("guid") as! String
} else {
guid = ""
}
} }
@objc func encodeWithCoder(aCoder: NSCoder) { @objc func encodeWithCoder(aCoder: NSCoder) {
aCoder.encodeObject(title, forKey: "title") aCoder.encodeObject(title, forKey: "title")
aCoder.encodeObject(phoneNumber, forKey: "phoneNumber") aCoder.encodeObject(phoneNumber, forKey: "phoneNumber")
aCoder.encodeObject(uuid, forKey: "uuid") aCoder.encodeObject(uuid, forKey: "uuid")
aCoder.encodeObject(guid, forKey: "guid")
}
func isPhoneNumber() -> Bool {
return !self.phoneNumber.isEmpty
} }
} }
...@@ -16,6 +16,8 @@ class FastPayCellData : CellData { ...@@ -16,6 +16,8 @@ class FastPayCellData : CellData {
internal var phoneNumberTitle : String = "" internal var phoneNumberTitle : String = ""
internal var phoneNumberValue : String = "" internal var phoneNumberValue : String = ""
internal var creditTitle : String = "" internal var creditTitle : String = ""
internal var accountNumberTitle = ""
internal var accountNumberValue = ""
internal var fastPayItem : FastPayItem? internal var fastPayItem : FastPayItem?
internal var creditValue : String = "" { internal var creditValue : String = "" {
didSet { didSet {
...@@ -40,6 +42,16 @@ class FastPayCellData : CellData { ...@@ -40,6 +42,16 @@ class FastPayCellData : CellData {
self.creditTitle = LS("fastPayCell_credit_title").uppercaseString self.creditTitle = LS("fastPayCell_credit_title").uppercaseString
} }
init (name : String, guid : String, credit : String) {
super.init()
self.name = name
self.accountNumberValue = guid
self.creditValue = credit
self.accountNumberTitle = LS("fastPayCell_accountNumber_title").uppercaseString
self.creditTitle = LS("fastPayCell_credit_title").uppercaseString
}
} }
class UIFastPayTableViewCell : UIBaseTableViewCell { class UIFastPayTableViewCell : UIBaseTableViewCell {
...@@ -60,8 +72,14 @@ class UIFastPayTableViewCell : UIBaseTableViewCell { ...@@ -60,8 +72,14 @@ class UIFastPayTableViewCell : UIBaseTableViewCell {
let myCellData = cellData as! FastPayCellData let myCellData = cellData as! FastPayCellData
lblName.setTextAndSizeToFit(myCellData.name) lblName.setTextAndSizeToFit(myCellData.name)
if ( myCellData.fastPayItem!.isPhoneNumber() ) {
lblPhoneNumberTitle.setTextAndSizeToFit(myCellData.phoneNumberTitle) lblPhoneNumberTitle.setTextAndSizeToFit(myCellData.phoneNumberTitle)
lblPhoneNumberValue.setTextAndSizeToFit("+7\(myCellData.phoneNumberValue)") lblPhoneNumberValue.setTextAndSizeToFit("+7\(myCellData.phoneNumberValue)")
} else {
lblPhoneNumberTitle.setTextAndSizeToFit(myCellData.accountNumberTitle)
lblPhoneNumberValue.setTextAndSizeToFit("\(myCellData.accountNumberValue)")
}
lblCreditTitle.setTextAndSizeToFit(myCellData.creditTitle) lblCreditTitle.setTextAndSizeToFit(myCellData.creditTitle)
lblCreditValue.setTextAndSizeToFit(myCellData.creditValue) lblCreditValue.setTextAndSizeToFit(myCellData.creditValue)
button.setTitle(LS("pay"), forState: .Normal) button.setTitle(LS("pay"), forState: .Normal)
...@@ -71,6 +89,11 @@ class UIFastPayTableViewCell : UIBaseTableViewCell { ...@@ -71,6 +89,11 @@ class UIFastPayTableViewCell : UIBaseTableViewCell {
self.cellData = myCellData self.cellData = myCellData
sendRequest() sendRequest()
self.button.titleLabel?.numberOfLines = 0
self.button.titleLabel?.adjustsFontSizeToFitWidth = true
self.button.titleLabel?.lineBreakMode = NSLineBreakMode.ByWordWrapping
} }
private func sendRequest() { private func sendRequest() {
...@@ -78,6 +101,8 @@ class UIFastPayTableViewCell : UIBaseTableViewCell { ...@@ -78,6 +101,8 @@ class UIFastPayTableViewCell : UIBaseTableViewCell {
let loadingIndicator = UIActivityIndicatorView() let loadingIndicator = UIActivityIndicatorView()
loadingIndicator.startAnimating() loadingIndicator.startAnimating()
self.addSubview(loadingIndicator) self.addSubview(loadingIndicator)
if cellData.fastPayItem!.isPhoneNumber() {
Facade.sharedInstance().getBalance(cellData.phoneNumberValue, onSuccess: { (balance) in Facade.sharedInstance().getBalance(cellData.phoneNumberValue, onSuccess: { (balance) in
var summ = balance var summ = balance
if (summ < 0) { if (summ < 0) {
...@@ -88,16 +113,38 @@ class UIFastPayTableViewCell : UIBaseTableViewCell { ...@@ -88,16 +113,38 @@ class UIFastPayTableViewCell : UIBaseTableViewCell {
if balance <= 0 { if balance <= 0 {
self.lblCreditTitle.setTextAndSizeToFit(LS("fastPayCell_credit_title2").uppercaseString) self.lblCreditTitle.setTextAndSizeToFit(LS("fastPayCell_credit_title2").uppercaseString)
self.button.enabled = false self.button.enabled = false
self.button.titleLabel?.text = "оплата не требуется" self.button.titleLabel?.text = LS("fastPay_positive_balance")
}
loadingIndicator.stopAnimating()
loadingIndicator.removeFromSuperview()
}) { (nsError) in
cellData.creditValue = LS("fastPay_error_during_request")
loadingIndicator.stopAnimating()
loadingIndicator.removeFromSuperview()
}
} else {
Facade.sharedInstance().getBalanceByGuid(cellData.accountNumberValue, onSuccess: { (balance) in
var summ = Double(balance)!
if (summ < 0) {
summ = summ * -1
}
cellData.creditValue = "\(summ) тг."
cellData.summ = "\(summ)"
if Double(balance)! <= 0 {
self.lblCreditTitle.setTextAndSizeToFit(LS("fastPayCell_credit_title2").uppercaseString)
self.button.enabled = false
self.button.titleLabel?.text = LS("fastPay_positive_balance")
} }
loadingIndicator.stopAnimating() loadingIndicator.stopAnimating()
loadingIndicator.removeFromSuperview() loadingIndicator.removeFromSuperview()
}) { (nsError) in }) { (nsError) in
cellData.creditValue = "ошибка получения данных" cellData.creditValue = LS("fastPay_error_during_request")
loadingIndicator.stopAnimating() loadingIndicator.stopAnimating()
loadingIndicator.removeFromSuperview() loadingIndicator.removeFromSuperview()
} }
} }
}
@IBOutlet weak var button: UIButtonRoundedBlue! @IBOutlet weak var button: UIButtonRoundedBlue!
//MARK: - IBActions //MARK: - IBActions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment