-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0032a2
commit 1071ee6
Showing
744 changed files
with
422,481 additions
and
82,253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// CollectDataViewController.swift | ||
// Example | ||
// | ||
// Created by Mindy Lou on 5/9/24. | ||
// Copyright © 2024 Stripe. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import Static | ||
import StripeTerminal | ||
|
||
class CollectDataViewController: EventDisplayingViewController { | ||
override var cancelLogMethod: LogEvent.Method { | ||
return .cancelCollectData | ||
} | ||
|
||
private let collectDataConfig: CollectDataConfiguration | ||
|
||
init(collectDataConfiguration: CollectDataConfiguration) { | ||
self.collectDataConfig = collectDataConfiguration | ||
super.init() | ||
} | ||
|
||
required init?(coder aDecoder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
collectData(config: collectDataConfig) | ||
} | ||
|
||
private func collectData(config: CollectDataConfiguration) { | ||
var collectDataEvent = LogEvent(method: .collectData) | ||
events.append(collectDataEvent) | ||
cancelable = Terminal.shared.collectData(config, completion: { [weak self] collectedData, error in | ||
if let error = error { | ||
collectDataEvent.result = .errored | ||
collectDataEvent.object = .error(error as NSError) | ||
} else if let data = collectedData { | ||
collectDataEvent.result = .succeeded | ||
collectDataEvent.object = .collectedData(data) | ||
|
||
#if SCP_RETRIEVES_COLLECTED_DATA | ||
if let id = data.stripeId { | ||
var retrieveCollectedDataEvent = LogEvent(method: .collectData) | ||
self?.events.append(retrieveCollectedDataEvent) | ||
AppDelegate.apiClient?.retrieveReaderCollectedData(id: id, completion: { json, error in | ||
if let error = error { | ||
retrieveCollectedDataEvent.result = .errored | ||
retrieveCollectedDataEvent.object = .error(error as NSError) | ||
} else if let json = json { | ||
retrieveCollectedDataEvent.object = .json(json) | ||
} | ||
self?.events.append(retrieveCollectedDataEvent) | ||
}) | ||
} | ||
#endif | ||
} | ||
self?.events.append(collectDataEvent) | ||
self?.complete() | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// StartCollectDataViewController.swift | ||
// Example | ||
// | ||
// Created by Mindy Lou on 5/9/24. | ||
// Copyright © 2024 Stripe. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import Static | ||
import StripeTerminal | ||
|
||
class StartCollectDataViewController: TableViewController { | ||
|
||
convenience init() { | ||
self.init(style: .grouped) | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
addKeyboardDisplayObservers() | ||
title = "Collect Data" | ||
|
||
updateContent() | ||
} | ||
|
||
override func viewDidAppear(_ animated: Bool) { | ||
super.viewDidAppear(animated) | ||
// pop if no reader is connected | ||
guard Terminal.shared.connectedReader != nil else { | ||
navigationController?.popViewController(animated: true) | ||
return | ||
} | ||
} | ||
|
||
internal func startCollectMagstripeData() { | ||
do { | ||
let collectDataConfig = try CollectDataConfigurationBuilder().setCollectDataType(.magstripe).build() | ||
let viewController = CollectDataViewController(collectDataConfiguration: collectDataConfig) | ||
let navigationController = LargeTitleNavigationController(rootViewController: viewController) | ||
present(navigationController, animated: true) | ||
} catch { | ||
presentAlert(error: error) | ||
} | ||
} | ||
|
||
private func updateContent() { | ||
var sections = [Section]() | ||
let dataCollectionForms = Section(rows: [ | ||
Row(text: "Collect magstripe data", selection: { [unowned self] in | ||
startCollectMagstripeData() | ||
}, cellClass: ButtonCell.self), | ||
]) | ||
|
||
sections.append(dataCollectionForms) | ||
dataSource.sections = sections | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.