Skip to content
Permalink
Browse files

Fixed errors from code review. Additionally, moved where fetchBankInf…

…o API request is called so it is fired upon only when user want to change default bank acct. User's default bank account ID is now being used in the makePayment API call.
  • Loading branch information
rrk12005 committed Apr 8, 2019
1 parent 61ca428 commit 520d31a8569e21fefa41ce7812a2f8cdc6214724
@@ -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-->
@@ -255,8 +255,8 @@
</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"/>
<outlet property="bankNameLabel" destination="y0D-7u-Qtr" id="5Ao-39-aie"/>
<outlet property="last4Label" destination="FMl-Jx-r2b" id="w7N-Dp-fkz"/>
</connections>
</tableRow>
</items>
@@ -10,6 +10,6 @@ import Foundation
import WatchKit

class BankAcctCell: NSObject {
@IBOutlet weak var BankNameLabel: WKInterfaceLabel!
@IBOutlet weak var Last4Label: WKInterfaceLabel!
@IBOutlet weak var bankNameLabel: WKInterfaceLabel!
@IBOutlet weak var last4Label: WKInterfaceLabel!
}
@@ -16,6 +16,7 @@ class PaymentDetailInterfaceController: WKInterfaceController {
var paymentButtonArmed: Bool = false
var paymentAmount: Double = 0.0
var dictForBankAcct: [String: [BankAcct]] = [:]
var bankID: String = ""
@IBOutlet weak var activityIndicator: WKInterfaceImage!
@IBOutlet weak var activityIndicatorLabel: WKInterfaceLabel!
@IBOutlet weak var contentGroup: WKInterfaceGroup!
@@ -24,25 +25,17 @@ class PaymentDetailInterfaceController: WKInterfaceController {
@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)

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
}

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
@@ -61,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["bankID"] ?? "9999"
}

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])
@@ -87,7 +84,19 @@ class PaymentDetailInterfaceController: WKInterfaceController {
}

@IBAction func bankAccountsTapped() {
self.pushController(withName: "PaymentOptions", context: self.dictForBankAcct)
configureInterfaceObjects(true)
activityIndicator.configureForActivityIndicator()
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.pushController(withName: "PaymentOptions", context: self.dictForBankAcct)
}

}

override func willActivate() {
@@ -109,14 +118,8 @@ class PaymentDetailInterfaceController: WKInterfaceController {
paymentButton.setHidden(hide)
payFrom.setHidden(hide)
separate.setHidden(hide)
contentGroup.setHidden(hide)
/*if(!hide){
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)
}
}*/
contentGroup.setHidden(hide)
activityIndicatorLabel.setVerticalAlignment(.center)
activityIndicatorLabel.setHidden(!hide)
}
}
@@ -36,19 +36,19 @@ class PaymentOptionsInterfaceController: WKInterfaceController {
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))")
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")
self.dictForDefault.updateValue(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")
UserDefaults.standard.set(dictForDefault, forKey: "default_bank_acct")
pop()
}
}
@@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
110B4615225BBDD70028B53A /* UserDefaults+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110B4614225BBDD70028B53A /* UserDefaults+Extensions.swift */; };
110B4616225BBDD70028B53A /* UserDefaults+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110B4614225BBDD70028B53A /* UserDefaults+Extensions.swift */; };
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 */; };
@@ -89,6 +91,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
110B4614225BBDD70028B53A /* UserDefaults+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserDefaults+Extensions.swift"; sourceTree = "<group>"; };
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>"; };
@@ -194,6 +197,7 @@
67BAC26F219E254800713FEF /* Assets.xcassets */,
67BAC271219E254800713FEF /* LaunchScreen.storyboard */,
67BAC274219E254800713FEF /* Info.plist */,
110B4614225BBDD70028B53A /* UserDefaults+Extensions.swift */,
);
path = SynchronyFinancial;
sourceTree = "<group>";
@@ -480,6 +484,7 @@
files = (
67E17B86223812C2008871FE /* Defaults.swift in Sources */,
674BD1532239A39D0076AFD6 /* PayBillInterfaceController.swift in Sources */,
110B4615225BBDD70028B53A /* UserDefaults+Extensions.swift in Sources */,
48F2430D2214CBF700B9C894 /* Account.swift in Sources */,
678C388622309F7D00FEAAF6 /* AccountCell.swift in Sources */,
11E6ADB92253FA050009922E /* BankAcct.swift in Sources */,
@@ -510,6 +515,7 @@
676392B422429DC800740A8C /* TransactionsInterfaceController.swift in Sources */,
48DA0058221D12E70081A500 /* AccountCell.swift in Sources */,
67228CD8224D6E2700CA29E4 /* WKInterfaceImage+Extensions.swift in Sources */,
110B4616225BBDD70028B53A /* UserDefaults+Extensions.swift in Sources */,
481864A9224802BB0059CF7A /* PaymentDetailInterfaceController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -8,9 +8,9 @@
import Foundation

public enum AccountType: Int {
case checkings = 0
case savings = 1
public enum AccountType: String {
case checkings = "C"
case savings = "S"
}

class BankAcct: NSObject {
@@ -26,16 +26,3 @@ class BankAcct: NSObject {
}
}

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,0 +1,22 @@
//
// UserDefaults+Extensions.swift
// SynchronyFinancial
//
// Created by Rahul Kantesaria on 4/8/19.
// Copyright © 2019 Alan Maynard. All rights reserved.
//
import Foundation

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 520d31a

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