Skip to content
Permalink
Browse files

SWF-13 finished addition of ability to choose bank account to pay for…

…. new structure of storing default bank account in UseraDefaults
  • Loading branch information
rrk12005 committed Apr 7, 2019
1 parent 0b6fb67 commit 76ef02638d5e788a6b5b93559f8fd867be454a66
@@ -9,8 +9,7 @@
import Foundation
import WatchKit

class BankAcctCell: NSObject{
class BankAcctCell: NSObject {
@IBOutlet weak var BankNameLabel: WKInterfaceLabel!
@IBOutlet weak var Last4Label: WKInterfaceLabel!

}
@@ -103,7 +103,6 @@ class FetchData {
let modifiable = $0["is_payment_modifiable"].string {
let type: TransactionType = $0["payment_amount_type"].stringValue == "" ? .purchase : .reimbursement
let isModifiable: Bool = modifiable == "Y" ? true : false

transactions.append(Transaction(type: type, amount: amount, merchantID: desc, date: date, confirmationNum: confirmationNum, paymentId: paymentId, isPending: true, isModifiable: isModifiable))
}
}
@@ -141,8 +140,6 @@ class FetchData {
let last4Acct = $0["last4_bank_acct_number"].string,
let accttype: AccountType = $0["bank_account_type"].stringValue ==
"C" ? .checkings : .savings {
print(bankId)
print(accttype)
bankIds.append(BankAcct(bankAcctId: bankId, acctType: accttype, bankName: bankName, last4Acct: last4Acct))
}
}
@@ -155,12 +152,10 @@ class FetchData {
}

static func cancelPayment(accountAlias: String, confirmationNum: String, paymentId: Int, completion: @escaping (String, Error?) -> Void){

var paymentHeader = Defaults.headerForCancelPmt
paymentHeader["account_alias"] = accountAlias
paymentHeader["payment_confirmation_number"] = confirmationNum
paymentHeader["payment_id"] = paymentId

Alamofire.request(Defaults.CANCEL_PAYMENT_URL, method: .post, parameters: paymentHeader, encoding: JSONEncoding.default, headers: Defaults.authHeader).responseJSON { payload in
switch payload.result {
case .success(let value):
@@ -9,13 +9,12 @@
import WatchKit
import Foundation


class PaymentDetailInterfaceController: WKInterfaceController {
var selectedAccount: Account?
var dictForAcct: [String: Account] = [:]
var paymentButtonArmed: Bool = false
var paymentAmount: Double = 0.0
var dictForBankAcct: [String:[BankAcct]] = [:]
var dictForBankAcct: [String: [BankAcct]] = [:]
@IBOutlet var activityIndicator: WKInterfaceImage!
@IBOutlet weak var detailButton: WKInterfaceButton!
@IBOutlet weak var amount: WKInterfaceLabel!
@@ -32,7 +31,7 @@ class PaymentDetailInterfaceController: WKInterfaceController {
return
}

FetchData.getBankInfo{ accts, error in guard error == nil else {
FetchData.getBankInfo { accts, error in guard error == nil else {
NSLog("Error retrieving payment methods for account in paymentDetailInterfaceController.")
return
}
@@ -44,8 +43,6 @@ class PaymentDetailInterfaceController: WKInterfaceController {
self.paymentAmount = amount
self.selectedAccount = acct
paymentButton.setTitle(String(format: "Pay $%.2f", amount))


}

@IBAction func paymentAction() {
@@ -69,10 +66,9 @@ class PaymentDetailInterfaceController: WKInterfaceController {
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
if let bankacct = UserDefaults.standard.string(forKey: "default_bank_acct"){
detailButton.setTitle(bankacct)
if let bankacct = UserDefaults.standard.dictionary(forKey: "default_bank_acct") as? [String: String] {
detailButton.setTitle(bankacct["bankName"])
}
print("hots here")
}

override func didDeactivate() {
@@ -95,5 +91,4 @@ class PaymentDetailInterfaceController: WKInterfaceController {
}
}*/
}

}
@@ -13,18 +13,16 @@ class PaymentOptionsInterfaceController: WKInterfaceController {

@IBOutlet weak var bankAcctTable: WKInterfaceTable!
var bankAccts: [BankAcct] = []
var dictForDefault: [String: String] = [:]
override func awake(withContext context: Any?) {
super.awake(withContext: context)

//grab the potential list of bank accounts from the payment detail controller
guard let data = context as? [String: [BankAcct]], let accts = data["paymentOptions"] else {
NSLog("Error receiving context containing bank accounts in PaymentOptionsInterfaceController")
return
}

bankAccts = accts
print(bankAccts.count)
configureRows()

}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
@@ -34,9 +32,9 @@ class PaymentOptionsInterfaceController: WKInterfaceController {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
private func configureRows(){
private func configureRows() {
bankAcctTable.setNumberOfRows(bankAccts.count, withRowType: "bankAcctCell")
for index in 0..<bankAcctTable.numberOfRows{
for index in 0..<bankAcctTable.numberOfRows {
if let row = bankAcctTable.rowController(at: index) as? BankAcctCell {
row.BankNameLabel.setText(bankAccts[index].bankName)
row.Last4Label.setText("(\(bankAccts[index].last4Acct))")
@@ -46,7 +44,11 @@ class PaymentOptionsInterfaceController: WKInterfaceController {

override func table(_ table: WKInterfaceTable, didSelectRowAt rowIndex: Int) {
let acct = bankAccts[rowIndex]
UserDefaults.standard.set(acct.bankName, forKey: "default_bank_acct")
self.dictForDefault.updateValue(String(acct.acctType.rawValue), forKey: "acctType")
self.dictForDefault.updateValue(acct.bankAcctId, forKey: "bankAcctId")
self.dictForDefault.updateValue(acct.bankName, forKey: "bankName")
self.dictForDefault.updateValue(acct.last4Acct, forKey: "last4Acct")
UserDefaults.standard.set(self.dictForDefault, forKey: "default_bank_acct")
pop()
}
}
@@ -55,7 +55,6 @@ final class Defaults {
let start_date = formatter.string(from: Calendar.current.date(byAdding: .day, value: -14, to: Date()) ?? Date())
let end_date = formatter.string(from: Date())


return ["account_alias": account_alias,
"begin_sequence": "1",
"end_date": end_date,

0 comments on commit 76ef026

Please sign in to comment.
You can’t perform that action at this time.