Skip to content
Permalink
18c29c8bcb
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
79 lines (66 sloc) 2.76 KB
//
// PaymentDetailInterfaceController.swift
// SynchronyFinancial
//
// Created by Monday on 2019/03/24.
// Copyright © 2019 Alan Maynard. All rights reserved.
//
import WatchKit
import Foundation
class PaymentDetailInterfaceController: WKInterfaceController {
var selectedAccount: Account?
var dictForAcct: [String: Account] = [:]
var paymentButtonArmed: Bool = false
var paymentAmount: Double = 0.0
var dictForBankAcct: [String:[BankAcct]] = [:]
@IBOutlet weak var detailButton: WKInterfaceButton!
@IBOutlet weak var amount: WKInterfaceLabel!
@IBOutlet weak var paymentButton: WKInterfaceButton!
override func awake(withContext context: Any?) {
super.awake(withContext: context)
guard let data = context as? [String: Any], let acct = data["acct"] as? Account, let amount = data["payment_amount"] as? Double else {
NSLog("Error getting account object and payment amount")
return
}
FetchData.getBankInfo{ accts, error in guard error == nil else {
NSLog("Error retrieving payment methods for account in paymentDetailInterfaceController.")
return
}
self.dictForBankAcct.updateValue(accts, forKey: "paymentOptions")
}
self.paymentAmount = amount
self.selectedAccount = acct
paymentButton.setTitle(String(format: "Pay $%.2f", amount))
if let p1 = self.dictForBankAcct["paymentOptions"] {
UserDefaults.standard.set(p1[0], forKey: "default_bank_acct")
print("yes")
self.detailButton.setTitle(p1[0].bankName)
}
}
@IBAction func paymentAction() {
if paymentButtonArmed {
popToRootController()
} else {
// animate(withDuration: 0.75) {
// self.paymentButton.setBackgroundColor(UIColor.init(red: 141, green: 241, blue: 48, alpha: 1.0))
// }
paymentButton.setBackgroundColor(#colorLiteral(red: 0.6092301607, green: 0.9366738796, blue: 0.2432599962, alpha: 1))
paymentButtonArmed = true
paymentButton.setTitle("Pay Now")
}
}
@IBAction func bankAccountsTapped() {
self.pushController(withName: "PaymentOptions", context: self.dictForBankAcct)
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
if let bankacct = UserDefaults.standard.value(forKey: "default_bank_acct") as? BankAcct {
detailButton.setTitle(bankacct.bankName)
}
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
}