Skip to content

Swf 21 hook up to web apis #11

Merged
merged 23 commits into from Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
79afbdf
SWF-21 [cocoapods] install Alamofire
ahm11003 Mar 12, 2019
ff0b413
Merge branch 'master' into SWF-21-hook-up-to-web-apis
ahm11003 Mar 12, 2019
f2a8883
SWF-21 [cocoapods] install SwiftyJSON
ahm11003 Mar 13, 2019
e85d2cb
SWF-21 initial web service setup
ahm11003 Mar 14, 2019
da5294a
Updated Accounts Model and created request to Multi-Account-Summary-D…
rrk12005 Mar 14, 2019
a2599ec
Quick Fix for bug where request not parsing payload JSON
rrk12005 Mar 14, 2019
ba4409d
SWF-21 improve login logic & more
ahm11003 Mar 21, 2019
8405351
Merge branch 'master' into SWF-21-hook-up-to-web-apis
ahm11003 Mar 28, 2019
c80231e
SWF-21 pass fetched accounts to AccountTVIC
ahm11003 Mar 28, 2019
c4cc995
SWF-21 Modified header for transactions fetch
ahm11003 Mar 28, 2019
21d742c
SWF-21 preliminary fetch function for transactions
ahm11003 Mar 28, 2019
8487ce3
SWF-21 Initial transaction implementation
ahm11003 Mar 28, 2019
24deb73
SWF-21 Initial setup for “loading” during account tap
ahm11003 Mar 28, 2019
a3682e4
SWF-21 basic paradigm for passing account data to root interface cont…
ahm11003 Mar 28, 2019
56caa7c
SWF-21 Extensions on WKInterfaceImage
ahm11003 Mar 28, 2019
2c01f37
SWF-21 Replace alerts with new activity indicator
ahm11003 Mar 28, 2019
82d2319
SWF-21 Remove unused code
ahm11003 Mar 28, 2019
28a7fc1
Merge branch 'master' into SWF-21-hook-up-to-web-apis
ahm11003 Mar 29, 2019
3ee46a5
SWF-21 move fetch transactions call
ahm11003 Mar 29, 2019
6bedc02
SWF-21 UI fixes
ahm11003 Mar 29, 2019
00d3583
SWF-21 Care credit image assets, loading label
ahm11003 Mar 29, 2019
d5f19aa
Added requests and handlers for fetching pending transactions, fetchi…
rrk12005 Apr 2, 2019
86153df
fixed constructor implementation for transaction and added newline af…
rrk12005 Apr 3, 2019
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
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
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline after this closing brace for the enum

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
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we should only need one initializer for this class. We can achieve this like:
init(type: TransactionType, amount: Double, merchantID: String, date: Date, confirmation: 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 = confirmation ?? ""
self.paymentId = paymentId ?? 0
self.isPending = isPending ?? false
self.isModifiable = isModifiable ?? false
}

This way we can choose to pass in values for confirmation, paymentID, isPending and isModifiable but if not they default to nil and we assign default values inside the body of the initializer. So for a processed transaction we can just omit those parameters in the function call.

//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
}
}