Skip to content

Swe 13 choose bank account #15

Merged
merged 12 commits into from Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="14490.70" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Qge-pO-HLc">
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="14460.31" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Qge-pO-HLc">
<device id="watch38" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="watchOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="14490.21"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="14460.16"/>
</dependencies>
<scenes>
<!--root-->
Expand Down Expand Up @@ -201,9 +201,13 @@
<objects>
<controller id="t8d-XB-ngB" customClass="PaymentDetailInterfaceController" customModule="SynchronyFinancial_WatchKit_App" customModuleProvider="target">
<items>
<imageView alignment="left" hidden="YES" id="fzG-LV-j7G"/>
<label width="1" alignment="center" text="Pay From:" textAlignment="center" id="xE5-Zl-U7d"/>
<button width="1" height="40" alignment="left" title="Synchrony (1234)" id="SZD-0B-PrF" userLabel="detailButton">
<button width="1" height="40" alignment="left" title="Select Bank" id="SZD-0B-PrF" userLabel="detailButton">
<fontDescription key="font" type="system" pointSize="15"/>
<connections>
<action selector="bankAccountsTapped" destination="t8d-XB-ngB" id="bQR-Mu-nB6"/>
</connections>
</button>
<separator alignment="left" verticalAlignment="center" id="et0-Sq-Qxm">
<color key="color" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
Expand All @@ -218,14 +222,46 @@
</button>
</items>
<connections>
<outlet property="activityIndicator" destination="fzG-LV-j7G" id="zqA-Vd-Kjv"/>
<outlet property="amount" destination="mT0-3D-JGP" id="rff-wG-B82"/>
<outlet property="detailButton" destination="SZD-0B-PrF" id="xEw-gE-yIP"/>
<outlet property="payFrom" destination="xE5-Zl-U7d" id="62t-6n-KSD"/>
<outlet property="paymentButton" destination="FgU-iZ-2XU" id="yZe-dZ-nBV"/>
<outlet property="separate" destination="et0-Sq-Qxm" id="JfK-S7-H9d"/>
</connections>
</controller>
</objects>
<point key="canvasLocation" x="1085" y="186"/>
</scene>
<!--PaymentOptions-->
<scene sceneID="T56-bi-gCI">
<objects>
<controller identifier="PaymentOptions" id="jbp-Bi-Bk7" userLabel="PaymentOptions" customClass="PaymentOptionsInterfaceController" customModule="SynchronyFinancial_WatchKit_Extension">
<items>
<table alignment="left" id="RJQ-am-qV6" userLabel="Banks Table">
<items>
<tableRow identifier="bankAcctCell" id="Mfw-7m-ih3" customClass="BankAcctCell" customModule="SynchronyFinancial_WatchKit_Extension">
<group key="rootItem" width="1" height="43" alignment="left" layout="vertical" id="8u2-82-z5f">
<items>
<label width="136" alignment="left" text="Bank Name" id="y0D-7u-Qtr" userLabel="Bank Name Label"/>
<label width="58" height="20" alignment="left" text="(1234)" id="FMl-Jx-r2b" userLabel="last4 Label"/>
</items>
</group>
<connections>
<outlet property="BankNameLabel" destination="y0D-7u-Qtr" id="viE-xk-diN"/>
<outlet property="Last4Label" destination="FMl-Jx-r2b" id="1ho-kI-jgE"/>
</connections>
</tableRow>
</items>
</table>
</items>
<connections>
<outlet property="bankAcctTable" destination="RJQ-am-qV6" id="mjy-8f-Qzt"/>
</connections>
</controller>
</objects>
<point key="canvasLocation" x="1416" y="186"/>
</scene>
<!--Transactions-->
<scene sceneID="yXO-yR-k6b">
<objects>
Expand Down
@@ -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!
Copy link
Collaborator

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.

@IBOutlet weak var Last4Label: WKInterfaceLabel!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

}
Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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 ==
Copy link
Collaborator

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 for AccountType we should just be able to say:
let accttype = AccountType(rawValue: $0["bank_account_type"].stringValue)

"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)
Expand All @@ -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):
Expand Down
Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super.awake(withContext: context) should be the first call within this function

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think you intend to show the activityIndicatorLabel here and then hide it again once web service returns

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
}


Copy link
Collaborator

Choose a reason for hiding this comment

The 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))
Expand All @@ -44,14 +58,37 @@ class PaymentDetailInterfaceController: WKInterfaceController {
paymentButton.setTitle("Pay Now")
}
}

@IBAction func bankAccountsTapped() {
self.pushController(withName: "PaymentOptions", context: self.dictForBankAcct)
Copy link
Collaborator

@ahm11003 ahm11003 Apr 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary use of explicit self in function call as well as when passing in 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)
/*if(!hide){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug code should be removed prior to merging into master

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)
}
}*/
}
}
@@ -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()
}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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()
}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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()
}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this line is creating a new String from the acct.acctType.rawValue which will evaluate to either "1" or "0". Is that the intended behavior? Is there a reason we couldn't just use the rawValue which is int?

Copy link
Collaborator

Choose a reason for hiding this comment

The 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 self

Copy link
Owner Author

Choose a reason for hiding this comment

The 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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in that case we should change the raw value of AccountType to be String so we can avoid this conversion. The raw values of checking and savings can simply be string representations of those words

Copy link
Owner Author

Choose a reason for hiding this comment

The 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()
}
}
10 changes: 8 additions & 2 deletions SynchronyFinancial/SynchronyFinancial.xcodeproj/project.pbxproj
Expand Up @@ -8,10 +8,11 @@

/* Begin PBXBuildFile section */
1123372E223ABD6400B70925 /* FetchData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1123372D223ABD6400B70925 /* FetchData.swift */; };
112969422257B8920082AAC5 /* PaymentOptionsInterfaceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 112969412257B8920082AAC5 /* PaymentOptionsInterfaceController.swift */; };
112B56512257C3D9003E9C78 /* BankAcctCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 112B56502257C3D9003E9C78 /* BankAcctCell.swift */; };
11E6ADB92253FA050009922E /* BankAcct.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11E6ADB82253FA050009922E /* BankAcct.swift */; };
11E6ADBA225401DB0009922E /* BankAcct.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11E6ADB82253FA050009922E /* BankAcct.swift */; };
281283568A34D3C5D9C7B383 /* libPods-SynchronyFinancial WatchKit Extension.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CAA6D46F907ADAABF49FD409 /* libPods-SynchronyFinancial WatchKit Extension.a */; };
481864A8224802BB0059CF7A /* PaymentDetailInterfaceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 481864A7224802BB0059CF7A /* PaymentDetailInterfaceController.swift */; };
481864A9224802BB0059CF7A /* PaymentDetailInterfaceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 481864A7224802BB0059CF7A /* PaymentDetailInterfaceController.swift */; };
48DA0058221D12E70081A500 /* AccountCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48DA0057221D12E70081A500 /* AccountCell.swift */; };
48F243072214C98600B9C894 /* AccountTableInterfaceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48F243062214C98600B9C894 /* AccountTableInterfaceController.swift */; };
Expand Down Expand Up @@ -87,6 +88,8 @@

/* Begin PBXFileReference section */
1123372D223ABD6400B70925 /* FetchData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchData.swift; sourceTree = "<group>"; };
112969412257B8920082AAC5 /* PaymentOptionsInterfaceController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentOptionsInterfaceController.swift; sourceTree = "<group>"; };
112B56502257C3D9003E9C78 /* BankAcctCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BankAcctCell.swift; sourceTree = "<group>"; };
11E6ADB82253FA050009922E /* BankAcct.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BankAcct.swift; sourceTree = "<group>"; };
1BEF4B8BF190D117CA6104E5 /* Pods-SynchronyFinancial WatchKit App.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SynchronyFinancial WatchKit App.release.xcconfig"; path = "Pods/Target Support Files/Pods-SynchronyFinancial WatchKit App/Pods-SynchronyFinancial WatchKit App.release.xcconfig"; sourceTree = "<group>"; };
250BDAF6AD4E1CCA82995E30 /* Pods-SynchronyFinancial WatchKit Extension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SynchronyFinancial WatchKit Extension.release.xcconfig"; path = "Pods/Target Support Files/Pods-SynchronyFinancial WatchKit Extension/Pods-SynchronyFinancial WatchKit Extension.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -217,6 +220,8 @@
676392B52242A3F800740A8C /* TransactionCell.swift */,
67BAC293219E254900713FEF /* Info.plist */,
1123372D223ABD6400B70925 /* FetchData.swift */,
112969412257B8920082AAC5 /* PaymentOptionsInterfaceController.swift */,
112B56502257C3D9003E9C78 /* BankAcctCell.swift */,
);
path = "SynchronyFinancial WatchKit Extension";
sourceTree = "<group>";
Expand Down Expand Up @@ -471,7 +476,6 @@
674BD1532239A39D0076AFD6 /* PayBillInterfaceController.swift in Sources */,
48F2430D2214CBF700B9C894 /* Account.swift in Sources */,
678C388622309F7D00FEAAF6 /* AccountCell.swift in Sources */,
481864A8224802BB0059CF7A /* PaymentDetailInterfaceController.swift in Sources */,
11E6ADB92253FA050009922E /* BankAcct.swift in Sources */,
48F2430E2214CBF700B9C894 /* Transaction.swift in Sources */,
67BAC269219E254700713FEF /* AppDelegate.swift in Sources */,
Expand All @@ -483,13 +487,15 @@
buildActionMask = 2147483647;
files = (
11E6ADBA225401DB0009922E /* BankAcct.swift in Sources */,
112B56512257C3D9003E9C78 /* BankAcctCell.swift in Sources */,
678C3885223098C400FEAAF6 /* Account.swift in Sources */,
67BAC28E219E254900713FEF /* ExtensionDelegate.swift in Sources */,
674BD1542239A39D0076AFD6 /* PayBillInterfaceController.swift in Sources */,
678C38842230950100FEAAF6 /* AccountDetailsInterfaceController.swift in Sources */,
673F396E21A644570051469E /* MainMenuInterfaceController.swift in Sources */,
67E17B87223812C2008871FE /* Defaults.swift in Sources */,
1123372E223ABD6400B70925 /* FetchData.swift in Sources */,
112969422257B8920082AAC5 /* PaymentOptionsInterfaceController.swift in Sources */,
48F243072214C98600B9C894 /* AccountTableInterfaceController.swift in Sources */,
676392B62242A3F800740A8C /* TransactionCell.swift in Sources */,
48F2430F2214CC2200B9C894 /* Transaction.swift in Sources */,
Expand Down
20 changes: 19 additions & 1 deletion SynchronyFinancial/SynchronyFinancial/BankAcct.swift
Expand Up @@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extension on UserDefaults should be in its own file, namely UserDefaults+Extensions.swift

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
}
}
1 change: 0 additions & 1 deletion SynchronyFinancial/SynchronyFinancial/Defaults.swift
Expand Up @@ -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,
Expand Down