From 315e1ae60b82f86911c5a0506ad9818cd57ad343 Mon Sep 17 00:00:00 2001 From: BreX900 Date: Mon, 16 Oct 2023 14:23:01 +0200 Subject: [PATCH] fix(android): Fixed `Terminal.discoverReaders` method errors not being propagated fix: Fixed `Terminal.discoverReaders` method errors are not mapped to `TerminalException` fix: Fixed `Terminal.supportsReadersOfType` to support deviceType to null for UNKNOWN deviceType on android fix: Fixed `TerminalException.message` was not properly mapped --- .../lib/src/generators/dart_api_builder.dart | 10 +++++++++- stripe_terminal/CHANGELOG.md | 6 +++++- stripe_terminal/ROADMAP.md | 1 + .../main/kotlin/mek/stripeterminal/TerminalPlugin.kt | 9 +++++++-- .../kotlin/mek/stripeterminal/api/TerminalApi.kt | 6 +++--- .../stripeterminal/plugin/DiscoverReadersSubject.kt | 7 ++++--- stripe_terminal/example/ios/Podfile.lock | 4 ++-- stripe_terminal/example/lib/main.dart | 7 +++++-- stripe_terminal/example/pubspec.lock | 2 +- stripe_terminal/example/pubspec.yaml | 4 ++-- stripe_terminal/ios/Classes/Api/TerminalApi.swift | 5 ++--- .../ios/Classes/Plugin/DiscoveryDelegatePlugin.swift | 4 +++- stripe_terminal/ios/Classes/TerminalPlugin.swift | 4 ++-- .../lib/src/platform/terminal_platform.api.dart | 12 ++++++++---- .../lib/src/platform/terminal_platform.dart | 2 +- stripe_terminal/lib/src/terminal.dart | 2 +- stripe_terminal/lib/src/terminal_exception.dart | 2 +- stripe_terminal/pubspec.yaml | 2 +- 18 files changed, 58 insertions(+), 31 deletions(-) diff --git a/one_for_all_generator/lib/src/generators/dart_api_builder.dart b/one_for_all_generator/lib/src/generators/dart_api_builder.dart index 5be46af..5b2c3ec 100644 --- a/one_for_all_generator/lib/src/generators/dart_api_builder.dart +++ b/one_for_all_generator/lib/src/generators/dart_api_builder.dart @@ -72,11 +72,19 @@ class DartApiBuilder extends ApiBuilder { final parameters = e.parameters.map((e) => codecs.encodeSerialization(e.type, e.name)).join(', '); + final errorHandler = hostExceptionHandler != null + ? '.handleError((error, _) {' + ' if (error is PlatformException) ${hostExceptionHandler.accessor}(error);' + ' throw error;' + '})' + : ''; + return Method((b) => b ..update((b) => _updateHostApiMethod(e, b)) ..body = Code('return _\$${e.name.no_}' '.receiveBroadcastStream([$parameters])' - '.map((e) => ${codecs.encodeDeserialization(returnType, 'e')});')); + '.map((e) => ${codecs.encodeDeserialization(returnType, 'e')})' + '$errorHandler;')); })) ..methods.addAll(element.methods.where((e) => e.isHostApiMethod).map((e) { final returnType = e.returnType.singleTypeArg; diff --git a/stripe_terminal/CHANGELOG.md b/stripe_terminal/CHANGELOG.md index 1c384c3..caccd43 100644 --- a/stripe_terminal/CHANGELOG.md +++ b/stripe_terminal/CHANGELOG.md @@ -1,4 +1,8 @@ - +## 3.1.1 +- fix(android): Fixed `Terminal.discoverReaders` method errors not being propagated +- fix: Fixed `Terminal.discoverReaders` method errors are not mapped to `TerminalException` +- fix: Fixed `Terminal.supportsReadersOfType` to support deviceType to null for UNKNOWN deviceType on android +- fix: Fixed `TerminalException.message` was not properly mapped ## 3.1.0 - feat: Mapped more exception codecs: Android (`collectInputsUnsupported`), IOS (`readerConnectionOfflineNeedsUpdate`, diff --git a/stripe_terminal/ROADMAP.md b/stripe_terminal/ROADMAP.md index 9458061..7830082 100644 --- a/stripe_terminal/ROADMAP.md +++ b/stripe_terminal/ROADMAP.md @@ -15,6 +15,7 @@ - (Not exist on ios) `Reader.device` has been removed and replaced with [`Reader.bluetoothDevice`](https://stripe.dev/stripe-terminal-android/external/com.stripe.stripeterminal.external.models/-reader/bluetooth-device.html) and [`Reader.usbDevice`](https://stripe.dev/stripe-terminal-android/external/com.stripe.stripeterminal.external.models/-reader/usb-device.html). ### Ready +- Feat: Added support to `Terminal.updateSimulatorConfiguration` ### In progress diff --git a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/TerminalPlugin.kt b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/TerminalPlugin.kt index 896e48b..61a1541 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/TerminalPlugin.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/TerminalPlugin.kt @@ -16,6 +16,7 @@ import com.stripe.stripeterminal.external.callable.RefundCallback import com.stripe.stripeterminal.external.callable.SetupIntentCallback import com.stripe.stripeterminal.external.models.CollectConfiguration import com.stripe.stripeterminal.external.models.ConnectionConfiguration +import com.stripe.stripeterminal.external.models.DeviceType import com.stripe.stripeterminal.external.models.ListLocationsParameters import com.stripe.stripeterminal.external.models.Location import com.stripe.stripeterminal.external.models.PaymentIntent @@ -27,6 +28,9 @@ import com.stripe.stripeterminal.external.models.SetupIntent import com.stripe.stripeterminal.external.models.SetupIntentCancellationParameters import com.stripe.stripeterminal.external.models.SetupIntentConfiguration import com.stripe.stripeterminal.external.models.SetupIntentParameters +import com.stripe.stripeterminal.external.models.SimulatedCard +import com.stripe.stripeterminal.external.models.SimulatedCardType +import com.stripe.stripeterminal.external.models.SimulatorConfiguration import com.stripe.stripeterminal.external.models.TerminalException import com.stripe.stripeterminal.log.LogLevel import mek.stripeterminal.api.CartApi @@ -117,10 +121,11 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { override fun onGetConnectionStatus(): ConnectionStatusApi = _terminal.connectionStatus.toApi() override fun onSupportsReadersOfType( - deviceType: DeviceTypeApi, + deviceType: DeviceTypeApi?, discoveryConfiguration: DiscoveryConfigurationApi, ): Boolean { - val hostDeviceType = deviceType.toHost() ?: return false + val hostDeviceType = (if (deviceType != null) deviceType.toHost() else DeviceType.UNKNOWN) + ?: return false val hostDiscoveryConfiguration = discoveryConfiguration.toHost() ?: return false val result = _terminal.supportsReadersOfType( deviceType = hostDeviceType, diff --git a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/api/TerminalApi.kt b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/api/TerminalApi.kt index 57b2a9c..47a5236 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/api/TerminalApi.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/api/TerminalApi.kt @@ -63,7 +63,7 @@ interface TerminalPlatformApi { fun onGetConnectionStatus(): ConnectionStatusApi fun onSupportsReadersOfType( - deviceType: DeviceTypeApi, + deviceType: DeviceTypeApi?, discoveryConfiguration: DiscoveryConfigurationApi, ): Boolean @@ -251,7 +251,7 @@ interface TerminalPlatformApi { result.success(res.ordinal) } "supportsReadersOfType" -> { - val res = onSupportsReadersOfType((args[0] as Int).let { DeviceTypeApi.values()[it] }, (args[1] as List).let { DiscoveryConfigurationApi.deserialize(it) }) + val res = onSupportsReadersOfType((args[0] as Int?)?.let { DeviceTypeApi.values()[it] }, (args[1] as List).let { DiscoveryConfigurationApi.deserialize(it) }) result.success(res) } "connectBluetoothReader" -> { @@ -1189,7 +1189,7 @@ data class TerminalExceptionApi( } enum class TerminalExceptionCodeApi { - UNKNOWN, READER_NOT_RECOVERED, PAYMENT_INTENT_NOT_RECOVERED, SETUP_INTENT_NOT_RECOVERED, CANCEL_FAILED, NOT_CONNECTED_TO_READER, ALREADY_CONNECTED_TO_READER, BLUETOOTH_DISABLED, BLUETOOTH_PERMISSION_DENIED, CONFIRM_INVALID_PAYMENT_INTENT, INVALID_CLIENT_SECRET, INVALID_READER_FOR_UPDATE, UNSUPPORTED_OPERATION, UNEXPECTED_OPERATION, UNSUPPORTED_SDK, FEATURE_NOT_AVAILABLE_WITH_CONNECTED_READER, USB_PERMISSION_DENIED, USB_DISCOVERY_TIMED_OUT, INVALID_PARAMETER, INVALID_REQUIRED_PARAMETER, INVALID_TIP_PARAMETER, LOCAL_MOBILE_UNSUPPORTED_DEVICE, LOCAL_MOBILE_UNSUPPORTED_OPERATING_SYSTEM_VERSION, LOCAL_MOBILE_DEVICE_TAMPERED, LOCAL_MOBILE_DEBUG_NOT_SUPPORTED, OFFLINE_MODE_UNSUPPORTED_OPERATING_SYSTEM_VERSION, CANCELED, LOCATION_SERVICES_DISABLED, BLUETOOTH_SCAN_TIMED_OUT, BLUETOOTH_LOW_ENERGY_UNSUPPORTED, READER_SOFTWARE_UPDATE_FAILED_BATTERY_LOW, READER_SOFTWARE_UPDATE_FAILED_INTERRUPTED, READER_SOFTWARE_UPDATE_FAILED_EXPIRED_UPDATE, BLUETOOTH_CONNECTION_FAILED_BATTERY_CRITICALLY_LOW, CARD_INSERT_NOT_READ, CARD_SWIPE_NOT_READ, CARD_READ_TIMED_OUT, CARD_REMOVED, CUSTOMER_CONSENT_REQUIRED, CARD_LEFT_IN_READER, FEATURE_NOT_ENABLED_ON_ACCOUNT, PASSCODE_NOT_ENABLED, COMMAND_NOT_ALLOWED_DURING_CALL, INVALID_AMOUNT, INVALID_CURRENCY, APPLE_BUILT_IN_READER_T_O_S_ACCEPTANCE_REQUIRESI_CLOUD_SIGN_IN, APPLE_BUILT_IN_READER_T_O_S_ACCEPTANCE_CANCELED, APPLE_BUILT_IN_READER_FAILED_TO_PREPARE, APPLE_BUILT_IN_READER_DEVICE_BANNED, APPLE_BUILT_IN_READER_T_O_S_NOT_YET_ACCEPTED, APPLE_BUILT_IN_READER_T_O_S_ACCEPTANCE_FAILED, APPLE_BUILT_IN_READER_MERCHANT_BLOCKED, APPLE_BUILT_IN_READER_INVALID_MERCHANT, READER_BUSY, INCOMPATIBLE_READER, READER_COMMUNICATION_ERROR, UNKNOWN_READER_IP_ADDRESS, INTERNET_CONNECT_TIME_OUT, CONNECT_FAILED_READER_IS_IN_USE, READER_NOT_ACCESSIBLE_IN_BACKGROUND, BLUETOOTH_ERROR, BLUETOOTH_CONNECT_TIMED_OUT, BLUETOOTH_DISCONNECTED, BLUETOOTH_PEER_REMOVED_PAIRING_INFORMATION, BLUETOOTH_ALREADY_PAIRED_WITH_ANOTHER_DEVICE, BLUETOOTH_RECONNECT_STARTED, USB_DISCONNECTED, USB_RECONNECT_STARTED, READER_CONNECTED_TO_ANOTHER_DEVICE, READER_SOFTWARE_UPDATE_FAILED, READER_SOFTWARE_UPDATE_FAILED_READER_ERROR, READER_SOFTWARE_UPDATE_FAILED_SERVER_ERROR, NFC_DISABLED, UNSUPPORTED_READER_VERSION, UNEXPECTED_SDK_ERROR, UNEXPECTED_READER_ERROR, ENCRYPTION_KEY_FAILURE, ENCRYPTION_KEY_STILL_INITIALIZING, DECLINED_BY_STRIPE_API, DECLINED_BY_READER, OFFLINE_TEST_CARD_IN_LIVEMODE, NOT_CONNECTED_TO_INTERNET, REQUEST_TIMED_OUT, STRIPE_API_CONNECTION_ERROR, STRIPE_API_ERROR, STRIPE_API_RESPONSE_DECODING_ERROR, INTERNAL_NETWORK_ERROR, CONNECTION_TOKEN_PROVIDER_ERROR, SESSION_EXPIRED, UNSUPPORTED_MOBILE_DEVICE_CONFIGURATION, COMMAND_NOT_ALLOWED, AMOUNT_EXCEEDS_MAX_OFFLINE_AMOUNT, OFFLINE_PAYMENTS_DATABASE_TOO_LARGE, READER_CONNECTION_NOT_AVAILABLE_OFFLINE, READER_CONNECTION_OFFLINE_LOCATION_MISMATCH, READER_CONNECTION_OFFLINE_NEEDS_UPDATE, LOCATION_CONNECTION_NOT_AVAILABLE_OFFLINE, NO_LAST_SEEN_ACCOUNT, INVALID_OFFLINE_CURRENCY, REFUND_FAILED, CARD_SWIPE_NOT_AVAILABLE, INTERAC_NOT_SUPPORTED_OFFLINE, ONLINE_PIN_NOT_SUPPORTED_OFFLINE, OFFLINE_AND_CARD_EXPIRED, OFFLINE_TRANSACTION_DECLINED, OFFLINE_COLLECT_AND_CONFIRM_MISMATCH, FORWARDING_TEST_MODE_PAYMENT_IN_LIVE_MODE, FORWARDING_LIVE_MODE_PAYMENT_IN_TEST_MODE, OFFLINE_PAYMENT_INTENT_NOT_FOUND, UPDATE_PAYMENT_INTENT_UNAVAILABLE_WHILE_OFFLINE, UPDATE_PAYMENT_INTENT_UNAVAILABLE_WHILE_OFFLINE_MODE_ENABLED, MISSING_EMV_DATA, CONNECTION_TOKEN_PROVIDER_ERROR_WHILE_FORWARDING, CONNECTION_TOKEN_PROVIDER_TIMED_OUT, ACCOUNT_ID_MISMATCH_WHILE_FORWARDING, OFFLINE_BEHAVIOR_FORCE_OFFLINE_WITH_FEATURE_DISABLED, NOT_CONNECTED_TO_INTERNET_AND_OFFLINE_BEHAVIOR_REQUIRE_ONLINE, TEST_CARD_IN_LIVE_MODE, COLLECT_INPUTS_APPLICATION_ERROR, COLLECT_INPUTS_TIMED_OUT, COLLECT_INPUTS_UNSUPPORTED; + UNKNOWN, READER_NOT_RECOVERED, PAYMENT_INTENT_NOT_RECOVERED, SETUP_INTENT_NOT_RECOVERED, CANCEL_FAILED, NOT_CONNECTED_TO_READER, ALREADY_CONNECTED_TO_READER, BLUETOOTH_DISABLED, BLUETOOTH_PERMISSION_DENIED, CONFIRM_INVALID_PAYMENT_INTENT, INVALID_CLIENT_SECRET, INVALID_READER_FOR_UPDATE, UNSUPPORTED_OPERATION, UNEXPECTED_OPERATION, UNSUPPORTED_SDK, FEATURE_NOT_AVAILABLE_WITH_CONNECTED_READER, USB_PERMISSION_DENIED, USB_DISCOVERY_TIMED_OUT, INVALID_PARAMETER, INVALID_REQUIRED_PARAMETER, INVALID_TIP_PARAMETER, LOCAL_MOBILE_UNSUPPORTED_DEVICE, LOCAL_MOBILE_UNSUPPORTED_OPERATING_SYSTEM_VERSION, LOCAL_MOBILE_DEVICE_TAMPERED, LOCAL_MOBILE_DEBUG_NOT_SUPPORTED, OFFLINE_MODE_UNSUPPORTED_OPERATING_SYSTEM_VERSION, CANCELED, LOCATION_SERVICES_DISABLED, BLUETOOTH_SCAN_TIMED_OUT, BLUETOOTH_LOW_ENERGY_UNSUPPORTED, READER_SOFTWARE_UPDATE_FAILED_BATTERY_LOW, READER_SOFTWARE_UPDATE_FAILED_INTERRUPTED, READER_SOFTWARE_UPDATE_FAILED_EXPIRED_UPDATE, BLUETOOTH_CONNECTION_FAILED_BATTERY_CRITICALLY_LOW, CARD_INSERT_NOT_READ, CARD_SWIPE_NOT_READ, CARD_READ_TIMED_OUT, CARD_REMOVED, CUSTOMER_CONSENT_REQUIRED, CARD_LEFT_IN_READER, FEATURE_NOT_ENABLED_ON_ACCOUNT, PASSCODE_NOT_ENABLED, COMMAND_NOT_ALLOWED_DURING_CALL, INVALID_AMOUNT, INVALID_CURRENCY, APPLE_BUILT_IN_READER_T_O_S_ACCEPTANCE_REQUIRESI_CLOUD_SIGN_IN, APPLE_BUILT_IN_READER_T_O_S_ACCEPTANCE_CANCELED, APPLE_BUILT_IN_READER_FAILED_TO_PREPARE, APPLE_BUILT_IN_READER_DEVICE_BANNED, APPLE_BUILT_IN_READER_T_O_S_NOT_YET_ACCEPTED, APPLE_BUILT_IN_READER_T_O_S_ACCEPTANCE_FAILED, APPLE_BUILT_IN_READER_MERCHANT_BLOCKED, APPLE_BUILT_IN_READER_INVALID_MERCHANT, READER_BUSY, INCOMPATIBLE_READER, READER_COMMUNICATION_ERROR, UNKNOWN_READER_IP_ADDRESS, INTERNET_CONNECT_TIME_OUT, CONNECT_FAILED_READER_IS_IN_USE, READER_NOT_ACCESSIBLE_IN_BACKGROUND, BLUETOOTH_ERROR, BLUETOOTH_CONNECT_TIMED_OUT, BLUETOOTH_DISCONNECTED, BLUETOOTH_PEER_REMOVED_PAIRING_INFORMATION, BLUETOOTH_ALREADY_PAIRED_WITH_ANOTHER_DEVICE, BLUETOOTH_RECONNECT_STARTED, USB_DISCONNECTED, USB_RECONNECT_STARTED, READER_CONNECTED_TO_ANOTHER_DEVICE, READER_SOFTWARE_UPDATE_FAILED, READER_SOFTWARE_UPDATE_FAILED_READER_ERROR, READER_SOFTWARE_UPDATE_FAILED_SERVER_ERROR, NFC_DISABLED, UNSUPPORTED_READER_VERSION, UNEXPECTED_SDK_ERROR, UNEXPECTED_READER_ERROR, ENCRYPTION_KEY_FAILURE, ENCRYPTION_KEY_STILL_INITIALIZING, DECLINED_BY_STRIPE_API, DECLINED_BY_READER, NOT_CONNECTED_TO_INTERNET, REQUEST_TIMED_OUT, STRIPE_API_CONNECTION_ERROR, STRIPE_API_ERROR, STRIPE_API_RESPONSE_DECODING_ERROR, INTERNAL_NETWORK_ERROR, CONNECTION_TOKEN_PROVIDER_ERROR, SESSION_EXPIRED, UNSUPPORTED_MOBILE_DEVICE_CONFIGURATION, COMMAND_NOT_ALLOWED, AMOUNT_EXCEEDS_MAX_OFFLINE_AMOUNT, OFFLINE_PAYMENTS_DATABASE_TOO_LARGE, READER_CONNECTION_NOT_AVAILABLE_OFFLINE, READER_CONNECTION_OFFLINE_LOCATION_MISMATCH, READER_CONNECTION_OFFLINE_NEEDS_UPDATE, LOCATION_CONNECTION_NOT_AVAILABLE_OFFLINE, NO_LAST_SEEN_ACCOUNT, INVALID_OFFLINE_CURRENCY, REFUND_FAILED, CARD_SWIPE_NOT_AVAILABLE, INTERAC_NOT_SUPPORTED_OFFLINE, ONLINE_PIN_NOT_SUPPORTED_OFFLINE, OFFLINE_AND_CARD_EXPIRED, OFFLINE_TRANSACTION_DECLINED, OFFLINE_COLLECT_AND_CONFIRM_MISMATCH, FORWARDING_TEST_MODE_PAYMENT_IN_LIVE_MODE, FORWARDING_LIVE_MODE_PAYMENT_IN_TEST_MODE, OFFLINE_PAYMENT_INTENT_NOT_FOUND, UPDATE_PAYMENT_INTENT_UNAVAILABLE_WHILE_OFFLINE, UPDATE_PAYMENT_INTENT_UNAVAILABLE_WHILE_OFFLINE_MODE_ENABLED, MISSING_EMV_DATA, CONNECTION_TOKEN_PROVIDER_ERROR_WHILE_FORWARDING, CONNECTION_TOKEN_PROVIDER_TIMED_OUT, ACCOUNT_ID_MISMATCH_WHILE_FORWARDING, OFFLINE_BEHAVIOR_FORCE_OFFLINE_WITH_FEATURE_DISABLED, NOT_CONNECTED_TO_INTERNET_AND_OFFLINE_BEHAVIOR_REQUIRE_ONLINE, TEST_CARD_IN_LIVE_MODE, COLLECT_INPUTS_APPLICATION_ERROR, COLLECT_INPUTS_TIMED_OUT, COLLECT_INPUTS_UNSUPPORTED; } data class TippingConfigurationApi( diff --git a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/plugin/DiscoverReadersSubject.kt b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/plugin/DiscoverReadersSubject.kt index d3dbe4f..b41b105 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/plugin/DiscoverReadersSubject.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/plugin/DiscoverReadersSubject.kt @@ -49,11 +49,12 @@ class DiscoverReadersSubject { runOnMainThread { sink.success(readers.map { it.toApi() }) } } }, - callback = object : TerminalErrorHandler(sink::error), Callback { + callback = object : Callback { override fun onFailure(e: TerminalException) = runOnMainThread { - if (_cancelable == null) return@runOnMainThread + if (e.errorCode == TerminalException.TerminalErrorCode.CANCELED) return@runOnMainThread + _cancelable = null - super.onFailure(e) + sink.error(e.toPlatformError()) sink.endOfStream() } diff --git a/stripe_terminal/example/ios/Podfile.lock b/stripe_terminal/example/ios/Podfile.lock index 69b9628..35721bc 100644 --- a/stripe_terminal/example/ios/Podfile.lock +++ b/stripe_terminal/example/ios/Podfile.lock @@ -1,6 +1,6 @@ PODS: - Flutter (1.0.0) - - mek_stripe_terminal (3.1.0): + - mek_stripe_terminal (3.1.1): - Flutter - StripeTerminal (~> 3.1.0) - permission_handler_apple (9.1.1): @@ -26,7 +26,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 - mek_stripe_terminal: 83c57b917dc236752c47758613dc9c249c146883 + mek_stripe_terminal: 28fb87151cb2d580c02e33532ef483d5da855213 permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6 StripeTerminal: fa064cf68a7a3df7c2ee1b2e6d33c8866d1e6aef diff --git a/stripe_terminal/example/lib/main.dart b/stripe_terminal/example/lib/main.dart index 84e3d3e..464e4b1 100644 --- a/stripe_terminal/example/lib/main.dart +++ b/stripe_terminal/example/lib/main.dart @@ -78,7 +78,7 @@ class _MyAppState extends State { } final terminal = await Terminal.getInstance( - shouldPrintLogs: true, + shouldPrintLogs: false, fetchToken: _fetchConnectionToken, ); setState(() => _terminal = terminal); @@ -355,7 +355,10 @@ class _MyAppState extends State { child: const Text('Stop Scanning'), ), const Divider(), - ..._readers.map((e) { + ...[ + ..._readers, + if (_reader != null) _reader!, + ].map((e) { return ListTile( selected: e.serialNumber == _reader?.serialNumber, enabled: terminal != null && diff --git a/stripe_terminal/example/pubspec.lock b/stripe_terminal/example/pubspec.lock index dc9d77a..462d8bc 100644 --- a/stripe_terminal/example/pubspec.lock +++ b/stripe_terminal/example/pubspec.lock @@ -140,7 +140,7 @@ packages: path: ".." relative: true source: path - version: "3.1.0" + version: "3.1.1" meta: dependency: transitive description: diff --git a/stripe_terminal/example/pubspec.yaml b/stripe_terminal/example/pubspec.yaml index 6025737..d75926c 100644 --- a/stripe_terminal/example/pubspec.yaml +++ b/stripe_terminal/example/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: permission_handler: ^10.4.3 mek_stripe_terminal: - path: .. + path: ./.. shelf: ^1.4.1 shelf_router: ^1.1.4 @@ -27,7 +27,7 @@ dev_dependencies: dependency_overrides: one_for_all: - path: ../../one_for_all + path: ./../../one_for_all # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/stripe_terminal/ios/Classes/Api/TerminalApi.swift b/stripe_terminal/ios/Classes/Api/TerminalApi.swift index a8c2987..89ceeaa 100644 --- a/stripe_terminal/ios/Classes/Api/TerminalApi.swift +++ b/stripe_terminal/ios/Classes/Api/TerminalApi.swift @@ -100,7 +100,7 @@ protocol TerminalPlatformApi { func onGetConnectionStatus() throws -> ConnectionStatusApi func onSupportsReadersOfType( - _ deviceType: DeviceTypeApi, + _ deviceType: DeviceTypeApi?, _ discoveryConfiguration: DiscoveryConfigurationApi ) throws -> Bool @@ -298,7 +298,7 @@ func setTerminalPlatformApiHandler( let res = try hostApi.onGetConnectionStatus() result(res.rawValue) case "supportsReadersOfType": - let res = try hostApi.onSupportsReadersOfType(DeviceTypeApi(rawValue: args[0] as! Int)!, deserializeDiscoveryConfigurationApi(args[1] as! [Any?])) + let res = try hostApi.onSupportsReadersOfType(!(args[0] is NSNull) ? DeviceTypeApi(rawValue: args[0] as! Int)! : nil, deserializeDiscoveryConfigurationApi(args[1] as! [Any?])) result(res) case "connectBluetoothReader": runAsync { @@ -1356,7 +1356,6 @@ enum TerminalExceptionCodeApi: Int { case encryptionKeyStillInitializing case declinedByStripeApi case declinedByReader - case offlineTestCardInLivemode case notConnectedToInternet case requestTimedOut case stripeApiConnectionError diff --git a/stripe_terminal/ios/Classes/Plugin/DiscoveryDelegatePlugin.swift b/stripe_terminal/ios/Classes/Plugin/DiscoveryDelegatePlugin.swift index ff75d7d..b4a5800 100644 --- a/stripe_terminal/ios/Classes/Plugin/DiscoveryDelegatePlugin.swift +++ b/stripe_terminal/ios/Classes/Plugin/DiscoveryDelegatePlugin.swift @@ -44,7 +44,9 @@ class DiscoveryDelegatePlugin: NSObject, DiscoveryDelegate { self._cancelable = nil DispatchQueue.main.async { if let error = error as? NSError { - self._sink?.error(error.toPlatformError()) + let exception = error.toApi() + if (exception.code == TerminalExceptionCodeApi.canceled) {return} + self._sink?.error(exception.toPlatformError()) } self._sink?.endOfStream() diff --git a/stripe_terminal/ios/Classes/TerminalPlugin.swift b/stripe_terminal/ios/Classes/TerminalPlugin.swift index 4a1b7d5..2e06521 100644 --- a/stripe_terminal/ios/Classes/TerminalPlugin.swift +++ b/stripe_terminal/ios/Classes/TerminalPlugin.swift @@ -59,14 +59,14 @@ public class TerminalPlugin: NSObject, FlutterPlugin, TerminalPlatformApi { } func onSupportsReadersOfType( - _ deviceType: DeviceTypeApi, + _ deviceType: DeviceTypeApi?, _ discoveryConfiguration: DiscoveryConfigurationApi ) throws -> Bool { let hostDiscoveryMethod = discoveryConfiguration.toHostDiscoveryMethod() guard let hostDiscoveryMethod else { return false } - let hostDeviceType = deviceType.toHost() + let hostDeviceType = deviceType?.toHost() guard let hostDeviceType else { return false } diff --git a/stripe_terminal/lib/src/platform/terminal_platform.api.dart b/stripe_terminal/lib/src/platform/terminal_platform.api.dart index ea598d4..2535cba 100644 --- a/stripe_terminal/lib/src/platform/terminal_platform.api.dart +++ b/stripe_terminal/lib/src/platform/terminal_platform.api.dart @@ -12,8 +12,12 @@ class _$TerminalPlatform { Stream> discoverReaders(DiscoveryConfiguration configuration) { return _$discoverReaders - .receiveBroadcastStream([_$serializeDiscoveryConfiguration(configuration)]).map( - (e) => (e as List).map((e) => _$deserializeReader(e as List)).toList()); + .receiveBroadcastStream([_$serializeDiscoveryConfiguration(configuration)]) + .map((e) => (e as List).map((e) => _$deserializeReader(e as List)).toList()) + .handleError((error, _) { + if (error is PlatformException) TerminalPlatform._throwIfIsHostException(error); + throw error; + }); } Future init({required bool shouldPrintLogs}) async { @@ -45,12 +49,12 @@ class _$TerminalPlatform { } Future supportsReadersOfType({ - required DeviceType deviceType, + required DeviceType? deviceType, required DiscoveryConfiguration discoveryConfiguration, }) async { try { final result = await _$channel.invokeMethod('supportsReadersOfType', - [deviceType.index, _$serializeDiscoveryConfiguration(discoveryConfiguration)]); + [deviceType?.index, _$serializeDiscoveryConfiguration(discoveryConfiguration)]); return result as bool; } on PlatformException catch (exception) { TerminalPlatform._throwIfIsHostException(exception); diff --git a/stripe_terminal/lib/src/platform/terminal_platform.dart b/stripe_terminal/lib/src/platform/terminal_platform.dart index 685b405..05d59bc 100644 --- a/stripe_terminal/lib/src/platform/terminal_platform.dart +++ b/stripe_terminal/lib/src/platform/terminal_platform.dart @@ -44,7 +44,7 @@ class TerminalPlatform extends _$TerminalPlatform { @MethodApi(kotlin: MethodApiType.sync, swift: MethodApiType.sync) @override Future supportsReadersOfType({ - required DeviceType deviceType, + required DeviceType? deviceType, required DiscoveryConfiguration discoveryConfiguration, }); diff --git a/stripe_terminal/lib/src/terminal.dart b/stripe_terminal/lib/src/terminal.dart index 9e9a9ee..45d2f08 100644 --- a/stripe_terminal/lib/src/terminal.dart +++ b/stripe_terminal/lib/src/terminal.dart @@ -91,7 +91,7 @@ class Terminal { /// This makes it easy to quickly test your integration end-to-end, from pairing with /// a reader to taking payments. Future supportsReadersOfType({ - required DeviceType deviceType, + required DeviceType? deviceType, required DiscoveryConfiguration discoveryConfiguration, }) async { return await _platform.supportsReadersOfType( diff --git a/stripe_terminal/lib/src/terminal_exception.dart b/stripe_terminal/lib/src/terminal_exception.dart index 45cd96e..80b413c 100644 --- a/stripe_terminal/lib/src/terminal_exception.dart +++ b/stripe_terminal/lib/src/terminal_exception.dart @@ -506,7 +506,7 @@ class TerminalException { required this.stackTrace, required this.paymentIntent, required this.apiError, - }) : message = (message.isEmpty ? null : code.message) ?? ''; + }) : message = (message.isEmpty ? code.message : message) ?? ''; @override String toString() => [ diff --git a/stripe_terminal/pubspec.yaml b/stripe_terminal/pubspec.yaml index 1a9e462..c95df8e 100644 --- a/stripe_terminal/pubspec.yaml +++ b/stripe_terminal/pubspec.yaml @@ -1,6 +1,6 @@ name: mek_stripe_terminal description: A StripeTerminal plugin to discover readers, connect to them and process payments. -version: 3.1.0 +version: 3.1.1 repository: https://github.com/BreX900/mek-packages/tree/main/stripe_terminal homepage: https://github.com/BreX900/mek-packages/tree/main/stripe_terminal topics: