From d5f19aae2ecc660b3c005eacda307a59300cefa8 Mon Sep 17 00:00:00 2001 From: Rahul Kantesaria Date: Tue, 2 Apr 2019 18:17:57 -0400 Subject: [PATCH 1/4] Added requests and handlers for fetching pending transactions, fetching bank accounts, and updated transaction UI to show yellow color for pending transactions --- .../FetchData.swift | 53 +++++++++++++++++-- .../TransactionsInterfaceController.swift | 3 +- .../project.pbxproj | 8 ++- .../SynchronyFinancial/BankAcct.swift | 22 ++++++++ .../SynchronyFinancial/Transaction.swift | 24 ++++++++- 5 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 SynchronyFinancial/SynchronyFinancial/BankAcct.swift 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 } } From 86153dfea383341f1c3768687be6ec29f316f607 Mon Sep 17 00:00:00 2001 From: Rahul Kantesaria Date: Wed, 3 Apr 2019 13:18:40 -0400 Subject: [PATCH 2/4] fixed constructor implementation for transaction and added newline after enum in BankAcct --- .../SynchronyFinancial/BankAcct.swift | 1 + .../SynchronyFinancial/Transaction.swift | 23 ++++--------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/SynchronyFinancial/SynchronyFinancial/BankAcct.swift b/SynchronyFinancial/SynchronyFinancial/BankAcct.swift index 25d1189..ea16335 100644 --- a/SynchronyFinancial/SynchronyFinancial/BankAcct.swift +++ b/SynchronyFinancial/SynchronyFinancial/BankAcct.swift @@ -12,6 +12,7 @@ public enum AccountType: Int { case checkings = 0 case savings = 1 } + class BankAcct: NSObject { var bankAcctId: String var acctType: AccountType diff --git a/SynchronyFinancial/SynchronyFinancial/Transaction.swift b/SynchronyFinancial/SynchronyFinancial/Transaction.swift index 21dc45d..71c58b0 100644 --- a/SynchronyFinancial/SynchronyFinancial/Transaction.swift +++ b/SynchronyFinancial/SynchronyFinancial/Transaction.swift @@ -22,28 +22,15 @@ class Transaction: NSObject { var isPending: Bool var isModifiable: Bool - //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) { + confirmationNum: String? = nil, paymentId: Int? = nil, isPending: Bool? = nil, isModifiable: Bool? = nil) { self.type = type self.amount = amount self.merchantID = merchantID self.date = date - self.confirmationNum = confirmationNum - self.paymentId = paymentId - self.isPending = isPending - self.isModifiable = isModifiable + self.confirmationNum = confirmationNum ?? "" + self.paymentId = paymentId ?? 0 + self.isPending = isPending ?? false + self.isModifiable = isModifiable ?? false } } From ffd4f19259cc10ffff85d738b26852ce079293b0 Mon Sep 17 00:00:00 2001 From: Rahul Kantesaria Date: Wed, 3 Apr 2019 13:46:00 -0400 Subject: [PATCH 3/4] Added request for payment cancelation --- .../FetchData.swift | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/SynchronyFinancial/SynchronyFinancial WatchKit Extension/FetchData.swift b/SynchronyFinancial/SynchronyFinancial WatchKit Extension/FetchData.swift index a3f3558..995d6b5 100644 --- a/SynchronyFinancial/SynchronyFinancial WatchKit Extension/FetchData.swift +++ b/SynchronyFinancial/SynchronyFinancial WatchKit Extension/FetchData.swift @@ -151,5 +151,24 @@ 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): + let dict = JSON(value).dictionaryValue + guard dict["status"]?.dictionaryValue["response_code"]?.string == "0" else { return } + if let paymentCancelNum = dict["cancellation_confirmation_number"]?.stringValue { + completion(paymentCancelNum, nil) + } + case .failure(let error): + NSLog("Error: \(error.localizedDescription)") + } + } + } } From 41a9d58cee846c2e15a287b72ad9264f7c7a3c57 Mon Sep 17 00:00:00 2001 From: Alan Maynard Date: Thu, 4 Apr 2019 11:31:58 -0400 Subject: [PATCH 4/4] SWF-21 Implemented last 4 digits display - we now grab the last 4 digits of account number and store on the `Account` object - modified the `AccountCell` and table displays to reflect this change --- .../Base.lproj/Interface.storyboard | 4 +++- .../SynchronyFinancial WatchKit Extension/AccountCell.swift | 1 + .../AccountTableInterfaceController.swift | 1 + .../SynchronyFinancial WatchKit Extension/FetchData.swift | 3 ++- SynchronyFinancial/SynchronyFinancial/Account.swift | 4 +++- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/SynchronyFinancial/SynchronyFinancial WatchKit App/Base.lproj/Interface.storyboard b/SynchronyFinancial/SynchronyFinancial WatchKit App/Base.lproj/Interface.storyboard index ed397d2..037b541 100644 --- a/SynchronyFinancial/SynchronyFinancial WatchKit App/Base.lproj/Interface.storyboard +++ b/SynchronyFinancial/SynchronyFinancial WatchKit App/Base.lproj/Interface.storyboard @@ -99,11 +99,13 @@ - + diff --git a/SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountCell.swift b/SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountCell.swift index 8bba624..55d6587 100644 --- a/SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountCell.swift +++ b/SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountCell.swift @@ -11,4 +11,5 @@ import WatchKit class AccountCell: NSObject { @IBOutlet weak var accountName: WKInterfaceLabel! + @IBOutlet weak var last4Label: WKInterfaceLabel! } diff --git a/SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountTableInterfaceController.swift b/SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountTableInterfaceController.swift index 6f06f1a..72518cd 100644 --- a/SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountTableInterfaceController.swift +++ b/SynchronyFinancial/SynchronyFinancial WatchKit Extension/AccountTableInterfaceController.swift @@ -48,6 +48,7 @@ class AccountTableInterfaceController: WKInterfaceController { for index in 0..