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 Foundation
import WatchKit import WatchKit


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

} }
@@ -103,7 +103,6 @@ class FetchData {
let modifiable = $0["is_payment_modifiable"].string { let modifiable = $0["is_payment_modifiable"].string {
let type: TransactionType = $0["payment_amount_type"].stringValue == "" ? .purchase : .reimbursement let type: TransactionType = $0["payment_amount_type"].stringValue == "" ? .purchase : .reimbursement
let isModifiable: Bool = modifiable == "Y" ? true : false 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)) 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 last4Acct = $0["last4_bank_acct_number"].string,
let accttype: AccountType = $0["bank_account_type"].stringValue == let accttype: AccountType = $0["bank_account_type"].stringValue ==
"C" ? .checkings : .savings { "C" ? .checkings : .savings {
print(bankId)
print(accttype)
bankIds.append(BankAcct(bankAcctId: bankId, acctType: accttype, bankName: bankName, last4Acct: last4Acct)) 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){ static func cancelPayment(accountAlias: String, confirmationNum: String, paymentId: Int, completion: @escaping (String, Error?) -> Void){

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

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



class PaymentDetailInterfaceController: WKInterfaceController { class PaymentDetailInterfaceController: WKInterfaceController {
var selectedAccount: Account? var selectedAccount: Account?
var dictForAcct: [String: Account] = [:] var dictForAcct: [String: Account] = [:]
var paymentButtonArmed: Bool = false var paymentButtonArmed: Bool = false
var paymentAmount: Double = 0.0 var paymentAmount: Double = 0.0
var dictForBankAcct: [String:[BankAcct]] = [:] var dictForBankAcct: [String: [BankAcct]] = [:]
@IBOutlet var activityIndicator: WKInterfaceImage! @IBOutlet var activityIndicator: WKInterfaceImage!
@IBOutlet weak var detailButton: WKInterfaceButton! @IBOutlet weak var detailButton: WKInterfaceButton!
@IBOutlet weak var amount: WKInterfaceLabel! @IBOutlet weak var amount: WKInterfaceLabel!
@@ -32,7 +31,7 @@ class PaymentDetailInterfaceController: WKInterfaceController {
return 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.") NSLog("Error retrieving payment methods for account in paymentDetailInterfaceController.")
return return
} }
@@ -44,8 +43,6 @@ class PaymentDetailInterfaceController: WKInterfaceController {
self.paymentAmount = amount self.paymentAmount = amount
self.selectedAccount = acct self.selectedAccount = acct
paymentButton.setTitle(String(format: "Pay $%.2f", amount)) paymentButton.setTitle(String(format: "Pay $%.2f", amount))


} }


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


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

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


@IBOutlet weak var bankAcctTable: WKInterfaceTable! @IBOutlet weak var bankAcctTable: WKInterfaceTable!
var bankAccts: [BankAcct] = [] var bankAccts: [BankAcct] = []
var dictForDefault: [String: String] = [:]
override func awake(withContext context: Any?) { override func awake(withContext context: Any?) {
super.awake(withContext: context) 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 { guard let data = context as? [String: [BankAcct]], let accts = data["paymentOptions"] else {
NSLog("Error receiving context containing bank accounts in PaymentOptionsInterfaceController") NSLog("Error receiving context containing bank accounts in PaymentOptionsInterfaceController")
return return
} }

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

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


override func table(_ table: WKInterfaceTable, didSelectRowAt rowIndex: Int) { override func table(_ table: WKInterfaceTable, didSelectRowAt rowIndex: Int) {
let acct = bankAccts[rowIndex] 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() 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 start_date = formatter.string(from: Calendar.current.date(byAdding: .day, value: -14, to: Date()) ?? Date())
let end_date = formatter.string(from: Date()) let end_date = formatter.string(from: Date())



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

0 comments on commit 76ef026

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