diff --git a/stripe_terminal/android/.editorconfig b/stripe_terminal/android/.editorconfig new file mode 100644 index 0000000..d5e29b3 --- /dev/null +++ b/stripe_terminal/android/.editorconfig @@ -0,0 +1,3 @@ +[*.{kt,kts}] +ktlint_code_style = android_studio +max_line_length = off \ No newline at end of file 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 0d22a3d..7cf8b28 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/TerminalPlugin.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/TerminalPlugin.kt @@ -70,11 +70,11 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { arrayOf( Manifest.permission.BLUETOOTH_SCAN, - Manifest.permission.BLUETOOTH_ADMIN, + Manifest.permission.BLUETOOTH_ADMIN ) } else { arrayOf( - Manifest.permission.BLUETOOTH_ADMIN, + Manifest.permission.BLUETOOTH_ADMIN ) } @@ -86,7 +86,8 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { if (permissionStatus.contains(PackageManager.PERMISSION_DENIED)) { throw createApiError( TerminalExceptionCodeApi.UNKNOWN, - "You have declined the necessary permission, please allow from settings to continue.", + "You have declined the necessary permission, " + + "please allow from settings to continue." ) .toPlatformError() } @@ -104,7 +105,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { activity!!.applicationContext, if (shouldPrintLogs) LogLevel.VERBOSE else LogLevel.NONE, delegate, - delegate, + delegate ) } @@ -123,7 +124,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { override fun onSupportsReadersOfType( deviceType: DeviceTypeApi?, - discoveryConfiguration: DiscoveryConfigurationApi, + discoveryConfiguration: DiscoveryConfigurationApi ): Boolean { val hostDeviceType = (if (deviceType != null) deviceType.toHost() else DeviceType.UNKNOWN) ?: return false @@ -131,7 +132,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { val result = terminal.supportsReadersOfType( deviceType = hostDeviceType, - discoveryConfiguration = hostDiscoveryConfiguration, + discoveryConfiguration = hostDiscoveryConfiguration ) return result.isSupported } @@ -140,7 +141,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { discoverReadersController = DiscoverReadersControllerApi(binaryMessenger) discoverReadersController.setHandler( discoverReadersSubject::onListen, - discoverReadersSubject::onCancel, + discoverReadersSubject::onCancel ) } @@ -148,7 +149,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { result: Result, serialNumber: String, locationId: String, - autoReconnectOnUnexpectedDisconnect: Boolean, + autoReconnectOnUnexpectedDisconnect: Boolean ) { val reader = findActiveReader(serialNumber) @@ -157,19 +158,16 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { ConnectionConfiguration.BluetoothConnectionConfiguration( locationId = locationId, autoReconnectOnUnexpectedDisconnect = autoReconnectOnUnexpectedDisconnect, - bluetoothReaderReconnectionListener = readerReconnectionDelegate, + bluetoothReaderReconnectionListener = readerReconnectionDelegate ), readerDelegate, object : TerminalErrorHandler(result::error), ReaderCallback { override fun onSuccess(reader: Reader) = result.success(reader.toApi()) - }, + } ) } - override fun onConnectHandoffReader( - result: Result, - serialNumber: String, - ) { + override fun onConnectHandoffReader(result: Result, serialNumber: String) { val reader = findActiveReader(serialNumber) terminal.connectHandoffReader( @@ -178,45 +176,45 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { readerDelegate, object : TerminalErrorHandler(result::error), ReaderCallback { override fun onSuccess(reader: Reader) = result.success(reader.toApi()) - }, + } ) } override fun onConnectInternetReader( result: Result, serialNumber: String, - failIfInUse: Boolean, + failIfInUse: Boolean ) { val reader = findActiveReader(serialNumber) terminal.connectInternetReader( reader, ConnectionConfiguration.InternetConnectionConfiguration( - failIfInUse = failIfInUse, + failIfInUse = failIfInUse ), object : TerminalErrorHandler(result::error), ReaderCallback { override fun onSuccess(reader: Reader) = result.success(reader.toApi()) - }, + } ) } override fun onConnectMobileReader( result: Result, serialNumber: String, - locationId: String, + locationId: String ) { val reader = findActiveReader(serialNumber) val config = ConnectionConfiguration.LocalMobileConnectionConfiguration( - locationId = locationId, + locationId = locationId ) terminal.connectLocalMobileReader( reader, config, object : TerminalErrorHandler(result::error), ReaderCallback { override fun onSuccess(reader: Reader) = result.success(reader.toApi()) - }, + } ) } @@ -224,7 +222,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { result: Result, serialNumber: String, locationId: String, - autoReconnectOnUnexpectedDisconnect: Boolean, + autoReconnectOnUnexpectedDisconnect: Boolean ) { val reader = findActiveReader(serialNumber) @@ -233,12 +231,12 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { ConnectionConfiguration.UsbConnectionConfiguration( locationId = locationId, autoReconnectOnUnexpectedDisconnect = autoReconnectOnUnexpectedDisconnect, - usbReaderReconnectionListener = readerReconnectionDelegate, + usbReaderReconnectionListener = readerReconnectionDelegate ), readerDelegate, object : TerminalErrorHandler(result::error), ReaderCallback { override fun onSuccess(reader: Reader) = result.success(reader.toApi()) - }, + } ) } @@ -251,7 +249,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { readerReconnectionDelegate.cancelReconnect?.cancel( object : Callback, TerminalErrorHandler(result::error) { override fun onSuccess() = result.success(Unit) - }, + } ) } @@ -259,7 +257,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { result: Result>, endingBefore: String?, limit: Long?, - startingAfter: String?, + startingAfter: String? ) { val params = ListLocationsParameters.Builder() params.endingBefore = endingBefore @@ -268,11 +266,9 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { terminal.listLocations( params.build(), object : TerminalErrorHandler(result::error), LocationListCallback { - override fun onSuccess( - locations: List, - hasMore: Boolean, - ) = result.success(locations.map { it.toApi() }) - }, + override fun onSuccess(locations: List, hasMore: Boolean) = + result.success(locations.map { it.toApi() }) + } ) } @@ -285,7 +281,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { readerDelegate.cancelUpdate?.cancel( object : Callback, TerminalErrorHandler(result::error) { override fun onSuccess() = result.success(Unit) - }, + } ) } @@ -293,7 +289,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { terminal.disconnectReader( object : TerminalErrorHandler(result::error), Callback { override fun onSuccess() = result.success(Unit) - }, + } ) } @@ -309,24 +305,21 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { override fun onCreatePaymentIntent( result: Result, - parameters: PaymentIntentParametersApi, + parameters: PaymentIntentParametersApi ) { terminal.createPaymentIntent( params = parameters.toHost(), callback = - object : TerminalErrorHandler(result::error), PaymentIntentCallback { - override fun onSuccess(paymentIntent: PaymentIntent) { - paymentIntents[paymentIntent.id!!] = paymentIntent - result.success(paymentIntent.toApi()) - } - }, + object : TerminalErrorHandler(result::error), PaymentIntentCallback { + override fun onSuccess(paymentIntent: PaymentIntent) { + paymentIntents[paymentIntent.id!!] = paymentIntent + result.success(paymentIntent.toApi()) + } + } ) } - override fun onRetrievePaymentIntent( - result: Result, - clientSecret: String, - ) { + override fun onRetrievePaymentIntent(result: Result, clientSecret: String) { terminal.retrievePaymentIntent( clientSecret, object : TerminalErrorHandler(result::error), PaymentIntentCallback { @@ -334,7 +327,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { paymentIntents[paymentIntent.id!!] = paymentIntent result.success(paymentIntent.toApi()) } - }, + } ) } @@ -347,7 +340,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { skipTipping: Boolean, tippingConfiguration: TippingConfigurationApi?, shouldUpdatePaymentIntent: Boolean, - customerCancellationEnabled: Boolean, + customerCancellationEnabled: Boolean ) { val paymentIntent = findPaymentIntent(paymentIntentId) val config = @@ -362,38 +355,32 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { paymentIntent, config = config.build(), callback = - object : TerminalErrorHandler(result::error), PaymentIntentCallback { - override fun onFailure(e: TerminalException) { - cancelablesCollectPaymentMethod.remove(operationId) - super.onFailure(e) - } - - override fun onSuccess(paymentIntent: PaymentIntent) { - cancelablesCollectPaymentMethod.remove(operationId) - result.success(paymentIntent.toApi()) - paymentIntents[paymentIntent.id!!] = paymentIntent - } - }, + object : TerminalErrorHandler(result::error), PaymentIntentCallback { + override fun onFailure(e: TerminalException) { + cancelablesCollectPaymentMethod.remove(operationId) + super.onFailure(e) + } + + override fun onSuccess(paymentIntent: PaymentIntent) { + cancelablesCollectPaymentMethod.remove(operationId) + result.success(paymentIntent.toApi()) + paymentIntents[paymentIntent.id!!] = paymentIntent + } + } ) } - override fun onStopCollectPaymentMethod( - result: Result, - operationId: Long, - ) { + override fun onStopCollectPaymentMethod(result: Result, operationId: Long) { cancelablesCollectPaymentMethod .remove(operationId) ?.cancel( object : TerminalErrorHandler(result::error), Callback { override fun onSuccess() = result.success(Unit) - }, + } ) } - override fun onConfirmPaymentIntent( - result: Result, - paymentIntentId: String, - ) { + override fun onConfirmPaymentIntent(result: Result, paymentIntentId: String) { val paymentIntent = findPaymentIntent(paymentIntentId) terminal.confirmPaymentIntent( paymentIntent, @@ -410,14 +397,11 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { paymentIntents.remove(paymentIntent.id) result.success(paymentIntent.toApi()) } - }, + } ) } - override fun onCancelPaymentIntent( - result: Result, - paymentIntentId: String, - ) { + override fun onCancelPaymentIntent(result: Result, paymentIntentId: String) { val paymentIntent = findPaymentIntent(paymentIntentId) terminal.cancelPaymentIntent( paymentIntent, @@ -426,7 +410,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { paymentIntents.remove(paymentIntentId) result.success(paymentIntent.toApi()) } - }, + } ) } // endregion @@ -441,7 +425,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { metadata: HashMap?, onBehalfOf: String?, description: String?, - usage: SetupIntentUsageApi?, + usage: SetupIntentUsageApi? ) { terminal.createSetupIntent( SetupIntentParameters.Builder() @@ -456,14 +440,11 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { setupIntents[setupIntent.id] = setupIntent result.success(setupIntent.toApi()) } - }, + } ) } - override fun onRetrieveSetupIntent( - result: Result, - clientSecret: String, - ) { + override fun onRetrieveSetupIntent(result: Result, clientSecret: String) { terminal.retrieveSetupIntent( clientSecret, object : TerminalErrorHandler(result::error), SetupIntentCallback { @@ -471,7 +452,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { setupIntents[setupIntent.id] = setupIntent result.success(setupIntent.toApi()) } - }, + } ) } @@ -480,7 +461,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { operationId: Long, setupIntentId: String, customerConsentCollected: Boolean, - customerCancellationEnabled: Boolean, + customerCancellationEnabled: Boolean ) { val setupIntent = findSetupIntent(setupIntentId) val config = @@ -493,38 +474,32 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { customerConsentCollected = customerConsentCollected, config = config.build(), callback = - object : TerminalErrorHandler(result::error), SetupIntentCallback { - override fun onFailure(e: TerminalException) { - cancelablesCollectSetupIntentPaymentMethod.remove(operationId) - super.onFailure(e) - } - - override fun onSuccess(setupIntent: SetupIntent) { - cancelablesCollectSetupIntentPaymentMethod.remove(operationId) - setupIntents[setupIntent.id] = setupIntent - result.success(setupIntent.toApi()) - } - }, + object : TerminalErrorHandler(result::error), SetupIntentCallback { + override fun onFailure(e: TerminalException) { + cancelablesCollectSetupIntentPaymentMethod.remove(operationId) + super.onFailure(e) + } + + override fun onSuccess(setupIntent: SetupIntent) { + cancelablesCollectSetupIntentPaymentMethod.remove(operationId) + setupIntents[setupIntent.id] = setupIntent + result.success(setupIntent.toApi()) + } + } ) } - override fun onStopCollectSetupIntentPaymentMethod( - result: Result, - operationId: Long, - ) { + override fun onStopCollectSetupIntentPaymentMethod(result: Result, operationId: Long) { cancelablesCollectSetupIntentPaymentMethod .remove(operationId) ?.cancel( object : TerminalErrorHandler(result::error), Callback { override fun onSuccess() = result.success(Unit) - }, + } ) } - override fun onConfirmSetupIntent( - result: Result, - setupIntentId: String, - ) { + override fun onConfirmSetupIntent(result: Result, setupIntentId: String) { val setupIntent = findSetupIntent(setupIntentId) terminal.confirmSetupIntent( setupIntent, @@ -533,14 +508,11 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { setupIntents[setupIntent.id] = setupIntent result.success(setupIntent.toApi()) } - }, + } ) } - override fun onCancelSetupIntent( - result: Result, - setupIntentId: String, - ) { + override fun onCancelSetupIntent(result: Result, setupIntentId: String) { val setupIntent = findSetupIntent(setupIntentId) terminal.cancelSetupIntent( setupIntent, @@ -550,7 +522,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { setupIntents.remove(setupIntent.id) result.success(setupIntent.toApi()) } - }, + } ) } // endregion @@ -567,7 +539,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { metadata: HashMap?, reverseTransfer: Boolean?, refundApplicationFee: Boolean?, - customerCancellationEnabled: Boolean, + customerCancellationEnabled: Boolean ) { val config = RefundConfiguration.Builder().setEnableCustomerCancellation(customerCancellationEnabled) @@ -577,7 +549,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { RefundParameters.Builder( chargeId = chargeId, amount = amount, - currency = currency, + currency = currency ) .let { metadata?.let(it::setMetadata) @@ -585,32 +557,30 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { refundApplicationFee?.let(it::setRefundApplicationFee) it.build() }, + config = config.build(), callback = - object : TerminalErrorHandler(result::error), Callback { - override fun onFailure(e: TerminalException) { - cancelablesCollectRefundPaymentMethod.remove(operationId) - super.onFailure(e) - } - - override fun onSuccess() { - cancelablesCollectRefundPaymentMethod.remove(operationId) - result.success(Unit) - } - }, + object : TerminalErrorHandler(result::error), Callback { + override fun onFailure(e: TerminalException) { + cancelablesCollectRefundPaymentMethod.remove(operationId) + super.onFailure(e) + } + + override fun onSuccess() { + cancelablesCollectRefundPaymentMethod.remove(operationId) + result.success(Unit) + } + } ) } - override fun onStopCollectRefundPaymentMethod( - result: Result, - operationId: Long, - ) { + override fun onStopCollectRefundPaymentMethod(result: Result, operationId: Long) { cancelablesCollectRefundPaymentMethod .remove(operationId) ?.cancel( object : TerminalErrorHandler(result::error), Callback { override fun onSuccess() = result.success(Unit) - }, + } ) } @@ -618,21 +588,18 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { terminal.confirmRefund( object : TerminalErrorHandler(result::error), RefundCallback { override fun onSuccess(refund: Refund) = result.success(refund.toApi()) - }, + } ) } // endregion // region Display information to customers - override fun onSetReaderDisplay( - result: Result, - cart: CartApi, - ) { + override fun onSetReaderDisplay(result: Result, cart: CartApi) { terminal.setReaderDisplay( cart.toHost(), object : TerminalErrorHandler(result::error), Callback { override fun onSuccess() = result.success(Unit) - }, + } ) } @@ -640,7 +607,7 @@ class TerminalPlugin : FlutterPlugin, ActivityAware, TerminalPlatformApi { terminal.clearReaderDisplay( object : TerminalErrorHandler(result::error), Callback { override fun onSuccess() = result.success(Unit) - }, + } ) } // endregion diff --git a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/Utils.kt b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/Utils.kt index 6b0d317..36d6684 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/Utils.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/Utils.kt @@ -15,15 +15,12 @@ fun microsecondsToSeconds(value: Long): Int { return (value * 1000000).toInt() } -fun createApiError( - code: TerminalExceptionCodeApi, - message: String? = null, -): TerminalExceptionApi { +fun createApiError(code: TerminalExceptionCodeApi, message: String? = null): TerminalExceptionApi { return TerminalExceptionApi( code = code, message = message ?: "", stackTrace = null, paymentIntent = null, - apiError = null, + apiError = null ) } 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 b8f1f9b..046b6c3 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 @@ -16,12 +16,12 @@ import kotlinx.coroutines.withContext class PlatformError( val code: String, message: String?, - val details: Any? = null, + val details: Any? = null ) : RuntimeException(message ?: code) class Result( private val result: MethodChannel.Result, - private val serializer: (data: T) -> Any?, + private val serializer: (data: T) -> Any? ) { fun success(data: T) = result.success(serializer(data)) @@ -32,7 +32,7 @@ class Result( class ControllerSink( private val sink: EventChannel.EventSink, - private val serializer: (data: T) -> Any?, + private val serializer: (data: T) -> Any? ) { fun success(data: T) = sink.success(serializer(data)) @@ -50,38 +50,31 @@ interface TerminalPlatformApi { fun onSupportsReadersOfType( deviceType: DeviceTypeApi?, - discoveryConfiguration: DiscoveryConfigurationApi, + discoveryConfiguration: DiscoveryConfigurationApi ): Boolean fun onConnectBluetoothReader( result: Result, serialNumber: String, locationId: String, - autoReconnectOnUnexpectedDisconnect: Boolean, + autoReconnectOnUnexpectedDisconnect: Boolean ) - fun onConnectHandoffReader( - result: Result, - serialNumber: String, - ) + fun onConnectHandoffReader(result: Result, serialNumber: String) fun onConnectInternetReader( result: Result, serialNumber: String, - failIfInUse: Boolean, + failIfInUse: Boolean ) - fun onConnectMobileReader( - result: Result, - serialNumber: String, - locationId: String, - ) + fun onConnectMobileReader(result: Result, serialNumber: String, locationId: String) fun onConnectUsbReader( result: Result, serialNumber: String, locationId: String, - autoReconnectOnUnexpectedDisconnect: Boolean, + autoReconnectOnUnexpectedDisconnect: Boolean ) fun onGetConnectedReader(): ReaderApi? @@ -92,7 +85,7 @@ interface TerminalPlatformApi { result: Result>, endingBefore: String?, limit: Long?, - startingAfter: String?, + startingAfter: String? ) fun onInstallAvailableUpdate() @@ -107,13 +100,10 @@ interface TerminalPlatformApi { fun onCreatePaymentIntent( result: Result, - parameters: PaymentIntentParametersApi, + parameters: PaymentIntentParametersApi ) - fun onRetrievePaymentIntent( - result: Result, - clientSecret: String, - ) + fun onRetrievePaymentIntent(result: Result, clientSecret: String) fun onStartCollectPaymentMethod( result: Result, @@ -122,23 +112,14 @@ interface TerminalPlatformApi { skipTipping: Boolean, tippingConfiguration: TippingConfigurationApi?, shouldUpdatePaymentIntent: Boolean, - customerCancellationEnabled: Boolean, + customerCancellationEnabled: Boolean ) - fun onStopCollectPaymentMethod( - result: Result, - operationId: Long, - ) + fun onStopCollectPaymentMethod(result: Result, operationId: Long) - fun onConfirmPaymentIntent( - result: Result, - paymentIntentId: String, - ) + fun onConfirmPaymentIntent(result: Result, paymentIntentId: String) - fun onCancelPaymentIntent( - result: Result, - paymentIntentId: String, - ) + fun onCancelPaymentIntent(result: Result, paymentIntentId: String) fun onCreateSetupIntent( result: Result, @@ -146,36 +127,24 @@ interface TerminalPlatformApi { metadata: HashMap?, onBehalfOf: String?, description: String?, - usage: SetupIntentUsageApi?, + usage: SetupIntentUsageApi? ) - fun onRetrieveSetupIntent( - result: Result, - clientSecret: String, - ) + fun onRetrieveSetupIntent(result: Result, clientSecret: String) fun onStartCollectSetupIntentPaymentMethod( result: Result, operationId: Long, setupIntentId: String, customerConsentCollected: Boolean, - customerCancellationEnabled: Boolean, + customerCancellationEnabled: Boolean ) - fun onStopCollectSetupIntentPaymentMethod( - result: Result, - operationId: Long, - ) + fun onStopCollectSetupIntentPaymentMethod(result: Result, operationId: Long) - fun onConfirmSetupIntent( - result: Result, - setupIntentId: String, - ) + fun onConfirmSetupIntent(result: Result, setupIntentId: String) - fun onCancelSetupIntent( - result: Result, - setupIntentId: String, - ) + fun onCancelSetupIntent(result: Result, setupIntentId: String) fun onStartCollectRefundPaymentMethod( result: Result, @@ -186,27 +155,18 @@ interface TerminalPlatformApi { metadata: HashMap?, reverseTransfer: Boolean?, refundApplicationFee: Boolean?, - customerCancellationEnabled: Boolean, + customerCancellationEnabled: Boolean ) - fun onStopCollectRefundPaymentMethod( - result: Result, - operationId: Long, - ) + fun onStopCollectRefundPaymentMethod(result: Result, operationId: Long) fun onConfirmRefund(result: Result) - fun onSetReaderDisplay( - result: Result, - cart: CartApi, - ) + fun onSetReaderDisplay(result: Result, cart: CartApi) fun onClearReaderDisplay(result: Result) - private fun onMethodCall( - call: MethodCall, - result: MethodChannel.Result, - ) { + private fun onMethodCall(call: MethodCall, result: MethodChannel.Result) { try { val args = call.arguments>()!! @@ -235,13 +195,22 @@ interface TerminalPlatformApi { (args[0] as Int?)?.let { DeviceTypeApi.values()[it] }, - (args[1] as List).let { DiscoveryConfigurationApi.deserialize(it) }, + (args[1] as List).let { + DiscoveryConfigurationApi.deserialize( + it + ) + } ) result.success(res) } "connectBluetoothReader" -> { val res = Result(result) { it.serialize() } - onConnectBluetoothReader(res, args[0] as String, args[1] as String, args[2] as Boolean) + onConnectBluetoothReader( + res, + args[0] as String, + args[1] as String, + args[2] as Boolean + ) } "connectHandoffReader" -> { val res = Result(result) { it.serialize() } @@ -257,7 +226,12 @@ interface TerminalPlatformApi { } "connectUsbReader" -> { val res = Result(result) { it.serialize() } - onConnectUsbReader(res, args[0] as String, args[1] as String, args[2] as Boolean) + onConnectUsbReader( + res, + args[0] as String, + args[1] as String, + args[2] as Boolean + ) } "getConnectedReader" -> { val res = onGetConnectedReader() @@ -269,7 +243,12 @@ interface TerminalPlatformApi { } "listLocations" -> { val res = Result>(result) { it.map { it.serialize() } } - onListLocations(res, args[0] as String?, (args[1] as? Number)?.toLong(), args[2] as String?) + onListLocations( + res, + args[0] as String?, + (args[1] as? Number)?.toLong(), + args[2] as String? + ) } "installAvailableUpdate" -> { onInstallAvailableUpdate() @@ -284,7 +263,11 @@ interface TerminalPlatformApi { onDisconnectReader(res) } "setSimulatorConfiguration" -> { - onSetSimulatorConfiguration((args[0] as List).let { SimulatorConfigurationApi.deserialize(it) }) + onSetSimulatorConfiguration( + (args[0] as List).let { + SimulatorConfigurationApi.deserialize(it) + } + ) result.success(null) } "getPaymentStatus" -> { @@ -293,7 +276,12 @@ interface TerminalPlatformApi { } "createPaymentIntent" -> { val res = Result(result) { it.serialize() } - onCreatePaymentIntent(res, (args[0] as List).let { PaymentIntentParametersApi.deserialize(it) }) + onCreatePaymentIntent( + res, + (args[0] as List).let { + PaymentIntentParametersApi.deserialize(it) + } + ) } "retrievePaymentIntent" -> { val res = Result(result) { it.serialize() } @@ -310,7 +298,7 @@ interface TerminalPlatformApi { TippingConfigurationApi.deserialize(it) }, args[4] as Boolean, - args[5] as Boolean, + args[5] as Boolean ) } "stopCollectPaymentMethod" -> { @@ -335,12 +323,12 @@ interface TerminalPlatformApi { *(it as HashMap<*, *>).map { (k, v) -> k as String to v as String - }.toTypedArray(), + }.toTypedArray() ) }, args[2] as String?, args[3] as String?, - (args[4] as Int?)?.let { SetupIntentUsageApi.values()[it] }, + (args[4] as Int?)?.let { SetupIntentUsageApi.values()[it] } ) } "retrieveSetupIntent" -> { @@ -354,7 +342,7 @@ interface TerminalPlatformApi { (args[0] as Number).toLong(), args[1] as String, args[2] as Boolean, - args[3] as Boolean, + args[3] as Boolean ) } "stopCollectSetupIntentPaymentMethod" -> { @@ -378,10 +366,10 @@ interface TerminalPlatformApi { *(it as HashMap<*, *>).map { (k, v) -> k as String to v as String - }.toTypedArray(), + }.toTypedArray() ) }, - args[5] as Boolean?, args[6] as Boolean?, args[7] as Boolean, + args[5] as Boolean?, args[6] as Boolean?, args[7] as Boolean ) } "stopCollectRefundPaymentMethod" -> { @@ -413,7 +401,7 @@ interface TerminalPlatformApi { fun setHandler( binaryMessenger: BinaryMessenger, api: TerminalPlatformApi, - coroutineScope: CoroutineScope? = null, + coroutineScope: CoroutineScope? = null ) { channel = MethodChannel(binaryMessenger, "mek_stripe_terminal#TerminalPlatform") this.coroutineScope = coroutineScope ?: MainScope() @@ -428,27 +416,31 @@ interface TerminalPlatformApi { } class DiscoverReadersControllerApi( - binaryMessenger: BinaryMessenger, + binaryMessenger: BinaryMessenger ) { - private val channel: EventChannel = EventChannel(binaryMessenger, "mek_stripe_terminal#TerminalPlatform#discoverReaders") + private val channel: EventChannel = + EventChannel(binaryMessenger, "mek_stripe_terminal#TerminalPlatform#discoverReaders") fun setHandler( - onListen: (sink: ControllerSink>, configuration: DiscoveryConfigurationApi) -> Unit, - onCancel: () -> Unit, + onListen: ( + sink: ControllerSink>, + configuration: DiscoveryConfigurationApi + ) -> Unit, + onCancel: () -> Unit ) { channel.setStreamHandler( object : EventChannel.StreamHandler { - override fun onListen( - arguments: Any?, - events: EventChannel.EventSink, - ) { + override fun onListen(arguments: Any?, events: EventChannel.EventSink) { val args = arguments as List val sink = ControllerSink>(events) { it.map { it.serialize() } } - onListen(sink, (args[0] as List).let { DiscoveryConfigurationApi.deserialize(it) }) + onListen( + sink, + (args[0] as List).let { DiscoveryConfigurationApi.deserialize(it) } + ) } override fun onCancel(arguments: Any?) = onCancel() - }, + } ) } @@ -456,13 +448,14 @@ class DiscoverReadersControllerApi( } class TerminalHandlersApi( - binaryMessenger: BinaryMessenger, + binaryMessenger: BinaryMessenger ) { - private val channel: MethodChannel = MethodChannel(binaryMessenger, "mek_stripe_terminal#TerminalHandlers") + private val channel: MethodChannel = + MethodChannel(binaryMessenger, "mek_stripe_terminal#TerminalHandlers") fun requestConnectionToken( onError: (error: PlatformError) -> Unit, - onSuccess: (data: String) -> Unit, + onSuccess: (data: String) -> Unit ) { channel.invokeMethod( "_onRequestConnectionToken", @@ -470,14 +463,11 @@ class TerminalHandlersApi( object : MethodChannel.Result { override fun notImplemented() {} - override fun error( - code: String, - message: String?, - details: Any?, - ) = onError(PlatformError(code, message, details)) + override fun error(code: String, message: String?, details: Any?) = + onError(PlatformError(code, message, details)) override fun success(result: Any?) = onSuccess(result as String) - }, + } ) } @@ -508,9 +498,12 @@ class TerminalHandlersApi( fun readerBatteryLevelUpdate( batteryLevel: Double, batteryStatus: BatteryStatusApi?, - isCharging: Boolean, + isCharging: Boolean ) { - channel.invokeMethod("_onReaderBatteryLevelUpdate", listOf(batteryLevel, batteryStatus?.ordinal, isCharging)) + channel.invokeMethod( + "_onReaderBatteryLevelUpdate", + listOf(batteryLevel, batteryStatus?.ordinal, isCharging) + ) } fun readerReportLowBatteryWarning() { @@ -531,9 +524,12 @@ class TerminalHandlersApi( fun readerFinishInstallingUpdate( update: ReaderSoftwareUpdateApi?, - exception: TerminalExceptionApi?, + exception: TerminalExceptionApi? ) { - channel.invokeMethod("_onReaderFinishInstallingUpdate", listOf(update?.serialize(), exception?.serialize())) + channel.invokeMethod( + "_onReaderFinishInstallingUpdate", + listOf(update?.serialize(), exception?.serialize()) + ) } fun readerReconnectFailed(reader: ReaderApi) { @@ -555,7 +551,7 @@ data class AddressApi( val line1: String?, val line2: String?, val postalCode: String?, - val state: String?, + val state: String? ) { fun serialize(): List { return listOf( @@ -564,17 +560,17 @@ data class AddressApi( line1, line2, postalCode, - state, + state ) } } data class AmountDetailsApi( - val tip: TipApi?, + val tip: TipApi? ) { fun serialize(): List { return listOf( - tip?.serialize(), + tip?.serialize() ) } } @@ -582,12 +578,12 @@ data class AmountDetailsApi( enum class BatteryStatusApi { CRITICAL, LOW, - NOMINAL, + NOMINAL } enum class CaptureMethodApi { AUTOMATIC, - MANUAL, + MANUAL } enum class CardBrandApi { @@ -599,7 +595,7 @@ enum class CardBrandApi { UNION_PAY, VISA, INTERAC, - EFTPOS_AU, + EFTPOS_AU } data class CardDetailsApi( @@ -608,7 +604,7 @@ data class CardDetailsApi( val expMonth: Long, val expYear: Long, val funding: CardFundingTypeApi?, - val last4: String?, + val last4: String? ) { fun serialize(): List { return listOf( @@ -617,7 +613,7 @@ data class CardDetailsApi( expMonth, expYear, funding?.ordinal, - last4, + last4 ) } } @@ -625,23 +621,23 @@ data class CardDetailsApi( enum class CardFundingTypeApi { CREDIT, DEBIT, - PREPAID, + PREPAID } data class CardNetworksApi( val available: List, - val preferred: String?, + val preferred: String? ) { fun serialize(): List { return listOf( available.map { it.ordinal }, - preferred, + preferred ) } } enum class CardPresentCaptureMethodApi { - MANUAL_PREFERRED, + MANUAL_PREFERRED } data class CardPresentDetailsApi( @@ -656,7 +652,7 @@ data class CardPresentDetailsApi( val incrementalAuthorizationStatus: IncrementalAuthorizationStatusApi?, val last4: String?, val networks: CardNetworksApi?, - val receipt: ReceiptDetailsApi?, + val receipt: ReceiptDetailsApi? ) { fun serialize(): List { return listOf( @@ -671,7 +667,7 @@ data class CardPresentDetailsApi( incrementalAuthorizationStatus?.ordinal, last4, networks?.serialize(), - receipt?.serialize(), + receipt?.serialize() ) } } @@ -680,7 +676,7 @@ data class CardPresentParametersApi( val captureMethod: CardPresentCaptureMethodApi?, val requestExtendedAuthorization: Boolean?, val requestIncrementalAuthorizationSupport: Boolean?, - val requestedPriority: CardPresentRoutingApi?, + val requestedPriority: CardPresentRoutingApi? ) { companion object { fun deserialize(serialized: List): CardPresentParametersApi { @@ -688,7 +684,7 @@ data class CardPresentParametersApi( captureMethod = (serialized[0] as Int?)?.let { CardPresentCaptureMethodApi.values()[it] }, requestExtendedAuthorization = serialized[1] as Boolean?, requestIncrementalAuthorizationSupport = serialized[2] as Boolean?, - requestedPriority = (serialized[3] as Int?)?.let { CardPresentRoutingApi.values()[it] }, + requestedPriority = (serialized[3] as Int?)?.let { CardPresentRoutingApi.values()[it] } ) } } @@ -696,22 +692,24 @@ data class CardPresentParametersApi( enum class CardPresentRoutingApi { DOMESTIC, - INTERNATIONAL, + INTERNATIONAL } data class CartApi( val currency: String, val lineItems: List, val tax: Long, - val total: Long, + val total: Long ) { companion object { fun deserialize(serialized: List): CartApi { return CartApi( currency = serialized[0] as String, - lineItems = (serialized[1] as List<*>).map { (it as List).let { CartLineItemApi.deserialize(it) } }, + lineItems = (serialized[1] as List<*>).map { + (it as List).let { CartLineItemApi.deserialize(it) } + }, tax = (serialized[2] as Number).toLong(), - total = (serialized[3] as Number).toLong(), + total = (serialized[3] as Number).toLong() ) } } @@ -720,14 +718,14 @@ data class CartApi( data class CartLineItemApi( val amount: Long, val description: String, - val quantity: Long, + val quantity: Long ) { companion object { fun deserialize(serialized: List): CartLineItemApi { return CartLineItemApi( amount = (serialized[0] as Number).toLong(), description = serialized[1] as String, - quantity = (serialized[2] as Number).toLong(), + quantity = (serialized[2] as Number).toLong() ) } } @@ -743,7 +741,7 @@ data class ChargeApi( val metadata: HashMap, val paymentMethodDetails: PaymentMethodDetailsApi?, val statementDescriptorSuffix: String?, - val status: ChargeStatusApi, + val status: ChargeStatusApi ) { fun serialize(): List { return listOf( @@ -756,7 +754,7 @@ data class ChargeApi( hashMapOf(*metadata.map { (k, v) -> k to v }.toTypedArray()), paymentMethodDetails?.serialize(), statementDescriptorSuffix, - status.ordinal, + status.ordinal ) } } @@ -764,18 +762,18 @@ data class ChargeApi( enum class ChargeStatusApi { SUCCEEDED, PENDING, - FAILED, + FAILED } enum class ConfirmationMethodApi { AUTOMATIC, - MANUAL, + MANUAL } enum class ConnectionStatusApi { NOT_CONNECTED, CONNECTED, - CONNECTING, + CONNECTING } enum class DeviceTypeApi { @@ -792,19 +790,31 @@ enum class DeviceTypeApi { ETNA, STRIPE_S700, STRIPE_S700_DEVKIT, - APPLE_BUILT_IN, + APPLE_BUILT_IN } sealed class DiscoveryConfigurationApi { companion object { fun deserialize(serialized: List): DiscoveryConfigurationApi { return when (serialized[0]) { - "BluetoothDiscoveryConfiguration" -> BluetoothDiscoveryConfigurationApi.deserialize(serialized.drop(1)) - "BluetoothProximityDiscoveryConfiguration" -> BluetoothProximityDiscoveryConfigurationApi.deserialize(serialized.drop(1)) - "HandoffDiscoveryConfiguration" -> HandoffDiscoveryConfigurationApi.deserialize(serialized.drop(1)) - "InternetDiscoveryConfiguration" -> InternetDiscoveryConfigurationApi.deserialize(serialized.drop(1)) - "LocalMobileDiscoveryConfiguration" -> LocalMobileDiscoveryConfigurationApi.deserialize(serialized.drop(1)) - "UsbDiscoveryConfiguration" -> UsbDiscoveryConfigurationApi.deserialize(serialized.drop(1)) + "BluetoothDiscoveryConfiguration" -> BluetoothDiscoveryConfigurationApi.deserialize( + serialized.drop(1) + ) + "BluetoothProximityDiscoveryConfiguration" -> BluetoothProximityDiscoveryConfigurationApi.deserialize( + serialized.drop(1) + ) + "HandoffDiscoveryConfiguration" -> HandoffDiscoveryConfigurationApi.deserialize( + serialized.drop(1) + ) + "InternetDiscoveryConfiguration" -> InternetDiscoveryConfigurationApi.deserialize( + serialized.drop(1) + ) + "LocalMobileDiscoveryConfiguration" -> LocalMobileDiscoveryConfigurationApi.deserialize( + serialized.drop(1) + ) + "UsbDiscoveryConfiguration" -> UsbDiscoveryConfigurationApi.deserialize( + serialized.drop(1) + ) else -> throw Error() } } @@ -813,25 +823,25 @@ sealed class DiscoveryConfigurationApi { data class BluetoothDiscoveryConfigurationApi( val isSimulated: Boolean, - val timeout: Long?, + val timeout: Long? ) : DiscoveryConfigurationApi() { companion object { fun deserialize(serialized: List): BluetoothDiscoveryConfigurationApi { return BluetoothDiscoveryConfigurationApi( isSimulated = serialized[0] as Boolean, - timeout = serialized[1] as Long?, + timeout = serialized[1] as Long? ) } } } data class BluetoothProximityDiscoveryConfigurationApi( - val isSimulated: Boolean, + val isSimulated: Boolean ) : DiscoveryConfigurationApi() { companion object { fun deserialize(serialized: List): BluetoothProximityDiscoveryConfigurationApi { return BluetoothProximityDiscoveryConfigurationApi( - isSimulated = serialized[0] as Boolean, + isSimulated = serialized[0] as Boolean ) } } @@ -847,25 +857,25 @@ class HandoffDiscoveryConfigurationApi : DiscoveryConfigurationApi() { data class InternetDiscoveryConfigurationApi( val isSimulated: Boolean, - val locationId: String?, + val locationId: String? ) : DiscoveryConfigurationApi() { companion object { fun deserialize(serialized: List): InternetDiscoveryConfigurationApi { return InternetDiscoveryConfigurationApi( isSimulated = serialized[0] as Boolean, - locationId = serialized[1] as String?, + locationId = serialized[1] as String? ) } } } data class LocalMobileDiscoveryConfigurationApi( - val isSimulated: Boolean, + val isSimulated: Boolean ) : DiscoveryConfigurationApi() { companion object { fun deserialize(serialized: List): LocalMobileDiscoveryConfigurationApi { return LocalMobileDiscoveryConfigurationApi( - isSimulated = serialized[0] as Boolean, + isSimulated = serialized[0] as Boolean ) } } @@ -873,13 +883,13 @@ data class LocalMobileDiscoveryConfigurationApi( data class UsbDiscoveryConfigurationApi( val isSimulated: Boolean, - val timeout: Long?, + val timeout: Long? ) : DiscoveryConfigurationApi() { companion object { fun deserialize(serialized: List): UsbDiscoveryConfigurationApi { return UsbDiscoveryConfigurationApi( isSimulated = serialized[0] as Boolean, - timeout = serialized[1] as Long?, + timeout = serialized[1] as Long? ) } } @@ -887,7 +897,7 @@ data class UsbDiscoveryConfigurationApi( enum class IncrementalAuthorizationStatusApi { NOT_SUPPORTED, - SUPPORTED, + SUPPORTED } data class LocationApi( @@ -895,7 +905,7 @@ data class LocationApi( val displayName: String?, val id: String?, val livemode: Boolean?, - val metadata: HashMap, + val metadata: HashMap ) { fun serialize(): List { return listOf( @@ -903,14 +913,14 @@ data class LocationApi( displayName, id, livemode, - hashMapOf(*metadata.map { (k, v) -> k to v }.toTypedArray()), + hashMapOf(*metadata.map { (k, v) -> k to v }.toTypedArray()) ) } } enum class LocationStatusApi { SET, - NOT_SET, + NOT_SET } data class PaymentIntentApi( @@ -943,7 +953,7 @@ data class PaymentIntentApi( val statementDescriptor: String?, val statementDescriptorSuffix: String?, val status: PaymentIntentStatusApi, - val transferGroup: String?, + val transferGroup: String? ) { fun serialize(): List { return listOf( @@ -976,7 +986,7 @@ data class PaymentIntentApi( statementDescriptor, statementDescriptorSuffix, status.ordinal, - transferGroup, + transferGroup ) } } @@ -997,7 +1007,7 @@ data class PaymentIntentParametersApi( val statementDescriptor: String?, val statementDescriptorSuffix: String?, val transferDataDestination: String?, - val transferGroup: String?, + val transferGroup: String? ) { companion object { fun deserialize(serialized: List): PaymentIntentParametersApi { @@ -1008,16 +1018,22 @@ data class PaymentIntentParametersApi( currency = serialized[3] as String, customerId = serialized[4] as String?, description = serialized[5] as String?, - metadata = hashMapOf(*(serialized[6] as HashMap<*, *>).map { (k, v) -> k as String to v as String }.toTypedArray()), + metadata = hashMapOf( + *(serialized[6] as HashMap<*, *>).map { (k, v) -> k as String to v as String }.toTypedArray() + ), onBehalfOf = serialized[7] as String?, - paymentMethodOptionsParameters = (serialized[8] as List?)?.let { PaymentMethodOptionsParametersApi.deserialize(it) }, - paymentMethodTypes = (serialized[9] as List<*>).map { (it as Int).let { PaymentMethodTypeApi.values()[it] } }, + paymentMethodOptionsParameters = (serialized[8] as List?)?.let { + PaymentMethodOptionsParametersApi.deserialize(it) + }, + paymentMethodTypes = (serialized[9] as List<*>).map { + (it as Int).let { PaymentMethodTypeApi.values()[it] } + }, receiptEmail = serialized[10] as String?, setupFutureUsage = (serialized[11] as Int?)?.let { PaymentIntentUsageApi.values()[it] }, statementDescriptor = serialized[12] as String?, statementDescriptorSuffix = serialized[13] as String?, transferDataDestination = serialized[14] as String?, - transferGroup = serialized[15] as String?, + transferGroup = serialized[15] as String? ) } } @@ -1030,12 +1046,12 @@ enum class PaymentIntentStatusApi { REQUIRES_CONFIRMATION, REQUIRES_PAYMENT_METHOD, REQUIRES_ACTION, - SUCCEEDED, + SUCCEEDED } enum class PaymentIntentUsageApi { ON_SESSION, - OFF_SESSION, + OFF_SESSION } data class PaymentMethodApi( @@ -1044,7 +1060,7 @@ data class PaymentMethodApi( val customerId: String?, val id: String, val interacPresent: CardPresentDetailsApi?, - val metadata: HashMap, + val metadata: HashMap ) { fun serialize(): List { return listOf( @@ -1053,30 +1069,32 @@ data class PaymentMethodApi( customerId, id, interacPresent?.serialize(), - hashMapOf(*metadata.map { (k, v) -> k to v }.toTypedArray()), + hashMapOf(*metadata.map { (k, v) -> k to v }.toTypedArray()) ) } } data class PaymentMethodDetailsApi( val cardPresent: CardPresentDetailsApi?, - val interacPresent: CardPresentDetailsApi?, + val interacPresent: CardPresentDetailsApi? ) { fun serialize(): List { return listOf( cardPresent?.serialize(), - interacPresent?.serialize(), + interacPresent?.serialize() ) } } data class PaymentMethodOptionsParametersApi( - val cardPresentParameters: CardPresentParametersApi, + val cardPresentParameters: CardPresentParametersApi ) { companion object { fun deserialize(serialized: List): PaymentMethodOptionsParametersApi { return PaymentMethodOptionsParametersApi( - cardPresentParameters = (serialized[0] as List).let { CardPresentParametersApi.deserialize(it) }, + cardPresentParameters = (serialized[0] as List).let { + CardPresentParametersApi.deserialize(it) + } ) } } @@ -1085,14 +1103,14 @@ data class PaymentMethodOptionsParametersApi( enum class PaymentMethodTypeApi { CARD_PRESENT, CARD, - INTERACT_PRESENT, + INTERACT_PRESENT } enum class PaymentStatusApi { NOT_READY, READY, WAITING_FOR_INPUT, - PROCESSING, + PROCESSING } data class ReaderApi( @@ -1104,7 +1122,7 @@ data class ReaderApi( val locationId: String?, val locationStatus: LocationStatusApi?, val serialNumber: String, - val simulated: Boolean, + val simulated: Boolean ) { fun serialize(): List { return listOf( @@ -1116,7 +1134,7 @@ data class ReaderApi( locationId, locationStatus?.ordinal, serialNumber, - simulated, + simulated ) } } @@ -1131,19 +1149,19 @@ enum class ReaderDisplayMessageApi { MULTIPLE_CONTACTLESS_CARDS_DETECTED, TRY_ANOTHER_READ_METHOD, TRY_ANOTHER_CARD, - CARD_REMOVED_TOO_EARLY, + CARD_REMOVED_TOO_EARLY } enum class ReaderEventApi { CARD_INSERTED, - CARD_REMOVED, + CARD_REMOVED } enum class ReaderInputOptionApi { INSERT_CARD, SWIPE_CARD, TAP_CARD, - MANUAL_ENTRY, + MANUAL_ENTRY } data class ReaderSoftwareUpdateApi( @@ -1153,7 +1171,7 @@ data class ReaderSoftwareUpdateApi( val requiredAt: Long, val settingsVersion: String?, val timeEstimate: UpdateTimeEstimateApi, - val version: String, + val version: String ) { fun serialize(): List { return listOf( @@ -1163,7 +1181,7 @@ data class ReaderSoftwareUpdateApi( requiredAt, settingsVersion, timeEstimate.ordinal, - version, + version ) } } @@ -1176,7 +1194,7 @@ data class ReceiptDetailsApi( val authorizationResponseCode: String, val dedicatedFileName: String?, val terminalVerificationResults: String?, - val transactionStatusInformation: String?, + val transactionStatusInformation: String? ) { fun serialize(): List { return listOf( @@ -1187,7 +1205,7 @@ data class ReceiptDetailsApi( authorizationResponseCode, dedicatedFileName, terminalVerificationResults, - transactionStatusInformation, + transactionStatusInformation ) } } @@ -1202,7 +1220,7 @@ data class RefundApi( val metadata: HashMap, val paymentMethodDetails: PaymentMethodDetailsApi?, val reason: String?, - val status: RefundStatusApi?, + val status: RefundStatusApi? ) { fun serialize(): List { return listOf( @@ -1215,7 +1233,7 @@ data class RefundApi( hashMapOf(*metadata.map { (k, v) -> k to v }.toTypedArray()), paymentMethodDetails?.serialize(), reason, - status?.ordinal, + status?.ordinal ) } } @@ -1223,7 +1241,7 @@ data class RefundApi( enum class RefundStatusApi { SUCCEEDED, PENDING, - FAILED, + FAILED } data class SetupAttemptApi( @@ -1235,7 +1253,7 @@ data class SetupAttemptApi( val paymentMethodDetails: SetupAttemptPaymentMethodDetailsApi?, val paymentMethodId: String?, val setupIntentId: String, - val status: SetupAttemptStatusApi, + val status: SetupAttemptStatusApi ) { fun serialize(): List { return listOf( @@ -1247,31 +1265,31 @@ data class SetupAttemptApi( paymentMethodDetails?.serialize(), paymentMethodId, setupIntentId, - status.ordinal, + status.ordinal ) } } data class SetupAttemptCardPresentDetailsApi( val emvAuthData: String, - val generatedCard: String, + val generatedCard: String ) { fun serialize(): List { return listOf( emvAuthData, - generatedCard, + generatedCard ) } } data class SetupAttemptPaymentMethodDetailsApi( val cardPresent: SetupAttemptCardPresentDetailsApi?, - val interacPresent: SetupAttemptCardPresentDetailsApi?, + val interacPresent: SetupAttemptCardPresentDetailsApi? ) { fun serialize(): List { return listOf( cardPresent?.serialize(), - interacPresent?.serialize(), + interacPresent?.serialize() ) } } @@ -1282,7 +1300,7 @@ enum class SetupAttemptStatusApi { PROCESSING, SUCCEEDED, FAILED, - ABANDONED, + ABANDONED } data class SetupIntentApi( @@ -1292,7 +1310,7 @@ data class SetupIntentApi( val latestAttempt: SetupAttemptApi?, val metadata: HashMap, val status: SetupIntentStatusApi, - val usage: SetupIntentUsageApi, + val usage: SetupIntentUsageApi ) { fun serialize(): List { return listOf( @@ -1302,7 +1320,7 @@ data class SetupIntentApi( latestAttempt?.serialize(), hashMapOf(*metadata.map { (k, v) -> k to v }.toTypedArray()), status.ordinal, - usage.ordinal, + usage.ordinal ) } } @@ -1313,30 +1331,30 @@ enum class SetupIntentStatusApi { REQUIRES_ACTION, PROCESSING, SUCCEEDED, - CANCELLED, + CANCELLED } enum class SetupIntentUsageApi { ON_SESSION, - OFF_SESSION, + OFF_SESSION } enum class SimulateReaderUpdateApi { AVAILABLE, NONE, REQUIRED, - RANDOM, + RANDOM } data class SimulatedCardApi( val testCardNumber: String?, - val type: SimulatedCardTypeApi?, + val type: SimulatedCardTypeApi? ) { companion object { fun deserialize(serialized: List): SimulatedCardApi { return SimulatedCardApi( testCardNumber = serialized[0] as String?, - type = (serialized[1] as Int?)?.let { SimulatedCardTypeApi.values()[it] }, + type = (serialized[1] as Int?)?.let { SimulatedCardTypeApi.values()[it] } ) } } @@ -1370,20 +1388,24 @@ enum class SimulatedCardTypeApi { ONLINE_PIN_CVM, ONLINE_PIN_SCA_RETRY, OFFLINE_PIN_CVM, - OFFLINE_PIN_SCA_RETRY, + OFFLINE_PIN_SCA_RETRY } data class SimulatorConfigurationApi( val simulatedCard: SimulatedCardApi, val simulatedTipAmount: Long?, - val update: SimulateReaderUpdateApi, + val update: SimulateReaderUpdateApi ) { companion object { fun deserialize(serialized: List): SimulatorConfigurationApi { return SimulatorConfigurationApi( - simulatedCard = (serialized[0] as List).let { SimulatedCardApi.deserialize(it) }, + simulatedCard = (serialized[0] as List).let { + SimulatedCardApi.deserialize( + it + ) + }, simulatedTipAmount = (serialized[1] as? Number)?.toLong(), - update = (serialized[2] as Int).let { SimulateReaderUpdateApi.values()[it] }, + update = (serialized[2] as Int).let { SimulateReaderUpdateApi.values()[it] } ) } } @@ -1394,7 +1416,7 @@ data class TerminalExceptionApi( val code: TerminalExceptionCodeApi, val message: String, val paymentIntent: PaymentIntentApi?, - val stackTrace: String?, + val stackTrace: String? ) { fun serialize(): List { return listOf( @@ -1402,7 +1424,7 @@ data class TerminalExceptionApi( code.ordinal, message, paymentIntent?.serialize(), - stackTrace, + stackTrace ) } } @@ -1527,26 +1549,26 @@ enum class TerminalExceptionCodeApi { TEST_CARD_IN_LIVE_MODE, COLLECT_INPUTS_APPLICATION_ERROR, COLLECT_INPUTS_TIMED_OUT, - COLLECT_INPUTS_UNSUPPORTED, + COLLECT_INPUTS_UNSUPPORTED } data class TipApi( - val amount: Long?, + val amount: Long? ) { fun serialize(): List { return listOf( - amount, + amount ) } } data class TippingConfigurationApi( - val eligibleAmount: Long, + val eligibleAmount: Long ) { companion object { fun deserialize(serialized: List): TippingConfigurationApi { return TippingConfigurationApi( - eligibleAmount = (serialized[0] as Number).toLong(), + eligibleAmount = (serialized[0] as Number).toLong() ) } } @@ -1556,12 +1578,12 @@ enum class UpdateComponentApi { INCREMENTAL, FIRMWARE, CONFIG, - KEYS, + KEYS } enum class UpdateTimeEstimateApi { LESS_THAN_ONE_MINUTE, ONE_TO_TWO_MINUTES, TWO_TO_FIVE_MINUTES, - FIVE_TO_FIFTEEN_MINUTES, + FIVE_TO_FIFTEEN_MINUTES } diff --git a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/CardMappings.kt b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/CardMappings.kt index 83a1311..51c1f9e 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/CardMappings.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/CardMappings.kt @@ -27,7 +27,7 @@ fun CardDetails.toApi(): CardDetailsApi { expMonth = expMonth.toLong(), expYear = expYear.toLong(), funding = fundingToApi(funding), - last4 = last4, + last4 = last4 ) } @@ -68,7 +68,7 @@ fun CardPresentDetails.toApi(): CardPresentDetailsApi { receipt = receiptDetails?.toApi(), emvAuthData = emvAuthData, networks = networks?.toApi(), - incrementalAuthorizationStatus = incrementalAuthorizationStatus.toApi(), + incrementalAuthorizationStatus = incrementalAuthorizationStatus.toApi() ) } @@ -81,17 +81,15 @@ fun ReceiptDetails.toApi(): ReceiptDetailsApi { applicationCryptogram = applicationCryptogram, dedicatedFileName = dedicatedFileName, transactionStatusInformation = tsi, - terminalVerificationResults = tvr, + terminalVerificationResults = tvr ) } fun CardNetworks.toApi(): CardNetworksApi { return CardNetworksApi( available = - available.map { - cardBrandToApi(it)!! - }, - preferred = preferred, + available.map { cardBrandToApi(it)!! }, + preferred = preferred ) } diff --git a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/ChargeMappings.kt b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/ChargeMappings.kt index 93bdac7..2fc54ea 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/ChargeMappings.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/ChargeMappings.kt @@ -11,26 +11,25 @@ fun Charge.toApi(): ChargeApi { return ChargeApi( amount = amount, currency = currency!!, - status = - when (status) { - "pending" -> ChargeStatusApi.PENDING - "failed" -> ChargeStatusApi.FAILED - "succeeded" -> ChargeStatusApi.SUCCEEDED - else -> throw Error("Unsupported $status") - }, + status = when (status) { + "pending" -> ChargeStatusApi.PENDING + "failed" -> ChargeStatusApi.FAILED + "succeeded" -> ChargeStatusApi.SUCCEEDED + else -> throw Error("Unsupported $status") + }, paymentMethodDetails = paymentMethodDetails?.toApi(), description = description, id = id, metadata = metadata?.toHashMap() ?: hashMapOf(), statementDescriptorSuffix = statementDescriptorSuffix, calculatedStatementDescriptor = calculatedStatementDescriptor, - authorizationCode = authorizationCode, + authorizationCode = authorizationCode ) } fun PaymentMethodDetails.toApi(): PaymentMethodDetailsApi { return PaymentMethodDetailsApi( cardPresent = cardPresentDetails?.toApi(), - interacPresent = interacPresentDetails?.toApi(), + interacPresent = interacPresentDetails?.toApi() ) } diff --git a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/ExceptionMappings.kt b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/ExceptionMappings.kt index d13bbc7..98eee50 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/ExceptionMappings.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/ExceptionMappings.kt @@ -20,7 +20,7 @@ fun TerminalException.toApi(): TerminalExceptionApi { message = errorMessage, stackTrace = stackTraceToString(), paymentIntent = paymentIntent?.toApi(), - apiError = apiError?.toString(), + apiError = apiError?.toString() ) } @@ -28,12 +28,9 @@ private fun TerminalException.TerminalErrorCode.toApiCode(): TerminalExceptionCo return when (this) { TerminalException.TerminalErrorCode.CANCEL_FAILED -> TerminalExceptionCodeApi.CANCEL_FAILED TerminalException.TerminalErrorCode.NOT_CONNECTED_TO_READER -> TerminalExceptionCodeApi.NOT_CONNECTED_TO_READER - TerminalException.TerminalErrorCode.ALREADY_CONNECTED_TO_READER -> - TerminalExceptionCodeApi.ALREADY_CONNECTED_TO_READER - TerminalException.TerminalErrorCode.BLUETOOTH_PERMISSION_DENIED -> - TerminalExceptionCodeApi.BLUETOOTH_PERMISSION_DENIED - TerminalException.TerminalErrorCode.CONFIRM_INVALID_PAYMENT_INTENT -> - TerminalExceptionCodeApi.CONFIRM_INVALID_PAYMENT_INTENT + TerminalException.TerminalErrorCode.ALREADY_CONNECTED_TO_READER -> TerminalExceptionCodeApi.ALREADY_CONNECTED_TO_READER + TerminalException.TerminalErrorCode.BLUETOOTH_PERMISSION_DENIED -> TerminalExceptionCodeApi.BLUETOOTH_PERMISSION_DENIED + TerminalException.TerminalErrorCode.CONFIRM_INVALID_PAYMENT_INTENT -> TerminalExceptionCodeApi.CONFIRM_INVALID_PAYMENT_INTENT TerminalException.TerminalErrorCode.INVALID_CLIENT_SECRET -> TerminalExceptionCodeApi.INVALID_CLIENT_SECRET TerminalException.TerminalErrorCode.UNSUPPORTED_OPERATION -> TerminalExceptionCodeApi.UNSUPPORTED_OPERATION TerminalException.TerminalErrorCode.UNEXPECTED_OPERATION -> TerminalExceptionCodeApi.UNEXPECTED_OPERATION @@ -41,115 +38,75 @@ private fun TerminalException.TerminalErrorCode.toApiCode(): TerminalExceptionCo TerminalException.TerminalErrorCode.USB_PERMISSION_DENIED -> TerminalExceptionCodeApi.USB_PERMISSION_DENIED TerminalException.TerminalErrorCode.MISSING_PREREQUISITE -> null TerminalException.TerminalErrorCode.MISSING_REQUIRED_PARAMETER -> TerminalExceptionCodeApi.INVALID_PARAMETER - TerminalException.TerminalErrorCode.INVALID_REQUIRED_PARAMETER -> - TerminalExceptionCodeApi.INVALID_REQUIRED_PARAMETER + TerminalException.TerminalErrorCode.INVALID_REQUIRED_PARAMETER -> TerminalExceptionCodeApi.INVALID_REQUIRED_PARAMETER TerminalException.TerminalErrorCode.INVALID_TIP_PARAMETER -> TerminalExceptionCodeApi.INVALID_TIP_PARAMETER TerminalException.TerminalErrorCode.LOCAL_MOBILE_LIBRARY_NOT_INCLUDED -> null - TerminalException.TerminalErrorCode.LOCAL_MOBILE_UNSUPPORTED_DEVICE -> - TerminalExceptionCodeApi.LOCAL_MOBILE_UNSUPPORTED_DEVICE - TerminalException.TerminalErrorCode.LOCAL_MOBILE_UNSUPPORTED_ANDROID_VERSION -> - TerminalExceptionCodeApi.LOCAL_MOBILE_UNSUPPORTED_OPERATING_SYSTEM_VERSION - TerminalException.TerminalErrorCode.LOCAL_MOBILE_DEVICE_TAMPERED -> - TerminalExceptionCodeApi.LOCAL_MOBILE_DEVICE_TAMPERED - TerminalException.TerminalErrorCode.LOCAL_MOBILE_DEBUG_NOT_SUPPORTED -> - TerminalExceptionCodeApi.LOCAL_MOBILE_DEBUG_NOT_SUPPORTED - TerminalException.TerminalErrorCode.OFFLINE_MODE_UNSUPPORTED_ANDROID_VERSION -> - TerminalExceptionCodeApi.OFFLINE_MODE_UNSUPPORTED_OPERATING_SYSTEM_VERSION + TerminalException.TerminalErrorCode.LOCAL_MOBILE_UNSUPPORTED_DEVICE -> TerminalExceptionCodeApi.LOCAL_MOBILE_UNSUPPORTED_DEVICE + TerminalException.TerminalErrorCode.LOCAL_MOBILE_UNSUPPORTED_ANDROID_VERSION -> TerminalExceptionCodeApi.LOCAL_MOBILE_UNSUPPORTED_OPERATING_SYSTEM_VERSION + TerminalException.TerminalErrorCode.LOCAL_MOBILE_DEVICE_TAMPERED -> TerminalExceptionCodeApi.LOCAL_MOBILE_DEVICE_TAMPERED + TerminalException.TerminalErrorCode.LOCAL_MOBILE_DEBUG_NOT_SUPPORTED -> TerminalExceptionCodeApi.LOCAL_MOBILE_DEBUG_NOT_SUPPORTED + TerminalException.TerminalErrorCode.OFFLINE_MODE_UNSUPPORTED_ANDROID_VERSION -> TerminalExceptionCodeApi.OFFLINE_MODE_UNSUPPORTED_OPERATING_SYSTEM_VERSION TerminalException.TerminalErrorCode.CANCELED -> TerminalExceptionCodeApi.CANCELED - TerminalException.TerminalErrorCode.LOCATION_SERVICES_DISABLED -> - TerminalExceptionCodeApi.LOCATION_SERVICES_DISABLED + TerminalException.TerminalErrorCode.LOCATION_SERVICES_DISABLED -> TerminalExceptionCodeApi.LOCATION_SERVICES_DISABLED TerminalException.TerminalErrorCode.BLUETOOTH_SCAN_TIMED_OUT -> TerminalExceptionCodeApi.BLUETOOTH_SCAN_TIMED_OUT - TerminalException.TerminalErrorCode.BLUETOOTH_LOW_ENERGY_UNSUPPORTED -> - TerminalExceptionCodeApi.BLUETOOTH_LOW_ENERGY_UNSUPPORTED - TerminalException.TerminalErrorCode.READER_SOFTWARE_UPDATE_FAILED_BATTERY_LOW -> - TerminalExceptionCodeApi.READER_SOFTWARE_UPDATE_FAILED_BATTERY_LOW - TerminalException.TerminalErrorCode.READER_SOFTWARE_UPDATE_FAILED_INTERRUPTED -> - TerminalExceptionCodeApi.READER_SOFTWARE_UPDATE_FAILED_INTERRUPTED + TerminalException.TerminalErrorCode.BLUETOOTH_LOW_ENERGY_UNSUPPORTED -> TerminalExceptionCodeApi.BLUETOOTH_LOW_ENERGY_UNSUPPORTED + TerminalException.TerminalErrorCode.READER_SOFTWARE_UPDATE_FAILED_BATTERY_LOW -> TerminalExceptionCodeApi.READER_SOFTWARE_UPDATE_FAILED_BATTERY_LOW + TerminalException.TerminalErrorCode.READER_SOFTWARE_UPDATE_FAILED_INTERRUPTED -> TerminalExceptionCodeApi.READER_SOFTWARE_UPDATE_FAILED_INTERRUPTED TerminalException.TerminalErrorCode.CARD_INSERT_NOT_READ -> TerminalExceptionCodeApi.CARD_INSERT_NOT_READ TerminalException.TerminalErrorCode.CARD_SWIPE_NOT_READ -> TerminalExceptionCodeApi.CARD_SWIPE_NOT_READ TerminalException.TerminalErrorCode.CARD_READ_TIMED_OUT -> TerminalExceptionCodeApi.CARD_READ_TIMED_OUT TerminalException.TerminalErrorCode.CARD_REMOVED -> TerminalExceptionCodeApi.CARD_REMOVED - TerminalException.TerminalErrorCode.CUSTOMER_CONSENT_REQUIRED -> - TerminalExceptionCodeApi.CUSTOMER_CONSENT_REQUIRED + TerminalException.TerminalErrorCode.CUSTOMER_CONSENT_REQUIRED -> TerminalExceptionCodeApi.CUSTOMER_CONSENT_REQUIRED TerminalException.TerminalErrorCode.CARD_LEFT_IN_READER -> TerminalExceptionCodeApi.CARD_LEFT_IN_READER TerminalException.TerminalErrorCode.USB_DISCOVERY_TIMED_OUT -> TerminalExceptionCodeApi.USB_DISCOVERY_TIMED_OUT - TerminalException.TerminalErrorCode.FEATURE_NOT_ENABLED_ON_ACCOUNT -> - TerminalExceptionCodeApi.FEATURE_NOT_ENABLED_ON_ACCOUNT + TerminalException.TerminalErrorCode.FEATURE_NOT_ENABLED_ON_ACCOUNT -> TerminalExceptionCodeApi.FEATURE_NOT_ENABLED_ON_ACCOUNT TerminalException.TerminalErrorCode.READER_BUSY -> TerminalExceptionCodeApi.READER_BUSY - TerminalException.TerminalErrorCode.READER_COMMUNICATION_ERROR -> - TerminalExceptionCodeApi.READER_COMMUNICATION_ERROR + TerminalException.TerminalErrorCode.READER_COMMUNICATION_ERROR -> TerminalExceptionCodeApi.READER_COMMUNICATION_ERROR TerminalException.TerminalErrorCode.BLUETOOTH_ERROR -> TerminalExceptionCodeApi.BLUETOOTH_ERROR TerminalException.TerminalErrorCode.BLUETOOTH_DISCONNECTED -> TerminalExceptionCodeApi.BLUETOOTH_DISCONNECTED - TerminalException.TerminalErrorCode.BLUETOOTH_RECONNECT_STARTED -> - TerminalExceptionCodeApi.BLUETOOTH_RECONNECT_STARTED + TerminalException.TerminalErrorCode.BLUETOOTH_RECONNECT_STARTED -> TerminalExceptionCodeApi.BLUETOOTH_RECONNECT_STARTED TerminalException.TerminalErrorCode.USB_DISCONNECTED -> TerminalExceptionCodeApi.USB_DISCONNECTED TerminalException.TerminalErrorCode.USB_RECONNECT_STARTED -> TerminalExceptionCodeApi.USB_RECONNECT_STARTED - TerminalException.TerminalErrorCode.READER_CONNECTED_TO_ANOTHER_DEVICE -> - TerminalExceptionCodeApi.READER_CONNECTED_TO_ANOTHER_DEVICE - TerminalException.TerminalErrorCode.READER_SOFTWARE_UPDATE_FAILED -> - TerminalExceptionCodeApi.READER_SOFTWARE_UPDATE_FAILED - TerminalException.TerminalErrorCode.READER_SOFTWARE_UPDATE_FAILED_READER_ERROR -> - TerminalExceptionCodeApi.READER_SOFTWARE_UPDATE_FAILED_READER_ERROR - TerminalException.TerminalErrorCode.READER_SOFTWARE_UPDATE_FAILED_SERVER_ERROR -> - TerminalExceptionCodeApi.READER_SOFTWARE_UPDATE_FAILED_SERVER_ERROR + TerminalException.TerminalErrorCode.READER_CONNECTED_TO_ANOTHER_DEVICE -> TerminalExceptionCodeApi.READER_CONNECTED_TO_ANOTHER_DEVICE + TerminalException.TerminalErrorCode.READER_SOFTWARE_UPDATE_FAILED -> TerminalExceptionCodeApi.READER_SOFTWARE_UPDATE_FAILED + TerminalException.TerminalErrorCode.READER_SOFTWARE_UPDATE_FAILED_READER_ERROR -> TerminalExceptionCodeApi.READER_SOFTWARE_UPDATE_FAILED_READER_ERROR + TerminalException.TerminalErrorCode.READER_SOFTWARE_UPDATE_FAILED_SERVER_ERROR -> TerminalExceptionCodeApi.READER_SOFTWARE_UPDATE_FAILED_SERVER_ERROR TerminalException.TerminalErrorCode.LOCAL_MOBILE_NFC_DISABLED -> TerminalExceptionCodeApi.NFC_DISABLED - TerminalException.TerminalErrorCode.UNSUPPORTED_READER_VERSION -> - TerminalExceptionCodeApi.UNSUPPORTED_READER_VERSION + TerminalException.TerminalErrorCode.UNSUPPORTED_READER_VERSION -> TerminalExceptionCodeApi.UNSUPPORTED_READER_VERSION TerminalException.TerminalErrorCode.UNEXPECTED_SDK_ERROR -> TerminalExceptionCodeApi.UNEXPECTED_SDK_ERROR TerminalException.TerminalErrorCode.DECLINED_BY_STRIPE_API -> TerminalExceptionCodeApi.DECLINED_BY_STRIPE_API TerminalException.TerminalErrorCode.DECLINED_BY_READER -> TerminalExceptionCodeApi.DECLINED_BY_READER TerminalException.TerminalErrorCode.REQUEST_TIMED_OUT -> TerminalExceptionCodeApi.REQUEST_TIMED_OUT - TerminalException.TerminalErrorCode.STRIPE_API_CONNECTION_ERROR -> - TerminalExceptionCodeApi.STRIPE_API_CONNECTION_ERROR + TerminalException.TerminalErrorCode.STRIPE_API_CONNECTION_ERROR -> TerminalExceptionCodeApi.STRIPE_API_CONNECTION_ERROR TerminalException.TerminalErrorCode.STRIPE_API_ERROR -> TerminalExceptionCodeApi.STRIPE_API_ERROR - TerminalException.TerminalErrorCode.STRIPE_API_RESPONSE_DECODING_ERROR -> - TerminalExceptionCodeApi.STRIPE_API_RESPONSE_DECODING_ERROR - TerminalException.TerminalErrorCode.CONNECTION_TOKEN_PROVIDER_ERROR -> - TerminalExceptionCodeApi.CONNECTION_TOKEN_PROVIDER_ERROR + TerminalException.TerminalErrorCode.STRIPE_API_RESPONSE_DECODING_ERROR -> TerminalExceptionCodeApi.STRIPE_API_RESPONSE_DECODING_ERROR + TerminalException.TerminalErrorCode.CONNECTION_TOKEN_PROVIDER_ERROR -> TerminalExceptionCodeApi.CONNECTION_TOKEN_PROVIDER_ERROR TerminalException.TerminalErrorCode.SESSION_EXPIRED -> TerminalExceptionCodeApi.SESSION_EXPIRED - TerminalException.TerminalErrorCode.ANDROID_API_LEVEL_ERROR -> - TerminalExceptionCodeApi.UNSUPPORTED_MOBILE_DEVICE_CONFIGURATION - TerminalException.TerminalErrorCode.AMOUNT_EXCEEDS_MAX_OFFLINE_AMOUNT -> - TerminalExceptionCodeApi.AMOUNT_EXCEEDS_MAX_OFFLINE_AMOUNT - TerminalException.TerminalErrorCode.OFFLINE_PAYMENTS_DATABASE_TOO_LARGE -> - TerminalExceptionCodeApi.OFFLINE_PAYMENTS_DATABASE_TOO_LARGE - TerminalException.TerminalErrorCode.READER_CONNECTION_NOT_AVAILABLE_OFFLINE -> - TerminalExceptionCodeApi.READER_CONNECTION_NOT_AVAILABLE_OFFLINE - TerminalException.TerminalErrorCode.LOCATION_CONNECTION_NOT_AVAILABLE_OFFLINE -> - TerminalExceptionCodeApi.LOCATION_CONNECTION_NOT_AVAILABLE_OFFLINE + TerminalException.TerminalErrorCode.ANDROID_API_LEVEL_ERROR -> TerminalExceptionCodeApi.UNSUPPORTED_MOBILE_DEVICE_CONFIGURATION + TerminalException.TerminalErrorCode.AMOUNT_EXCEEDS_MAX_OFFLINE_AMOUNT -> TerminalExceptionCodeApi.AMOUNT_EXCEEDS_MAX_OFFLINE_AMOUNT + TerminalException.TerminalErrorCode.OFFLINE_PAYMENTS_DATABASE_TOO_LARGE -> TerminalExceptionCodeApi.OFFLINE_PAYMENTS_DATABASE_TOO_LARGE + TerminalException.TerminalErrorCode.READER_CONNECTION_NOT_AVAILABLE_OFFLINE -> TerminalExceptionCodeApi.READER_CONNECTION_NOT_AVAILABLE_OFFLINE + TerminalException.TerminalErrorCode.LOCATION_CONNECTION_NOT_AVAILABLE_OFFLINE -> TerminalExceptionCodeApi.LOCATION_CONNECTION_NOT_AVAILABLE_OFFLINE TerminalException.TerminalErrorCode.NO_LAST_SEEN_ACCOUNT -> TerminalExceptionCodeApi.NO_LAST_SEEN_ACCOUNT TerminalException.TerminalErrorCode.INVALID_OFFLINE_CURRENCY -> TerminalExceptionCodeApi.INVALID_OFFLINE_CURRENCY TerminalException.TerminalErrorCode.CARD_SWIPE_NOT_AVAILABLE -> TerminalExceptionCodeApi.CARD_SWIPE_NOT_AVAILABLE - TerminalException.TerminalErrorCode.INTERAC_NOT_SUPPORTED_OFFLINE -> - TerminalExceptionCodeApi.INTERAC_NOT_SUPPORTED_OFFLINE - TerminalException.TerminalErrorCode.ONLINE_PIN_NOT_SUPPORTED_OFFLINE -> - TerminalExceptionCodeApi.ONLINE_PIN_NOT_SUPPORTED_OFFLINE + TerminalException.TerminalErrorCode.INTERAC_NOT_SUPPORTED_OFFLINE -> TerminalExceptionCodeApi.INTERAC_NOT_SUPPORTED_OFFLINE + TerminalException.TerminalErrorCode.ONLINE_PIN_NOT_SUPPORTED_OFFLINE -> TerminalExceptionCodeApi.ONLINE_PIN_NOT_SUPPORTED_OFFLINE TerminalException.TerminalErrorCode.OFFLINE_AND_CARD_EXPIRED -> TerminalExceptionCodeApi.OFFLINE_AND_CARD_EXPIRED - TerminalException.TerminalErrorCode.OFFLINE_TRANSACTION_DECLINED -> - TerminalExceptionCodeApi.OFFLINE_TRANSACTION_DECLINED - TerminalException.TerminalErrorCode.OFFLINE_COLLECT_AND_CONFIRM_MISMATCH -> - TerminalExceptionCodeApi.OFFLINE_COLLECT_AND_CONFIRM_MISMATCH - TerminalException.TerminalErrorCode.OFFLINE_TESTMODE_PAYMENT_IN_LIVEMODE -> - TerminalExceptionCodeApi.FORWARDING_TEST_MODE_PAYMENT_IN_LIVE_MODE - TerminalException.TerminalErrorCode.OFFLINE_LIVEMODE_PAYMENT_IN_TESTMODE -> - TerminalExceptionCodeApi.FORWARDING_LIVE_MODE_PAYMENT_IN_TEST_MODE - TerminalException.TerminalErrorCode.OFFLINE_PAYMENT_INTENT_NOT_FOUND -> - TerminalExceptionCodeApi.OFFLINE_PAYMENT_INTENT_NOT_FOUND + TerminalException.TerminalErrorCode.OFFLINE_TRANSACTION_DECLINED -> TerminalExceptionCodeApi.OFFLINE_TRANSACTION_DECLINED + TerminalException.TerminalErrorCode.OFFLINE_COLLECT_AND_CONFIRM_MISMATCH -> TerminalExceptionCodeApi.OFFLINE_COLLECT_AND_CONFIRM_MISMATCH + TerminalException.TerminalErrorCode.OFFLINE_TESTMODE_PAYMENT_IN_LIVEMODE -> TerminalExceptionCodeApi.FORWARDING_TEST_MODE_PAYMENT_IN_LIVE_MODE + TerminalException.TerminalErrorCode.OFFLINE_LIVEMODE_PAYMENT_IN_TESTMODE -> TerminalExceptionCodeApi.FORWARDING_LIVE_MODE_PAYMENT_IN_TEST_MODE + TerminalException.TerminalErrorCode.OFFLINE_PAYMENT_INTENT_NOT_FOUND -> TerminalExceptionCodeApi.OFFLINE_PAYMENT_INTENT_NOT_FOUND TerminalException.TerminalErrorCode.MISSING_EMV_DATA -> TerminalExceptionCodeApi.MISSING_EMV_DATA - TerminalException.TerminalErrorCode.CONNECTION_TOKEN_PROVIDER_ERROR_WHILE_FORWARDING -> - TerminalExceptionCodeApi.CONNECTION_TOKEN_PROVIDER_ERROR_WHILE_FORWARDING - TerminalException.TerminalErrorCode.ACCOUNT_ID_MISMATCH_WHILE_FORWARDING -> - TerminalExceptionCodeApi.ACCOUNT_ID_MISMATCH_WHILE_FORWARDING - TerminalException.TerminalErrorCode.FORCE_OFFLINE_WITH_FEATURE_DISABLED -> - TerminalExceptionCodeApi.OFFLINE_BEHAVIOR_FORCE_OFFLINE_WITH_FEATURE_DISABLED - TerminalException.TerminalErrorCode.NOT_CONNECTED_TO_INTERNET_AND_REQUIRE_ONLINE_SET -> - TerminalExceptionCodeApi.NOT_CONNECTED_TO_INTERNET_AND_OFFLINE_BEHAVIOR_REQUIRE_ONLINE + TerminalException.TerminalErrorCode.CONNECTION_TOKEN_PROVIDER_ERROR_WHILE_FORWARDING -> TerminalExceptionCodeApi.CONNECTION_TOKEN_PROVIDER_ERROR_WHILE_FORWARDING + TerminalException.TerminalErrorCode.ACCOUNT_ID_MISMATCH_WHILE_FORWARDING -> TerminalExceptionCodeApi.ACCOUNT_ID_MISMATCH_WHILE_FORWARDING + TerminalException.TerminalErrorCode.FORCE_OFFLINE_WITH_FEATURE_DISABLED -> TerminalExceptionCodeApi.OFFLINE_BEHAVIOR_FORCE_OFFLINE_WITH_FEATURE_DISABLED + TerminalException.TerminalErrorCode.NOT_CONNECTED_TO_INTERNET_AND_REQUIRE_ONLINE_SET -> TerminalExceptionCodeApi.NOT_CONNECTED_TO_INTERNET_AND_OFFLINE_BEHAVIOR_REQUIRE_ONLINE TerminalException.TerminalErrorCode.TEST_CARD_IN_LIVEMODE -> TerminalExceptionCodeApi.TEST_CARD_IN_LIVE_MODE - TerminalException.TerminalErrorCode.COLLECT_INPUTS_APPLICATION_ERROR -> - TerminalExceptionCodeApi.COLLECT_INPUTS_APPLICATION_ERROR + TerminalException.TerminalErrorCode.COLLECT_INPUTS_APPLICATION_ERROR -> TerminalExceptionCodeApi.COLLECT_INPUTS_APPLICATION_ERROR TerminalException.TerminalErrorCode.COLLECT_INPUTS_TIMED_OUT -> TerminalExceptionCodeApi.COLLECT_INPUTS_TIMED_OUT TerminalException.TerminalErrorCode.COLLECT_INPUTS_INVALID_PARAMETER -> TerminalExceptionCodeApi.INVALID_PARAMETER - TerminalException.TerminalErrorCode.COLLECT_INPUTS_UNSUPPORTED -> - TerminalExceptionCodeApi.COLLECT_INPUTS_UNSUPPORTED + TerminalException.TerminalErrorCode.COLLECT_INPUTS_UNSUPPORTED -> TerminalExceptionCodeApi.COLLECT_INPUTS_UNSUPPORTED } } diff --git a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/PaymentIntentMappings.kt b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/PaymentIntentMappings.kt index d00c040..68ff739 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/PaymentIntentMappings.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/PaymentIntentMappings.kt @@ -26,15 +26,14 @@ fun PaymentIntent.toApi(): PaymentIntentApi { created = created, status = status!!.toApi(), amount = amount.toDouble(), - captureMethod = - when (captureMethod!!) { - "automatic" -> CaptureMethodApi.AUTOMATIC - "manual" -> CaptureMethodApi.MANUAL - else -> - throw IllegalArgumentException( - "Not supported CaptureMethod '$captureMethod' on PaymentIntent $id", - ) - }, + captureMethod = when (captureMethod!!) { + "automatic" -> CaptureMethodApi.AUTOMATIC + "manual" -> CaptureMethodApi.MANUAL + else -> + throw IllegalArgumentException( + "Not supported CaptureMethod '$captureMethod' on PaymentIntent $id" + ) + }, currency = currency!!, metadata = metadata?.toHashMap() ?: hashMapOf(), charges = getCharges().map { it.toApi() }, @@ -52,25 +51,23 @@ fun PaymentIntent.toApi(): PaymentIntentApi { canceledAt = canceledAt, cancellationReason = cancellationReason, clientSecret = clientSecret, - confirmationMethod = - when (confirmationMethod) { - "automatic" -> ConfirmationMethodApi.AUTOMATIC - "manual" -> ConfirmationMethodApi.MANUAL - else -> null - }, + confirmationMethod = when (confirmationMethod) { + "automatic" -> ConfirmationMethodApi.AUTOMATIC + "manual" -> ConfirmationMethodApi.MANUAL + else -> null + }, description = description, invoiceId = invoice, onBehalfOf = onBehalfOf, receiptEmail = receiptEmail, reviewId = review, - setupFutureUsage = - when (setupFutureUsage) { - "on_session" -> PaymentIntentUsageApi.ON_SESSION - "off_session" -> PaymentIntentUsageApi.OFF_SESSION - else -> null - }, + setupFutureUsage = when (setupFutureUsage) { + "on_session" -> PaymentIntentUsageApi.ON_SESSION + "off_session" -> PaymentIntentUsageApi.OFF_SESSION + else -> null + }, transferGroup = transferGroup, - customerId = customer, + customerId = customer ) } @@ -87,7 +84,7 @@ fun PaymentIntentStatus.toApi(): PaymentIntentStatusApi { fun AmountDetails.toApi(): AmountDetailsApi { return AmountDetailsApi( - tip = tip?.toApi(), + tip = tip?.toApi() ) } @@ -105,19 +102,18 @@ fun PaymentIntentParametersApi.toHost(): PaymentIntentParameters { PaymentIntentParameters.Builder( amount = amount, currency = currency, - captureMethod = - when (captureMethod) { - CaptureMethodApi.MANUAL -> CaptureMethod.Manual - CaptureMethodApi.AUTOMATIC -> CaptureMethod.Automatic - }, + captureMethod = when (captureMethod) { + CaptureMethodApi.MANUAL -> CaptureMethod.Manual + CaptureMethodApi.AUTOMATIC -> CaptureMethod.Automatic + }, allowedPaymentMethodTypes = - paymentMethodTypes.map { - when (it) { - PaymentMethodTypeApi.CARD_PRESENT -> PaymentMethodType.CARD_PRESENT - PaymentMethodTypeApi.CARD -> PaymentMethodType.CARD - PaymentMethodTypeApi.INTERACT_PRESENT -> PaymentMethodType.INTERAC_PRESENT - } - }, + paymentMethodTypes.map { + when (it) { + PaymentMethodTypeApi.CARD_PRESENT -> PaymentMethodType.CARD_PRESENT + PaymentMethodTypeApi.CARD -> PaymentMethodType.CARD + PaymentMethodTypeApi.INTERACT_PRESENT -> PaymentMethodType.INTERAC_PRESENT + } + } ) b.setMetadata(metadata) description?.let(b::setDescription) diff --git a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/PaymentMethod.kt b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/PaymentMethod.kt index 48a30d2..d0f2304 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/PaymentMethod.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/PaymentMethod.kt @@ -11,6 +11,6 @@ fun PaymentMethod.toApi(): PaymentMethodApi { cardPresent = cardPresentDetails?.toApi(), interacPresent = interacPresentDetails?.toApi(), customerId = customer, - metadata = metadata?.toHashMap() ?: hashMapOf(), + metadata = metadata?.toHashMap() ?: hashMapOf() ) } diff --git a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/ReaderMappings.kt b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/ReaderMappings.kt index a3a7489..f03be6f 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/ReaderMappings.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/ReaderMappings.kt @@ -49,7 +49,7 @@ fun Reader.toApi(): ReaderApi { locationId = location?.id, location = location?.toApi(), label = label, - serialNumber = serialNumber!!, + serialNumber = serialNumber!! ) } @@ -86,7 +86,7 @@ fun Location.toApi(): LocationApi { displayName = displayName, id = id, livemode = livemode, - metadata = metadata?.toHashMap() ?: hashMapOf(), + metadata = metadata?.toHashMap() ?: hashMapOf() ) } @@ -97,7 +97,7 @@ fun Address.toApi(): AddressApi { line1 = line1, line2 = line2, postalCode = postalCode, - state = state, + state = state ) } @@ -151,7 +151,7 @@ fun ReaderSoftwareUpdate.toApi(): ReaderSoftwareUpdateApi { requiredAt = requiredAt.time, settingsVersion = settingsVersion, timeEstimate = timeEstimate.toApi(), - version = version, + version = version ) } @@ -184,23 +184,23 @@ fun DiscoveryConfigurationApi.toHost(): DiscoveryConfiguration? { is BluetoothDiscoveryConfigurationApi -> DiscoveryConfiguration.BluetoothDiscoveryConfiguration( isSimulated = isSimulated, - timeout = timeout?.let { microsecondsToSeconds(it) } ?: 0, + timeout = timeout?.let { microsecondsToSeconds(it) } ?: 0 ) is BluetoothProximityDiscoveryConfigurationApi -> null is HandoffDiscoveryConfigurationApi -> DiscoveryConfiguration.HandoffDiscoveryConfiguration() is InternetDiscoveryConfigurationApi -> DiscoveryConfiguration.InternetDiscoveryConfiguration( isSimulated = isSimulated, - location = locationId, + location = locationId ) is LocalMobileDiscoveryConfigurationApi -> DiscoveryConfiguration.LocalMobileDiscoveryConfiguration( - isSimulated = isSimulated, + isSimulated = isSimulated ) is UsbDiscoveryConfigurationApi -> DiscoveryConfiguration.UsbDiscoveryConfiguration( isSimulated = isSimulated, - timeout = timeout?.let { microsecondsToSeconds(it) } ?: 0, + timeout = timeout?.let { microsecondsToSeconds(it) } ?: 0 ) } } @@ -229,7 +229,7 @@ fun CartApi.toHost(): Cart { currency = currency, tax = tax, total = total, - lineItems = lineItems.map { it.toHost() }, + lineItems = lineItems.map { it.toHost() } ) .build() } @@ -238,7 +238,7 @@ fun CartLineItemApi.toHost(): CartLineItem { return CartLineItem.Builder( description = description, quantity = quantity.toInt(), - amount = amount, + amount = amount ) .build() } diff --git a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/RefundMappings.kt b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/RefundMappings.kt index b6dc2bf..a3063e2 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/RefundMappings.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/RefundMappings.kt @@ -14,14 +14,13 @@ fun Refund.toApi(): RefundApi { currency = currency!!, metadata = metadata?.toHashMap() ?: HashMap(), reason = reason, - status = - when (status) { - "succeeded" -> RefundStatusApi.SUCCEEDED - "pending" -> RefundStatusApi.PENDING - "failed" -> RefundStatusApi.FAILED - else -> null - }, + status = when (status) { + "succeeded" -> RefundStatusApi.SUCCEEDED + "pending" -> RefundStatusApi.PENDING + "failed" -> RefundStatusApi.FAILED + else -> null + }, paymentMethodDetails = paymentMethodDetails?.toApi(), - failureReason = failureReason, + failureReason = failureReason ) } diff --git a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/SetupIntentMappings.kt b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/SetupIntentMappings.kt index 313ad36..be166ec 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/SetupIntentMappings.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/SetupIntentMappings.kt @@ -24,7 +24,7 @@ fun SetupIntent.toApi(): SetupIntentApi { metadata = metadata.toHashMap(), usage = usage!!.toApi(), status = status!!.toApi(), - latestAttempt = latestAttempt?.toApi(), + latestAttempt = latestAttempt?.toApi() ) } @@ -56,7 +56,7 @@ fun SetupAttempt.toApi(): SetupAttemptApi { paymentMethodId = paymentMethodId, paymentMethodDetails = paymentMethodDetails.toApi(), setupIntentId = setupIntentId!!, - status = status.toApi(), + status = status.toApi() ) } @@ -74,14 +74,14 @@ fun SetupAttemptStatus.toApi(): SetupAttemptStatusApi { fun SetupIntentPaymentMethodDetails.toApi(): SetupAttemptPaymentMethodDetailsApi { return SetupAttemptPaymentMethodDetailsApi( cardPresent = cardPresentDetails?.toApi(), - interacPresent = interacPresentDetails?.toApi(), + interacPresent = interacPresentDetails?.toApi() ) } fun SetupIntentCardPresentDetails.toApi(): SetupAttemptCardPresentDetailsApi { return SetupAttemptCardPresentDetailsApi( emvAuthData = emvAuthData!!, - generatedCard = generatedCard!!, + generatedCard = generatedCard!! ) } diff --git a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/SimulatorConfigurationMappings.kt b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/SimulatorConfigurationMappings.kt index 546182a..389caf8 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/SimulatorConfigurationMappings.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/SimulatorConfigurationMappings.kt @@ -13,7 +13,7 @@ fun SimulatorConfigurationApi.toHost(): SimulatorConfiguration { return SimulatorConfiguration( update = update.toHost(), simulatedCard = simulatedCard.toHost(), - simulatedTipAmount = simulatedTipAmount, + simulatedTipAmount = simulatedTipAmount ) } diff --git a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/TipMappings.kt b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/TipMappings.kt index 2c04219..150ea1a 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/TipMappings.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/mappings/TipMappings.kt @@ -7,7 +7,7 @@ import mek.stripeterminal.api.TippingConfigurationApi fun Tip.toApi(): TipApi { return TipApi( - amount = amount, + amount = amount ) } 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 7b70114..aa4541f 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 @@ -31,15 +31,12 @@ class DiscoverReadersSubject { } @SuppressLint("MissingPermission") - fun onListen( - sink: ControllerSink>, - configuration: DiscoveryConfigurationApi, - ) { + fun onListen(sink: ControllerSink>, configuration: DiscoveryConfigurationApi) { val hostConfiguration = configuration.toHost() if (hostConfiguration == null) { sink.error( createApiError(TerminalExceptionCodeApi.UNKNOWN, "Discovery method not supported") - .toPlatformError(), + .toPlatformError() ) sink.endOfStream() return @@ -53,27 +50,26 @@ class DiscoverReadersSubject { .discoverReaders( config = hostConfiguration, discoveryListener = - object : DiscoveryListener { - override fun onUpdateDiscoveredReaders(readers: List) { - _readers = readers - runOnMainThread { sink.success(readers.map { it.toApi() }) } - } - }, + object : DiscoveryListener { + override fun onUpdateDiscoveredReaders(readers: List) { + _readers = readers + runOnMainThread { sink.success(readers.map { it.toApi() }) } + } + }, callback = - object : Callback { - override fun onFailure(e: TerminalException) = - runOnMainThread { - if (e.errorCode == TerminalException.TerminalErrorCode.CANCELED) { - return@runOnMainThread - } + object : Callback { + override fun onFailure(e: TerminalException) = runOnMainThread { + if (e.errorCode == TerminalException.TerminalErrorCode.CANCELED) { + return@runOnMainThread + } - cancelable = null - sink.error(e.toPlatformError()) - sink.endOfStream() - } + cancelable = null + sink.error(e.toPlatformError()) + sink.endOfStream() + } - override fun onSuccess() = runOnMainThread { sink.endOfStream() } - }, + override fun onSuccess() = runOnMainThread { sink.endOfStream() } + } ) } diff --git a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/plugin/ReaderDelegatePlugin.kt b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/plugin/ReaderDelegatePlugin.kt index 31fdc29..462011e 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/plugin/ReaderDelegatePlugin.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/plugin/ReaderDelegatePlugin.kt @@ -17,61 +17,51 @@ class ReaderDelegatePlugin(private val _handlers: TerminalHandlersApi) : ReaderListener, HandoffReaderListener { var cancelUpdate: Cancelable? = null - override fun onReportReaderEvent(event: ReaderEvent) = - runOnMainThread { - _handlers.readerReportEvent(event.toApi()) - } + override fun onReportReaderEvent(event: ReaderEvent) = runOnMainThread { + _handlers.readerReportEvent(event.toApi()) + } - override fun onRequestReaderDisplayMessage(message: ReaderDisplayMessage) = - runOnMainThread { - _handlers.readerRequestDisplayMessage(message.toApi()) - } + override fun onRequestReaderDisplayMessage(message: ReaderDisplayMessage) = runOnMainThread { + _handlers.readerRequestDisplayMessage(message.toApi()) + } - override fun onRequestReaderInput(options: ReaderInputOptions) = - runOnMainThread { - _handlers.readerRequestInput(options.options.mapNotNull { it.toApi() }) - } + override fun onRequestReaderInput(options: ReaderInputOptions) = runOnMainThread { + _handlers.readerRequestInput(options.options.mapNotNull { it.toApi() }) + } override fun onBatteryLevelUpdate( batteryLevel: Float, batteryStatus: BatteryStatus, - isCharging: Boolean, + isCharging: Boolean ) = runOnMainThread { _handlers.readerBatteryLevelUpdate( batteryLevel = batteryLevel.toDouble(), batteryStatus = batteryStatus.toApi(), - isCharging = isCharging, + isCharging = isCharging ) } - override fun onReportLowBatteryWarning() = - runOnMainThread { - _handlers.readerReportLowBatteryWarning() - } + override fun onReportLowBatteryWarning() = runOnMainThread { + _handlers.readerReportLowBatteryWarning() + } + + override fun onReportAvailableUpdate(update: ReaderSoftwareUpdate) = runOnMainThread { + _handlers.readerReportAvailableUpdate(update.toApi()) + } - override fun onReportAvailableUpdate(update: ReaderSoftwareUpdate) = + override fun onStartInstallingUpdate(update: ReaderSoftwareUpdate, cancelable: Cancelable?) = runOnMainThread { - _handlers.readerReportAvailableUpdate(update.toApi()) + this.cancelUpdate = cancelable + _handlers.readerStartInstallingUpdate(update.toApi()) } - override fun onStartInstallingUpdate( - update: ReaderSoftwareUpdate, - cancelable: Cancelable?, - ) = runOnMainThread { - this.cancelUpdate = cancelable - _handlers.readerStartInstallingUpdate(update.toApi()) + override fun onReportReaderSoftwareUpdateProgress(progress: Float) = runOnMainThread { + _handlers.readerReportSoftwareUpdateProgress(progress.toDouble()) } - override fun onReportReaderSoftwareUpdateProgress(progress: Float) = + override fun onFinishInstallingUpdate(update: ReaderSoftwareUpdate?, e: TerminalException?) = runOnMainThread { - _handlers.readerReportSoftwareUpdateProgress(progress.toDouble()) + cancelUpdate = null + _handlers.readerFinishInstallingUpdate(update?.toApi(), e?.toApi()) } - - override fun onFinishInstallingUpdate( - update: ReaderSoftwareUpdate?, - e: TerminalException?, - ) = runOnMainThread { - cancelUpdate = null - _handlers.readerFinishInstallingUpdate(update?.toApi(), e?.toApi()) - } } diff --git a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/plugin/ReaderReconnectionListenerPlugin.kt b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/plugin/ReaderReconnectionListenerPlugin.kt index 6599671..cf7a59e 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/plugin/ReaderReconnectionListenerPlugin.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/plugin/ReaderReconnectionListenerPlugin.kt @@ -11,23 +11,19 @@ class ReaderReconnectionListenerPlugin(private val _handlers: TerminalHandlersAp ReaderReconnectionListener { var cancelReconnect: Cancelable? = null - override fun onReaderReconnectStarted( - reader: Reader, - cancelReconnect: Cancelable, - ) = runOnMainThread { - this.cancelReconnect = cancelReconnect - _handlers.readerReconnectStarted(reader.toApi()) - } - - override fun onReaderReconnectFailed(reader: Reader) = + override fun onReaderReconnectStarted(reader: Reader, cancelReconnect: Cancelable) = runOnMainThread { - cancelReconnect = null - _handlers.readerReconnectFailed(reader.toApi()) + this.cancelReconnect = cancelReconnect + _handlers.readerReconnectStarted(reader.toApi()) } - override fun onReaderReconnectSucceeded(reader: Reader) = - runOnMainThread { - cancelReconnect = null - _handlers.readerReconnectSucceeded(reader.toApi()) - } + override fun onReaderReconnectFailed(reader: Reader) = runOnMainThread { + cancelReconnect = null + _handlers.readerReconnectFailed(reader.toApi()) + } + + override fun onReaderReconnectSucceeded(reader: Reader) = runOnMainThread { + cancelReconnect = null + _handlers.readerReconnectSucceeded(reader.toApi()) + } } diff --git a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/plugin/TerminalDelegatePlugin.kt b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/plugin/TerminalDelegatePlugin.kt index 19cba29..6d2848e 100644 --- a/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/plugin/TerminalDelegatePlugin.kt +++ b/stripe_terminal/android/src/main/kotlin/mek/stripeterminal/plugin/TerminalDelegatePlugin.kt @@ -13,28 +13,28 @@ import mek.stripeterminal.runOnMainThread class TerminalDelegatePlugin(private val _handlers: TerminalHandlersApi) : ConnectionTokenProvider, TerminalListener { - override fun fetchConnectionToken(callback: ConnectionTokenCallback) = - runOnMainThread { - _handlers.requestConnectionToken( - { error -> callback.onFailure(ConnectionTokenException(error.message ?: "", error)) }, - { token -> callback.onSuccess(token) }, - ) - } + override fun fetchConnectionToken(callback: ConnectionTokenCallback) = runOnMainThread { + _handlers.requestConnectionToken( + { error -> + callback.onFailure( + ConnectionTokenException(error.message ?: "", error) + ) + }, + { token -> callback.onSuccess(token) } + ) + } // region Terminal listeners - override fun onConnectionStatusChange(status: ConnectionStatus) = - runOnMainThread { - _handlers.connectionStatusChange(status.toApi()) - } + override fun onConnectionStatusChange(status: ConnectionStatus) = runOnMainThread { + _handlers.connectionStatusChange(status.toApi()) + } - override fun onUnexpectedReaderDisconnect(reader: Reader) = - runOnMainThread { - _handlers.unexpectedReaderDisconnect(reader.toApi()) - } + override fun onUnexpectedReaderDisconnect(reader: Reader) = runOnMainThread { + _handlers.unexpectedReaderDisconnect(reader.toApi()) + } - override fun onPaymentStatusChange(status: PaymentStatus) = - runOnMainThread { - _handlers.paymentStatusChange(status.toApi()) - } + override fun onPaymentStatusChange(status: PaymentStatus) = runOnMainThread { + _handlers.paymentStatusChange(status.toApi()) + } // endregion }