Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' into SWE-12-enable-payment-suite
# Conflicts:
#	SynchronyFinancial/SynchronyFinancial WatchKit Extension/FetchData.swift
#	SynchronyFinancial/SynchronyFinancial.xcodeproj/project.pbxproj
  • Loading branch information
ahm11003 committed Apr 4, 2019
2 parents 50d5863 + 4aa6841 commit 534958f
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 10 deletions.
Expand Up @@ -99,11 +99,13 @@
<tableRow identifier="account" id="5xi-FS-LlJ" customClass="AccountCell" customModule="SynchronyFinancial_WatchKit_Extension">
<group key="rootItem" width="1" height="44" alignment="left" layout="vertical" id="mYi-9N-Ue7">
<items>
<label alignment="left" text="Label" id="Tl1-Kc-YJS"/>
<label alignment="left" text="Account Name" id="Tl1-Kc-YJS"/>
<label width="136" alignment="left" verticalAlignment="bottom" text="(...XXXX)" textAlignment="left" id="OWC-kI-GEy"/>
</items>
</group>
<connections>
<outlet property="accountName" destination="Tl1-Kc-YJS" id="cgD-CY-lzh"/>
<outlet property="last4Label" destination="OWC-kI-GEy" id="su7-E3-eEF"/>
</connections>
</tableRow>
</items>
Expand Down
Expand Up @@ -11,4 +11,5 @@ import WatchKit

class AccountCell: NSObject {
@IBOutlet weak var accountName: WKInterfaceLabel!
@IBOutlet weak var last4Label: WKInterfaceLabel!
}
Expand Up @@ -48,6 +48,7 @@ class AccountTableInterfaceController: WKInterfaceController {
for index in 0..<accountTable.numberOfRows {
if let row = accountTable.rowController(at: index) as? AccountCell {
row.accountName.setText(accounts[index].accountName)
row.last4Label.setText("(...\(accounts[index].last4))")
}
}
}
Expand Down
Expand Up @@ -41,14 +41,15 @@ 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
formatter.dateFormat = "yyyyMMdd"
if let accounts = dict["account_number_list"]?.arrayValue {
accounts.forEach {
if let accountAlias = $0.dictionaryValue["account_alias"]?.string,
let last4 = $0["last4_acct_number"].string,
let creditLimitString = $0.dictionaryValue["credit_limit"]?.string,
let creditLimit = Double(creditLimitString),
let payDueDateString = $0.dictionaryValue["next_payment_due_date"]?.string,
Expand All @@ -62,7 +63,7 @@ class FetchData {
let statementBalString = $0.dictionaryValue["statement_bal"]?.string,
let statementBalance = Double(statementBalString),
let accountName = $0.dictionaryValue["cc_program_name"]?.string {
let inAccount = Account(accountAlias: accountAlias, creditLimit: creditLimit, paymentDueDate: paymentDueDate, curBalance: currentBalance, availCredit: availableCredit, minPayDue: minPaymentDue, statementBal: statementBalance, accountName: accountName)
let inAccount = Account(accountAlias, creditLimit, last4, paymentDueDate, currentBalance, availableCredit, minPaymentDue, statementBalance, accountName)
accountList.append(inAccount)
}
}
Expand All @@ -89,15 +90,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,6 +125,53 @@ 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)
}
}
}

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)")
}
}
}

static func submitPayment(for alias: String, type: String, amount: Double, bankID: String, completion: @escaping (String, String, Error?) -> Void) {
var paymentHeader = Defaults.headerForPmt
Expand Down
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 */; };
481864A9224802BB0059CF7A /* PaymentDetailInterfaceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 481864A7224802BB0059CF7A /* PaymentDetailInterfaceController.swift */; };
48DA0058221D12E70081A500 /* AccountCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48DA0057221D12E70081A500 /* AccountCell.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 @@ -178,8 +181,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 @@ -469,6 +473,8 @@
674BD1532239A39D0076AFD6 /* PayBillInterfaceController.swift in Sources */,
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 @@ -478,6 +484,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
4 changes: 3 additions & 1 deletion SynchronyFinancial/SynchronyFinancial/Account.swift
Expand Up @@ -10,6 +10,7 @@ import Foundation
class Account: NSObject {
var accountAlias: String
var creditLimit: Double
var last4: String
//var transactions: [Transaction]
var paymentDueDate: Date
//var cycleEndDate: Date
Expand All @@ -20,9 +21,10 @@ class Account: NSObject {
var statementBal: Double
var accountName: String

init(accountAlias: String, creditLimit: Double, paymentDueDate: Date, curBalance: Double, availCredit: Double, minPayDue: Double, statementBal: Double, accountName: String) {
init(_ accountAlias: String, _ creditLimit: Double, _ last4: String, _ paymentDueDate: Date, _ curBalance: Double, _ availCredit: Double, _ minPayDue: Double, _ statementBal: Double, _ accountName: String) {
self.accountAlias = accountAlias
self.creditLimit = creditLimit
self.last4 = last4
//self.transactions = transactions
//self.balance = transactions.map { $0.amount }.reduce(0.0, +)
self.paymentDueDate = paymentDueDate
Expand Down
23 changes: 23 additions & 0 deletions SynchronyFinancial/SynchronyFinancial/BankAcct.swift
@@ -0,0 +1,23 @@
//
// 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
}
}
11 changes: 10 additions & 1 deletion SynchronyFinancial/SynchronyFinancial/Transaction.swift
Expand Up @@ -17,11 +17,20 @@ 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) {
init(type: TransactionType, amount: Double, merchantID: String, date: Date,
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 ?? 0
self.isPending = isPending ?? false
self.isModifiable = isModifiable ?? false
}
}

0 comments on commit 534958f

Please sign in to comment.