Skip to content

Commit

Permalink
PLA-7001: Reader id input (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanj-tyro authored Jul 2, 2024
1 parent c3291b4 commit e44598f
Show file tree
Hide file tree
Showing 12 changed files with 738 additions and 897 deletions.
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

0 comments on commit e44598f

Please sign in to comment.