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 all 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,13 +201,16 @@
<objects>
<controller id="t8d-XB-ngB" customClass="PaymentDetailInterfaceController" customModule="SynchronyFinancial_WatchKit_App" customModuleProvider="target">
<items>
<imageView alignment="left" hidden="YES" id="qfi-KI-QXK"/>
<label width="1" alignment="center" hidden="YES" text="Processing ..." textAlignment="center" id="kgd-iG-og7"/>
<imageView alignment="left" hidden="YES" id="jH5-mg-vuQ"/>
<label width="1" alignment="center" hidden="YES" text="Processing ..." textAlignment="center" id="YNm-eO-7xL"/>
<group width="1" height="1" alignment="left" layout="vertical" id="9VF-fb-CV3">
<items>
<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 @@ -224,17 +227,48 @@
</group>
</items>
<connections>
<outlet property="activityIndicator" destination="qfi-KI-QXK" id="wVj-x3-NzV"/>
<outlet property="activityIndicatorLabel" destination="kgd-iG-og7" id="csx-e2-1eZ"/>
<outlet property="activityIndicator" destination="jH5-mg-vuQ" id="ucI-rB-ebj"/>
<outlet property="activityIndicatorLabel" destination="YNm-eO-7xL" id="okk-cx-k3L"/>
<outlet property="amount" destination="mT0-3D-JGP" id="rff-wG-B82"/>
<outlet property="contentGroup" destination="9VF-fb-CV3" id="vfa-YT-ipt"/>
<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="5Ao-39-aie"/>
<outlet property="last4Label" destination="FMl-Jx-r2b" id="w7N-Dp-fkz"/>
</connections>
</tableRow>
</items>
</table>
</items>
<connections>
<outlet property="bankAcctTable" destination="RJQ-am-qV6" id="mjy-8f-Qzt"/>
</connections>
</controller>
</objects>
<point key="canvasLocation" x="1400" y="186"/>
</scene>
<!--PaymentResult-->
<scene sceneID="mFc-oM-oG1">
<objects>
Expand All @@ -253,7 +287,7 @@
</connections>
</controller>
</objects>
<point key="canvasLocation" x="1408" y="185"/>
<point key="canvasLocation" x="1400" y="516"/>
</scene>
<!--Transactions-->
<scene sceneID="yXO-yR-k6b">
Expand Down Expand Up @@ -282,7 +316,7 @@
</connections>
</controller>
</objects>
<point key="canvasLocation" x="1085" y="-229"/>
<point key="canvasLocation" x="1085" y="-233"/>
</scene>
<!--TransactionDetails-->
<scene sceneID="aqX-eB-bdU">
Expand Down Expand Up @@ -322,7 +356,7 @@
</connections>
</controller>
</objects>
<point key="canvasLocation" x="1420" y="-229.5"/>
<point key="canvasLocation" x="1400" y="-233"/>
</scene>
<!--Cancellation-->
<scene sceneID="ZZZ-KP-exO">
Expand All @@ -341,10 +375,10 @@
</connections>
</controller>
</objects>
<point key="canvasLocation" x="1806" y="-229"/>
<point key="canvasLocation" x="1722" y="-229"/>
</scene>
</scenes>
<inferredMetricsTieBreakers>
<segue reference="AFS-lo-piH"/>
<segue reference="kTV-Eb-cpT"/>
</inferredMetricsTieBreakers>
</document>
@@ -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!
}
Expand Up @@ -97,7 +97,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 @@ -131,11 +130,10 @@ class FetchData {
//"fetch_bank_account_details"
dict["fetch_bank_account_details"]?.arrayValue.forEach {
if let bankId = $0["bank_account_id"].string,
let accttype: AccountType = $0["bank_account_type"].stringValue ==
"C" ? .checkings : .savings {
//print(bankId)
//print(accttype)
bankIds.append(BankAcct(bankAcctId: bankId, acctType: accttype))
let bankName = $0["bank_name"].string,
let last4Acct = $0["last4_bank_acct_number"].string,
let accttype: AccountType = AccountType(rawValue: $0["bank_account_type"].stringValue) {
bankIds.append(BankAcct(bankAcctId: bankId, acctType: accttype, bankName: bankName, last4Acct: last4Acct))
}
}
completion(bankIds, nil)
Expand All @@ -151,7 +149,6 @@ class FetchData {
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 @@ -15,22 +15,23 @@ 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)

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
}

self.paymentAmount = amount
Expand All @@ -50,12 +51,17 @@ 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
guard let bankacct = UserDefaults.standard.getDefaultBankAccount() else {
NSLog("Error retrieving Payment Option")
return
}
FetchData.submitPayment(for: alias, type: type, amount: self.paymentAmount, bankID: bankacct.bankAcctId) { 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])
return
}

self.dictForPayment.updateValue(confirmationNum, forKey: "payment_confirmation_number")
self.dictForPayment.updateValue(paymentID, forKey: "payment_id")
self.activityIndicator.stopAnimatingAsIndicator()
Expand All @@ -75,13 +81,49 @@ class PaymentDetailInterfaceController: WKInterfaceController {
}
}

@IBAction func bankAccountsTapped() {
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() {
// 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"])
}*/
//let userDefaults = UserDefaults.standard
guard let bankacct = UserDefaults.standard.getDefaultBankAccount() else {
NSLog("Error recieving default bank account in Payment Details Controller")
return
}
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)
}
}
@@ -0,0 +1,56 @@
//
// 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()
}

override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}

override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}

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]
dictForDefault.updateValue(acct.acctType.rawValue, forKey: "acctType")
dictForDefault.updateValue(acct.bankAcctId, forKey: "bankAcctId")
dictForDefault.updateValue(acct.bankName, forKey: "bankName")
dictForDefault.updateValue(acct.last4Acct, forKey: "last4Acct")
UserDefaults.standard.set(dictForDefault, forKey: "default_bank_acct")
pop()
}
}