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>
...@@ -9,28 +9,27 @@ ...@@ -9,28 +9,27 @@
import Foundation import Foundation
extension Facade { extension Facade {
func createOrder(params: [String: AnyObject], onSuccess: (data: NSData) -> Void, onError: ((error: String) -> Void), onFinish: () -> Void) { func createOrder(params: [String: AnyObject], onSuccess: (data: NSData) -> Void, onError: ((error: String) -> Void), onFinish: () -> Void) {
request(Router.CreateOrder(params)).responseData { (resp) in request(Router.CreateOrder(params)).responseData { (resp) in
Router.globalLog.debug(resp.request!) Router.globalLog.debug(resp.request!)
onFinish() onFinish()
if let error = resp.result.error { if let error = resp.result.error {
Router.globalLog.error(error.debugDescription) Router.globalLog.error(error.debugDescription)
onError(error: error.localizedDescription) onError(error: error.localizedDescription)
} else { } else {
let json = JSON(data: resp.data!) let json = JSON(data: resp.data!)
Router.globalLog.debug(resp.response!) Router.globalLog.debug(resp.response!)
Router.globalLog.debug(json) Router.globalLog.debug(json)
if let errorCode = json["error_code"].int, let errorMsg = json["error"].string where errorCode != 0 { if let errorCode = json["error_code"].int, let errorMsg = json["error"].string where errorCode != 0 {
Router.globalLog.error("errorCode: \(errorCode), errorMsg: \(errorMsg)") Router.globalLog.error("errorCode: \(errorCode), errorMsg: \(errorMsg)")
onError(error: errorMsg) onError(error: errorMsg)
} else { } else {
onSuccess(data: resp.data!) onSuccess(data: resp.data!)
}
}
} }
}
} }
}
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 {
......
...@@ -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" = "Ошибка получения данных";
...@@ -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)
lblPhoneNumberTitle.setTextAndSizeToFit(myCellData.phoneNumberTitle) if ( myCellData.fastPayItem!.isPhoneNumber() ) {
lblPhoneNumberValue.setTextAndSizeToFit("+7\(myCellData.phoneNumberValue)") lblPhoneNumberTitle.setTextAndSizeToFit(myCellData.phoneNumberTitle)
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,27 +101,51 @@ class UIFastPayTableViewCell : UIBaseTableViewCell { ...@@ -78,27 +101,51 @@ class UIFastPayTableViewCell : UIBaseTableViewCell {
let loadingIndicator = UIActivityIndicatorView() let loadingIndicator = UIActivityIndicatorView()
loadingIndicator.startAnimating() loadingIndicator.startAnimating()
self.addSubview(loadingIndicator) self.addSubview(loadingIndicator)
Facade.sharedInstance().getBalance(cellData.phoneNumberValue, onSuccess: { (balance) in
var summ = balance if cellData.fastPayItem!.isPhoneNumber() {
if (summ < 0) { Facade.sharedInstance().getBalance(cellData.phoneNumberValue, onSuccess: { (balance) in
summ = summ * -1 var summ = balance
} if (summ < 0) {
cellData.creditValue = "\(summ) тг." summ = summ * -1
cellData.summ = "\(summ)" }
if balance <= 0 { cellData.creditValue = "\(summ) тг."
self.lblCreditTitle.setTextAndSizeToFit(LS("fastPayCell_credit_title2").uppercaseString) cellData.summ = "\(summ)"
self.button.enabled = false if balance <= 0 {
self.button.titleLabel?.text = "оплата не требуется" self.lblCreditTitle.setTextAndSizeToFit(LS("fastPayCell_credit_title2").uppercaseString)
self.button.enabled = false
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()
} }
loadingIndicator.stopAnimating() } else {
loadingIndicator.removeFromSuperview() 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.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