-
Notifications
You must be signed in to change notification settings - Fork 0
Swe 13 choose bank account #15
Changes from 5 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! | ||
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. same as above |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
} | ||
} | ||
|
@@ -137,11 +136,11 @@ class FetchData { | |
//"fetch_bank_account_details" | ||
dict["fetch_bank_account_details"]?.arrayValue.forEach { | ||
if let bankId = $0["bank_account_id"].string, | ||
let bankName = $0["bank_name"].string, | ||
let last4Acct = $0["last4_bank_acct_number"].string, | ||
let accttype: AccountType = $0["bank_account_type"].stringValue == | ||
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 now that we have a raw value of |
||
"C" ? .checkings : .savings { | ||
//print(bankId) | ||
//print(accttype) | ||
bankIds.append(BankAcct(bankAcctId: bankId, acctType: accttype)) | ||
bankIds.append(BankAcct(bankAcctId: bankId, acctType: accttype, bankName: bankName, last4Acct: last4Acct)) | ||
} | ||
} | ||
completion(bankIds, nil) | ||
|
@@ -153,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): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,18 +14,32 @@ class PaymentDetailInterfaceController: WKInterfaceController { | |
var dictForAcct: [String: Account] = [:] | ||
var paymentButtonArmed: Bool = false | ||
var paymentAmount: Double = 0.0 | ||
|
||
var dictForBankAcct: [String: [BankAcct]] = [:] | ||
@IBOutlet var activityIndicator: WKInterfaceImage! | ||
@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?) { | ||
configureInterfaceObjects(true) | ||
activityIndicator.configureForActivityIndicator() | ||
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 | ||
} | ||
|
||
|
||
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 |
||
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.configureInterfaceObjects(false) | ||
//self.detailButton.setTitle("Hello") | ||
self.activityIndicator.stopAnimatingAsIndicator() | ||
} | ||
self.paymentAmount = amount | ||
self.selectedAccount = acct | ||
paymentButton.setTitle(String(format: "Pay $%.2f", amount)) | ||
|
@@ -44,14 +58,37 @@ class PaymentDetailInterfaceController: WKInterfaceController { | |
paymentButton.setTitle("Pay Now") | ||
} | ||
} | ||
|
||
@IBAction func bankAccountsTapped() { | ||
self.pushController(withName: "PaymentOptions", context: self.dictForBankAcct) | ||
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. unnecessary use of explicit |
||
} | ||
|
||
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) | ||
/*if(!hide){ | ||
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. debug code should be removed prior to merging into |
||
if let p1 = self.dictForBankAcct["paymentOptions"] { | ||
let x = p1[0] | ||
UserDefaults.standard.set(x, forKey: "default_bank_acct") | ||
print("yes") | ||
detailButton.setTitle(p1[0].bankName) | ||
} | ||
}*/ | ||
} | ||
} |
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(String(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. So this line is creating a new 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, for this line and the lines below, we don't need the explicit use of 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. since it's a dictionary of strings, this value needs to be a string, therefore the conversion from int to string is necessary to store the value in the dict 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 in that case we should change the raw value of 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. good point. I'll add that with my changes |
||
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() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,26 @@ public enum AccountType: Int { | |
class BankAcct: NSObject { | ||
var bankAcctId: String | ||
var acctType: AccountType | ||
init(bankAcctId: String, acctType: AccountType) { | ||
var bankName: String | ||
var last4Acct: String | ||
init(bankAcctId: String, acctType: AccountType, bankName: String, last4Acct: String) { | ||
self.bankAcctId = bankAcctId | ||
self.acctType = acctType | ||
self.bankName = bankName | ||
self.last4Acct = last4Acct | ||
} | ||
} | ||
|
||
extension UserDefaults { | ||
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. This extension on |
||
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 | ||
} | ||
} |
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.
variable names should begin with a lowercase and follow camel case style.