Skip to content
Permalink
Browse files

Merge pull request #12 from rrk12005/SWF-21-hook-up-to-web-apis

Added request for payment cancelation
  • Loading branch information
ahm11003 committed Apr 4, 2019
2 parents 2fbd1fb + 41a9d58 commit 4aa68412ccdf220dc06bf0ff86da177ff5ad6e65
@@ -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>
@@ -11,4 +11,5 @@ import WatchKit

class AccountCell: NSObject {
@IBOutlet weak var accountName: WKInterfaceLabel!
@IBOutlet weak var last4Label: WKInterfaceLabel!
}
@@ -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))")
}
}
}
@@ -49,6 +49,7 @@ class FetchData {
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,
@@ -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)
}
}
@@ -151,5 +152,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)")
}
}
}
}
@@ -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
@@ -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

0 comments on commit 4aa6841

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