Skip to content
Permalink
Browse files

SWF-13 updating default payment option

  • Loading branch information
rrk12005 committed Apr 6, 2019
1 parent 6ffbf64 commit 18c29c8bcb26dc2161b0eeb4ac8d2cbae7f2eadf
@@ -27,10 +27,22 @@ class PaymentDetailInterfaceController: WKInterfaceController {
NSLog("Error getting account object and payment amount") NSLog("Error getting account object and payment amount")
return return
} }

FetchData.getBankInfo{ accts, error in guard error == nil else {
NSLog("Error retrieving payment methods for account in paymentDetailInterfaceController.")
return
}

self.dictForBankAcct.updateValue(accts, forKey: "paymentOptions")

}
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))
if let p1 = self.dictForBankAcct["paymentOptions"] {
UserDefaults.standard.set(p1[0], forKey: "default_bank_acct")
print("yes")
self.detailButton.setTitle(p1[0].bankName)
}
} }


@IBAction func paymentAction() { @IBAction func paymentAction() {
@@ -47,20 +59,16 @@ class PaymentDetailInterfaceController: WKInterfaceController {
} }
} }


@IBAction func bankAccountsTapped(){ @IBAction func bankAccountsTapped() {
FetchData.getBankInfo{ accts, error in guard error == nil else{ self.pushController(withName: "PaymentOptions", context: self.dictForBankAcct)
NSLog("Error retrieving payment methods for account in paymentDetailInterfaceController.")
return
}

self.dictForBankAcct.updateValue(accts, forKey: "paymentOptions")
self.pushController(withName: "PaymentOptions", context: self.dictForBankAcct)
}
} }


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.value(forKey: "default_bank_acct") as? BankAcct {
detailButton.setTitle(bankacct.bankName)
}
} }


override func didDeactivate() { override func didDeactivate() {
@@ -25,3 +25,17 @@ class BankAcct: NSObject {
self.last4Acct = last4Acct self.last4Acct = last4Acct
} }
} }

extension UserDefaults {
func setDefaultBankAccount(_ acct: BankAcct) {
UserDefaults.standard.set(acct, forKey: "default_bank_acct")
}

func getDefaultBankAccount() -> BankAcct? {
if let bank = UserDefaults.standard.value(forKey: "default_bank_acct") as? BankAcct {
return bank
}

return nil
}
}

0 comments on commit 18c29c8

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