Skip to content
Permalink
Browse files

Updated Accounts Model and created request to Multi-Account-Summary-D…

…etails and fetching necessary data
  • Loading branch information
rrk12005 committed Mar 14, 2019
1 parent e85d2cb commit da5294af842b95d03cf676f0d485c0c3342e7e5f
@@ -0,0 +1,52 @@
//
// FetchData.swift
// SynchronyFinancial WatchKit Extension
//
// Created by Rahul Kantesaria on 3/14/19.
// Copyright © 2019 Alan Maynard. All rights reserved.
//
import Foundation
import Alamofire
import SwiftyJSON

class FetchData{
class func getAccountInfo(){
var accountList: [Account] = []
Alamofire.request(Defaults.MULTI_ACCT_URL, method: .post, parameters: Defaults.headerForMulti, encoding: JSONEncoding.default, headers: Defaults.authHeader).responseJSON { payload in
switch payload.result {
case .success(let value):
let json = JSON(value)
let dict = json.dictionaryValue
guard dict["status"]?.dictionaryValue["response_code"]?.string == "0" else { return }
if let accounts = dict["account_number_list"]?.arrayValue{
for account in accounts{
guard let accountAlias = account.dictionaryValue["account_alias"]?.string else {return}
guard let creditLimit = account.dictionaryValue["credit_limit"]?.double else {return}
guard let payDueDate = account.dictionaryValue["next_payment_due_date"]?.string else {return}
guard let curBal = account.dictionaryValue["current_balance"]?.double else {return}
guard let availCredit = account.dictionaryValue["available_credit"]?.double else {return}
guard let minPayDue = account.dictionaryValue["minimum_payment_due"]?.double else {return}
guard let statementBal = account.dictionaryValue["statement_bal"]?.double else {return}
guard let accountName = account.dictionaryValue["cc_program_name"]?.string else {return}
debugPrint(accountAlias)
debugPrint(creditLimit)
debugPrint(payDueDate)
debugPrint(curBal)
debugPrint(availCredit)
debugPrint(minPayDue)
debugPrint(statementBal)
debugPrint(accountName)
let inAccount = Account(accountAlias: accountAlias, creditLimit: creditLimit, paymentDueDate: payDueDate, curBalance: curBal, availCredit: availCredit, minPayDue: minPayDue, statementBal: statementBal, accountName: accountName)
accountList.append(inAccount)
}
}
//debugPrint(json)
case .failure(let error):
NSLog("Error: %s", error.localizedDescription)
}
}
}


}
@@ -29,11 +29,15 @@ class MainMenuInterfaceController: WKInterfaceController {
debugPrint(token)
// now we should save our token somewhere safe (UserDefaults)
UserDefaults.standard.set(token, forKey: "access_token")

}
case .failure(let error):
NSLog("Error: %s", error.localizedDescription)
}
}
//just here for testing. Should be moved into the accounts controller when that branch is merged
FetchData.getAccountInfo()

}

override func willActivate() {
@@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
1123372E223ABD6400B70925 /* FetchData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1123372D223ABD6400B70925 /* FetchData.swift */; };
281283568A34D3C5D9C7B383 /* libPods-SynchronyFinancial WatchKit Extension.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CAA6D46F907ADAABF49FD409 /* libPods-SynchronyFinancial WatchKit Extension.a */; };
6717460A21F8FCBF00696468 /* Transaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6717460921F8FCBE00696468 /* Transaction.swift */; };
6717460C21F8FCC100696468 /* Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6717460B21F8FCC100696468 /* Account.swift */; };
@@ -72,6 +73,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
1123372D223ABD6400B70925 /* FetchData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchData.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>"; };
@@ -183,6 +185,7 @@
67BAC28D219E254900713FEF /* ExtensionDelegate.swift */,
67BAC291219E254900713FEF /* Assets.xcassets */,
67BAC293219E254900713FEF /* Info.plist */,
1123372D223ABD6400B70925 /* FetchData.swift */,
);
path = "SynchronyFinancial WatchKit Extension";
sourceTree = "<group>";
@@ -448,6 +451,7 @@
673F396E21A644570051469E /* MainMenuInterfaceController.swift in Sources */,
67E17B87223812C2008871FE /* Defaults.swift in Sources */,
6717460E21F8FCDB00696468 /* Transaction.swift in Sources */,
1123372E223ABD6400B70925 /* FetchData.swift in Sources */,
6717460D21F8FCD800696468 /* Account.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -8,19 +8,31 @@
import Foundation

class Account: NSObject {
var accountNumber: String
var limit: Double
var balance: Double
var transactions: [Transaction]
var paymentDueDate: Date
var cycleEndDate: Date
var accountAlias: String
var creditLimit: Double
//var transactions: [Transaction]
var paymentDueDate: String
//var cycleEndDate: Date
var curBalance: Double
var availCredit: Double
//var balance: Double
var minPayDue: Double
var statementBal: Double
var accountName: String

init(accountNumber: String, limit: Double, transactions: [Transaction], paymentDueDate: Date, cycleEndDate: Date) {
self.accountNumber = accountNumber
self.limit = limit
self.transactions = transactions
self.balance = transactions.map { $0.amount }.reduce(0.0, +)
init(accountAlias: String, creditLimit: Double, paymentDueDate: String, curBalance: Double, availCredit : Double, minPayDue: Double, statementBal: Double, accountName: String) {
self.accountAlias = accountAlias
self.creditLimit = creditLimit
//self.transactions = transactions
//self.balance = transactions.map { $0.amount }.reduce(0.0, +)
self.paymentDueDate = paymentDueDate
self.cycleEndDate = cycleEndDate
//self.cycleEndDate = cycleEndDate
self.curBalance = curBalance
self.minPayDue = minPayDue
self.availCredit = availCredit
self.statementBal = statementBal
self.accountName = accountName
}


}
@@ -19,6 +19,8 @@ final class Defaults {
static let MAKE_PAYMENT_URL = "https://syf-paysol-mocks.getsandbox.com/paysol/payment/api/rest/v1_0/make_payment"

static let defaultHeader = ["channel": "AW", "device_id": "apple_watch", "trans_id": "apple_watch"]
static let token = UserDefaults.standard.string(forKey: "access_token") as! String
static let authHeader = ["Authorization": "Bearer \(token)"]

static var headerForLogin: [String: Any] = {
return ["client_id": "carecredit",
@@ -0,0 +1,3 @@
import UIKit

var str = "Hello, playground"

0 comments on commit da5294a

Please sign in to comment.
You can’t perform that action at this time.