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 @@
landmarkType = "7">
</BreakpointContent>
</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>
</Bucket>
......@@ -9,28 +9,27 @@
import Foundation
extension Facade {
func createOrder(params: [String: AnyObject], onSuccess: (data: NSData) -> Void, onError: ((error: String) -> Void), onFinish: () -> Void) {
request(Router.CreateOrder(params)).responseData { (resp) in
Router.globalLog.debug(resp.request!)
onFinish()
if let error = resp.result.error {
Router.globalLog.error(error.debugDescription)
onError(error: error.localizedDescription)
} else {
let json = JSON(data: resp.data!)
Router.globalLog.debug(resp.response!)
Router.globalLog.debug(json)
if let errorCode = json["error_code"].int, let errorMsg = json["error"].string where errorCode != 0 {
Router.globalLog.error("errorCode: \(errorCode), errorMsg: \(errorMsg)")
onError(error: errorMsg)
} else {
onSuccess(data: resp.data!)
request(Router.CreateOrder(params)).responseData { (resp) in
Router.globalLog.debug(resp.request!)
onFinish()
if let error = resp.result.error {
Router.globalLog.error(error.debugDescription)
onError(error: error.localizedDescription)
} else {
let json = JSON(data: resp.data!)
Router.globalLog.debug(resp.response!)
Router.globalLog.debug(json)
if let errorCode = json["error_code"].int, let errorMsg = json["error"].string where errorCode != 0 {
Router.globalLog.error("errorCode: \(errorCode), errorMsg: \(errorMsg)")
onError(error: errorMsg)
} else {
onSuccess(data: resp.data!)
}
}
}
}
}
}
func getBalance(phoneNumber: String, onSuccess: ((Int) -> Void)? = nil, onError: ((NSError) -> Void)? = nil) {
if Facade.accessToken == nil || Facade.clientId == nil {
......
......@@ -43,7 +43,7 @@ extension FastPayManager {
func getStoredFastPays() -> [FastPayItem] {
var result : [FastPayItem] = []
createInternalFastPay()
//createInternalFastPay()
let storeresult = retrieveFastPays()
if (storeresult != nil) {
result = storeresult!
......@@ -84,6 +84,7 @@ extension FastPayManager {
if (items == nil) {
items = []
}
//removeFromStoreFastPay(fastPay)
items!.append(fastPay)
saveStoreFastPay(items!)
}
......@@ -92,8 +93,8 @@ extension FastPayManager {
let items = getStoredFastPays()
let mutableItems : NSMutableArray = NSMutableArray(array: items)
for item in mutableItems {
let fastPay = item as! FastPayItem
if fastPay.compare(fastPay) {
let fastPay2 = item as! FastPayItem
if fastPay2.compare(fastPay) {
mutableItems.removeObject(item)
break
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -612,3 +612,10 @@
"callback_request" = "Заявка на обратный звонок";
"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 @@
"callback_request" = "Заявка на обратный звонок";
"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 @@
"callback_request" = "Заявка на обратный звонок";
"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 {
cellsData = []
let items = FastPayManager.sharedInstance().getStoredFastPays()
for fastPay in items {
let cellData = FastPayCellData(name: fastPay.title, phoneNumber: fastPay.phoneNumber, credit: "")
let cellData = getFastPayCellData(fastPay)
cellData.fastPayItem = fastPay
cellData.onClick = {
self.showEditForm(cellData.fastPayItem!)
......@@ -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) {
performSegueWithIdentifier("createPayIdentifier", sender: fastPay)
}
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)
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 }
self.processRequest(true)
Facade.sharedInstance().createOrder(request.params, onSuccess: { (data) in
......@@ -120,7 +144,6 @@ class UIFastPayViewController : ViewControllerWithMenu, UITableViewDelegate {
}, onFinish: {
self.processRequest(false)
})
}
//MARK: - IBOutlets
......
......@@ -13,11 +13,21 @@ class FastPayItem : NSObject, NSCoding {
internal var title : String = ""
internal var phoneNumber : String = ""
internal var uuid : String = ""
internal var guid : String = ""
init(title: String, phoneNumber : String) {
self.title = title
self.phoneNumber = phoneNumber
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()
}
......@@ -32,12 +42,23 @@ class FastPayItem : NSObject, NSCoding {
title = aDecoder.decodeObjectForKey("title") as! String
phoneNumber = aDecoder.decodeObjectForKey("phoneNumber") 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) {
aCoder.encodeObject(title, forKey: "title")
aCoder.encodeObject(phoneNumber, forKey: "phoneNumber")
aCoder.encodeObject(uuid, forKey: "uuid")
aCoder.encodeObject(guid, forKey: "guid")
}
func isPhoneNumber() -> Bool {
return !self.phoneNumber.isEmpty
}
}
......@@ -16,6 +16,8 @@ class FastPayCellData : CellData {
internal var phoneNumberTitle : String = ""
internal var phoneNumberValue : String = ""
internal var creditTitle : String = ""
internal var accountNumberTitle = ""
internal var accountNumberValue = ""
internal var fastPayItem : FastPayItem?
internal var creditValue : String = "" {
didSet {
......@@ -40,6 +42,16 @@ class FastPayCellData : CellData {
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 {
......@@ -60,8 +72,14 @@ class UIFastPayTableViewCell : UIBaseTableViewCell {
let myCellData = cellData as! FastPayCellData
lblName.setTextAndSizeToFit(myCellData.name)
lblPhoneNumberTitle.setTextAndSizeToFit(myCellData.phoneNumberTitle)
lblPhoneNumberValue.setTextAndSizeToFit("+7\(myCellData.phoneNumberValue)")
if ( myCellData.fastPayItem!.isPhoneNumber() ) {
lblPhoneNumberTitle.setTextAndSizeToFit(myCellData.phoneNumberTitle)
lblPhoneNumberValue.setTextAndSizeToFit("+7\(myCellData.phoneNumberValue)")
} else {
lblPhoneNumberTitle.setTextAndSizeToFit(myCellData.accountNumberTitle)
lblPhoneNumberValue.setTextAndSizeToFit("\(myCellData.accountNumberValue)")
}
lblCreditTitle.setTextAndSizeToFit(myCellData.creditTitle)
lblCreditValue.setTextAndSizeToFit(myCellData.creditValue)
button.setTitle(LS("pay"), forState: .Normal)
......@@ -71,6 +89,11 @@ class UIFastPayTableViewCell : UIBaseTableViewCell {
self.cellData = myCellData
sendRequest()
self.button.titleLabel?.numberOfLines = 0
self.button.titleLabel?.adjustsFontSizeToFitWidth = true
self.button.titleLabel?.lineBreakMode = NSLineBreakMode.ByWordWrapping
}
private func sendRequest() {
......@@ -78,27 +101,51 @@ class UIFastPayTableViewCell : UIBaseTableViewCell {
let loadingIndicator = UIActivityIndicatorView()
loadingIndicator.startAnimating()
self.addSubview(loadingIndicator)
Facade.sharedInstance().getBalance(cellData.phoneNumberValue, onSuccess: { (balance) in
var summ = balance
if (summ < 0) {
summ = summ * -1
}
cellData.creditValue = "\(summ) тг."
cellData.summ = "\(summ)"
if balance <= 0 {
self.lblCreditTitle.setTextAndSizeToFit(LS("fastPayCell_credit_title2").uppercaseString)
self.button.enabled = false
self.button.titleLabel?.text = "оплата не требуется"
if cellData.fastPayItem!.isPhoneNumber() {
Facade.sharedInstance().getBalance(cellData.phoneNumberValue, onSuccess: { (balance) in
var summ = balance
if (summ < 0) {
summ = summ * -1
}
cellData.creditValue = "\(summ) тг."
cellData.summ = "\(summ)"
if 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
cellData.creditValue = LS("fastPay_error_during_request")
loadingIndicator.stopAnimating()
loadingIndicator.removeFromSuperview()
}
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.removeFromSuperview()
}) { (nsError) in
cellData.creditValue = "ошибка получения данных"
cellData.creditValue = LS("fastPay_error_during_request")
loadingIndicator.stopAnimating()
loadingIndicator.removeFromSuperview()
}
}
}
@IBOutlet weak var button: UIButtonRoundedBlue!
//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