Skip to content
Permalink
Newer
Older
100644 125 lines (109 sloc) 5.7 KB
1
//
2
// PaymentDetailInterfaceController.swift
3
// SynchronyFinancial
4
//
5
// Created by Monday on 2019/03/24.
6
// Copyright © 2019 Alan Maynard. All rights reserved.
7
//
8
9
import WatchKit
10
import Foundation
11
12
class PaymentDetailInterfaceController: WKInterfaceController {
13
var selectedAccount: Account?
14
var dictForAcct: [String: Account] = [:]
15
var dictForPayment: [String: String] = [:]
16
var paymentButtonArmed: Bool = false
17
var paymentAmount: Double = 0.0
18
var dictForBankAcct: [String: [BankAcct]] = [:]
20
@IBOutlet weak var activityIndicator: WKInterfaceImage!
21
@IBOutlet weak var activityIndicatorLabel: WKInterfaceLabel!
22
@IBOutlet weak var contentGroup: WKInterfaceGroup!
23
@IBOutlet weak var detailButton: WKInterfaceButton!
24
@IBOutlet weak var amount: WKInterfaceLabel!
25
@IBOutlet weak var paymentButton: WKInterfaceButton!
26
@IBOutlet weak var payFrom: WKInterfaceLabel!
27
@IBOutlet weak var separate: WKInterfaceSeparator!
30
override func awake(withContext context: Any?) {
31
super.awake(withContext: context)
33
guard let data = context as? [String: Any], let acct = data["acct"] as? Account, let amount = data["payment_amount"] as? Double else {
34
NSLog("Error getting account object and payment amount")
35
return
36
}
40
self.paymentAmount = amount
41
self.selectedAccount = acct
42
paymentButton.setTitle(String(format: "Pay $%.2f", amount))
43
}
45
@IBAction func paymentAction() {
46
if paymentButtonArmed {
47
guard let alias = selectedAccount?.accountAlias else { return }
48
let cancel = WKAlertAction(title: "Cancel", style: .cancel, handler: {})
49
let submit = WKAlertAction(title: "Pay Now", style: .default, handler: {
50
self.contentGroup.setHidden(true)
51
self.activityIndicator.configureForActivityIndicator()
52
self.activityIndicatorLabel.setHidden(false)
53
self.activityIndicatorLabel.setVerticalAlignment(.center)
54
let type: PaymentType = self.paymentAmount == self.selectedAccount?.curBalance ? .currentBal : .minimumDue
56
// process this payment using default bank account (9999) until ability to change account is implemented
57
if let bankacct = UserDefaults.standard.dictionary(forKey: "default_bank_acct") as? [String: String] {
58
self.bankID = bankacct["bankAcctId"] ?? "9999"
59
}
60
61
FetchData.submitPayment(for: alias, type: type, amount: self.paymentAmount, bankID: self.bankID) { confirmationNum, paymentID, error in
62
guard error == nil else {
63
let dismiss = WKAlertAction(title: "Dismiss", style: .cancel, handler: {})
64
self.presentAlert(withTitle: "Error", message: "We were unable to process your payment at this time. Please try again later.", preferredStyle: .alert, actions: [dismiss])
65
return
66
}
67
self.dictForPayment.updateValue(confirmationNum, forKey: "payment_confirmation_number")
68
self.dictForPayment.updateValue(paymentID, forKey: "payment_id")
69
self.activityIndicator.stopAnimatingAsIndicator()
70
self.activityIndicatorLabel.setHidden(true)
71
self.contentGroup.setHidden(false)
72
self.presentController(withName: "PaymentResult", context: self.dictForPayment)
73
self.popToRootController()
74
}
75
})
76
presentAlert(withTitle: "Disclaimer", message: "By tapping \"Pay Now\", you are authorizing Synchrony Bank to process a one time payment in the amount of \(String(format: "$%.2f", paymentAmount)).", preferredStyle: .actionSheet, actions: [cancel, submit])
78
animate(withDuration: 0.5) {
79
self.paymentButton.setBackgroundColor(#colorLiteral(red: 0.6092301607, green: 0.9366738796, blue: 0.2432599962, alpha: 1))
80
self.paymentButtonArmed = true
81
self.paymentButton.setTitle("Pay Now")
82
}
83
}
84
}
86
@IBAction func bankAccountsTapped() {
87
configureInterfaceObjects(true)
88
activityIndicator.configureForActivityIndicator()
89
FetchData.getBankInfo { accts, error in guard error == nil else {
90
NSLog("Error retrieving payment methods for account in paymentDetailInterfaceController.")
91
return
92
}
93
self.dictForBankAcct.updateValue(accts, forKey: "paymentOptions")
94
self.configureInterfaceObjects(false)
95
//self.detailButton.setTitle("Hello")
96
self.activityIndicator.stopAnimatingAsIndicator()
97
self.pushController(withName: "PaymentOptions", context: self.dictForBankAcct)
98
}
99
101
102
override func willActivate() {
103
// This method is called when watch view controller is about to be visible to user
104
super.willActivate()
105
if let bankacct = UserDefaults.standard.dictionary(forKey: "default_bank_acct") as? [String: String] {
106
detailButton.setTitle(bankacct["bankName"])
108
}
109
110
override func didDeactivate() {
111
// This method is called when watch view controller is no longer visible
112
super.didDeactivate()
113
}
115
private func configureInterfaceObjects(_ hide: Bool) {
116
detailButton.setHidden(hide)
117
amount.setHidden(hide)
118
paymentButton.setHidden(hide)
119
payFrom.setHidden(hide)
120
separate.setHidden(hide)
121
contentGroup.setHidden(hide)
122
activityIndicatorLabel.setVerticalAlignment(.center)
123
activityIndicatorLabel.setHidden(!hide)
125
}
You can’t perform that action at this time.