Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLA-7001: Reader id input #40

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion SampleApp.xcodeproj

This file was deleted.

642 changes: 0 additions & 642 deletions SampleApp/SampleApp.xcodeproj/project.pbxproj

This file was deleted.

This file was deleted.

11 changes: 6 additions & 5 deletions SampleApp/SampleApp/POS/DemoConnectionProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ import TyroTapToPaySDK
// Create an endpoint on your server to generate the connection secret
let DEMO_CONNECTION_SECRET_ENDPOINT_URL = "https://api.tyro.com/connect/tap-to-pay/demo/connections"

// Create the reader id and set it here
// Only one reader can be used on one device at any time otherwise transactions will fail
let DEMO_READER_ID = "f310e43b-a6c9-4c43-9535-ff68b2b9c4a1"

final class DemoConnectionProvider: ConnectionProvider {
static let timeoutIntervalSeconds: TimeInterval = 10
private let restClient = RestClient()
private var readerId: String

init(readerId: String) {
self.readerId = readerId
}

func createConnection() async throws -> String {
let payload = try JSONEncoder().encode(DemoConnectionRequest(readerId: DEMO_READER_ID))
let payload = try JSONEncoder().encode(DemoConnectionRequest(readerId: self.readerId))
let response = try await restClient.post(
requestUrl: DEMO_CONNECTION_SECRET_ENDPOINT_URL,
payload: payload
Expand Down
76 changes: 0 additions & 76 deletions SampleApp/SampleApp/Resources/Localizable.xcstrings

This file was deleted.

156 changes: 81 additions & 75 deletions SampleApp/SampleApp/SampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,90 +10,96 @@ import TyroTapToPaySDK

@main
struct SampleApp: App {
var body: some Scene {
WindowGroup {
Home()
.navigationBarHidden(true)
}
}
}
@State var readerId: String?

struct Home : View {
@Environment(\.scenePhase) private var scenePhase: ScenePhase
@ObservedObject var tapToPaySdk: TyroTapToPay
private var contentViewModel: ContentViewModel
var body: some Scene {
WindowGroup {
if readerId != nil {
Home(readerId: readerId!)
.navigationBarHidden(true)
} else {
EnterReaderIdView(onSubmitReaderId: { readerId in
self.readerId = readerId
})
}
}
}
}

@State private var isSettingsPresented = false
struct Home: View {
@Environment(\.scenePhase) private var scenePhase: ScenePhase
@ObservedObject var tapToPaySdk: TyroTapToPay
private var contentViewModel: ContentViewModel

@State private var selectedIndex: Int = 0;
@State private var isSettingsPresented = false
@State private var selectedIndex: Int = 0

init() {
do {
let tapToPaySdk = try TyroTapToPay(
environment: .sandbox,
connectionProvider: DemoConnectionProvider()
)
contentViewModel = ContentViewModel(tapToPaySdk: tapToPaySdk)
self.tapToPaySdk = tapToPaySdk
} catch {
fatalError(error.localizedDescription)
}
}
init(readerId: String) {
do {
let tapToPaySdk = try TyroTapToPay(
environment: .sandbox,
connectionProvider: DemoConnectionProvider(readerId: readerId)
)
contentViewModel = ContentViewModel(tapToPaySdk: tapToPaySdk)
self.tapToPaySdk = tapToPaySdk
} catch {
fatalError(error.localizedDescription)
}
}

var body: some View {
TabView(selection: $selectedIndex) {
NavigationStack {
VStack {
HStack {
Spacer(minLength: 0)
Image(.tyroLogo)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(maxWidth: 100)
.padding()
Spacer(minLength: 0)
Button(action: {
isSettingsPresented.toggle()
}) {
Image(systemName: "gear")
.renderingMode(.template)
.resizable()
.frame(width: 25, height: 25)
var body: some View {
TabView(selection: $selectedIndex) {
NavigationStack {
VStack {
HStack {
Spacer(minLength: 0)
Image(.tyroLogo)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(maxWidth: 100)
.padding()
Spacer(minLength: 0)
Button(action: {
isSettingsPresented.toggle()
}) {
Image(systemName: "gear")
.renderingMode(.template)
.resizable()
.frame(width: 25, height: 25)
}.fullScreenCover(isPresented: $isSettingsPresented) {
TyroSettingsViewWrapper()
}
}.padding()
ContentView(viewModel: contentViewModel)
}.navigationTitle("")
}.tabItem {
Label("Home", systemImage: "house")
}.tag(0)

}.fullScreenCover(isPresented: $isSettingsPresented) {
TyroSettingsViewWrapper()
}
}.padding()
ContentView(viewModel: contentViewModel)
}.navigationTitle("")
}.tabItem {
Label("Home", systemImage: "house")
}.tag(0)

NavigationStack {
TyroSettingsView().navigationTitle("Tyro Settings")
}.tabItem {
Label("Admin", systemImage: "gear")
}.tag(1)
}
}
NavigationStack {
TyroSettingsView().navigationTitle("Tyro Settings")
}.tabItem {
Label("Admin", systemImage: "gear")
}.tag(1)
}
}
}

struct TyroSettingsViewWrapper: View {
@Environment(\.dismiss) var dismiss
var body: some View {
NavigationStack {
ZStack {
TyroSettingsView()
}.toolbar(content: {
Button {
dismiss()
} label: {
Image(systemName: "xmark")
}
})
}
}
@Environment(\.dismiss) var dismiss
var body: some View {
NavigationStack {
ZStack {
TyroSettingsView()
}.toolbar(content: {
Button {
dismiss()
} label: {
Image(systemName: "xmark")
}
})
}
}
}

extension TyroTapToPay: ObservableObject {
Expand Down
Loading