-
Notifications
You must be signed in to change notification settings - Fork 0
Swe 13 choose bank account #15
Changes from 8 commits
63bb56b
6ffbf64
18c29c8
0b6fb67
76ef026
61ca428
520d31a
cc16cdf
3594b68
0c9a242
8b78622
d60bd62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// BankAcctCell.swift | ||
// SynchronyFinancial WatchKit Extension | ||
// | ||
// Created by Rahul Kantesaria on 4/5/19. | ||
// Copyright © 2019 Alan Maynard. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import WatchKit | ||
|
||
class BankAcctCell: NSObject { | ||
@IBOutlet weak var bankNameLabel: WKInterfaceLabel! | ||
@IBOutlet weak var last4Label: WKInterfaceLabel! | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,24 +15,28 @@ class PaymentDetailInterfaceController: WKInterfaceController { | |
var dictForPayment: [String: String] = [:] | ||
var paymentButtonArmed: Bool = false | ||
var paymentAmount: Double = 0.0 | ||
|
||
@IBOutlet weak var contentGroup: WKInterfaceGroup! | ||
var dictForBankAcct: [String: [BankAcct]] = [:] | ||
var bankID: String = "" | ||
@IBOutlet weak var activityIndicator: WKInterfaceImage! | ||
@IBOutlet weak var activityIndicatorLabel: WKInterfaceLabel! | ||
@IBOutlet weak var contentGroup: WKInterfaceGroup! | ||
@IBOutlet weak var detailButton: WKInterfaceButton! | ||
@IBOutlet weak var amount: WKInterfaceLabel! | ||
@IBOutlet weak var paymentButton: WKInterfaceButton! | ||
@IBOutlet weak var payFrom: WKInterfaceLabel! | ||
@IBOutlet weak var separate: WKInterfaceSeparator! | ||
|
||
|
||
override func awake(withContext context: Any?) { | ||
super.awake(withContext: context) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I think you intend to show the |
||
|
||
guard let data = context as? [String: Any], | ||
let acct = data["acct"] as? Account, | ||
let amount = data["payment_amount"] as? Double else { | ||
NSLog("Error getting account object and payment amount") | ||
return | ||
|
||
guard let data = context as? [String: Any], let acct = data["acct"] as? Account, let amount = data["payment_amount"] as? Double else { | ||
NSLog("Error getting account object and payment amount") | ||
return | ||
} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can remove this blank line and the line below |
||
|
||
self.paymentAmount = amount | ||
self.selectedAccount = acct | ||
paymentButton.setTitle(String(format: "Pay $%.2f", amount)) | ||
|
@@ -50,7 +54,11 @@ class PaymentDetailInterfaceController: WKInterfaceController { | |
let type: PaymentType = self.paymentAmount == self.selectedAccount?.curBalance ? .currentBal : .minimumDue | ||
|
||
// process this payment using default bank account (9999) until ability to change account is implemented | ||
FetchData.submitPayment(for: alias, type: type, amount: self.paymentAmount, bankID: "9999") { confirmationNum, paymentID, error in | ||
if let bankacct = UserDefaults.standard.dictionary(forKey: "default_bank_acct") as? [String: String] { | ||
self.bankID = bankacct["bankAcctId"] ?? "9999" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we shouldn't be falling back on "9999" as a "default" bank account id unless that is consistent across ALL user accounts. |
||
} | ||
|
||
FetchData.submitPayment(for: alias, type: type, amount: self.paymentAmount, bankID: self.bankID) { confirmationNum, paymentID, error in | ||
guard error == nil else { | ||
let dismiss = WKAlertAction(title: "Dismiss", style: .cancel, handler: {}) | ||
self.presentAlert(withTitle: "Error", message: "We were unable to process your payment at this time. Please try again later.", preferredStyle: .alert, actions: [dismiss]) | ||
|
@@ -74,14 +82,44 @@ class PaymentDetailInterfaceController: WKInterfaceController { | |
} | ||
} | ||
} | ||
|
||
@IBAction func bankAccountsTapped() { | ||
configureInterfaceObjects(true) | ||
activityIndicator.configureForActivityIndicator() | ||
FetchData.getBankInfo { accts, error in guard error == nil else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
NSLog("Error retrieving payment methods for account in paymentDetailInterfaceController.") | ||
return | ||
} | ||
self.dictForBankAcct.updateValue(accts, forKey: "paymentOptions") | ||
self.configureInterfaceObjects(false) | ||
//self.detailButton.setTitle("Hello") | ||
self.activityIndicator.stopAnimatingAsIndicator() | ||
self.pushController(withName: "PaymentOptions", context: self.dictForBankAcct) | ||
} | ||
|
||
} | ||
|
||
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.dictionary(forKey: "default_bank_acct") as? [String: String] { | ||
detailButton.setTitle(bankacct["bankName"]) | ||
} | ||
} | ||
|
||
override func didDeactivate() { | ||
// This method is called when watch view controller is no longer visible | ||
super.didDeactivate() | ||
} | ||
|
||
private func configureInterfaceObjects(_ hide: Bool) { | ||
detailButton.setHidden(hide) | ||
amount.setHidden(hide) | ||
paymentButton.setHidden(hide) | ||
payFrom.setHidden(hide) | ||
separate.setHidden(hide) | ||
contentGroup.setHidden(hide) | ||
activityIndicatorLabel.setVerticalAlignment(.center) | ||
activityIndicatorLabel.setHidden(!hide) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// BankSelectionInterfaceController.swift | ||
// SynchronyFinancial WatchKit Extension | ||
// | ||
// Created by Rahul Kantesaria on 4/5/19. | ||
// Copyright © 2019 Alan Maynard. All rights reserved. | ||
// | ||
|
||
import WatchKit | ||
import Foundation | ||
|
||
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 | ||
configureRows() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. insert new line after this closing brace |
||
override func willActivate() { | ||
// This method is called when watch view controller is about to be visible to user | ||
super.willActivate() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. insert new line after this closing brace |
||
override func didDeactivate() { | ||
// This method is called when watch view controller is no longer visible | ||
super.didDeactivate() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. insert new line after this closing brace |
||
private func configureRows() { | ||
bankAcctTable.setNumberOfRows(bankAccts.count, withRowType: "bankAcctCell") | ||
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))") | ||
} | ||
} | ||
} | ||
|
||
override func table(_ table: WKInterfaceTable, didSelectRowAt rowIndex: Int) { | ||
let acct = bankAccts[rowIndex] | ||
self.dictForDefault.updateValue(acct.acctType.rawValue, forKey: "acctType") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove explicit use of |
||
self.dictForDefault.updateValue(acct.bankAcctId, forKey: "bankAcctId") | ||
self.dictForDefault.updateValue(acct.bankName, forKey: "bankName") | ||
self.dictForDefault.updateValue(acct.last4Acct, forKey: "last4Acct") | ||
UserDefaults.standard.set(dictForDefault, forKey: "default_bank_acct") | ||
pop() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So now that we have a raw value of
String
forAccountType
we should just be able to say:let accttype = AccountType(rawValue: $0["bank_account_type"].stringValue)