From f81aa17aad880b33fb3eae84843b0b66c8750aa9 Mon Sep 17 00:00:00 2001 From: Ian Lin Date: Fri, 2 Aug 2024 16:49:20 +0800 Subject: [PATCH 1/5] bump SDKs to 3.8.0 --- android/build.gradle | 2 +- .../main/java/com/stripeterminalreactnative/Mappers.kt | 4 ++++ dev-app/ios/Podfile.lock | 10 +++++----- src/types/Reader.ts | 2 ++ stripe-terminal-react-native.podspec | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index a6a01d6b..4b96296c 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -28,7 +28,7 @@ def getExtOrIntegerDefault(name) { return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['StripeTerminalReactNative_' + name]).toInteger() } -def terminalAndroidSdkVersion = '3.7.1' +def terminalAndroidSdkVersion = '3.8.0' def reactNativeSdkVersion = getVersionFromNpm() android { diff --git a/android/src/main/java/com/stripeterminalreactnative/Mappers.kt b/android/src/main/java/com/stripeterminalreactnative/Mappers.kt index 6c573661..9dbe4a20 100644 --- a/android/src/main/java/com/stripeterminalreactnative/Mappers.kt +++ b/android/src/main/java/com/stripeterminalreactnative/Mappers.kt @@ -142,6 +142,8 @@ internal fun mapFromDeviceType(type: DeviceType): String { DeviceType.STRIPE_M2 -> "stripeM2" DeviceType.STRIPE_S700 -> "stripeS700" DeviceType.STRIPE_S700_DEVKIT -> "stripeS700Devkit" + DeviceType.STRIPE_S710 -> "stripeS710" + DeviceType.STRIPE_S710_DEVKIT -> "stripeS710Devkit" DeviceType.UNKNOWN -> "unknown" DeviceType.VERIFONE_P400 -> "verifoneP400" DeviceType.WISECUBE -> "wiseCube" @@ -161,6 +163,8 @@ internal fun mapToDeviceType(type: String): DeviceType? { "stripeM2" -> DeviceType.STRIPE_M2 "stripeS700" -> DeviceType.STRIPE_S700 "stripeS700Devkit" -> DeviceType.STRIPE_S700_DEVKIT + "stripeS710" -> DeviceType.STRIPE_S710 + "stripeS710Devkit" -> DeviceType.STRIPE_S710_DEVKIT "verifoneP400" -> DeviceType.VERIFONE_P400 "wiseCube" -> DeviceType.WISECUBE "wisePad3" -> DeviceType.WISEPAD_3 diff --git a/dev-app/ios/Podfile.lock b/dev-app/ios/Podfile.lock index 9951eb41..d565bc03 100644 --- a/dev-app/ios/Podfile.lock +++ b/dev-app/ios/Podfile.lock @@ -440,11 +440,11 @@ PODS: - SocketRocket (0.6.1) - stripe-terminal-react-native (0.0.1-beta.20): - React-Core - - StripeTerminal (~> 3.7.0) + - StripeTerminal (~> 3.8.0) - stripe-terminal-react-native/Tests (0.0.1-beta.20): - React-Core - - StripeTerminal (~> 3.7.0) - - StripeTerminal (3.7.0) + - StripeTerminal (~> 3.8.0) + - StripeTerminal (3.8.0) - Yoga (1.14.0) DEPENDENCIES: @@ -644,8 +644,8 @@ SPEC CHECKSUMS: RNGestureHandler: 32a01c29ecc9bb0b5bf7bc0a33547f61b4dc2741 RNScreens: 3c2d122f5e08c192e254c510b212306da97d2581 SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 - stripe-terminal-react-native: 319a20a3c4bfbe87ef68959222ed7914cbc5e15d - StripeTerminal: 7188b9f8bb3f3c9f0ad5f18217f26ccb07001988 + stripe-terminal-react-native: a80516d1e73bc3ecad3b4eef44c1d1d178d87335 + StripeTerminal: fd415b94c968581c76e502b6161b358930a670af Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5 PODFILE CHECKSUM: e42df060dac549df682e535ef903a0f36c3e799c diff --git a/src/types/Reader.ts b/src/types/Reader.ts index 5212c0e0..1c2fa2be 100644 --- a/src/types/Reader.ts +++ b/src/types/Reader.ts @@ -97,6 +97,8 @@ export namespace Reader { | 'wisePadEDevkit' | 'stripeS700Devkit' | 'stripeS700' + | 'stripeS710Devkit' + | 'stripeS710' | 'cotsDevice' | 'appleBuiltIn' | 'etna'; diff --git a/stripe-terminal-react-native.podspec b/stripe-terminal-react-native.podspec index 467441d3..a8f7eee2 100644 --- a/stripe-terminal-react-native.podspec +++ b/stripe-terminal-react-native.podspec @@ -21,5 +21,5 @@ Pod::Spec.new do |s| end s.dependency 'React-Core' - s.dependency 'StripeTerminal', '~> 3.7.0' + s.dependency 'StripeTerminal', '~> 3.8.0' end From 5694fae47d7e2972734d4a5e3c902688c814dabe Mon Sep 17 00:00:00 2001 From: Ian Lin Date: Wed, 7 Aug 2024 10:50:42 +0800 Subject: [PATCH 2/5] bump iOS to 3.8.1 --- dev-app/ios/Podfile.lock | 10 +++++----- stripe-terminal-react-native.podspec | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dev-app/ios/Podfile.lock b/dev-app/ios/Podfile.lock index d565bc03..1ed1ec3b 100644 --- a/dev-app/ios/Podfile.lock +++ b/dev-app/ios/Podfile.lock @@ -440,11 +440,11 @@ PODS: - SocketRocket (0.6.1) - stripe-terminal-react-native (0.0.1-beta.20): - React-Core - - StripeTerminal (~> 3.8.0) + - StripeTerminal (~> 3.8.1) - stripe-terminal-react-native/Tests (0.0.1-beta.20): - React-Core - - StripeTerminal (~> 3.8.0) - - StripeTerminal (3.8.0) + - StripeTerminal (~> 3.8.1) + - StripeTerminal (3.8.1) - Yoga (1.14.0) DEPENDENCIES: @@ -644,8 +644,8 @@ SPEC CHECKSUMS: RNGestureHandler: 32a01c29ecc9bb0b5bf7bc0a33547f61b4dc2741 RNScreens: 3c2d122f5e08c192e254c510b212306da97d2581 SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 - stripe-terminal-react-native: a80516d1e73bc3ecad3b4eef44c1d1d178d87335 - StripeTerminal: fd415b94c968581c76e502b6161b358930a670af + stripe-terminal-react-native: 88b439710351cde325e1916c862878eb7b1f78ed + StripeTerminal: 79618e96297bf13eee53177c6888abb0b99c5958 Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5 PODFILE CHECKSUM: e42df060dac549df682e535ef903a0f36c3e799c diff --git a/stripe-terminal-react-native.podspec b/stripe-terminal-react-native.podspec index a8f7eee2..9f91d27a 100644 --- a/stripe-terminal-react-native.podspec +++ b/stripe-terminal-react-native.podspec @@ -21,5 +21,5 @@ Pod::Spec.new do |s| end s.dependency 'React-Core' - s.dependency 'StripeTerminal', '~> 3.8.0' + s.dependency 'StripeTerminal', '~> 3.8.1' end From 00f20d76fea96dc259ebf3f6d4269b24cf5033ed Mon Sep 17 00:00:00 2001 From: Ian Lin Date: Thu, 8 Aug 2024 19:06:34 +0800 Subject: [PATCH 3/5] to support LocalMobileUxConfiguration setting. --- .../com/stripeterminalreactnative/Mappers.kt | 33 ++++++++++++ .../StripeTerminalReactNativeModule.kt | 53 +++++++++++++++++-- src/StripeTerminalSdk.tsx | 4 ++ src/functions.ts | 29 ++++++++++ src/hooks/useStripeTerminal.tsx | 20 +++++++ src/types/index.ts | 36 +++++++++++++ 6 files changed, 171 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/stripeterminalreactnative/Mappers.kt b/android/src/main/java/com/stripeterminalreactnative/Mappers.kt index 9dbe4a20..42587204 100644 --- a/android/src/main/java/com/stripeterminalreactnative/Mappers.kt +++ b/android/src/main/java/com/stripeterminalreactnative/Mappers.kt @@ -19,6 +19,7 @@ import com.stripe.stripeterminal.external.models.ConnectionStatus import com.stripe.stripeterminal.external.models.DeviceType import com.stripe.stripeterminal.external.models.DisconnectReason import com.stripe.stripeterminal.external.models.EmailResult +import com.stripe.stripeterminal.external.models.LocalMobileUxConfiguration import com.stripe.stripeterminal.external.models.Location import com.stripe.stripeterminal.external.models.LocationStatus import com.stripe.stripeterminal.external.models.NetworkStatus @@ -871,3 +872,35 @@ fun mapFromBatteryStatus(status: BatteryStatus): String { else -> { "UNKNOWN" } } } + +fun mapToTapZoneIndicator(indicator: String?): LocalMobileUxConfiguration.TapZoneIndicator { + return when (indicator) { + "default" -> LocalMobileUxConfiguration.TapZoneIndicator.DEFAULT + "above" -> LocalMobileUxConfiguration.TapZoneIndicator.ABOVE + "below" -> LocalMobileUxConfiguration.TapZoneIndicator.BELOW + "front" -> LocalMobileUxConfiguration.TapZoneIndicator.FRONT + "behind" -> LocalMobileUxConfiguration.TapZoneIndicator.BEHIND + else -> LocalMobileUxConfiguration.TapZoneIndicator.DEFAULT + } +} + +fun mapToDarkMode(mode: String?): LocalMobileUxConfiguration.DarkMode { + return when (mode) { + "dark" -> LocalMobileUxConfiguration.DarkMode.DARK + "light" -> LocalMobileUxConfiguration.DarkMode.LIGHT + "system" -> LocalMobileUxConfiguration.DarkMode.SYSTEM + else -> LocalMobileUxConfiguration.DarkMode.SYSTEM + } +} + +fun hexToArgb(color: String): Int { + return try { + val alpha = color.substring(0, 2).toInt(16) + val red = color.substring(2, 4).toInt(16) + val green = color.substring(4, 6).toInt(16) + val blue = color.substring(6, 8).toInt(16) + (alpha shl 24) or (red shl 16) or (green shl 8) or blue + } catch (e: NumberFormatException) { + throw IllegalArgumentException("Invalid ARGB hex format", e) + } +} diff --git a/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt b/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt index c22800d2..a350a1fa 100644 --- a/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt +++ b/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt @@ -24,12 +24,12 @@ import com.stripe.stripeterminal.external.models.Cart import com.stripe.stripeterminal.external.models.CollectConfiguration import com.stripe.stripeterminal.external.models.CollectInputsParameters import com.stripe.stripeterminal.external.models.ConfirmConfiguration -import com.stripe.stripeterminal.external.models.ConnectionStatus import com.stripe.stripeterminal.external.models.CreateConfiguration import com.stripe.stripeterminal.external.models.DiscoveryConfiguration import com.stripe.stripeterminal.external.models.EmailInput import com.stripe.stripeterminal.external.models.Input import com.stripe.stripeterminal.external.models.ListLocationsParameters +import com.stripe.stripeterminal.external.models.LocalMobileUxConfiguration import com.stripe.stripeterminal.external.models.NumericInput import com.stripe.stripeterminal.external.models.OfflineBehavior import com.stripe.stripeterminal.external.models.PaymentIntent @@ -774,7 +774,7 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) : val refundApplicationFee = params.getBoolean("refundApplicationFee") val reverseTransfer = params.getBoolean("reverseTransfer") - var intentParamsBuild = if (!paymentIntentId.isNullOrBlank()) { + val intentParamsBuild = if (!paymentIntentId.isNullOrBlank()) { RefundParameters.Builder( RefundParameters.Id.PaymentIntent(paymentIntentId), amount, @@ -835,7 +835,7 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) : @ReactMethod @Suppress("unused") fun getConnectedReader(promise: Promise) { - promise.resolve((terminal.connectedReader ?: null)?.let { mapFromReader(it) }) + promise.resolve(terminal.connectedReader?.let { mapFromReader(it) }) } @ReactMethod @@ -850,7 +850,7 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) : val textToSpeechViaSpeakers = requireParam(getBoolean(params, "textToSpeechViaSpeakers")) { "You must provide textToSpeechViaSpeakers parameters." } - var readerSettingsParameters = ReaderSettingsParameters.AccessibilityParameters( + val readerSettingsParameters = ReaderSettingsParameters.AccessibilityParameters( textToSpeechViaSpeakers ) terminal.setReaderSettings(readerSettingsParameters, RNReadSettingsCallback(promise)) @@ -1057,6 +1057,51 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) : promise.resolve(mapFromReaderSupportResult(readerSupportResult)) } + @ReactMethod + @Suppress("unused") + fun setLocalMobileUxConfiguration(params: ReadableMap, promise: Promise) = withExceptionResolver(promise) { + val localMobileUxConfigurationBuilder = LocalMobileUxConfiguration.Builder() + + var tapZone: LocalMobileUxConfiguration.TapZone? = null + val tapZoneParam = params.getMap("tapZone") + tapZoneParam?.let { + val tapZoneIndicator = mapToTapZoneIndicator(tapZoneParam.getString("tapZoneIndicator")) + + val tapZonePosition = tapZoneParam.getMap("tapZonePosition")?.let { + LocalMobileUxConfiguration.TapZonePosition.Manual( + it.getDouble("xBias").toFloat(), + it.getDouble("yBias").toFloat()) + } + + val tapZoneBuilder = LocalMobileUxConfiguration.TapZone.Manual.Builder() + tapZoneIndicator.let { tapZoneBuilder.indicator(it) } + tapZonePosition?.let { tapZoneBuilder.position(it) } + tapZone = tapZoneBuilder.build() + } + localMobileUxConfigurationBuilder.tapZone(tapZone?:LocalMobileUxConfiguration.TapZone.Default) + + val colorsParam = params.getMap("colors") + colorsParam?.let { + val colorSchemeBuilder = LocalMobileUxConfiguration.ColorScheme.Builder() + colorSchemeBuilder.apply { + primary(it.getString("primary")?.let { + LocalMobileUxConfiguration.Color.Value(hexToArgb(it)) } ?: + LocalMobileUxConfiguration.Color.Default) + success(it.getString("success")?.let { + LocalMobileUxConfiguration.Color.Value(hexToArgb(it)) } ?: + LocalMobileUxConfiguration.Color.Default) + error(it.getString("error")?.let { + LocalMobileUxConfiguration.Color.Value(hexToArgb(it)) } ?: + LocalMobileUxConfiguration.Color.Default) + } + localMobileUxConfigurationBuilder.colors(colorSchemeBuilder.build()) + } + + localMobileUxConfigurationBuilder.darkMode(mapToDarkMode(params.getString("darkMode"))) + + terminal.setLocalMobileUxConfiguration(localMobileUxConfigurationBuilder.build()) + } + @ReactMethod fun addListener(eventName: String?) { // Set up any upstream listeners or background tasks as necessary diff --git a/src/StripeTerminalSdk.tsx b/src/StripeTerminalSdk.tsx index 4c7f22c6..76c9ecad 100644 --- a/src/StripeTerminalSdk.tsx +++ b/src/StripeTerminalSdk.tsx @@ -37,6 +37,7 @@ import type { ConfirmSetupIntentMethodParams, CancelSetupIntentMethodParams, CancelPaymentMethodParams, + LocalMobileUxConfiguration, } from './types'; const { StripeTerminalReactNative } = NativeModules; @@ -168,6 +169,9 @@ export interface StripeTerminalSdkType { supportsReadersOfType( params: Reader.ReaderSupportParams ): Promise; + setLocalMobileUxConfiguration(params: LocalMobileUxConfiguration): Promise<{ + error?: StripeError; + }>; } export default StripeTerminalReactNative as StripeTerminalSdkType; diff --git a/src/functions.ts b/src/functions.ts index 4a256a37..9c95a393 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -38,7 +38,10 @@ import type { ConfirmSetupIntentMethodParams, CancelSetupIntentMethodParams, CancelPaymentMethodParams, + LocalMobileUxConfiguration, } from './types'; +import { CommonError } from './types'; +import { Platform } from 'react-native'; export async function initialize( params: InitParams @@ -924,3 +927,29 @@ export async function supportsReadersOfType( } }, 'supportsReadersOfType')(); } + +export async function setLocalMobileUxConfiguration( + params: LocalMobileUxConfiguration +): Promise<{ + error?: StripeError; +}> { + if (Platform.OS === 'ios') { + return { + error: { + message: "'setLocalMobileUxConfiguration' is unsupported on iOS", + code: CommonError.Failed, + }, + }; + } + + return Logger.traceSdkMethod(async () => { + try { + await StripeTerminalSdk.setLocalMobileUxConfiguration(params); + return {}; + } catch (error) { + return { + error: error as any, + }; + } + }, 'setLocalMobileUxConfiguration')(); +} diff --git a/src/hooks/useStripeTerminal.tsx b/src/hooks/useStripeTerminal.tsx index 4d5538ec..38386d2e 100644 --- a/src/hooks/useStripeTerminal.tsx +++ b/src/hooks/useStripeTerminal.tsx @@ -26,6 +26,7 @@ import type { ConfirmSetupIntentMethodParams, CancelSetupIntentMethodParams, CancelPaymentMethodParams, + LocalMobileUxConfiguration, } from '../types'; import { discoverReaders, @@ -70,6 +71,7 @@ import { getPaymentStatus, getConnectionStatus, getConnectedReader, + setLocalMobileUxConfiguration, } from '../functions'; import { StripeTerminalContext } from '../components/StripeTerminalContext'; import { useListener } from './useListener'; @@ -1024,6 +1026,23 @@ export function useStripeTerminal(props?: Props) { [_isInitialized, setLoading] ); + const _setLocalMobileUxConfiguration = useCallback( + async (params: LocalMobileUxConfiguration) => { + if (!_isInitialized()) { + console.error(NOT_INITIALIZED_ERROR_MESSAGE); + throw Error(NOT_INITIALIZED_ERROR_MESSAGE); + } + setLoading(true); + + const response = await setLocalMobileUxConfiguration(params); + + setLoading(false); + + return response; + }, + [_isInitialized, setLoading] + ); + return { initialize: _initialize, discoverReaders: _discoverReaders, @@ -1068,6 +1087,7 @@ export function useStripeTerminal(props?: Props) { cancelCollectInputs: _cancelCollectInputs, cancelReaderReconnection: _cancelReaderReconnection, supportsReadersOfType: _supportsReadersOfType, + setLocalMobileUxConfiguration: _setLocalMobileUxConfiguration, emitter: emitter, discoveredReaders, connectedReader, diff --git a/src/types/index.ts b/src/types/index.ts index 0289f29d..e67dab6f 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -491,3 +491,39 @@ export type AmountDetails = { export type Amount = { amount: number; }; + +export type LocalMobileUxConfiguration = { + tapZone: TapZone; + darkMode: DarkMode; + colors: Colors; +}; + +export type TapZone = { + tapZoneIndicator: TapZoneIndicator; + tapZonePosition: TapZonePosition; +}; + +export type TapZonePosition = { + xBias: number; + yBias: number; +}; + +export enum TapZoneIndicator { + DEFAULT = 'default', + ABOVE = 'above', + BELOW = 'below', + FRONT = 'front', + BEHIND = 'behind', +} + +export type Colors = { + primary: string; + success: string; + error: string; +}; + +export enum DarkMode { + DARK = 'dark', + LIGHT = 'light', + SYSTEM = 'system', +} From 6eb8ecadb49187955693540c3b11fc99fcbf1606 Mon Sep 17 00:00:00 2001 From: Ian Lin Date: Thu, 8 Aug 2024 19:24:31 +0800 Subject: [PATCH 4/5] update snapshots. --- src/__tests__/__snapshots__/functions.test.ts.snap | 1 + src/__tests__/__snapshots__/index.test.tsx.snap | 12 ++++++++++++ .../__snapshots__/useStripeTerminal.test.tsx.snap | 1 + 3 files changed, 14 insertions(+) diff --git a/src/__tests__/__snapshots__/functions.test.ts.snap b/src/__tests__/__snapshots__/functions.test.ts.snap index 8be3df81..ed99eedb 100644 --- a/src/__tests__/__snapshots__/functions.test.ts.snap +++ b/src/__tests__/__snapshots__/functions.test.ts.snap @@ -41,6 +41,7 @@ Object { "retrievePaymentIntent": [Function], "retrieveSetupIntent": [Function], "setConnectionToken": [Function], + "setLocalMobileUxConfiguration": [Function], "setReaderDisplay": [Function], "setReaderSettings": [Function], "setSimulatedCard": [Function], diff --git a/src/__tests__/__snapshots__/index.test.tsx.snap b/src/__tests__/__snapshots__/index.test.tsx.snap index 793e6d54..21ad7a9d 100644 --- a/src/__tests__/__snapshots__/index.test.tsx.snap +++ b/src/__tests__/__snapshots__/index.test.tsx.snap @@ -10,6 +10,11 @@ Object { "Failed": "Failed", "Unknown": "Unknown", }, + "DarkMode": Object { + "DARK": "dark", + "LIGHT": "light", + "SYSTEM": "system", + }, "FETCH_TOKEN_PROVIDER": "FETCH_TOKEN_PROVIDER", "FINISH_DISCOVERING_READERS": "FINISH_DISCOVERING_READERS", "FINISH_INSTALLING_UPDATE": "FINISH_INSTALLING_UPDATE", @@ -52,6 +57,13 @@ Object { }, "StripeTerminalProvider": [Function], "StripeTerminalProviderProps": undefined, + "TapZoneIndicator": Object { + "ABOVE": "above", + "BEHIND": "behind", + "BELOW": "below", + "DEFAULT": "default", + "FRONT": "front", + }, "ToggleResult": Object { "DISABLED": "disabled", "ENABLED": "enabled", diff --git a/src/hooks/__tests__/__snapshots__/useStripeTerminal.test.tsx.snap b/src/hooks/__tests__/__snapshots__/useStripeTerminal.test.tsx.snap index 4bc9d79f..1cadf20b 100644 --- a/src/hooks/__tests__/__snapshots__/useStripeTerminal.test.tsx.snap +++ b/src/hooks/__tests__/__snapshots__/useStripeTerminal.test.tsx.snap @@ -46,6 +46,7 @@ Object { "rebootReader": [Function], "retrievePaymentIntent": [Function], "retrieveSetupIntent": [Function], + "setLocalMobileUxConfiguration": [Function], "setReaderDisplay": [Function], "setReaderSettings": [Function], "setSimulatedCard": [Function], From 56dd0052552affc562207aa5aba373088a32d129 Mon Sep 17 00:00:00 2001 From: Ian Lin Date: Fri, 9 Aug 2024 17:12:54 +0800 Subject: [PATCH 5/5] some improvements --- .../com/stripeterminalreactnative/Mappers.kt | 11 +++----- .../StripeTerminalReactNativeModule.kt | 28 +++++++++---------- src/types/index.ts | 16 +++++------ 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/android/src/main/java/com/stripeterminalreactnative/Mappers.kt b/android/src/main/java/com/stripeterminalreactnative/Mappers.kt index c835f82c..717603fa 100644 --- a/android/src/main/java/com/stripeterminalreactnative/Mappers.kt +++ b/android/src/main/java/com/stripeterminalreactnative/Mappers.kt @@ -1,5 +1,6 @@ package com.stripeterminalreactnative +import android.graphics.Color import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.WritableArray @@ -906,18 +907,14 @@ fun mapToDarkMode(mode: String?): LocalMobileUxConfiguration.DarkMode { "dark" -> LocalMobileUxConfiguration.DarkMode.DARK "light" -> LocalMobileUxConfiguration.DarkMode.LIGHT "system" -> LocalMobileUxConfiguration.DarkMode.SYSTEM - else -> LocalMobileUxConfiguration.DarkMode.SYSTEM + else -> LocalMobileUxConfiguration.DarkMode.LIGHT } } fun hexToArgb(color: String): Int { return try { - val alpha = color.substring(0, 2).toInt(16) - val red = color.substring(2, 4).toInt(16) - val green = color.substring(4, 6).toInt(16) - val blue = color.substring(6, 8).toInt(16) - (alpha shl 24) or (red shl 16) or (green shl 8) or blue - } catch (e: NumberFormatException) { + Color.parseColor(color) + } catch (e: IllegalArgumentException) { throw IllegalArgumentException("Invalid ARGB hex format", e) } } diff --git a/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt b/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt index 61a75721..21904b3c 100644 --- a/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt +++ b/android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt @@ -1096,12 +1096,12 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) : LocalMobileUxConfiguration.TapZonePosition.Manual( it.getDouble("xBias").toFloat(), it.getDouble("yBias").toFloat()) - } + } ?: LocalMobileUxConfiguration.TapZonePosition.Default - val tapZoneBuilder = LocalMobileUxConfiguration.TapZone.Manual.Builder() - tapZoneIndicator.let { tapZoneBuilder.indicator(it) } - tapZonePosition?.let { tapZoneBuilder.position(it) } - tapZone = tapZoneBuilder.build() + tapZone = LocalMobileUxConfiguration.TapZone.Manual.Builder() + .indicator(tapZoneIndicator) + .position(tapZonePosition) + .build() } localMobileUxConfigurationBuilder.tapZone(tapZone?:LocalMobileUxConfiguration.TapZone.Default) @@ -1109,15 +1109,9 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) : colorsParam?.let { val colorSchemeBuilder = LocalMobileUxConfiguration.ColorScheme.Builder() colorSchemeBuilder.apply { - primary(it.getString("primary")?.let { - LocalMobileUxConfiguration.Color.Value(hexToArgb(it)) } ?: - LocalMobileUxConfiguration.Color.Default) - success(it.getString("success")?.let { - LocalMobileUxConfiguration.Color.Value(hexToArgb(it)) } ?: - LocalMobileUxConfiguration.Color.Default) - error(it.getString("error")?.let { - LocalMobileUxConfiguration.Color.Value(hexToArgb(it)) } ?: - LocalMobileUxConfiguration.Color.Default) + primary(it.getString("primary").toLocalMobileColor()) + success(it.getString("success").toLocalMobileColor()) + error(it.getString("error").toLocalMobileColor()) } localMobileUxConfigurationBuilder.colors(colorSchemeBuilder.build()) } @@ -1127,6 +1121,12 @@ class StripeTerminalReactNativeModule(reactContext: ReactApplicationContext) : terminal.setLocalMobileUxConfiguration(localMobileUxConfigurationBuilder.build()) } + private fun String?.toLocalMobileColor(): LocalMobileUxConfiguration.Color { + return this + ?.let { LocalMobileUxConfiguration.Color.Value(hexToArgb(it)) } + ?: LocalMobileUxConfiguration.Color.Default + } + @ReactMethod fun addListener(eventName: String?) { // Set up any upstream listeners or background tasks as necessary diff --git a/src/types/index.ts b/src/types/index.ts index 2151e52d..200e3f6e 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -519,14 +519,14 @@ export type CollectDataResultType = }; export type LocalMobileUxConfiguration = { - tapZone: TapZone; - darkMode: DarkMode; - colors: Colors; + tapZone?: TapZone; + darkMode?: DarkMode; + colors?: Colors; }; export type TapZone = { - tapZoneIndicator: TapZoneIndicator; - tapZonePosition: TapZonePosition; + tapZoneIndicator?: TapZoneIndicator; + tapZonePosition?: TapZonePosition; }; export type TapZonePosition = { @@ -543,9 +543,9 @@ export enum TapZoneIndicator { } export type Colors = { - primary: string; - success: string; - error: string; + primary?: string; + success?: string; + error?: string; }; export enum DarkMode {