Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added requests and handlers for fetching pending transactions, fetchi…
…ng bank accounts, and updated transaction UI to show yellow color for pending transactions
  • Loading branch information
rrk12005 committed Apr 2, 2019
1 parent 00d3583 commit d5f19aa
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 7 deletions.
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}
}


}
Expand Up @@ -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))
}
}
}
Expand Down
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -85,6 +87,7 @@

/* Begin PBXFileReference section */
1123372D223ABD6400B70925 /* FetchData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchData.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>"; };
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 = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
);
Expand All @@ -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 */,
Expand Down
22 changes: 22 additions & 0 deletions 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
}
}
24 changes: 23 additions & 1 deletion SynchronyFinancial/SynchronyFinancial/Transaction.swift
Expand Up @@ -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
}
}

0 comments on commit d5f19aa

Please sign in to comment.