Skip to content
Permalink
8b78622535
Go to file
 
 
Cannot retrieve contributors at this time
80 lines (67 sloc) 3.03 KB
//
// TransactionDetailsInterfaceController.swift
// SynchronyFinancial WatchKit Extension
//
// Created by Alan Maynard on 4/2/19.
// Copyright © 2019 Alan Maynard. All rights reserved.
//
import WatchKit
import Foundation
class TransactionDetailsInterfaceController: WKInterfaceController {
@IBOutlet var activityIndicator: WKInterfaceImage!
@IBOutlet var activityIndicatorLabel: WKInterfaceLabel!
@IBOutlet weak var contentGroup: WKInterfaceGroup!
@IBOutlet var transactionName: WKInterfaceLabel!
@IBOutlet var dateLabel: WKInterfaceLabel!
@IBOutlet var amountLabel: WKInterfaceLabel!
@IBOutlet var cancelButton: WKInterfaceButton!
var transaction: Transaction?
var account: Account?
override func awake(withContext context: Any?) {
super.awake(withContext: context)
guard let data = context as? [String: Any],
let transaction = data["transaction"] as? Transaction,
let merchant = data["merchant"] as? String,
let date = data["date"] as? Date,
let amount = data["amount"] as? Double,
let acct = data["acct"] as? Account else {
NSLog("Error receiving context in TransactionDetails.")
return
}
self.transaction = transaction
account = acct
transactionName.setText(merchant)
dateLabel.setText("Date: \(DateFormatter.localizedString(from: date, dateStyle: .short, timeStyle: .none))")
amountLabel.setText(String(format: "Amount: $%.2f", amount))
cancelButton.setHidden(!transaction.isModifiable)
}
@IBAction func cancelButtonTapped() {
guard let t = transaction, let acct = account else {
NSLog("Error: no values for transaction or account.")
return
}
activityIndicator.configureForActivityIndicator()
activityIndicatorLabel.setHidden(false)
contentGroup.setHidden(true)
FetchData.cancelPayment(accountAlias: acct.accountAlias, confirmationNum: t.confirmationNum, paymentId: t.paymentId) { conf, error in
guard error == nil else {
self.presentAlert(withTitle: "Error", message: "We were unable to process your cancellation at this time. Please try again later.", preferredStyle: .alert, actions: [WKAlertAction(title: "Dismiss", style: .default, handler:{})])
return
}
self.activityIndicatorLabel.setHidden(true)
self.activityIndicator.stopAnimating()
self.contentGroup.setHidden(false)
let context: [String: String] = ["cancellation_confirm": conf]
self.presentController(withName: "Cancellation", context: context)
self.popToRootController()
}
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
}
You can’t perform that action at this time.