diff --git a/SynchronyFinancial/SynchronyFinancial WatchKit Extension/FetchData.swift b/SynchronyFinancial/SynchronyFinancial WatchKit Extension/FetchData.swift index a45a644..a3f3558 100644 --- a/SynchronyFinancial/SynchronyFinancial WatchKit Extension/FetchData.swift +++ b/SynchronyFinancial/SynchronyFinancial WatchKit Extension/FetchData.swift @@ -41,7 +41,7 @@ class FetchData { let json = JSON(value) let dict = json.dictionaryValue guard dict["status"]?.dictionaryValue["response_code"]?.string == "0" else { return } - print(json) + //print(json) let formatter = DateFormatter() formatter.locale = Locale.current @@ -89,15 +89,32 @@ class FetchData { case .success(let value): let dict = JSON(value).dictionaryValue guard dict["status"]?.dictionaryValue["response_code"]?.string == "0" else { return } - - // let's parse just processed transactions for now + + //let's first parse the pending transactions + dict["pending_transaction_list"]?.arrayValue.forEach { + if let desc = $0["description"].string, + let date = formatter.date(from: $0["transaction_date"].stringValue), + let amountString = $0["transaction_amount"].string, + let amount = Double(amountString), + let confirmationNum = $0["payment_confirmation_number"].string, + let paymentIdString = $0["payment_id"].string, + let paymentId = Int(paymentIdString), + 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)) + } + } + + // let's parse just processed transactions now dict["processed_transaction_list"]?.arrayValue.forEach { if let desc = $0["description"].string, let date = formatter.date(from: $0["transaction_date"].stringValue), let amountString = $0["transaction_amount"].string, let amount = Double(amountString) { let type: TransactionType = $0["payment_amount_type"].stringValue == "" ? .purchase : .reimbursement - transactions.append(Transaction(type: type, amount: amount, merchantID: desc, date: date)) + transactions.append(Transaction(type: type, amount: amount, merchantID: desc, date: date, isPending: false)) } } completion(transactions, nil) @@ -107,4 +124,32 @@ class FetchData { } } } + + static func getBankInfo(completion: @escaping ([BankAcct], Error?) -> Void) { + var bankIds: [BankAcct] = [] + Alamofire.request(Defaults.FETCH_BANKS_URL, method: .post, parameters: Defaults.headerForMulti, encoding: JSONEncoding.default, headers: Defaults.authHeader).responseJSON { payload in + switch payload.result { + case .success(let value): + let dict = JSON(value).dictionaryValue + //print(dict) + guard dict["status"]?.dictionaryValue["response_code"]?.string == "0" else {return } + //"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)) + } + } + completion(bankIds, nil) + case .failure(let error): + NSLog("Error: %s", error.localizedDescription) + completion([], error) + } + } + } + + } diff --git a/SynchronyFinancial/SynchronyFinancial WatchKit Extension/TransactionsInterfaceController.swift b/SynchronyFinancial/SynchronyFinancial WatchKit Extension/TransactionsInterfaceController.swift index 5f3e709..93689b4 100644 --- a/SynchronyFinancial/SynchronyFinancial WatchKit Extension/TransactionsInterfaceController.swift +++ b/SynchronyFinancial/SynchronyFinancial WatchKit Extension/TransactionsInterfaceController.swift @@ -44,7 +44,8 @@ class TransactionsInterfaceController: WKInterfaceController { if let row = transactionsTable.rowController(at: index) as? TransactionCell { row.transactionLabel.setText(transactions[index].merchantID) row.valueLabel.setText(String(format: "$%.2f", transactions[index].amount)) - row.valueLabel.setTextColor(transactions[index].type == .purchase ? UIColor.red : UIColor.green) + row.valueLabel.setTextColor(transactions[index].isPending == true ? UIColor.yellow : + (transactions[index].type == .purchase ? UIColor.red : UIColor.green)) } } } diff --git a/SynchronyFinancial/SynchronyFinancial.xcodeproj/project.pbxproj b/SynchronyFinancial/SynchronyFinancial.xcodeproj/project.pbxproj index 6d5600b..5f786f7 100644 --- a/SynchronyFinancial/SynchronyFinancial.xcodeproj/project.pbxproj +++ b/SynchronyFinancial/SynchronyFinancial.xcodeproj/project.pbxproj @@ -8,6 +8,8 @@ /* Begin PBXBuildFile section */ 1123372E223ABD6400B70925 /* FetchData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1123372D223ABD6400B70925 /* FetchData.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 */; }; @@ -85,6 +87,7 @@ /* Begin PBXFileReference section */ 1123372D223ABD6400B70925 /* FetchData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchData.swift; sourceTree = ""; }; + 11E6ADB82253FA050009922E /* BankAcct.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BankAcct.swift; sourceTree = ""; }; 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 = ""; }; 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 = ""; }; 396A16E056D05DEC937A07DA /* Pods-SynchronyFinancial.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SynchronyFinancial.release.xcconfig"; path = "Pods/Target Support Files/Pods-SynchronyFinancial/Pods-SynchronyFinancial.release.xcconfig"; sourceTree = ""; }; @@ -177,8 +180,9 @@ children = ( 48F2430B2214CBF700B9C894 /* Account.swift */, 48F2430C2214CBF700B9C894 /* Transaction.swift */, - 67E17B85223812C2008871FE /* Defaults.swift */, 67BAC268219E254700713FEF /* AppDelegate.swift */, + 11E6ADB82253FA050009922E /* BankAcct.swift */, + 67E17B85223812C2008871FE /* Defaults.swift */, 67BAC26C219E254700713FEF /* Main.storyboard */, 67BAC26F219E254800713FEF /* Assets.xcassets */, 67BAC271219E254800713FEF /* LaunchScreen.storyboard */, @@ -468,6 +472,7 @@ 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 */, ); @@ -477,6 +482,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 11E6ADBA225401DB0009922E /* BankAcct.swift in Sources */, 678C3885223098C400FEAAF6 /* Account.swift in Sources */, 67BAC28E219E254900713FEF /* ExtensionDelegate.swift in Sources */, 674BD1542239A39D0076AFD6 /* PayBillInterfaceController.swift in Sources */, diff --git a/SynchronyFinancial/SynchronyFinancial/BankAcct.swift b/SynchronyFinancial/SynchronyFinancial/BankAcct.swift new file mode 100644 index 0000000..25d1189 --- /dev/null +++ b/SynchronyFinancial/SynchronyFinancial/BankAcct.swift @@ -0,0 +1,22 @@ +// +// Banks.swift +// SynchronyFinancial +// +// Created by Rahul Kantesaria on 4/2/19. +// Copyright © 2019 Alan Maynard. All rights reserved. +// + +import Foundation + +public enum AccountType: Int { + case checkings = 0 + case savings = 1 +} +class BankAcct: NSObject { + var bankAcctId: String + var acctType: AccountType + init(bankAcctId: String, acctType: AccountType) { + self.bankAcctId = bankAcctId + self.acctType = acctType + } +} diff --git a/SynchronyFinancial/SynchronyFinancial/Transaction.swift b/SynchronyFinancial/SynchronyFinancial/Transaction.swift index 7975d90..21dc45d 100644 --- a/SynchronyFinancial/SynchronyFinancial/Transaction.swift +++ b/SynchronyFinancial/SynchronyFinancial/Transaction.swift @@ -17,11 +17,33 @@ class Transaction: NSObject { var amount: Double var merchantID: String var date: Date + var confirmationNum: String + var paymentId: Int + var isPending: Bool + var isModifiable: Bool - init(type: TransactionType, amount: Double, merchantID: String, date: Date) { + //this constructor is for the case if it is a posted transaction + init(type: TransactionType, amount: Double, merchantID: String, date: Date, isPending: Bool) { self.type = type self.amount = amount self.merchantID = merchantID self.date = date + self.confirmationNum = "" + self.paymentId = 0 + self.isPending = isPending + self.isModifiable = false + } + + //this constructor is for the case if it is a pending transaction + init(type: TransactionType, amount: Double, merchantID: String, date: Date, + confirmationNum: String, paymentId: Int, isPending: Bool, isModifiable: Bool) { + self.type = type + self.amount = amount + self.merchantID = merchantID + self.date = date + self.confirmationNum = confirmationNum + self.paymentId = paymentId + self.isPending = isPending + self.isModifiable = isModifiable } }