@@ -142,11 +142,11 @@ extension StripeCardReaderService: CardReaderService {
142142 throw error
143143 }
144144 case . localMobile:
145- let localMobileConfig = LocalMobileDiscoveryConfigurationBuilder ( )
145+ let tapToPayConfig = TapToPayDiscoveryConfigurationBuilder ( )
146146 do {
147- config = try localMobileConfig . setSimulated ( shouldUseSimulatedCardReader) . build ( )
147+ config = try tapToPayConfig . setSimulated ( shouldUseSimulatedCardReader) . build ( )
148148 } catch let error as UnderlyingError {
149- DDLogError ( " Failed to start LocalMobileDiscovery . Error: \( String ( describing: error. failureReason) ) " )
149+ DDLogError ( " Failed to start TapToPayDiscovery . Error: \( String ( describing: error. failureReason) ) " )
150150 throw error
151151 } catch {
152152 DDLogError ( " \( error) " )
@@ -159,8 +159,6 @@ extension StripeCardReaderService: CardReaderService {
159159 throw CardReaderServiceError . bluetoothDenied
160160 }
161161
162- Terminal . shared. delegate = self
163-
164162 // We're now ready to start discovery, but first we'll check that we're not starting or canceling
165163 // another discovery process.
166164 // If we can't grab a lock quickly, let's fail rather than wait indefinitely
@@ -198,7 +196,7 @@ extension StripeCardReaderService: CardReaderService {
198196 // as the simulator won't have Bluetooth available.
199197 // If we're using Tap to Pay on iPhone, bluetooth is not required.
200198 private func shouldSkipBluetoothCheck( discoveryConfiguration: DiscoveryConfiguration ) -> Bool {
201- shouldUseSimulatedCardReader || discoveryConfiguration. discoveryMethod == . localMobile
199+ shouldUseSimulatedCardReader || discoveryConfiguration. discoveryMethod == . tapToPay
202200 }
203201
204202 public func cancelDiscovery( ) -> Future < Void , Error > {
@@ -273,7 +271,7 @@ extension StripeCardReaderService: CardReaderService {
273271 /// https://stripe.dev/stripe-terminal-ios/docs/Classes/SCPTerminal.html#/c:objc(cs)SCPTerminal(im)disconnectReader:
274272 /// The completion block for disconnect, apparently, is called when the SDK has not really transitioned to an idle state.
275273 /// Clients might need to dispatch operations that rely on this completion block to start a second operation on the card reader.
276- /// (for example, starting a `localMobile ` connection after a BlueTooth reader has been disconnected)
274+ /// (for example, starting a `tapToPay ` connection after a BlueTooth reader has been disconnected)
277275 Terminal . shared. disconnectReader { error in
278276 DispatchQueue . main. asyncAfter ( deadline: . now( ) + 1 ) {
279277 if let error = error {
@@ -453,7 +451,7 @@ extension StripeCardReaderService: CardReaderService {
453451
454452 connectionAttemptInvalidated = false
455453 switch stripeReader. deviceType {
456- case . appleBuiltIn :
454+ case . tapToPay :
457455 return getLocalMobileConfiguration ( stripeReader, options: options) . flatMap { configuration in
458456 self . connect ( stripeReader, configuration: configuration)
459457 }
@@ -480,7 +478,7 @@ extension StripeCardReaderService: CardReaderService {
480478 self . readerLocationProvider? . fetchDefaultLocationID { result in
481479 switch result {
482480 case . success( let locationId) :
483- let buildConfig = BluetoothConnectionConfigurationBuilder ( locationId: locationId)
481+ let buildConfig = BluetoothConnectionConfigurationBuilder ( delegate : self , locationId: locationId)
484482 do {
485483 let config = try buildConfig. build ( )
486484 return promise ( . success( config) )
@@ -497,7 +495,7 @@ extension StripeCardReaderService: CardReaderService {
497495 }
498496
499497 private func getLocalMobileConfiguration( _ reader: StripeTerminal . Reader ,
500- options: CardReaderConnectionOptions ? ) -> Future < LocalMobileConnectionConfiguration , Error > {
498+ options: CardReaderConnectionOptions ? ) -> Future < TapToPayConnectionConfiguration , Error > {
501499 return Future ( ) { [ weak self] promise in
502500 guard let self = self else {
503501 promise ( . failure( CardReaderServiceError . connection ( ) ) )
@@ -509,7 +507,7 @@ extension StripeCardReaderService: CardReaderService {
509507 self . readerLocationProvider? . fetchDefaultLocationID { result in
510508 switch result {
511509 case . success( let locationId) :
512- let localMobileConfig = LocalMobileConnectionConfigurationBuilder ( locationId: locationId)
510+ let localMobileConfig = TapToPayConnectionConfigurationBuilder ( delegate : self , locationId: locationId)
513511 localMobileConfig. setMerchantDisplayName ( nil )
514512 localMobileConfig. setOnBehalfOf ( nil )
515513 localMobileConfig. setTosAcceptancePermitted ( options? . builtInOptions? . termsOfServiceAcceptancePermitted ?? true )
@@ -540,7 +538,7 @@ extension StripeCardReaderService: CardReaderService {
540538 return
541539 }
542540
543- Terminal . shared. connectBluetoothReader ( reader, delegate : self , connectionConfig: configuration) { [ weak self] ( reader, error) in
541+ Terminal . shared. connectReader ( reader, connectionConfig: configuration) { [ weak self] ( reader, error) in
544542 guard let self = self else {
545543 promise ( . failure( CardReaderServiceError . connection ( ) ) )
546544 return
@@ -573,14 +571,14 @@ extension StripeCardReaderService: CardReaderService {
573571 }
574572 }
575573
576- public func connect( _ reader: StripeTerminal . Reader , configuration: LocalMobileConnectionConfiguration ) -> Future < CardReader , Error > {
574+ public func connect( _ reader: StripeTerminal . Reader , configuration: TapToPayConnectionConfiguration ) -> Future < CardReader , Error > {
577575 return Future { [ weak self] promise in
578576 guard let self = self else {
579577 promise ( . failure( CardReaderServiceError . connection ( ) ) )
580578 return
581579 }
582580
583- Terminal . shared. connectLocalMobileReader ( reader, delegate : self , connectionConfig: configuration) { [ weak self] ( reader, error) in
581+ Terminal . shared. connectReader ( reader, connectionConfig: configuration) { [ weak self] ( reader, error) in
584582 guard let self = self else {
585583 promise ( . failure( CardReaderServiceError . connection ( ) ) )
586584 return
@@ -873,7 +871,7 @@ extension StripeCardReaderService: DiscoveryDelegate {
873871
874872
875873// MARK: - ReaderDisplayDelegate.
876- extension StripeCardReaderService : BluetoothReaderDelegate {
874+ extension StripeCardReaderService : MobileReaderDelegate {
877875 public func reader( _ reader: Reader , didReportAvailableUpdate update: ReaderSoftwareUpdate ) {
878876 softwareUpdateSubject. send ( . available)
879877 }
@@ -960,29 +958,33 @@ extension StripeCardReaderService: BluetoothReaderDelegate {
960958
961959 connectedReadersSubject. send ( [ connectedReaderWithUpdatedBatteryLevel] )
962960 }
961+
962+ public func reader( _ reader: Reader , didDisconnect reason: DisconnectReason ) {
963+ connectedReadersSubject. send ( [ ] )
964+ }
963965}
964966
965- extension StripeCardReaderService : LocalMobileReaderDelegate {
966- public func localMobileReader ( _ reader: Reader , didRequestReaderInput inputOptions: ReaderInputOptions = [ ] ) {
967+ extension StripeCardReaderService : TapToPayReaderDelegate {
968+ public func tapToPayReader ( _ reader: Reader , didRequestReaderInput inputOptions: ReaderInputOptions = [ ] ) {
967969 sendReaderEvent ( CardReaderEvent . make ( stripeReaderInputOptions: inputOptions) )
968970 }
969971
970- public func localMobileReader ( _ reader: Reader , didRequestReaderDisplayMessage displayMessage: ReaderDisplayMessage ) {
972+ public func tapToPayReader ( _ reader: Reader , didRequestReaderDisplayMessage displayMessage: ReaderDisplayMessage ) {
971973 sendReaderEvent ( CardReaderEvent . make ( displayMessage: displayMessage) )
972974 }
973975
974976
975977 // TODO: use a specific `deviceSetup` in these three functions instead of reusing the softwareUpdateSubject
976978 // https://github.com/woocommerce/woocommerce-ios/issues/8088
977- public func localMobileReader ( _ reader: Reader , didStartInstallingUpdate update: ReaderSoftwareUpdate , cancelable: Cancelable ? ) {
979+ public func tapToPayReader ( _ reader: Reader , didStartInstallingUpdate update: ReaderSoftwareUpdate , cancelable: Cancelable ? ) {
978980 softwareUpdateSubject. send ( . started( cancelable: cancelable. map ( StripeCancelable . init ( cancelable: ) ) ) )
979981 }
980982
981- public func localMobileReader ( _ reader: Reader , didReportReaderSoftwareUpdateProgress progress: Float ) {
983+ public func tapToPayReader ( _ reader: Reader , didReportReaderSoftwareUpdateProgress progress: Float ) {
982984 softwareUpdateSubject. send ( . installing( progress: progress) )
983985 }
984986
985- public func localMobileReader ( _ reader: Reader , didFinishInstallingUpdate update: ReaderSoftwareUpdate ? , error: Error ? ) {
987+ public func tapToPayReader ( _ reader: Reader , didFinishInstallingUpdate update: ReaderSoftwareUpdate ? , error: Error ? ) {
986988 if let error = error {
987989 let underlyingError = Self . logAndDecodeError ( error)
988990 softwareUpdateSubject. send ( . failed(
@@ -1002,18 +1004,11 @@ extension StripeCardReaderService: LocalMobileReaderDelegate {
10021004 }
10031005 }
10041006
1005- public func localMobileReaderDidAcceptTermsOfService ( _ reader: Reader ) {
1007+ public func tapToPayReaderDidAcceptTermsOfService ( _ reader: Reader ) {
10061008 builtInCardReaderAcceptToSSubject. send ( ( ) )
10071009 }
10081010}
10091011
1010- // MARK: - Terminal delegate
1011- extension StripeCardReaderService : TerminalDelegate {
1012- public func terminal( _ terminal: Terminal , didReportUnexpectedReaderDisconnect reader: Reader ) {
1013- connectedReadersSubject. send ( [ ] )
1014- }
1015- }
1016-
10171012// MARK: - Reader events
10181013private extension StripeCardReaderService {
10191014 func sendReaderEvent( _ event: CardReaderEvent ) {
0 commit comments